Copyright © 2006-2019 MultiMedia Soft

StartFromMemory method

Previous pageReturn to chapter overviewNext page

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.

Sound files in various RAW formats can be loaded using the StartFromMemoryRaw method.

 

A successful call to this method will fire the RecordingStarted event followed by a number of RecordingPerc events and finally by the RecordingStopped event.

 

For details about recording from files see the How to record from files, memory or clipboard section.

 

 

Syntax

 

[Visual Basic]

control.StartFromMemory (

strOutputPath as string,

pBuffer as variant,

nBufferLen as long

) as enumErrorCodes


 

[C++]

short control.StartFromMemory (

LPCTSTR strOutputPath,

const VARIANT FAR& pBuffer,

long nBufferLen

);


 

 

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 error code meaning

enumErrorCodes.ERR_NOERROR (0)

The method call was successful.

 

 

Samples

 

Below you can find a couple of samples that demonstrate how to record a sound store inside a memory buffer in Visual Basic 6 and Visual C++ 6: the sound has been taken from a .RES resource file using the "identifier" variable.

 

Visual Basic 6

 

' the memory buffer must be declared as global

Dim bytSound() As Byte

 

Private Sub Command1_Click()

 Dim length As Long

 bytSound = LoadResData(identifier, 10)

 length = UBound(bytSound)

 

 ' record sound from memory buffer and resample its contents using the first available format (index '0' is usually 11025, mono, 8 bits)

 ActiveSoundRecorder1.RecorderStartFromMemory 0, "c:\output.wav", VarPtr(bytSound(0)), length

End Sub

 

 

Visual C++ 6 with MFC

 

void CMyDialog::OnButton1()

{

 HINSTANCE hInst = AfxGetResourceHandle();

 HRSRC hrsrc = ::FindResource(hInst, MAKEINTRESOURCE (identifier), RT_RCDATA);

 if (!hrsrc)

     return;

 

 HGLOBAL hg = LoadResource(hInst, hrsrc);

 if (!hg)

     return;

 

 BYTE    *pRes = (BYTE*) LockResource(hg);

 ASSERT(pRes);

 int iSize = ::SizeofResource(hInst, hrsrc);

 

 VARIANT      va;

 VariantInit (&va);

 va.vt = VT_BYREF | VT_UI1;

 va.pbVal = (BYTE *) pRes;

 

 // record sound from memory buffer and resample its contents using the first available format (index '0' is usually 11025, mono, 8 bits)

 m_ctrlActiveRecorder.RecorderStartFromMemory (0, "c:\\output.wav", va, iSize);

}