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