2
0

sndfile_load.m 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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_load (@var{filename})
  18. ## Load data from the file given by @var{filename}.
  19. ## @end deftypefn
  20. ## Author: Erik de Castro Lopo <erikd@mega-nerd.com>
  21. ## Description: Load the sound data from the given file name
  22. function [data fs] = sndfile_load (filename)
  23. if (nargin != 1),
  24. error ("Need an input filename") ;
  25. endif
  26. samplerate = -1 ;
  27. samplingrate = -1 ;
  28. wavedata = -1 ;
  29. eval (sprintf ('load -f %s', filename)) ;
  30. if (samplerate > 0),
  31. fs = samplerate ;
  32. elseif (samplingrate > 0),
  33. fs = samplingrate ;
  34. else
  35. error ("Not able to find sample rate.") ;
  36. endif
  37. if (max (size (wavedata)) > 1),
  38. data = wavedata ;
  39. else
  40. error ("Not able to find waveform data.") ;
  41. endif
  42. endfunction