Page 1 of 1
VoltageSound crash in VoltageSound_ReadSamples()
Posted: Tue Aug 09, 2022 5:02 pm
by Waverley Instruments
So I'm probably doing something wrong here, but I can reproduce the crash with a small alteration to the Sound File Player example.
The change is simply to add a button that effectively reloads the MP3, something like:
Code: Select all
if (component == button1) {
if (doubleValue == 1) sound.LoadFromResource("ElectroTrash.mp3");
}
Steps to reproduce:
- Launch in debug mode with hack as described above
- Flip switch to start playback - all good!
- Flip switch to stop playback
- Click button to re-load MP3
- Flip switch to start playback
- CRASH in VoltageSound_ReadSamples()
Is there some re-init sequence I should be doing? I've tried resetting the current sample index, seeking to the start and so on, but no joy so far. I'm still digging...
I get the same issue when loading from a file and thought it might be specific to that, but apparently not.
Any help and / or thoughts much appreciated!
Cheers, -Rob at WI.
Re: VoltageSound crash in VoltageSound_ReadSamples()
Posted: Tue Aug 09, 2022 5:44 pm
by Aarnville
It's not a class I have ever used. Do you get any error messages, maybe in the Log file? You have probably already tried these things but:
1. Is it happy to play, stop, play, stop etc if you don't try to reload the MP3?
2. Have you tried repeating all the steps in Initialise() after reloading the MP3? I can't see anything that should need this except the preloading of the sample buffers, and yes, you'll definitely need to reset curSample.
3. Have you tried loading the MP3 into a completely new instance of VoltageSound when the button is pressed and switching ProcessSample() to use it? This one is not a suggestion for production, just a way to see if you can influence the problem.
4. Finally, getting increasingly more desperate, how about deleting all the stuff in Initialise() and putting it in your button notify. This is to test if the problem is related to trying to load/reuse the already loaded VoltageSound object.
Re: VoltageSound crash in VoltageSound_ReadSamples()
Posted: Tue Aug 09, 2022 6:21 pm
by Waverley Instruments
Thanks Ian! Little update on this, seems re-instantiating fixes it, which tends to suggest / confirm that loading from a new resource somehow gets its internal buffer messed-up in some way.
Going back to my hack, here's the hack to "fix" it...
Code: Select all
if (component == button1) {
if (doubleValue == 1) {
// comment out this line to get the crash!
sound = new VoltageSound("Sound", this);
//
sound.LoadFromResource("ElectroTrash.mp3");
curSample = 0;
sound.ReadSamples(bufferSize, left, right);
}
}
Re: VoltageSound crash in VoltageSound_ReadSamples()
Posted: Wed Aug 10, 2022 5:06 am
by Aarnville
Waverley Instruments wrote: ↑Tue Aug 09, 2022 6:21 pm
Thanks Ian! Little update on this, seems re-instantiating fixes it, which tends to suggest / confirm that loading from a new resource somehow gets its internal buffer messed-up in some way.
Going back to my hack, here's the hack to "fix" it...
Code: Select all
if (component == button1) {
if (doubleValue == 1) {
// comment out this line to get the crash!
sound = new VoltageSound("Sound", this);
//
sound.LoadFromResource("ElectroTrash.mp3");
curSample = 0;
sound.ReadSamples(bufferSize, left, right);
}
}
Glad you got it sorted. It feels like more of a bug than a feature in the VoltageSound class. I seem to recall finding a few oddities with the SamplerVoice class too - enough to make me think I'm better off coding my own version of it should I ever need it for a proper module.
Re: VoltageSound crash in VoltageSound_ReadSamples()
Posted: Wed Aug 10, 2022 6:14 am
by Waverley Instruments
Thanks again Ian! Yep, this seems to be an accepted workaround for now. Specifically:
instantiate a new VoltageSound object and do any other setup required when loading the new sample.
Cheers, -Rob