Copyright © 2008-2023 MultiMedia Soft

LoadSoundChannelFromMemory method

Previous pageReturn to chapter overviewNext page

Remarks

 

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.

 

 

Syntax

 

[Visual Basic]

control.LoadSoundChannelFromMemory (

pBuffer as variant,

nBufferLength as long,

nChannel as Integer

) as enumErrorCodes


 

[C++]

short control.LoadSoundChannelFromMemory (

const VARIANT FAR& pBuffer,

long nBufferLength,

short nChannel

);


 

 

Parameter

Description

 

 

pBuffer

Input buffer containing the original sound

nBufferLength

Length of the input buffer expressed in bytes

nChannel

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

 

 

 

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 load a sound stored in memory in Visual Basic 6 and Visual C++ 6: in these samples the file is taken from a file and contents of its left channel (0) are stored in memory: 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.LoadSoundChannelFromMemory VarPtr(bytSound(0)), length, 0

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;

 

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

m_ctrlActiveEditor.LoadSoundChannelFromMemory (va, iSize, 0);

}