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