matlab\audiovideo – Звуковая и видео поддержка
Audio input/output objects
<audioplayer> - Audio player object.
AUDIOPLAYER Audio player object.
AUDIOPLAYER(Y, Fs) creates an AUDIOPLAYER object for signal Y, using
sample rate Fs. A handle to the object is returned.
AUDIOPLAYER(Y, Fs, NBITS) creates an AUDIOPLAYER object and uses NBITS
bits per sample for floating point signal Y. Valid values for NBITS
are 8, 16, and 24 on Windows, 8 and 16 on UNIX. The default number of
bits per sample for floating point signals is 16.
AUDIOPLAYER(Y, Fs, NBITS, ID) creates an AUDIOPLAYER object using
audio device identifier ID for output. If ID equals -1 the default
output device will be used. This option is only available on Windows.
AUDIOPLAYER(R) creates an AUDIOPLAYER object from AUDIORECORDER object R.
AUDIOPLAYER(R, ID) creates an AUDIOPLAYER object from AUDIORECORDER object R using audio device identifier ID for output. This option is only available on Windows.
Example: Load snippet of Handel's Hallelujah Chorus and play back
only the first three seconds.
load handel;
p = audioplayer(y, Fs);
play(p, [1 (get(p, 'SampleRate') * 3)]);
See also audiorecorder, audiodevinfo, methods, audioplayer/get,
audioplayer/set.
Reference page in Help browser
doc audioplayer
<audiorecorder> - Audio recorder object.
AUDIORECORDER Audio recorder object.
AUDIORECORDER creates an 8000 Hz, 8-bit, 1 channel AUDIORECORDER object.
A handle to the object is returned.
AUDIORECORDER(Fs, NBITS, NCHANS) creates an AUDIORECORDER object with
sample rate Fs in Hertz, number of bits NBITS, and number of channels NCHANS.
Common sample rates are 8000, 11025, 22050, and 44100 Hz
(only 44100, 48000, and 96000 on a Macintosh). The number of bits
must be 8, 16, or 24 on Windows, 8 or 16 on UNIX. The number of channels
must be 1 or 2 (mono or stereo).
AUDIORECORDER(Fs, NBITS, NCHANS, ID) creates an AUDIORECORDER object using audio device identifier ID for input. If ID equals -1 the default input device will be used. This option is only available on Windows.
Example: Record your voice on-the-fly. Use a sample rate of 22050 Hz,
16 Bits, and one channel. Speak into the microphone, then
pause the recording. Play back what you've recorded so far.
Record some more, then stop the recording. Finally, return
the recorded data to MATLAB as an int16 array.
r = audiorecorder(22050, 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'); % get data as int16 array
See also audioplayer, audiodevinfo, methods, audiorecorder/get,
audiorecorder/set.
Reference page in Help browser
doc audiorecorder
Audio hardware drivers
<sound> - Play vector as sound.
SOUND Play vector as sound.
SOUND(Y,FS) sends the signal in vector Y (with sample frequency
FS) out to the speaker on platforms that support sound. Values in
Y are assumed to be in the range -1.0 <= y <= 1.0. Values outside
that range are clipped. Stereo sounds are played, on platforms
that support it, when Y is an N-by-2 matrix.
SOUND(Y) plays the sound at the default sample rate of 8192 Hz.
SOUND(Y,FS,BITS) plays the sound using BITS bits/sample if
possible. Most platforms support BITS=8 or 16.
Example:
load handel
sound(y,Fs)
You should hear a snippet of Handel's Hallelujah Chorus.
See also soundsc, wavplay.
Reference page in Help browser
doc sound
<soundsc> - Autoscale and play vector as sound.
SOUNDSC Autoscale and play vector as sound.
SOUNDSC(Y,...) is the same as SOUND(Y,...) except the data is
scaled so that the sound is played as loud as possible without
clipping. The mean of the dynamic range of the data is set to
zero after the normalization.
SOUNDSC(Y,...,SLIM) where SLIM = [SLOW SHIGH] linearly scales
Values in y in the range [slow, shigh] to [-1, 1]. Values
outside this range are not clipped. By default, SLIM is
[MIN(Y) MAX(Y)].
See also sound, wavplay, wavrecord.
Reference page in Help browser
doc soundsc
Audio file import and export
<aufinfo> - Return information about AU file.
AUFINFO Text description of AU file contents.
Reference page in Help browser
doc aufinfo
<auread> - Read NeXT/SUN (".au") sound file.
AUREAD Read NeXT/SUN (".au") sound file.
Y=AUREAD(AUFILE) loads a sound file specified by the string AUFILE,
returning the sampled data in y. The ".au" extension is appended
if no extension is given. Amplitude values are in the range [-1,+1].
Supports multi-channel data in the following formats:
8-bit mu-law, 8-, 16-, and 32-bit linear, and floating point.
[Y,Fs,BITS]=AUREAD(AUFILE) returns the sample rate (Fs) in Hertz
and the number of bits per sample (BITS) used to encode the
data in the file.
[...]=AUREAD(AUFILE,N) returns only the first N samples from each
channel in the file.
[...]=AUREAD(AUFILE,[N1 N2]) returns only samples N1 through N2 from
each channel in the file.
SIZ=AUREAD(AUFILE,'size') returns the size of the audio data contained
in the file in place of the actual audio data, returning the
vector SIZ=[samples channels].
See also auwrite, wavread.
Reference page in Help browser
doc auread
<auwrite> - Write NeXT/SUN (".au") sound file.
AUWRITE Write NeXT/SUN (".au") sound file.
AUWRITE(Y,AUFILE) writes a sound file specified by the
string AUFILE. The data should be arranged with one channel
per column. Amplitude values outside the range [-1,+1] are
clipped prior to writing.
Supports multi-channel data for 8-bit mu-law, and 8- and
16-bit linear formats:
AUWRITE(Y,Fs,AUFILE) specifies the sample rate of the data
in Hertz.
AUWRITE(Y,Fs,BITS,AUFILE) selects the number of bits in
the encoder. Allowable settings are BITS=8 and BITS=16.
AUWRITE(Y,Fs,BITS,METHOD,AUFILE) allows selection of the
encoding method, which can be either 'mu' or 'linear'.
Note that mu-law files must be 8-bit. By default, method='mu'.
See also auread, wavwrite.
Reference page in Help browser
doc auwrite
<wavfinfo> - Return information about WAV file.
WAVFINFO Text description of WAV file contents.
Reference page in Help browser
doc wavfinfo
<wavread> - Read Microsoft WAVE (".wav") sound file.
WAVREAD Read Microsoft WAVE (".wav") sound file.
Y=WAVREAD(FILE) reads a WAVE file specified by the string FILE,
returning the sampled data in Y. The ".wav" extension is appended
if no extension is given.
[Y,FS,NBITS]=WAVREAD(FILE) returns the sample rate (FS) in Hertz
and the number of bits per sample (NBITS) used to encode the
data in the file.
[...]=WAVREAD(FILE,N) returns only the first N samples from each
channel in the file.
[...]=WAVREAD(FILE,[N1 N2]) returns only samples N1 through N2 from
each channel in the file.
[Y,...]=WAVREAD(...,FMT) specifies the data type format of Y used
to represent samples read from the file.
If FMT='double', Y contains double-precision normalized samples.
If FMT='native', Y contains samples in the native data type
found in the file. Interpretation of FMT is case-insensitive,
and partial matching is supported. If omitted, FMT='double'.
SIZ=WAVREAD(FILE,'size') returns the size of the audio data contained
in the file in place of the actual audio data, returning the
2-element vector SIZ=[samples channels].
[Y,FS,NBITS,OPTS]=WAVREAD(...) returns a structure OPTS of additional
information contained in the WAV file. The content of this
structure differs from file to file. Typical structure fields
include '.fmt' (audio format information) and '.info' (text
which may describe title, author, etc.)
Output Scaling
The range of values in Y depends on the data format FMT specified.
Some examples of output scaling based on typical bit-widths found
in a WAV file are given below for both 'double' and 'native' formats.
FMT='native'
#Bits MATLAB data type Data range
----- ----------------------------- -------------------
8 uint8 (unsigned integer) 0 <= Y <= 255
16 int16 (signed integer) -32768 <= Y <= +32767
24 int32 (signed integer) -2^23 <= Y <= 2^23-1
32 single (floating point) -1.0 <= Y <= +1.0
FMT='double'
#Bits MATLAB data type Data range
----- ------------------------- -------------------
N<32 double -1.0 <= Y < +1.0
N=32 double -1.0 <= Y <= +1.0
Note: Values in y might exceed -1.0 or +1.0 for the case of
N=32 bit data samples stored in the WAV file.
Supports multi-channel data, with up to 32 bits per sample.
Supports Microsoft PCM data format only.
See also wavwrite, auread, auwrite.
Reference page in Help browser
doc wavread
<wavwrite> - Write Microsoft WAVE (".wav") sound file.
WAVWRITE Write Microsoft WAVE (".wav") sound file.
WAVWRITE(Y,FS,NBITS,WAVEFILE) writes data Y to a Windows WAVE
file specified by the file name WAVEFILE, with a sample rate
of FS Hz and with NBITS number of bits. NBITS must be 8, 16,
24, or 32. Stereo data should be specified as a matrix with two
columns.
WAVWRITE(Y,FS,WAVEFILE) assumes NBITS=16 bits.
WAVWRITE(Y,WAVEFILE) assumes NBITS=16 bits and FS=8000 Hz.
Input Data Ranges
The range of values in Y depends on the number of bits specified by NBITS
and the data type of Y. Some examples of valid input ranges based on the
value of NBITS and Y's data type are listed in the tables below.
If Y contains integer data:
NBITS Y's data type Y's Data range Output Format
--------- ---------------- --------------------- -------------
8 uint8 0 <= Y <= 255 uint8
16 int16 -32768 <= Y <= +32767 int16
24 int32 -2^23 <= Y <= 2^23-1 int32
If Y contains floating point data:
NBITS Y's data type Y's Data range Output Format
--------- ------------------- --------------------- -------------
8 single or double -1.0 <= Y < +1.0 uint8
16 single or double -1.0 <= Y < +1.0 int16
24 single or double -1.0 <= Y < +1.0 int32
32 single or double -1.0 <= Y <= +1.0 single
Note that for floating point data where NBITS < 32, amplitude values
are clipped to the range -1.0 <= Y < +1.0.
8-, 16-, and 24-bit files are type 1 integer PCM.
32-bit files are written as type 3 normalized floating point.
See also wavread, auwrite.
Reference page in Help browser
doc wavwrite
Video file import/export
<VideoReader> - Read video frames from a video file.
VIDEOREADER Create a multimedia reader object.
OBJ = VIDEOREADER(FILENAME) constructs a multimedia reader object, OBJ, that
can read in video data from a multimedia file. FILENAME is a string
specifying the name of a multimedia file. There are no restrictions
on file extensions. By default, MATLAB looks for the file FILENAME on
the MATLAB path.
If the object cannot be constructed for any reason (for example, if the
file cannot be opened or does not exist, or if the file format is not
recognized or supported), then MATLAB throws an error.
OBJ = VIDEOREADER(FILENAME, 'P1', V1, 'P2', V2, ...)
constructs a multimedia reader object, assigning values V1, V2, etc. to the
specified properties P1, P2, etc.
If an invalid property name or property value is specified, MATLAB throws
an error and the object is not created. Note that the property value pairs
can be in any format supported by the SET function, e.g. parameter-value
string pairs, structures, or parameter-value cell array pairs.
Example:
% Construct a multimedia reader object associated with file 'xylophone.mpg' with
% user tag set to 'myreader1'.
readerobj = VideoReader('xylophone.mpg', 'tag', 'myreader1');
% Read in all video frames.
vidFrames = read(readerobj);
% Get the number of frames.
numFrames = get(readerobj, 'numberOfFrames');
% Create a MATLAB movie struct from the video frames.
for k = 1 : numFrames
mov(k).cdata = vidFrames(:,:,:,k);
mov(k).colormap = [];
end
% Create a figure
hf = figure;
% Resize figure based on the video's width and height
set(hf, 'position', [150 150 readerobj.Width readerobj.Height])
% Playback movie once at the video's frame rate
movie(hf, mov, 1, readerobj.FrameRate);
See also audiovideo, VideoReader/get, VideoReader/set, VideoReader/read, mmfileinfo.
Reference page in Help browser
doc VideoReader
<VideoWriter> - Write video frames to a video file.