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_save (@var{filename, data, fs}) Chris@0: ## Save the given @var{data} as audio data to the given at @var{fs}. Set Chris@0: ## the sample rate to @var{fs}. Chris@0: ## @end deftypefn Chris@0: Chris@0: ## Author: Erik de Castro Lopo Chris@0: ## Description: Save data as a sound file Chris@0: Chris@0: function sndfile_save (filename, data, fs) Chris@0: Chris@0: if nargin != 3, Chris@0: error ("Need three input arguments: filename, data and fs.") ; Chris@0: endif Chris@0: Chris@0: if (! isstr (filename)), Chris@0: error ("First parameter 'filename' is must be a string.") ; Chris@0: endif Chris@0: Chris@0: if (max (size (fs)) > 1), Chris@0: error ("Second parameter 'fs' must be a single value, not an array or matrix.") ; 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: str = sprintf ("save -mat-binary %s samplerate wavedata", filename) ; Chris@0: Chris@0: eval (str) ; Chris@0: Chris@0: endfunction