annotate src/libsndfile-1.0.27/Octave/sndfile_save.m @ 127:7867fa7e1b6b

Current fftw source
author Chris Cannam <cannam@all-day-breakfast.com>
date Tue, 18 Oct 2016 13:40:26 +0100
parents cd6cdf86811e
children
rev   line source
cannam@125 1 ## Copyright (C) 2002-2011 Erik de Castro Lopo
cannam@125 2 ##
cannam@125 3 ## This program is free software; you can redistribute it and/or modify
cannam@125 4 ## it under the terms of the GNU General Public License as published by
cannam@125 5 ## the Free Software Foundation; either version 2, or (at your option)
cannam@125 6 ## any later version.
cannam@125 7 ##
cannam@125 8 ## This program is distributed in the hope that it will be useful, but
cannam@125 9 ## WITHOUT ANY WARRANTY; without even the implied warranty of
cannam@125 10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
cannam@125 11 ## General Public License for more details.
cannam@125 12 ##
cannam@125 13 ## You should have received a copy of the GNU General Public License
cannam@125 14 ## along with this file. If not, write to the Free Software Foundation,
cannam@125 15 ## 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
cannam@125 16
cannam@125 17 ## -*- texinfo -*-
cannam@125 18 ## @deftypefn {Function File} {} sndfile_save (@var{filename, data, fs})
cannam@125 19 ## Save the given @var{data} as audio data to the given at @var{fs}. Set
cannam@125 20 ## the sample rate to @var{fs}.
cannam@125 21 ## @end deftypefn
cannam@125 22
cannam@125 23 ## Author: Erik de Castro Lopo <erikd@mega-nerd.com>
cannam@125 24 ## Description: Save data as a sound file
cannam@125 25
cannam@125 26 function sndfile_save (filename, data, fs)
cannam@125 27
cannam@125 28 if nargin != 3,
cannam@125 29 error ("Need three input arguments: filename, data and fs.") ;
cannam@125 30 endif
cannam@125 31
cannam@125 32 if (! isstr (filename)),
cannam@125 33 error ("First parameter 'filename' is must be a string.") ;
cannam@125 34 endif
cannam@125 35
cannam@125 36 if (max (size (fs)) > 1),
cannam@125 37 error ("Second parameter 'fs' must be a single value, not an array or matrix.") ;
cannam@125 38 endif
cannam@125 39
cannam@125 40 [nr nc] = size (data) ;
cannam@125 41
cannam@125 42 if (nr > nc),
cannam@125 43 data = data' ;
cannam@125 44 endif
cannam@125 45
cannam@125 46 samplerate = fs ;
cannam@125 47 wavedata = data ;
cannam@125 48
cannam@125 49 str = sprintf ("save -mat-binary %s samplerate wavedata", filename) ;
cannam@125 50
cannam@125 51 eval (str) ;
cannam@125 52
cannam@125 53 endfunction