Copyright © 2008-2018 MultiMedia Soft

LoadSoundChannelFromMemory method

Previous pageReturn to chapter overviewNext page



Loads a specific audio channel from the sound file stored inside a memory buffer for editing purposes. The sound file can be a stream file or a MOD music file (see the LoadSound method for supported formats).


You can manage how loaded sound will be added to the existing editing session through a previous call to the SetLoadingMode method.

You can limit the range of sound data that will be loaded from the given sound file with a previous call to the SetLoadingRange method.


For loading a channel from files in RAW format use the LoadSoundChannelFromRawMemory method.


A successful call to this method will fire the SoundLoadingStarted event followed by a number of SoundLoadingPerc events and finally by the SoundLoadingDone event.


IMPORTANT TOPIC: remember that the memory buffer containing song data must not be moved and needs to be available till the call to the CloseSound method.





[Visual Basic]

control.LoadSoundChannelFromMemory (

pBuffer as variant,

nBufferLength as long,

nChannel as Integer

) as enumErrorCodes



short control.LoadSoundChannelFromMemory (

const VARIANT FAR& pBuffer,

long nBufferLength,

short nChannel









Input buffer containing the original sound


Length of the input buffer expressed in bytes


Number representing the zero-based index of the audio channel to load.




Return value






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.




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)


' load song from memory buffer and resample its contents at 44100, stereo, 16 bits

ActiveSoundEditor1.LoadSoundFromMemory 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)



HGLOBAL hg = LoadResource(hInst, hrsrc);

if (!hg)



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


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


VARIANT      va;

VariantInit (&va);

va.vt = VT_BYREF | VT_UI1;

va.pbVal = (BYTE *) pRes;


// load song from memory buffer and resample its contents at 44100, stereo, 16 bits

m_ctrlActiveEditor.LoadSoundFromMemory (va, iSize);