Un4seen.BassBASSBuffer
Namespace: Un4seen.Bass
Assembly: Bass.Net (in Bass.Net.dll) Version: 2.4.17.5
The BASSBuffer type exposes the following members.
Name | Description | |
---|---|---|
BASSBuffer |
Default Constructor using the default buffer size.
| |
BASSBuffer(Single, Int32, Int32, Int32) |
Creates an instance of the ring buffer with a size acconding to the given parameters.
|
Name | Description | |
---|---|---|
Bps |
Gets the Bytes per sample used with the ring buffer (1=8-bit, 2=16-bit default, 4=32-bit).
| |
BufferLength |
Gets the total length in bytes of the ring buffer.
| |
NumChans |
Gets the number of channels used with the ring buffer (1=mono, 2=stereo default, etc).
| |
Readers |
Gets or Sets the number of parallel Readers which can be used with the ring buffer.
| |
SampleRate |
Gets the sample rate in Hz used with the ring buffer (default is 44100 Hz).
|
Name | Description | |
---|---|---|
Clear |
Clears the ring buffer (zeros all elements) and resets all read and write pointers.
| |
Count |
Returns the number of bytes available in the ring buffer for reading.
| |
Dispose |
Implement IDisposable.
| |
Finalize |
Finalization code.
(Overrides ObjectFinalize.) | |
Read(Byte, Int32, Int32) |
Reads (removes) the given number of sample data from the ring buffer.
| |
Read(IntPtr, Int32, Int32) |
Reads (removes) the given number of sample data from the ring buffer.
| |
Resize |
Resizes (enlarges) the ring buffer by the given factor.
| |
Space |
Returns the number of bytes available in the ring buffer for writing until an overflow of the read pointer will happen.
| |
Write(Byte, Int32) |
Writes (add) the given number of sample data to the ring buffer.
| |
Write(IntPtr, Int32) |
Writes (add) the given number of sample data to the ring buffer.
|
The default size of the ring buffer is 2 seconds (when using it with 44.1kHz, 16-bit stereo sample data).
This class supports multiple readers using the ring buffer (default is 1). Use the Readers property to set the maximum number of parallel readers accessing the ring buffer.
The ring buffer is not a dynamic buffer, meaning it has a fixed size once created. However, the ring buffer size might be increased at any time through the Resize(Single) method, even if you should avoid this for performance reasons.
Use the Write(IntPtr, Int32) method to add sample data to the ring buffer. And use the Read(IntPtr, Int32, Int32) method to retrieve sample data from the ring buffer.
This class might be useful for full-duplex monitoring of a recording streams or in order to clone existing streams.
In order to reduce latency, you might probably want to minimize the recording update period (see BASS_RecordStart(Int32, Int32, BASSFlag, RECORDPROC, IntPtr). You'll probably also want to reduce the update period (BASS_CONFIG_UPDATEPERIOD) and buffer length (BASS_CONFIG_BUFFER), to reduce output latency (see BASS_SetConfig(BASSConfig, Int32)).
private RECORDPROC _myRecProc; // make it global, so that the GC can not remove it private int _recHandle = 0; // The buffer: 44.1kHz, 16-bit, stereo (like we record!) private BASSBuffer _monBuffer = new BASSBuffer(2f, 44100, 2, 16); private int _monStream = 0; private STREAMPROC _monProc = null; ... // enable lower latency settings (optional) Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_UPDATEPERIOD, 20); Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_BUFFER, 100); // start recording with 20ms update period _myRecProc = new RECORDPROC(MyRecording); _recHandle = Bass.BASS_RecordStart(44100, 2, BASSFlag.BASS_DEFAULT, 20, _myRecProc, IntPtr.Zero); // setup the full-duplex monitoring _monProc = new STREAMPROC(MonitoringStream); _monStream = Bass.BASS_StreamCreate(44100, 2, 0, _monProc, IntPtr.Zero); // user = reader# Bass.BASS_ChannelPlay(_monStream, false); private bool MyRecording(int handle, IntPtr buffer, int length, IntPtr user) { monBuffer.Write(buffer, length); } private int MonitoringStream(int handle, IntPtr buffer, int length, IntPtr user) { return monBuffer.Read(buffer, length, user.ToInt32()); }