Main Content

Audio Input and Output

You can acquire and generate audio signals using one or more available channels of a supported audio device. You can also simultaneously operate channels on multiple supported audio devices. Data Acquisition Toolbox™ supports audio channels for devices that work with the DirectSound interface. You can:

  • Acquire and generate audio signals either in sequence or as separate operations.

  • Acquire and generate signals simultaneously where the signals may share their start time.

  • Acquire audio data in the background and filter or process the input data simultaneously. You can generate data immediately in response to the processed input data. In this case, both the acquisition and generation operations start and stop together.

Data Acquisition Toolbox does not read directly from or write directly to audio files using the multichannel audio feature. Instead, use the MATLAB® functions audioread and audiowrite.

Multichannel Audio Scan Rate

The Rate of an audio DataAcquisition is the scan rate at which it samples audio data. All channels in a DataAcquisition have the same scan rate. The default DataAcquisition rate for an audio DataAcquisition is 44100 Hz. If you have multiple devices in the DataAcquisition, make sure that they can all operate at a common scan rate.

Audio Measurement Range

Data you acquire or generate using audio channels contains double-precision values. These values are normalized to the range of -1 to +1. The DataAcquisition represents data acquired or generated in amplitude without units.

Acquire Audio Data

This example shows how to acquire audio data for seven seconds and plot the result.

Discover DirectSound audio devices installed on your system and create a DataAcquisition for these devices.

dev = daqlist;
dev =

  4×4 table

    DeviceID                        Description                                          Model                              DeviceInfo        
    ________    ____________________________________________________    ________________________________________    __________________________

    "Audio0"    "DirectSound Primary Sound Capture Driver"              "Primary Sound Capture Driver"              [1×1 daq.audio.DeviceInfo]
    "Audio1"    "DirectSound Headset Microphone (Plantronics BT600)"    "Headset Microphone (Plantronics BT600)"    [1×1 daq.audio.DeviceInfo]
    "Audio2"    "DirectSound Primary Sound Driver"                      "Primary Sound Driver"                      [1×1 daq.audio.DeviceInfo]
    "Audio3"    "DirectSound Headset Earphone (Plantronics BT600)"      "Headset Earphone (Plantronics BT600)"      [1×1 daq.audio.DeviceInfo]
d = daq("directsound")
d = 

DataAcquisition using DirectSound hardware:

                     Running: 0
                        Rate: 44100
           NumScansAvailable: 0
            NumScansAcquired: 0
              NumScansQueued: 0
    NumScansOutputByHardware: 0
                   RateLimit: []

Add an audio input channel for the microphone with id Audio1. The measurement type is Audio.

addinput(d,"Audio1",1,"Audio");
ch = 

    Index     Type      Device     Channel    Measurement Type        Range            Name   
    _____    ______    ________    _______    ________________    ______________    __________

      1      "audi"    "Audio1"      "1"          "Audio"         "-1.0 to +1.0"    "Audio1_1"

Acquire 7 seconds of data in the foreground and plot the data versus time.

[data,t] = read(d, seconds(7), "OutputFormat","Matrix");
plot(t,data)

Plot of 7 seconds of acquired audio data

Related Topics