Audio capture devices
Audio source
When AudioSource = as_Default (default value), the audio output of the video capture device is used for recording if this device exposes an audio output (e.g. a webcam with a built-in microphone); otherwise, the audio output of the current audio capture device is used.
When AudioSource = as_UseExternalAudio, the current audio capture device is used for recording, even if the video capture device has an audio output.
Audio capture device
The current audio capture device is selected by AudioDevice, an index in the AudioDevices list, which contains AudioDevicesCount items.
To select the audio capture device by name programmatically, use AudioDeviceIndex, which accepts the same * wildcards as VideoDeviceIndex (see Video capture devices), e.g.:
VideoGrabber.AudioDevice := VideoGrabber.AudioDeviceIndex ('*USB Audio*'); // 1st audio capture device whose name contains "USB Audio"
AudioDeviceIndex returns -1 if no device matches (AudioDevice = -1: automatic selection, see below). The FindIndexInListByName function can also be used, e.g.:
VideoGrabber.AudioDevice := VideoGrabber.FindIndexInListByName (VideoGrabber.AudioDevices, 'name of my audio device', false, true);
To select the microphone of a webcam, use AudioDeviceIndexFromVideoDevice rather than its name (see below): the microphones of several webcams of the same model have the same name.
The name of the current audio capture device is reported by AudioDeviceName.
Audio capture device of a webcam or USB capture device
When AudioDevice = -1 (default value, no audio capture device assigned) and AudioRecording or AudioDeviceRendering is enabled, the audio capture device of the current video capture device is selected automatically when the preview or the recording starts, e.g. the microphone of the selected webcam. A single TVideoGrabber instance records the video and the audio of the camera in the same file: no second instance is needed for the audio.
The audio capture device is searched first on the same USB device as the video capture device (USB device path). This works with several cameras of the same brand and model, which have the same name. If the video capture device has no audio interface on the same USB device, the audio capture device is searched by name.
Once the preview or the recording is started, AudioDevice and AudioDeviceName return the audio capture device selected. When another video capture device is selected, the automatic selection is done again for this device at the next start.
To know the audio capture device of a video capture device without starting, call AudioDeviceIndexFromVideoDevice (VideoDeviceIndex). It returns the index in the AudioDevices list of the audio capture device of the same USB device, or -1 if there is none (PCI / PCIe capture card, virtual camera, webcam without microphone). The devices are matched on their USB device path only, never on their names. The index is returned even when the device is unplugged: IsAudioDeviceConnected tells whether it is currently plugged in.
E.g. with several webcams of the same model, each one recorded by its own TVideoGrabber instance:
// cameraIndex = index of the webcam in the VideoDevices list
VideoGrabber.VideoDevice = cameraIndex;
VideoGrabber.AudioDevice = VideoGrabber.AudioDeviceIndexFromVideoDevice (cameraIndex); // -1: no microphone on this webcam
VideoGrabber.AudioRecording = VideoGrabber.AudioDevice >= 0;
VideoGrabber.StartRecording();
Device-dependent properties
When an audio capture device is selected, its device-dependent properties are reloaded from the registry and the OnAudioDeviceSelected event occurs: refresh from this event any control that uses e.g. the audio inputs.
Audio inputs
After an audio capture device is selected, the AudioInputs list returns the audio inputs available for this audio capture device. To select an audio input, assign its index in the list to the AudioInput property (in the 0...AudioInputsCount - 1 range).
Audio input level
The audio input level is adjusted with AudioInputLevel (in the 0..65535 range).
Audio input balance
The audio input balance is adjusted with AudioInputBalance, in the -32768...32767 range (the center point is 0).
The audio input balance may or may not be available, depending on the audio input. While preview or recording is running, IsAudioInputBalanceAvailable returns ts_True if the audio balance is available, and ts_False if not. When preview and recording are stopped, it returns ts_Undefined.
Audio recording
The recording of the current audio capture device is activated when AudioRecording is enabled.
Audio rendering
The audio rendering is activated when AudioDeviceRendering is enabled.
The audio volume is adjusted with AudioVolume and the audio balance with AudioBalance.
To mute or unmute the audio, enable or disable the MuteAudioRendering property.
These settings affect only the volume and balance of the audio rendering, not the volume and balance of the audio recording.
Device connection/disconnection
When an audio capture device is connected or disconnected, the OnDeviceArrivalOrRemoval event occurs. This event reports the name and index of the audio capture device in the global AudioDevices list.
The event also occurs when an audio capture device is enabled or disabled in the Windows sound settings, or when a microphone is plugged into or removed from a jack (on the sound cards that report it).
After an audio capture device has been disconnected, IsAudioDeviceConnected returns false for its index in the AudioDevices list until the device is reconnected.
If the device is used by preview or recording, the OnDeviceLost event occurs when the device is disconnected, and the preview or recording stops.