annotate src/libsndfile-1.0.25/Octave/sndfile_play.m @ 0:c7265573341e

Import initial set of sources
author Chris Cannam
date Mon, 18 Mar 2013 14:12:14 +0000
parents
children
rev   line source
Chris@0 1 ## Copyright (C) 2002-2011 Erik de Castro Lopo
Chris@0 2 ##
Chris@0 3 ## This program is free software; you can redistribute it and/or modify
Chris@0 4 ## it under the terms of the GNU General Public License as published by
Chris@0 5 ## the Free Software Foundation; either version 2, or (at your option)
Chris@0 6 ## any later version.
Chris@0 7 ##
Chris@0 8 ## This program is distributed in the hope that it will be useful, but
Chris@0 9 ## WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@0 10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Chris@0 11 ## General Public License for more details.
Chris@0 12 ##
Chris@0 13 ## You should have received a copy of the GNU General Public License
Chris@0 14 ## along with this file. If not, write to the Free Software Foundation,
Chris@0 15 ## 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Chris@0 16
Chris@0 17 ## -*- texinfo -*-
Chris@0 18 ## @deftypefn {Function File} {} sndfile_play (@var{data, fs})
Chris@0 19 ## Play @var{data} at sample rate @var{fs} using the sndfile-play
Chris@0 20 ## program.
Chris@0 21 ## @end deftypefn
Chris@0 22
Chris@0 23 ## Author: Erik de Castro Lopo <erikd@mega-nerd.com>
Chris@0 24 ## Description: Play the given data as a sound file
Chris@0 25
Chris@0 26 function sndfile_play (data, fs)
Chris@0 27
Chris@0 28 if nargin != 2,
Chris@0 29 error ("Need two input arguments: data and fs.") ;
Chris@0 30 endif
Chris@0 31
Chris@0 32 if (max (size (fs)) > 1),
Chris@0 33 error ("Second parameter fs must be a single value.") ;
Chris@0 34 endif
Chris@0 35
Chris@0 36 [nr nc] = size (data) ;
Chris@0 37
Chris@0 38 if (nr > nc),
Chris@0 39 data = data' ;
Chris@0 40 endif
Chris@0 41
Chris@0 42 samplerate = fs ;
Chris@0 43 wavedata = data ;
Chris@0 44
Chris@0 45 filename = tmpnam () ;
Chris@0 46
Chris@0 47 cmd = sprintf ("save -mat-binary %s fs data", filename) ;
Chris@0 48
Chris@0 49 eval (cmd) ;
Chris@0 50
Chris@0 51 cmd = sprintf ("sndfile-play %s", filename) ;
Chris@0 52
Chris@0 53 [output, status] = system (cmd) ;
Chris@0 54
Chris@0 55 if (status),
Chris@0 56 disp (outout) ;
Chris@0 57 endif
Chris@0 58
Chris@0 59 endfunction