octave_test.m 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # Copyright (C) 2007-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
  2. #
  3. # This program is free software; you can redistribute it and/or modify
  4. # it under the terms of the GNU Lesser General Public License as published by
  5. # the Free Software Foundation; either version 2.1 of the License, or
  6. # (at your option) any later version.
  7. #
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU Lesser General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU Lesser General Public License
  14. # along with this program; if not, write to the Free Software
  15. # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  16. # These tests are nowhere near comprehensive.
  17. printf (" Running Octave tests : ") ;
  18. fflush (stdout) ;
  19. filename = "whatever" ;
  20. srate_out = 32000 ;
  21. fmt_out = "wav-float" ;
  22. t = (2 * pi / srate_out * (0:srate_out-1))' ;
  23. data_out = sin (440.0 * t) ;
  24. # Write out a file.
  25. sfwrite (filename, data_out, srate_out, fmt_out) ;
  26. # Read it back in again.
  27. [ data_in, srate_in, fmt_in ] = sfread (filename) ;
  28. if (srate_in != srate_out)
  29. error ("\n\nSample rate mismatch : %d -> %d.\n\n", srate_out, srate_in) ;
  30. endif
  31. # Octave strcmp return 1 for the same.
  32. if (strcmp (fmt_in, fmt_out) != 1)
  33. error ("\n\nFormat error : '%s' -> '%s'.\n\n", fmt_out, fmt_in) ;
  34. endif
  35. err = max (abs (data_out - data_in)) ;
  36. if (err > 1e-7)
  37. error ("err : %g\n", err) ;
  38. endif
  39. printf ("ok") ;
  40. unlink (filename) ;