Obtain information on installed audio devices
Syntax
d = audiodevinfo
audiodevinfo(io)
audiodevinfo(io,ID)
audiodevinfo(io,ID,'DriverVersion')
audiodevinfo(io,name)
audiodevinfo(io,rate,bits,chans)
audiodevinfo(io,ID,rate,bits,chans)
Description
d = audiodevinfo
returns a structure, d
with an input field and an output field. Each field is an array of structures that contains information about the system's audio input and output devices. Each array contains these fields: a string with the name of the device, a string with the version of the installed driver (DriverVersion)
, and the device's numeric ID.
audiodevinfo(io)
returns the number of input (io
=1
) or output (io
=0
) audio devices on the system.
audiodevinfo(io,ID)
returns the name of the audio device specified by its ID
.
audiodevinfo(io,ID,'DriverVersion')
returns a string containing the driver version of the specified audio device.
audiodevinfo(io,name)
returns the device ID specified by name
. You can enter a partial name
, but the case must match. If no device with the specified name is found, -1
is returned.
audiodevinfo(io,rate,bits,chans)
returns the device ID of the first audio device that supports the specified sample rate
, number of bits
, and number of channels, chans
. If no matching device is found, -1
is returned.
audiodevinfo(io,ID,rate,bits,chans)
returns 1
if the device, specified by its ID
, supports the specified sample rate
, number of bits
, and number of channels, chans
. If the device does not support the specified parameters, 0
is returned.
Syntax
Description
y = audioplayer(x,Fs)
returns a handle to an audio player object y
using input audio signal x
. The input signal x
can be a vector or two-dimensional array containing single
, double
, int8
, uint8
, or int16
MATLAB data types. The input sample values for single
and double
data must be between -1 and 1. For int8
, uint8
, and int16
data, the ranges of sample values are -128 to 127, 0 to 255, and -32768 to 32767, respectively.
Fs
is the sampling rate in Hz to use for playback. Valid values for Fs
depend on the specific audio hardware installed. Typical values supported by most sound cards are 8000, 11025, 22050, and 44100 Hz.
y = audioplayer(x,Fs,nbits)
returns a handle to an audio player object where nbits
is the bit quantization to use for single
or double
data types. This is an optional parameter with a default value of 16.
Valid values for nbits
are 8
and 16
(and 24
, if a 24-bit device is installed). You do not need to specify nbits
for int8
, uint8
or int16
data because the quantization is set automatically to 8
or 16
, respectively.
y = audioplayer(r)
returns a handle to an audio player object from an audiorecorder
object r
.
y = audioplayer(r,id)
returns a handle to an audio player object from an audiorecorder
object r
, using the specified audio device id
for output.
After you create an audio player object, you can use the methods listed below on that object. y
represents the name of the returned audio player.
Audio player objects have the properties listed below. To set a user-settable property use this syntax:
Example
Load a sample audio file, create an audio player object, and play the audio at a higher sampling rate. x
contains the audio samples and Fs
is the sampling rate. You can use any of the audioplayer
functions listed above on the player
.
To stop the playback, use this command:
audiorecorderCreate an audio recorder object
Syntax
Description
y = audiorecorder
returns a handle to an 8-kHz, 8-bit, mono audio recorder object.
y = audiorecorder(Fs,nbits,channels)
returns a handle to an audio recorder object using the sampling rate
, Fs
( in Hz), the sample size of nbits
, and the number of channels
. Fs
can be any sampling rate supported by the audio hardware. Common sampling rates are 8000, 11025, 22050, and 44000. The value of nbits
must be 8
or 16
(or 24
, if a 24-bit device is installed). For mono or stereo, channels
must be 1
or 2
, respectively.
y = audiorecorder(Fs,nbits,channels,id)
returns a handle to an audio recorder object using the audio device specified by its id
for input.
After you create an audio recorder object, you can use the methods listed below on that object. y
represents the name of the returned audio recorder.
Method | Description |
record(y) record(y,length) | Starts recording. Records for length number of seconds. |
recordblocking(y,length) | Same as record, but does not return control until recording completes. |
stop(y) | Stops recording. |
pause(y) | Pauses recording. |
resume(y) | Restarts recording from where recording was paused. |
isrecording(y) | Indicates the status of recording. If 0 , recording is not in progress. If 1 , recording is in progress. |
play(y) | Creates an audioplayer , plays the recorded audio data, and returns a handle to the created audioplayer . |
getplayer(y) | Creates an audioplayer and returns a handle to the created audioplayer . |
getaudiodata(y)getaudiodata(y,'type') | Returns the recorded audio data to the MATLAB workspace. type is a string containing the desired data type. Supported data types are double , single , int16 , int8 , or uint8 . If type is omitted, it defaults to 'double' . For double and single , the array contains values between -1 and 1. For int8 , values are between -128 to 127. For uint8 , values are from 0 to 255. For int16 , values are from -32768 to 32767. If the recording is in mono, the returned array has one column. If it is in stereo, the array has two columns--one for each channel. |
display(y) disp(y) get(y) | Displays all property information about audio recorder y. |
Audio recorder objects have the properties listed below. To set a user-settable property use this syntax:
Example 1
Using a microphone, record 3.5 seconds of 44.1-kHz, 16-bit, stereo data, and then return the data to the MATLAB workspace as a double array.
recorder = audiorecorder(44100,16,2);
recordblocking(recorder,3.5);
audioarray = getaudiodata(recorder);
Example 2
Using a microphone, record 8-bit, 22-kHz mono data, play it back, record again and return the data to the MATLAB workspace as a uint8
array.
micrecorder = audiorecorder(22050,8,1);
record(micrecorder);
% Now, speak into microphone
stop(micrecorder);
speechplayer = play(micrecorder);
% Now, listen to the recording
stop(speechplayer);
speechdata = getaudiodata(micrecorder, 'uint8');
Remarks
The current implementation of AudioRecorder
is not intended for long, high sample rate recording because it uses system memory for storage and does not use disk buffering. When large recordings are attempted, MATLAB performance may degrade.
No comments:
Post a Comment