Main Content

listAudioDevices

List available ALSA audio devices

Add-On Required: This feature requires the Simulink Support Package for Raspberry Pi Hardware add-on.

Description

example

devices = listAudioDevices(raspPiObj,audioType) returns a list of Advanced Linux Sound Architecture (ALSA) audio devices connected to your Raspberry Pi® hardware. The type of listed audio devices (capture or playback) depends on the audioType specified in the function.

Note

Simulink® Online™ does not support the listAudioDevices function currently.

Examples

collapse all

To list all connected ALSA audio input devices:

  1. Create a connection to the Raspberry Pi hardware.

    raspPiObj = raspberrypi('192.168.1.5','pi','raspberrypi')
    rasPiObj = 
    
      raspberrypi with properties:
    
        DeviceAddress: '192.168.1.5'
                 Port: 22

    For more information on raspberrypi, see raspberrypi.

  2. Use the listAudioDevices function. In the function, specify audioType as 'capture'. The function returns a structured array with field names that correspond to the properties of ALSA audio input devices connected to raspPiObj.

    devices = listAudioDevices(raspPiObj,'capture')
    devices = 
    
      1×2 struct array with fields:
    
        Name
        Device
        Channels
        BitDepth
        SamplingRate
    

    In this example, the function returns a 1-by-2 array, indicating that two audio input devices are connected to raspPiObj.

  3. View the properties of the first ALSA audio input device.

    devices(1)
    ans = 
    
      struct with fields:
    
              Name: ' bcm2835 - bcm2835 ALSA↵'
            Device: '0,0'
          Channels: {'CHANNELS: [1 2]'}
          BitDepth: {'8-bit integer'  '16-bit integer'}
      SamplingRate: {'8000 48000'} 
    

To list all connected ALSA audio output devices:

  1. Create a connection to the Raspberry Pi hardware.

    raspPiObj = raspberrypi('192.168.1.5','pi','raspberrypi')
  2. Use the listAudioDevices function. In the function, specify audioType as 'playback'. The function returns a structured array with field names that correspond to the properties of ALSA audio output devices connected to raspPiObj.

    devices = listAudioDevices(raspPiObj, 'playback')
    devices = 
    
      1×3 struct array with fields:
    
        Name
        Device
        Channels
        BitDepth
        SamplingRate
    

    In this example, the function returns a 1-by-3 array, indicating that three audio output devices are connected to raspPiObj.

  3. View the properties of the second ALSA audio output device.

    devices(2)
    ans = 
    
      struct with fields:
    
              Name: ' bcm2835 - bcm2835 ALSA↵'
            Device: '0,1'
          Channels: {'CHANNELS: 2'}
          BitDepth: {'8-bit integer'  '16-bit integer'}
      SamplingRate: {'44100 48000'} 
    

Input Arguments

collapse all

The object that represents the connection to the Raspberry Pi hardware.

Example: raspPiObj

Specify the type of audio to be listed:

  • 'capture' — All ALSA audio input devices connected to Raspberry Pi.

  • 'playback' — All ALSA audio output devices connected to Raspberry Pi.

Example: 'playback'

Data Types: char

Output Arguments

collapse all

The type of listed audio devices depends on the audioType specified in the function. The resulting structured array contains these details:

  • Name: The name of the audio device.

  • Device: The device number of the audio device.

  • Channels: The number of channels supported by the audio device. For example, in List Available ALSA Audio Output Devices, the audio device supports audio from two channels only.

  • BitDepth: The data type in which the audio device reads or sends data.

  • SamplingRate: The sample rates supported by the audio device.

Data Types: cell