Info about audio device (within matlab)

devinfo = audiodevinfo
devs = audiodevinfo(IO)
name = audiodevinfo(IO, ID)
ID = audiodevinfo(IO, name)
DriverVersion = audiodevinfo(IO, ID, 'DriverVersion')
ID = audiodevinfo(IO, rate, bits, chans)
doesSupport = audiodevinfo(IO, ID, rate, bits, chans)

Description

  • devinfo = audiodevinfo returns a structure, devinfo, containing two fields, input and output. Each field is an array of structures, with each structure containing information about one of the audio input or output devices on the system. The individual device structure fields are:
  • Name — A string indicating the name of the device.
  • DriverVersion — A string indicating the type of the installed device driver.

  • ID — The ID of the device.
  • devs = audiodevinfo(IO) returns the number of input or output audio devices on the system. Use an IO value of 1 to indicate input, and an IO value of 0 to indicate output.
  • name = audiodevinfo(IO, ID) returns the name of the input or output audio device identified by device ID.
  • ID = audiodevinfo(IO, name) returns the device ID of the input or output audio device identified by the given name (partial matching, case sensitive). If no audio device is found with the given name, -1 is returned.
  • DriverVersion = audiodevinfo(IO, ID, 'DriverVersion') returns a string indicating the type of the specified audio input or output device.

  • ID = audiodevinfo(IO, rate, bits, chans) returns the device ID of the first input or output device that supports the sample rate, number of bits, and number of channels specified by the values of rate, bits, and chans, respectively. If no supporting device is found, -1 is returned.
  • doesSupport = audiodevinfo(IO, ID, rate, bits, chans) returns 1 or 0 for whether or not the input or output audio device specified by ID can support the given sample rate, number of bits, and number of channels.

Testing Audio in matlab

Produce a beep sound:

beep       % produces your computer's default beep sound
beep on    % on turns the beep on.
beep off   % on turns the beep off.
s = beep   % return the status of beep (on or off)

Or create an audio object and play it:

load handel;
player = audioplayer(y, Fs);
play(player)

Or play the data directly from the .mat file (converts matrix into sound):

load gong.mat;
sound(y, Fs);

Configuring the sound for the record/playback lab

At the terminal type:

alsamixer -V all

Maximize the window/terminal, navigate using the right-left keys and set the options as follows:

 * Master 100%
 * Headphone 100%
 * PCM 100%
 * Front 100%
 * Front Mic 100%
 * Front Mic Boost 60-70%
 * Line 0%
 * Mic 100%
 * Mic Boost 60-70%
 * Capture (L|R) 100%
 * Capture 100%
 * Digital 100%
 * InputSo 0%
 * Speaker 0%

Note: Speaker refers to the internal speaker.

Allowing multiple use of the sound device

This should be set in lab machines already, no need to create your own .asoundrc, it is in /etc/asound.conf

Note: If Matlab give you this error:

Device Error: Invalid Sample Rate

It means the sound device is locked.

gedit ~/.asoundrc 

Paste the code:

pcm.dmixer {
type dmix
ipc_key 1025
ipc_key_add_uid false
ipc_perm 0666
slave {
pcm "hw:0,0"
period_time 0
period_size 1024
buffer_size 8192
rate 44100
}
}
pcm.!default {
type plug
slave.pcm "dmixer"
}

Testing the Microphone and Speakers in Matlab in PHO307

Start Matlab and run the following code with the microphone and speaker plugged in the back of the machine. The recording will not work if the microphone is plugged in the front:

r = audiorecorder(44100, 16, 1);
record(r); % speak into microphone...
pause(r);
p = play(r); % listen
resume(r); % speak again
stop(r);
p = play(r); % listen to complete recording
mySpeech = getaudiodata(r, 'int16'); % you can use this for plotting the
signal

Old info

Use modern ALSA instead of the older OSS system, with the below command:

amixer set Mic cap on 25
amixer set PCM 35

The first line sets the mic to on, capturing, and level 25 (81% of max). This recorded audio fine in the test we just did with Simulink and we think it should Just Plain Work for the lab application. The second line sets the PCM at level 35 (90% of max). The recorded audio will be amplified while played back.

ECE: Linux_Audio_in_Matlab (last edited 2013-02-15 17:55:21 by ilyas)