Home > freetb4matlab > audio > sound.m



% error: sound(x [, fs, bs])


function sound(data, rate, buffer_size)


% error: sound(x [, fs, bs])
% Play the signal through the speakers.  Data is a matrix with
% one column per channel.  Rate fs defaults to 8000 Hz.  The signal
% is clipped to [-1, 1].  Buffer size bs controls how many audio samples 
% are clipped and buffered before sending them to the audio player.  bs 
% defaults to fs, which is equivalent to 1 second of audio.  
% Note that if $DISPLAY ~= $HOSTNAME:n then a remote shell is opened
% to the host specified in $HOSTNAME to play the audio.  See manual
% pages for ssh, ssh-keygen, ssh-agent and ssh-add to learn how to 
% set it up.
% This function writes the audio data through a pipe to the program
% 'play' from the sox distribution.  sox runs pretty much anywhere,
% but it only has audio drivers for OSS (primarily linux and freebsd)
% and SunOS.  In case your local machine is not one of these, write
% a shell script such as ~/bin/octaveplay, substituting AUDIO_UTILITY
% with whatever audio utility you happen to have on your system:
%   %~/bin/sh
%   cat > ~/.octave_play.au
%   SYSTEM_AUDIO_UTILITY ~/.octave_play.au
%   rm -f ~/.octave_play.au
% and set the global variable (e.g., in .octaverc)
%   global sound_play_utility='~/bin/octaveplay';
% If your audio utility can accept an AU file via a pipe, then you
% can use it directly:
%   global sound_play_utility='SYSTEM_AUDIO_UTILITY flags'
% where flags are whatever you need to tell it that it is receiving
% an AU file.
% With clever use of the command dd, you can chop out the header and
% dump the data directly to the audio device in big-endian format:
%   global sound_play_utility='dd of=/dev/audio ibs=2 skip=12'
% or little-endian format:
%   global sound_play_utility='dd of=/dev/dsp ibs=2 skip=12 conv=swab'
% but you lose the sampling rate in the process.  
% Finally, you could modify sound.m to produce data in a format that 
% you can dump directly to your audio device and use 'cat >/dev/audio' 
% as your sound_play_utility.  Things you may want to do are resample
% so that the rate is appropriate for your machine and convert the data
% to mulaw and output as bytes.
% If you experience buffer underruns while playing audio data, the bs
% buffer size parameter can be increased to tradeoff interactivity
% for smoother playback.  If bs=Inf, then all the data is clipped and 
% buffered before sending it to the audio player pipe.  By default, 1 
% sec of audio is buffered.


This function calls: This function is called by:
Generated on Sat 16-May-2009 00:04:49 by m2html © 2003