MultiMedia Soft forum

Please login or register.

Login with username, password and session length
Advanced search  

News:

SMF - Just Installed!

Author Topic: Sample code how to acces sound recorder's memory buffer  (Read 2262 times)

respect

  • Newbie
  • *
  • Posts: 8
    • View Profile
Sample code how to acces sound recorder's memory buffer
« 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.
Logged

Administrator

  • Administrator
  • Full Member
  • *****
  • Posts: 231
    • View Profile
    • MultiMedia Soft
Re: Sample code how to acces sound recorder's memory buffer
« Reply #1 on: December 11, 2015, 11:20:34 PM »

Hello,

in C# it should be something similar:

Code: [Select]
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
Logged

respect

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Sample code how to acces sound recorder's memory buffer
« Reply #2 on: December 16, 2015, 01:49:07 AM »

Hello,

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

Best Regards
Laszlo
Logged