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 by the garbage collector and needs to be available till the call to the CloseSound method.

 

 

Syntax

 

[Visual Basic]

Public Function LoadSoundChannelFromMemory (

pBuffer() as Byte,

nBufferLength as Int32,

nChannel as Int16

) as enumErrorCodes


 

[C#]

public enumErrorCodes LoadSoundChannelFromMemory (

byte[] pBuffer,

Int32 nBufferLength,

Int16 nChannel

);


 

[C++]

public: enumErrorCodes LoadSoundChannelFromMemory (

unsigned char __gc[] pBuffer,

Int32 nBufferLength,

Int16 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 (see the LastError property for further error details)

enumErrorCodes.ERR_NOERROR (0)

The method call was successful.

 

 

Sample

 

Below you can find a couple of samples that demonstrate how to load a sound stored in memory in Visual Basic.NET and Visual C# : in these samples the file is taken from a file and contents of its left channel (0) are stored in memory.

 

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)

 

If audioSoundEditor1.LoadSoundChannelFromMemory(m_byteBuffer, streamFile.Length, 0) = AudioSoundEditor.enumErrorCodes.ERR_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);

 

// load song from memory buffer

if (audioSoundEditor1.LoadSoundChannelFromMemory (m_byteBuffer, (Int32) streamFile.Length, 0) == AudioSoundEditor.enumErrorCodes.ERR_NOERROR)

{

    // do something

    ...

}

}