Supported bit resolutions are 8-bit, 16-bit, 24-bit and 32-bit. Supported sample rates are 8000, 11025, 22050, 44100, 48000 or 96000 Hz. Multi channel wave files are also supported. Use 1=mono, 2=stereo...
Un4seen.Bass.MiscWaveWriter
Namespace: Un4seen.Bass.Misc
Assembly: Bass.Net (in Bass.Net.dll) Version: 2.4.17.5
The WaveWriter type exposes the following members.
Name | Description | |
---|---|---|
WaveWriter(String, Int32, Boolean) |
Create a WaveWrite instance from a given BASS stream channel.
| |
WaveWriter(String, Int32, Int32, Boolean) |
Create a WaveWrite instance from a given BASS stream channel.
| |
WaveWriter(String, Int32, Int32, Int32, Boolean) |
Create a WaveWrite instance to save sample data to be processed to a wave file.
|
Name | Description | |
---|---|---|
BitsPerSample |
Gets or Sets the target resolution (number of bits per sample) of the Wave file being created.
This will be either 8, 16, 24 or 32. | |
FileName |
Gets or Sets the fully referenced path and file name of the wave file to write to data to.
| |
NumChannels |
Gets the number of channels of the Wave file being created (values between 1 and 9 should be fine).
E.g. 1=mono, 2=stereo... | |
OrigResolution |
Gets or Sets the original resolution (number of bits per sample) of the stream channel resp. sample data to process.
This should be either 8, 16 or 32. This value is used in the Write(IntPtr, Int32) methods to automatically convert the bit resolution according to the target BitsPerSample value. E.g. set this value to 32, if you receive 32-bit float sample data in a DSP callback and if you want to call the Write(IntPtr, Int32) method there directly, but have specified a target resolution of 8, 16 or 24 bit. | |
SampleRate |
Gets the sample rate of the Wave file being created.
e.g. 44100 for 44.1kHz. Typically one of the following: 11025, 22050, 44100, 48000, 96000. |
Name | Description | |
---|---|---|
Close |
Closes the WaveWriter and underlying wave file and updates the wave header accordingly.
| |
Dispose |
Disposes the current instance of the WaveWriter and all it's resources.
| |
Finalize |
Finalization code.
(Overrides ObjectFinalize.) | |
Write(Byte, Int32) |
Use this method to provide 8-bit sample data to the WaveWriter and write these samples to the wave file.
| |
Write(Int16, Int32) |
Use this method to provide 16-bit sample data to the WaveWriter and write these samples to the wave file.
| |
Write(IntPtr, Int32) |
Use this method to provide the sample data to the WaveWriter and write these samples to the wave file.
| |
Write(Single, Int32) |
Use this method to provide 32-bit sample data to the WaveWriter and write these samples to the wave file.
| |
WriteNoConvert |
Use this method to provide sample data to the WaveWriter and write these samples to the wave file.
|
The WaveWriter class is an internal implementation of the BASS.NET API and does not require any additional extension or add-on to the BASS audio library.
The typical use of this class is as followed:
a) Create an instance of the class and define the frequency, channels and bitrate.
b) Call the Write(IntPtr, Int32) method subsequently to write sample data to the wave file.
c) Finally call Close to close and finish the wave file.
Note: Not all media players support playback of all formats, especially multi-channel (more than stereo) or high-resolution (greater 16-bit) wave files.
The following speaker assignment is used for multi-channel wave files (as defined/recommended by Microsoft):
#Chans | Speaker Assignment |
---|---|
1 | Mono: SPEAKER_FRONT_LEFT |
2 | Stereo: SPEAKER_FRONT_LEFT, SPEAKER_FRONT_RIGHT |
3 | 2.1: SPEAKER_FRONT_LEFT, SPEAKER_FRONT_RIGHT, SPEAKER_FRONT_CENTER |
4 | 2.2: SPEAKER_FRONT_LEFT, SPEAKER_FRONT_RIGHT, SPEAKER_BACK_LEFT, SPEAKER_BACK_RIGHT |
5 | 2.2.1: SPEAKER_FRONT_LEFT, SPEAKER_FRONT_RIGHT, SPEAKER_FRONT_CENTER, SPEAKER_BACK_LEFT, SPEAKER_BACK_RIGHT |
6 | 5.1: SPEAKER_FRONT_LEFT, SPEAKER_FRONT_RIGHT, SPEAKER_FRONT_CENTER, SPEAKER_LOW_FREQUENCY, SPEAKER_BACK_LEFT, SPEAKER_BACK_RIGHT |
7 | 5.1.1: SPEAKER_FRONT_LEFT, SPEAKER_FRONT_RIGHT, SPEAKER_FRONT_CENTER, SPEAKER_LOW_FREQUENCY, SPEAKER_BACK_LEFT, SPEAKER_BACK_RIGHT, SPEAKER_BACK_CENTER |
8 | 7.1: SPEAKER_FRONT_LEFT, SPEAKER_FRONT_RIGHT, SPEAKER_FRONT_CENTER, SPEAKER_LOW_FREQUENCY, SPEAKER_BACK_LEFT, SPEAKER_BACK_RIGHT, SPEAKER_FRONT_LEFT_OF_CENTER, SPEAKER_FRONT_RIGHT_OF_CENTER |
9 | 7.1.1: SPEAKER_FRONT_LEFT, SPEAKER_FRONT_RIGHT, SPEAKER_FRONT_CENTER, SPEAKER_LOW_FREQUENCY, SPEAKER_BACK_LEFT, SPEAKER_BACK_RIGHT, SPEAKER_FRONT_LEFT_OF_CENTER, SPEAKER_FRONT_RIGHT_OF_CENTER, SPEAKER_BACK_CENTER |
> 9 | Undefined: SPEAKER_ALL |
int stream = Bass.BASS_StreamCreateFile("test.mp3", 0, 0, BASSFlag.BASS_STREAM_DECODE); WaveWriter WW = new WaveWriter("test.wav", stream, true); short[] data = new short[32768]; while (Bass.BASS_ChannelIsActive(stream) == BASSActive.BASS_ACTIVE_PLAYING) { int length = Bass.BASS_ChannelGetData(stream, data, 32768); if (length > 0) WW.Write(data, length); } // finilize the wave file! WW.Close(); Bass.BASS_StreamFree(stream);
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 }