ebitengine / oto

♪ A low-level library to play sound on multiple platforms ♪
Apache License 2.0
1.59k stars 133 forks source link

question about example #240

Open gucio321 opened 3 months ago

gucio321 commented 3 months ago

Hi there!

context

I'm working on a morse code generator app. I've based my code on oto's example (sine wave is exactly what I needed).

My issue

After implementing the code in my app I noticed 2 issues:

stuckReduction is a constant, which for me is 300 but could be reducd probably to about 100/200.

Let me know if my notes are worth adding to the example :smile:.

hajimehoshi commented 3 months ago

Does the current example cause crash? Then, could you file an issue and send a PR? Thanks,

hajimehoshi commented 3 months ago

Or, if the crash happens in your app, I need to see your code...

gucio321 commented 3 months ago

Well, I didn't manage to reproduce this crash with an example yet, maybe it is related to my Seek implementation or something?

my code is here: https://github.com/gucio321/morse/blob/master/pkg/generator/sine_wave.go try to comment out m.Lock/Unlock calls, then run cmd/gnerator. sometimes sounds are too long, sometimes (rarely) it crashes

gucio321 commented 3 months ago

you can run this: while true; do go run .; done

and after some time you should get

panic: runtime error: slice bounds out of range [:-17280]

goroutine 6 [running]:
github.com/gucio32/morse/pkg/generator.(*SineWave).Read(0xc000096af0, {0xc0000b0000?, 0x482fa9?, 0x0?})
        /home/me/git/morse/pkg/generator/sine_wave.go:54 +0x4f7
github.com/ebitengine/oto/v3/internal/mux.(*playerImpl).read(0xc0000bc000?, {0xc0000b0000?, 0xc000096b50?, 0x481200?})
        /home/me/go/pkg/mod/github.com/ebitengine/oto/v3@v3.2.0/internal/mux/mux.go:268 +0xc8
github.com/ebitengine/oto/v3/internal/mux.(*playerImpl).readSourceToBuffer(0xc0000aa1b0)
        /home/me/go/pkg/mod/github.com/ebitengine/oto/v3@v3.2.0/internal/mux/mux.go:529 +0x145
github.com/ebitengine/oto/v3/internal/mux.(*Mux).loop(0xc00008a0c0)
        /home/me/go/pkg/mod/github.com/ebitengine/oto/v3@v3.2.0/internal/mux/mux.go:108 +0x205
created by github.com/ebitengine/oto/v3/internal/mux.New in goroutine 1
        /home/me/go/pkg/mod/github.com/ebitengine/oto/v3@v3.2.0/internal/mux/mux.go:69 +0xf8
exit status 2
hajimehoshi commented 3 months ago

Oto implementation also uses mutex so Seek should be thread safe. I'll take a look later, but I hope you could create a more minimal case to reproduce the issue. Thanks,

hajimehoshi commented 3 months ago

You should return an error when p.pos < 0 or p.pos > p.length at Seek at least.

gucio321 commented 3 months ago

I found an interessting thing: if you modify an example like this: https://github.com/gucio321/oto/commit/d969893e144a41939b2a9ed9714f74eb53071bb3 not every sound is played

hajimehoshi commented 3 months ago

OK, please report issues one by one with a minimized test case to reproduce it. Thanks,