BASS.NET API for the Un4seen BASS Audio LibraryWaveWriterWrite Method (IntPtr, Int32)BASS.NET API for the Un4seen BASS Audio Library
Use this method to provide the sample data to the WaveWriter and write these samples to the wave file.

Namespace: Un4seen.Bass.Misc
Assembly: Bass.Net (in Bass.Net.dll) Version: 2.4.12.0
Syntax

public void Write(
	IntPtr buffer,
	int length
)

Parameters

buffer
Type: SystemIntPtr
The IntPtr containing the sample data.
length
Type: SystemInt32
The number of BYTEs in the buffer.
Remarks

This method is best used in DSPPROC, DOWNLOADPROC or RECORDPROC callback delegates.

Please note, that the sample data provided in the buffer must conform the OrigResolution property! Meaning if the OrigResolution=32 float sample data is expected, if OrigResolution=16 short sample data is expected and if OrigResolution=8 byte samples are expected!

However, the data written to the wave file will be in BitsPerSample resolution (as specified in the constructor). If the OrigResolution is different from this one an automatic bit resolution conversion will take place.

When using a decoding stream other overloads might be more conviniant.

Examples

Using a WaveWriter in a RECORDPROC to record 24-bit at 44.1kHz, stereo:
VB
Private _waveWriter As WaveWriter = Nothing ' make it global, so that the GC can not remove it
Private _myRecProc As RECORDPROC
Private _recHandle As Integer = 0
...
' start recording
_myRecProc = New RECORDPROC(AddressOf MyRecording)
_recHandle = Bass.BASS_RecordStart(44100, 2, 
                  BASSFlag.BASS_RECORD_PAUSE Or BASSFlag.BASS_SAMPLE_FLOAT, _myRecProc, IntPtr.Zero)
' create a WaveWriter using the _recHandle to set the freq. and channels, but write the wave at 24-bit
_waveWriter = New WaveWriter("test.wav", _recHandle, 24, True)
Bass.BASS_ChannelPlay(_recHandle, False)
...
' when finished recording call this!
If Not (_waveWriter Is Nothing) Then
  ' finilize the wave file!
  _waveWriter.Close()
End If
...
' the recording callback
Private Function MyRecording(handle As Integer, buffer As IntPtr, length As Integer, user As IntPtr) As Boolean
  ' we will get float sample data here
  ' so make sure the _waveWriter.OrigResolution property is set to 32
  ' this was automatically done, since we started recording with BASSFlag.BASS_SAMPLE_FLOAT
  _waveWriter.Write(buffer, length)
  Return True ' always continue recording
End Function
private WaveWriter _waveWriter = null; // make it global, so that the GC can not remove it
private RECORDPROC _myRecProc;
private int _recHandle = 0;
...
// start recording
_myRecProc = new RECORDPROC(MyRecording);
_recHandle = Bass.BASS_RecordStart(44100, 2, 
                  BASSFlag.BASS_RECORD_PAUSE | BASSFlag.BASS_SAMPLE_FLOAT, _myRecProc, IntPtr.Zero);
// create a WaveWriter using the _recHandle to set the freq. and channels, but write the wave at 24-bit
_waveWriter = new WaveWriter( "test.wav", _recHandle, 24, true);
Bass.BASS_ChannelPlay(_recHandle, false);
...
// when finished recording call this!
if (_waveWriter != null)
{
  // finilize the wave file!
  _waveWriter.Close();
}
...
// the recording callback
private bool MyRecording(int handle, IntPtr buffer, int length, IntPtr user)
{
  // we will get float sample data here
  // so make sure the _waveWriter.OrigResolution property is set to 32
  // this was automatically done, since we started recording with BASSFlag.BASS_SAMPLE_FLOAT
  _waveWriter.Write( buffer, length );
  return true; // always continue recording
}
See Also

Reference