sndfile_save.m 1.6 KB

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