I am converting audio to base64 from a MemoryBlock. This works well until I try and save 10ms, which just returns a zero length buffer. It is hard to tell whether my issue is occurring when writing using toBase64Encoding or when reading using fromBase64Encoding.
When I change my signal to 20ms the audio is read back correctly.
Does anyone know if there are any size issues with writing/reading to base64 from MemoryBlock?
IIRC when you write using a MemoryOutputStream into a MemoryBlock, make sure, the stream goes out of scope before checking the size.
I think I had similar issues a few years back, that went away after wrapping the writing part into a scope.
MemoryBlock block;
{
MemoryOutputStream stream (block, false);
stream.write (...);
// size wrong
}
// size correct now
Maybe that helps…
Hi @daniel
Thanks for that suggestion. I did a few tests and worked out that mine is not a scope issue. It might be something to do with the way I am reading the base64 back in again. I managed to deduce that there are some differences in the number of samples that I am sending to base64 and the number that come back.
For an audio signal ~20ms in length, at a sample rate of 96,000 I have 1977 samples going into the base64. When I read these out of the base64 I am getting 1152 in. I have included a snippet of code that reads the exact same base64 value in… I can only think that there must be something wrong with my reader code - if anyone can confirm that would be great?
memoryBlock.fromBase64Encoding(q.getPropertyAsValue("audio64", nullptr).toString());
MemoryInputStream* inStream = new MemoryInputStream(memoryBlock.getData(), memoryBlock.getSize(),true);
// Read audio into buffer
FlacAudioFormat format;
if (auto* reader = format.createReaderFor(inStream, true) )
{
AudioFormatReaderSource* p_inputSource = new AudioFormatReaderSource (reader, true);
p_inputSource->prepareToPlay(blockSize, _sampleRate);
int sampleCount = (int)p_inputSource->getTotalLength();
And when I use an audio signal that is ~10ms long, I get 1017 samples, however when I try an read in using the above method I get a sampleCount of 0. It seems to be losing samples?