Copyright © 2006-2019 MultiMedia Soft

StartSplitFromMemory method

Previous pageReturn to chapter overviewNext page

Remarks

 

Starts a new recording session from a sound contained inside a memory buffer and splits incoming sound in left and right channels.

The sound contained inside the memory buffer can be in any of the sound formats supported by the StartSplitFromFile method.

Sound files in various RAW formats can be loaded using the StartSplitFromMemoryRaw 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.

 

In this case the recording session wouldn't be kept inside the RecordedSound object so the only accepted recording mode, set through the SetRecordingMode method, is REC_MODE_NEW.

 

If the EncodeFormats.ForRecording property is set to ENCODING_FORMAT_WMA, the only supported encoding mode for the EncodeFormats.WMA.EncodeMode property is WMA_ENCODE_CBR_STD_16 and the WMA.CBR property must be set to a value that can support both stereo and mono, so the only compatible combinations are the following:

for sounds at 16000 Hz CBR must be set to 16000 (16 kbps)
for sounds at 22050 Hz CBR must be set to 20000 (20 kbps)
for sounds at 44100 Hz CBR must be set to 32000 (32 kbps) or 48000 (48 kbps)

 

If the EncodeFormats.ForRecording property is set to ENCODING_FORMAT_WAV, the splitting will only work if the EncodeFormats.WAV.EncodeMode property is set to a format supporting both mono and stereo formats meaning that, for example, it will not work for mono-only formats like WAV_ENCODE_GSM_610 or WAV_ENCODE_G721_ADPCM_32.

 

If the EncodeFormats.ForRecording property is set to ENCODING_FORMAT_AIFF, the splitting will only work if the EncodeFormats.AIFF.EncodeMode property is set to a format supporting both mono and stereo formats meaning that, for example, it will not work for mono-only formats like AIFF_ENCODE_GSM_610.

 

If the EncodeFormats.ForRecording property is set to ENCODING_FORMAT_AU, the splitting will only work if the EncodeFormats.AU.EncodeMode property is set to a format supporting both mono and stereo formats meaning that, for example, it will not work for mono-only formats like AU_ENCODE_G721_ADPCM_32 or AU_ENCODE_G723_ADPCM_24 or AU_ENCODE_G723_ADPCM_40.

 

If the EncodeFormats.ForRecording property is set to ENCODING_FORMAT_ACM, the splitting will only work if the selected codec supports both mono and stereo formats meaning that, for example, it will not work for mono-only codecs like GSM 6.10 or G721 ADPCM.

 

The split doesn't work if the EncodeFormats.ForRecording property is set to ENCODING_FORMAT_AAC because this format doesn't support creating mono sounds.

 

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

 

 

Syntax

 

[Visual Basic]

control.StartSplitFromMemory (

strOutputPathLeft as string,

strOutputPathRight as string,

pBuffer as variant,

nBufferLen as long

) as enumErrorCodes


 

[C++]

short control.StartSplitFromMemory (

LPCTSTR strOutputPathLeft,

LPCTSTR strOutputPathRight,

const VARIANT FAR& pBuffer,

long nBufferLen

);


 

 

Parameter

Description

 

 

strOutputPathLeft

String representing the absolute pathname of the destination file that will contain the left channel of recorded data. If this pathname should contain invalid characters, they would be automatically changed into an underscore '_' character.

strOutputPathRight

String representing the absolute pathname of the destination file that will contain the right channel of recorded data. If this pathname should contain invalid characters, they would be automatically changed into an underscore '_' character.

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);

}