2
0

sndfile_play.m 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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_play (@var{data, fs})
  18. ## Play @var{data} at sample rate @var{fs} using the sndfile-play
  19. ## program.
  20. ## @end deftypefn
  21. ## Author: Erik de Castro Lopo <erikd@mega-nerd.com>
  22. ## Description: Play the given data as a sound file
  23. function sndfile_play (data, fs)
  24. if nargin != 2,
  25. error ("Need two input arguments: data and fs.") ;
  26. endif
  27. if (max (size (fs)) > 1),
  28. error ("Second parameter fs must be a single value.") ;
  29. endif
  30. [nr nc] = size (data) ;
  31. if (nr > nc),
  32. data = data' ;
  33. endif
  34. samplerate = fs ;
  35. wavedata = data ;
  36. filename = tmpnam () ;
  37. cmd = sprintf ("save -mat-binary %s fs data", filename) ;
  38. eval (cmd) ;
  39. cmd = sprintf ("sndfile-play %s", filename) ;
  40. [output, status] = system (cmd) ;
  41. if (status),
  42. disp (outout) ;
  43. endif
  44. endfunction