libsndfile source files.
[Faustine.git] / interpretor / libsndfile-1.0.25 / Octave / octave_test.m
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
17 # These tests are nowhere near comprehensive.
18
19 printf (" Running Octave tests : ") ;
20 fflush (stdout) ;
21
22 filename = "whatever" ;
23 srate_out = 32000 ;
24 fmt_out = "wav-float" ;
25
26 t = (2 * pi / srate_out * (0:srate_out-1))' ;
27 data_out = sin (440.0 * t) ;
28
29 # Write out a file.
30 sfwrite (filename, data_out, srate_out, fmt_out) ;
31
32 # Read it back in again.
33 [ data_in, srate_in, fmt_in ] = sfread (filename) ;
34
35 if (srate_in != srate_out)
36 error ("\n\nSample rate mismatch : %d -> %d.\n\n", srate_out, srate_in) ;
37 endif
38
39 # Octave strcmp return 1 for the same.
40 if (strcmp (fmt_in, fmt_out) != 1)
41 error ("\n\nFormat error : '%s' -> '%s'.\n\n", fmt_out, fmt_in) ;
42 endif
43
44 err = max (abs (data_out - data_in)) ;
45
46 if (err > 1e-7)
47 error ("err : %g\n", err) ;
48 endif
49
50 printf ("ok") ;
51
52 unlink (filename) ;