MultiMedia Soft forum

MultiMedia Soft products => Audio recording components => Topic started by: respect on December 11, 2015, 06:50:11 PM

Title: Sample code how to acces sound recorder's memory buffer
Post by: respect on December 11, 2015, 06:50:11 PM
Can you please provide sample code:
how to access the memory buffer containing the sound recording in memory? I would like to store it as a byte array in a database.
Title: Re: Sample code how to acces sound recorder's memory buffer
Post by: Administrator on December 11, 2015, 11:20:34 PM
Hello,

in C# it should be something similar:


byte[]  m_buffTemp = null;

// get the pointer in memory and allocate a C# buffer
long   pSound = audioSoundRecorder1.RecordedSound.GetMemoryPtr();
Int32  size = audioSoundRecorder1.RecordedSound.GetMemorySize();
m_buffTemp = new byte[size];

// copy from real memory to C# buffer
Marshal.Copy ((IntPtr) pSound, m_buffTemp, 0, size);

// now output the C# buffer into a memory stream
MemoryStream    ms = new MemoryStream();
ms.Write(m_buffTemp, 0, size);

// now output the memory stream to a file
FileStream  fs = File.OpenWrite("c:\\test.wav");
fs.Write(ms.GetBuffer(), 0, (int) ms.Position);
fs.Close();


In this case, just for simplicity, the memory stream is written to a file but you could do what you prefer with it.

Hope this helps.

Kind Regards

Severino Delaurenti
MultiMedia Soft
Title: Re: Sample code how to acces sound recorder's memory buffer
Post by: respect on December 16, 2015, 01:49:07 AM
Hello,

thank you. It helped a lot, the code worked perfectly.

Best Regards
Laszlo