annotate src/libsndfile-1.0.27/Octave/octave_test.m @ 40:1df64224f5ac

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