Merge pull request #111 from juan-medina/master

Adding multichannel audio functions
This commit is contained in:
Milan Nikolic 2020-09-01 18:09:49 +02:00 committed by GitHub
commit fd64d4172a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 84 additions and 0 deletions

View file

@ -0,0 +1,66 @@
package main
import (
"fmt"
"github.com/gen2brain/raylib-go/raylib"
)
func main() {
// Initialization
//--------------------------------------------------------------------------------------
screenWidth := int32(800)
screenHeight := int32(450)
rl.InitWindow(screenWidth, screenHeight, "raylib [audio] example - Multichannel sound playing")
rl.InitAudioDevice() // Initialize audio device
fxWav := rl.LoadSound("sound.wav") // Load WAV audio file
fxOgg := rl.LoadSound("target.ogg") // Load OGG audio file
rl.SetSoundVolume(fxWav, 0.2)
rl.SetTargetFPS(60) // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
// Main game loop
for !rl.WindowShouldClose() { // Detect window close button or ESC key
// Update
//----------------------------------------------------------------------------------
if rl.IsKeyPressed(rl.KeyEnter) {
rl.PlaySoundMulti(fxWav)
} // Play a new wav sound instance
if rl.IsKeyPressed(rl.KeySpace) {
rl.PlaySoundMulti(fxOgg)
} // Play a new ogg sound instance
//----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
rl.BeginDrawing()
rl.ClearBackground(rl.RayWhite)
rl.DrawText("MULTICHANNEL SOUND PLAYING", 20, 20, 20, rl.Gray)
rl.DrawText("Press SPACE to play new ogg instance!", 200, 120, 20, rl.LightGray)
rl.DrawText("Press ENTER to play new wav instance!", 200, 180, 20, rl.LightGray)
rl.DrawText(fmt.Sprintf("CONCURRENT SOUNDS PLAYING: %02d", rl.GetSoundsPlaying()), 220, 280, 20, rl.Red)
rl.EndDrawing()
//----------------------------------------------------------------------------------
}
// De-Initialization
//--------------------------------------------------------------------------------------
rl.StopSoundMulti() // We must stop the buffer pool before unloading
rl.UnloadSound(fxWav) // Unload sound data
rl.UnloadSound(fxOgg) // Unload sound data
rl.CloseAudioDevice() // Close audio device
rl.CloseWindow() // Close window and OpenGL context
//--------------------------------------------------------------------------------------
}

Binary file not shown.

Binary file not shown.

View file

@ -334,3 +334,21 @@ func StopAudioStream(stream AudioStream) {
cstream := stream.cptr()
C.StopAudioStream(*cstream)
}
// PlaySoundMulti - Play a sound (using multichannel buffer pool)
func PlaySoundMulti(sound Sound) {
csound := sound.cptr()
C.PlaySoundMulti(*csound)
}
// GetSoundsPlaying - Get number of sounds playing in the multichannel
func GetSoundsPlaying() int {
ret := C.GetSoundsPlaying()
v := int(ret)
return v
}
// StopSoundMulti - Stop any sound playing (using multichannel buffer pool)
func StopSoundMulti() {
C.StopSoundMulti()
}