BASS.NET API for the Un4seen BASS Audio Library

BassBASS_RecordStart Method (Int32, Int32, BASSFlag, RECORDPROC, IntPtr)

BASS.NET API for the Un4seen BASS Audio Library
Starts recording.

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

[DllImportAttribute("bass")]
public static int BASS_RecordStart(
	int freq,
	int chans,
	BASSFlag flags,
	RECORDPROC proc,
	IntPtr user
)

Parameters

freq
Type: SystemInt32
The sample rate to record at.
chans
Type: SystemInt32
The number of channels... 1 = mono, 2 = stereo, etc.
flags
Type: Un4seen.BassBASSFlag
Any combination of these flags (see BASSFlag)
BASS_SAMPLE_8BITSUse 8-bit resolution. If neither this or the BASS_SAMPLE_FLOAT flags are specified, then the recorded data is 16-bit.
BASS_SAMPLE_FLOATUse 32-bit floating-point sample data. WDM drivers are required to use this flag in Windows. See Floating-point channels for more information.
BASS_RECORD_PAUSEStart the recording paused. Use BASS_ChannelPlay(Int32, Boolean) together with the handle returned by this method to start it.
proc
Type: Un4seen.BassRECORDPROC
The user defined function to receive the recorded sample data... can be if you do not wish to use a callback.
user
Type: SystemIntPtr
User instance data to pass to the callback function.

Return Value

Type: Int32
If successful, the new recording's handle is returned, else is returned. Use BASS_ErrorGetCode to get the error code.
Remarks

Use BASS_ChannelStop(Int32) to stop the recording, and BASS_ChannelPause(Int32) to paused it. Recording can also be started in a paused state (via the BASS_RECORD_PAUSE flag), allowing DSP/FX to be set on it before any data reaches the callback function.

The sample data will generally arrive from the recording device in blocks rather than in a continuous stream, so when specifying a very short period between callbacks, some calls may be skipped due to there being no new data available since the last call.

When not using a callback (proc = ), the recorded data is instead retrieved via BASS_ChannelGetData(Int32, IntPtr, Int32). To keep latency at a minimum, the amount of data in the recording buffer should be monitored (also done via BASS_ChannelGetData(Int32, IntPtr, Int32), with the BASS_DATA_AVAILABLE flag) to check that there is not too much data; freshly recorded data will only be retrieved after the older data in the buffer is.

When freq and/or chans is set to 0 for the device's current values, BASS_ChannelGetInfo(Int32, BASS_CHANNELINFO) can be used afterwards to find out what values are being used by the recording.

A recording may end unexpectedly if the device fails, eg. if it is disconnected/disabled. A BASS_SYNC_DEV_FAIL sync can be set via BASS_ChannelSetSync(Int32, BASSSync, Int64, SYNCPROC, IntPtr) to be informed if that happens. It will not be possible to resume the recording channel then; a new recording channel will need to be created when the device becomes available again.

ERROR CODEDescription
BASS_ERROR_INITBASS_RecordInit(Int32) has not been successfully called.
BASS_ERROR_BUSYThe device is busy. An existing recording must be stopped before starting another one. Multiple simultaneous recordings can be made from the same device on Windows XP and Vista, but generally not on older Windows.
BASS_ERROR_NOTAVAILThe recording device is not available. Another application may already be recording with it, or it could be a half-duplex device and is currently being used for playback.
BASS_ERROR_FORMATThe specified format is not supported. If using the BASS_SAMPLE_FLOAT flag, it could be that floating-point recording is not supported.
BASS_ERROR_MEMThere is insufficient memory.
BASS_ERROR_UNKNOWNSome other mystery problem!

Platform-specific

Multiple simultaneous recordings can be made from the same device on Windows XP and later, but generally not on older Windows. Multiple simultaneous recordings are possible on macOS and iOS, but may not always be on Linux. Loopback recording is only available on Windows Vista and above. The option to use the device's current sample rate and/or channel count is only available on Windows/macOS/iOS. On macOS and iOS, the device is instructed (when possible) to deliver data at the period set in the HIWORD of flags, even when a callback function is not used. On other platforms, it is up the the system when data arrives from the device. On macOS and iOS, this function may succeed but only capture silence when recording permission has not been granted. The AVCaptureDevice authorizationStatusForMediaType method (or the AVAudioSession recordPermission method on iOS) can be used to check the permission status.

Examples

Start recording at 44100hz 16-bit stereo:
private RECORDPROC _myRecProc; // make it global, so that the Garbage Collector can not remove it
...
Bass.BASS_RecordInit(-1);
_myRecProc = new RECORDPROC(MyRecording);
// start recording paused
int recChannel = Bass.BASS_RecordStart(44100, 2, BASSFlag.BASS_RECORD_PAUSE, _myRecProc, IntPtr.Zero);
...
// really start recording
Bass.BASS_ChannelPlay(recChannel, false);
...
// the recording callback
private bool MyRecording(int handle, IntPtr buffer, int length, IntPtr user)
{
  return true;
}
See BASS_RecordInit(Int32) for a recording callback sample.
See Also

Reference