make buffer bigger
This commit is contained in:
parent
a7fccc35a1
commit
1a0035bfed
1 changed files with 10 additions and 7 deletions
|
@ -9,9 +9,9 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
nSamples = 6000
|
||||
sampleRate = 6000
|
||||
nSamplesPerUpdate = 1400
|
||||
nSamples = 44000 * 10
|
||||
sampleRate = 44000
|
||||
bufferSize = nSamples
|
||||
frequency = 440
|
||||
targetFPS = 240
|
||||
)
|
||||
|
@ -19,6 +19,9 @@ const (
|
|||
func main() {
|
||||
rl.InitWindow(800, 450, "raylib [audio] example - raw audio streaming")
|
||||
position := rl.NewVector2(0, 0)
|
||||
|
||||
rl.SetAudioStreamBufferSizeDefault(bufferSize)
|
||||
|
||||
rl.InitAudioDevice()
|
||||
|
||||
// Init raw audio stream (sample rate: <nSamples>, sample size: 32bit-float, channels: 1-mono)
|
||||
|
@ -43,10 +46,10 @@ func main() {
|
|||
if rl.IsAudioStreamProcessed(stream) {
|
||||
elapsedTime := time.Since(startTime).Seconds()
|
||||
currentSampleIndex := int(math.Mod(elapsedTime*float64(sampleRate), float64(nSamples)))
|
||||
nextSampleIndex := currentSampleIndex + nSamplesPerUpdate
|
||||
nextSampleIndex := currentSampleIndex + bufferSize
|
||||
|
||||
if nextSampleIndex > nSamples {
|
||||
nextSampleIndex = nSamplesPerUpdate - (nSamples - currentSampleIndex)
|
||||
nextSampleIndex = bufferSize - (nSamples - currentSampleIndex)
|
||||
rl.UpdateAudioStream(stream, append(data[currentSampleIndex:], data[:nextSampleIndex]...))
|
||||
} else {
|
||||
rl.UpdateAudioStream(stream, data[currentSampleIndex:nextSampleIndex])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue