Data loading error from binary to AudioBuffer

Hi JUCE folks,

I’m working on a plugin instrument. The raw data is a customized binary file consisting some header and many wave raw data. When I try to load the data into my SynthesiserSound class, my basic operation is 1) slicing each each wave binary into MemoryBlock, then 2) converting each MemoryBlock to AudioBuffer.

My problem is that many sound samples in AudioBuffer are nan or arbitrary large numbers which making the playback sound clip heavily.

When I try to run the data loading code alone (aside from UI), it works fine. I’m not sure what goes wrong here. Thanks for any help.

Liang

How are you loading the MemoryBlock into the AudioBuffer? Make sure to clear it first when you are not doing it with a constructor.

I think, if you are only outputting audio in your plugin, you need to clear the buffer (=input) first and then render your stuff into it. Are you doing that?

I think my process is all right. Basically the file is 1) read as FileInputStream, 2) put my interested data section into a MemoryBlock, 3) declare a Audio::Pointer and set it the beginning of MemoryBlock, lastly 4) iterating Audio::Pointer and put every float sample into my AudioBuffer.

If I forgot to clear them, I should expect trunks of wrong data. But I’m encountering random data errors. For instance, my audio is 44100 samples long (1s). The 2545th converted sample goes 12313522.0000 or nan. After a few bizarre samples, it goes back to normal. This phenomenon is randomly happening.

I think this is really not a good assumption. The data in freshly allocated memory is not defined. Might be all zeros (because it got cleared recently by your application or a different application or the OS), might be trash.

And this is actually a very strong indication that you are missing a clear along the road.

I don’t think there is much one can do without seeing code.

You’re definitely right! I was making a mistake not clearing allocated memory.

I carefully examined every AudioBuffer involved. I added a clear method after AudioBuffer object declaration. The random error goes away. Thanks for you help.

Liang