StartFromMemory method
Remarks
Starts a new recording session from a sound contained inside a memory buffer.
The sound contained inside the memory buffer can be in any of the sound formats supported by the
StartFromFile method.
Calling this method will cause the control to fire a
RecordingStarted event. After completing the recording session the control will fire the
RecordingStopped event. Advancement can be controlled through the
RecordingPerc event.
Syntax
|
[Visual Basic]
Public Function StartFromMemory (
strOutputPath as string,
pBuffer() as Byte,
nBufferLength as Int32
|
|
[C#]
string strOutputPath,
byte[] pBuffer,
Int32 nBufferLength
);
|
|
[C++]
string strOutputPath,
unsigned char __gc[] pBuffer,
Int32 nBufferLength
);
|
|
Parameter
|
Description
|
|
|
|
|
strOutputPath
|
String representing the absolute pathname of the output file that will contain the recorded data. If this pathname should contain invalid characters, they would be automatically changed into an underscore '_' character.
If the string is left empty, the recording session will be performed in memory.
|
|
pBuffer
|
Input buffer containing the original sound
|
|
nBufferLen
|
Length of the input buffer expressed in bytes
|
Return value
|
Value
|
Meaning
|
|
|
|
|
Negative value
|
An error occurred. Check the LastError property value in order to see the last error.
|
|
enumErrorCodes.ERR_NOERROR (0)
|
The method call was successful.
|
Sample
Below you can find a couple of samples that demonstrate how to record from a sound stored in memory in Visual Basic.NET and Visual C# : in these samples the file is taken from a file and its contents are stored inside a memory buffer.
Visual Basic.NET
' declare the memory buffer (cannot be a local variable)
Dim m_byteBuffer() As Byte
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim openFileDialog1 As New OpenFileDialog
If openFileDialog1.ShowDialog() <> DialogResult.OK Then
Return
End If
' put the song file into a stream
Dim streamFile As FileStream
streamFile = New FileStream(openFileDialog1.FileName, FileMode.Open)
Dim binReader As BinaryReader
binReader = New BinaryReader(streamFile)
' reallocate the memory buffer space and store the song
ReDim m_byteBuffer(streamFile.Length)
binReader.Read(m_byteBuffer, 0, streamFile.Length)
' record sound from memory buffer and resample its contents using the first available format (index '0' is usually 11025, mono, 8 bits)
If AudioSoundRecorder1.RecorderStartFromMemory(0, "c:\output.wav", m_byteBuffer, streamFile.Length) = AudioDjStudio.enumErrorCodes.NOERROR Then
' do domething
....
End If
End Sub
Visual C#.NET
// declare the memory buffer (cannot be a local variable)
byte[] m_byteBuffer = null;
private void buttonLoad1_Click(object sender, System.EventArgs e)
{
OpenFileDialog openFileDialog1 = new OpenFileDialog();
if (openFileDialog1.ShowDialog() != DialogResult.OK)
return;
// put the song file into a stream
FileStream streamFile = new FileStream (openFileDialog1.FileName, FileMode.Open);
BinaryReader binReader = new BinaryReader (streamFile);
// allocate the memory buffer space and store the song
m_byteBuffer = new byte[streamFile.Length];
binReader.Read (m_byteBuffer, 0, (int) streamFile.Length);
// record sound from memory buffer and resample its contents using the first available format (index '0' is usually 11025, mono, 8 bits)
if (AudioSoundRecorder1.RecorderStartFromMemory(0, "c:\output.wav", m_byteBuffer, (Int32) streamFile.Length) == enumErrorCodes.NOERROR)
{
// do something
...
}
}