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