Chris@0: ## Copyright (C) 2002-2011 Erik de Castro Lopo Chris@0: ## Chris@0: ## This program is free software; you can redistribute it and/or modify Chris@0: ## it under the terms of the GNU General Public License as published by Chris@0: ## the Free Software Foundation; either version 2, or (at your option) Chris@0: ## any later version. Chris@0: ## Chris@0: ## This program is distributed in the hope that it will be useful, but Chris@0: ## WITHOUT ANY WARRANTY; without even the implied warranty of Chris@0: ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Chris@0: ## General Public License for more details. Chris@0: ## Chris@0: ## You should have received a copy of the GNU General Public License Chris@0: ## along with this file. If not, write to the Free Software Foundation, Chris@0: ## 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. Chris@0: Chris@0: ## -*- texinfo -*- Chris@0: ## @deftypefn {Function File} {} sndfile_play (@var{data, fs}) Chris@0: ## Play @var{data} at sample rate @var{fs} using the sndfile-play Chris@0: ## program. Chris@0: ## @end deftypefn Chris@0: Chris@0: ## Author: Erik de Castro Lopo Chris@0: ## Description: Play the given data as a sound file Chris@0: Chris@0: function sndfile_play (data, fs) Chris@0: Chris@0: if nargin != 2, Chris@0: error ("Need two input arguments: data and fs.") ; Chris@0: endif Chris@0: Chris@0: if (max (size (fs)) > 1), Chris@0: error ("Second parameter fs must be a single value.") ; Chris@0: endif Chris@0: Chris@0: [nr nc] = size (data) ; Chris@0: Chris@0: if (nr > nc), Chris@0: data = data' ; Chris@0: endif Chris@0: Chris@0: samplerate = fs ; Chris@0: wavedata = data ; Chris@0: Chris@0: filename = tmpnam () ; Chris@0: Chris@0: cmd = sprintf ("save -mat-binary %s fs data", filename) ; Chris@0: Chris@0: eval (cmd) ; Chris@0: Chris@0: cmd = sprintf ("sndfile-play %s", filename) ; Chris@0: Chris@0: [output, status] = system (cmd) ; Chris@0: Chris@0: if (status), Chris@0: disp (outout) ; Chris@0: endif Chris@0: Chris@0: endfunction