Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

question about example #240

Open
gucio321 opened this issue Jul 21, 2024 · 8 comments
Open

question about example #240

gucio321 opened this issue Jul 21, 2024 · 8 comments

Comments

@gucio321
Copy link
Contributor

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:

  • (*SinWave).Read sometimes panics with index out of range [:-3XXXX] or, sometimes sound was corrupted (longer and glitchy). I managed to fix that by adding sync.Mutex (For some reason Read was called twice by oto, idk why).
  • the other issue may be specific to my app, where it must not appear, and may be wanted here in example to keep it as simple as possible: when the sound starts playing and when it ends, you can hear a "tap". It is a hardware thing imo. It could be removed by the following:
                b := int16(math.Sin(2*math.Pi*float64(p)/length) * 0.3 * max)

                if p <= stuckReduction {
                        b = int16(float64(p) / (stuckReduction) * math.Sin(2*math.Pi*float64(p)/length) * 0.3 *
                }

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 😄.

@hajimehoshi
Copy link
Member

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

@hajimehoshi
Copy link
Member

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

@gucio321
Copy link
Contributor Author

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
Copy link
Contributor Author

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
Copy link
Member

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
Copy link
Member

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

@gucio321
Copy link
Contributor Author

I found an interessting thing: if you modify an example like this: gucio321@d969893 not every sound is played

@hajimehoshi
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants