Serializing/Deserializing AudioSampleStream

I’m trying to serialize an AudioSampleBuffer into XML, send it over a network, and then deserialize and I’m a bit stuck and could use some advice. I got the connection working fine but im not serializing/deserializing correctly so the deserialized sample is actually “chopped” for some reason and I’m sure it has to do with my janky methods of doing this.

I’m serializing each channel individually but I’m not getting the proper “size” of the buffer, I’m just using a sample count which I’m sure is wrong… if anyone could help me clear this up I would be grateful! Haven’t coded in 10 years so please forgive some of the ridiculous string management and other stuff :slight_smile:


	for (int i = 0; i < m_oAudioBuffer.getNumChannels(); i++)
		String strNumber(i);
		String strAttributeName = "channel:" + strNumber;
		String strXmlSampleData;
		MemoryBlock oMemory(m_oAudioBuffer.getReadPointer(i), m_oAudioBuffer.m_iSampleSize);
		strXmlSampleData = oMemory.toBase64Encoding();
		poXmlAudioSampleBuffer->setAttribute(strAttributeName, strXmlSampleData);


// This is in a "Sample" class which has a counted samplesize that I calculate from the recording itself when it happens
	XmlElement* poChildElement = poXmlElement->getChildElement(0);
	String channel1DataBase64 = poChildElement->getAttributeValue(0);
	String channel2DataBase64 = poChildElement->getAttributeValue(1);

	MemoryBlock channel1Data;

	MemoryBlock channel2Data;

	m_oAudioBuffer = AudioSampleBuffer(2, m_iSampleSize);
	m_oAudioBuffer.copyFrom(0, 0, static_cast<const float*>(channel1Data.getData()), m_iSampleSize);
	m_oAudioBuffer.copyFrom(1, 0, static_cast<const float*>(channel2Data.getData()), m_iSampleSize);

What is the m_oAudioBuffer.m_iSampleSize in this? Why are you not getting the size of the involved memory block directly from the audio buffer object? ( buffer.getNumSamples()*sizeof(float) )

MemoryBlock oMemory(m_oAudioBuffer.getReadPointer(i), m_oAudioBuffer.m_iSampleSize);

I was using a manually counted sample count instead of the count from the buffer, I see why this wasn’t working now. Also it wasn’t a member of audiosamplebuffer thats a typo.

This seems to have fixed my problem :slight_smile: thank you