Adding multichannel audio functions

This commit is contained in:
Juan Medina 2020-09-01 16:42:44 +01:00
parent f2de21371c
commit 01e81219da
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() cstream := stream.cptr()
C.StopAudioStream(*cstream) 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()
}