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