Chris@0
|
1 /*
|
Chris@0
|
2 ** Copyright (C) 2002-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
|
Chris@0
|
3 **
|
Chris@0
|
4 ** This program is free software; you can redistribute it and/or modify
|
Chris@0
|
5 ** it under the terms of the GNU General Public License as published by
|
Chris@0
|
6 ** the Free Software Foundation; either version 2 of the License, or
|
Chris@0
|
7 ** (at your option) any later version.
|
Chris@0
|
8 **
|
Chris@0
|
9 ** This program is distributed in the hope that it will be useful,
|
Chris@0
|
10 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
Chris@0
|
11 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
Chris@0
|
12 ** GNU General Public License for more details.
|
Chris@0
|
13 **
|
Chris@0
|
14 ** You should have received a copy of the GNU General Public License
|
Chris@0
|
15 ** along with this program; if not, write to the Free Software
|
Chris@0
|
16 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
Chris@0
|
17 */
|
Chris@0
|
18
|
Chris@0
|
19 #include "sfconfig.h"
|
Chris@0
|
20
|
Chris@0
|
21 #include <stdio.h>
|
Chris@0
|
22 #include <stdlib.h>
|
Chris@0
|
23 #include <string.h>
|
Chris@0
|
24 #include <math.h>
|
Chris@0
|
25
|
Chris@0
|
26 #if HAVE_UNISTD_H
|
Chris@0
|
27 #include <unistd.h>
|
Chris@0
|
28 #endif
|
Chris@0
|
29
|
Chris@0
|
30 #include <sndfile.h>
|
Chris@0
|
31
|
Chris@0
|
32 #include "utils.h"
|
Chris@0
|
33
|
Chris@0
|
34 #define BUFFER_SIZE (10000)
|
Chris@0
|
35
|
Chris@0
|
36 #ifndef M_PI
|
Chris@0
|
37 #define M_PI 3.14159265358979323846264338
|
Chris@0
|
38 #endif
|
Chris@0
|
39
|
Chris@0
|
40 static void dwvw_test (const char *filename, int format, int bit_width) ;
|
Chris@0
|
41
|
Chris@0
|
42 int
|
Chris@0
|
43 main (void)
|
Chris@0
|
44 {
|
Chris@0
|
45 dwvw_test ("dwvw12.raw", SF_FORMAT_RAW | SF_FORMAT_DWVW_12, 12) ;
|
Chris@0
|
46 dwvw_test ("dwvw16.raw", SF_FORMAT_RAW | SF_FORMAT_DWVW_16, 16) ;
|
Chris@0
|
47 dwvw_test ("dwvw24.raw", SF_FORMAT_RAW | SF_FORMAT_DWVW_24, 24) ;
|
Chris@0
|
48
|
Chris@0
|
49 return 0 ;
|
Chris@0
|
50 } /* main */
|
Chris@0
|
51
|
Chris@0
|
52 static void
|
Chris@0
|
53 dwvw_test (const char *filename, int format, int bit_width)
|
Chris@0
|
54 { static int write_buf [BUFFER_SIZE] ;
|
Chris@0
|
55 static int read_buf [BUFFER_SIZE] ;
|
Chris@0
|
56
|
Chris@0
|
57 SNDFILE *file ;
|
Chris@0
|
58 SF_INFO sfinfo ;
|
Chris@0
|
59 double value ;
|
Chris@0
|
60 int k, bit_mask ;
|
Chris@0
|
61
|
Chris@0
|
62 srand (123456) ;
|
Chris@0
|
63
|
Chris@0
|
64 /* Only want to grab the top bit_width bits. */
|
Chris@0
|
65 bit_mask = (-1 << (32 - bit_width)) ;
|
Chris@0
|
66
|
Chris@0
|
67 print_test_name ("dwvw_test", filename) ;
|
Chris@0
|
68
|
Chris@0
|
69 sf_info_setup (&sfinfo, format, 44100, 1) ;
|
Chris@0
|
70
|
Chris@0
|
71 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
|
Chris@0
|
72
|
Chris@0
|
73 /* Generate random.frames. */
|
Chris@0
|
74 for (k = 0 ; k < BUFFER_SIZE / 2 ; k++)
|
Chris@0
|
75 { value = 0x7FFFFFFF * sin (123.0 / sfinfo.samplerate * 2 * k * M_PI) ;
|
Chris@0
|
76 write_buf [k] = bit_mask & lrint (value) ;
|
Chris@0
|
77 } ;
|
Chris@0
|
78
|
Chris@0
|
79 for ( ; k < BUFFER_SIZE ; k++)
|
Chris@0
|
80 write_buf [k] = bit_mask & ((rand () << 11) ^ (rand () >> 11)) ;
|
Chris@0
|
81
|
Chris@0
|
82 sf_write_int (file, write_buf, BUFFER_SIZE) ;
|
Chris@0
|
83 sf_close (file) ;
|
Chris@0
|
84
|
Chris@0
|
85 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
|
Chris@0
|
86
|
Chris@0
|
87 if ((k = sf_read_int (file, read_buf, BUFFER_SIZE)) != BUFFER_SIZE)
|
Chris@0
|
88 { printf ("Error (line %d) : Only read %d/%d.frames.\n", __LINE__, k, BUFFER_SIZE) ;
|
Chris@0
|
89 exit (1) ;
|
Chris@0
|
90 }
|
Chris@0
|
91
|
Chris@0
|
92 for (k = 0 ; k < BUFFER_SIZE ; k++)
|
Chris@0
|
93 { if (read_buf [k] != write_buf [k])
|
Chris@0
|
94 { printf ("Error (line %d) : %d != %d at position %d/%d\n", __LINE__,
|
Chris@0
|
95 write_buf [k] >> (32 - bit_width), read_buf [k] >> (32 - bit_width),
|
Chris@0
|
96 k, BUFFER_SIZE) ;
|
Chris@0
|
97 oct_save_int (write_buf, read_buf, BUFFER_SIZE) ;
|
Chris@0
|
98 exit (1) ;
|
Chris@0
|
99 } ;
|
Chris@0
|
100 } ;
|
Chris@0
|
101
|
Chris@0
|
102 sf_close (file) ;
|
Chris@0
|
103
|
Chris@0
|
104 unlink (filename) ;
|
Chris@0
|
105 printf ("ok\n") ;
|
Chris@0
|
106
|
Chris@0
|
107 return ;
|
Chris@0
|
108 } /* dwvw_test */
|
Chris@0
|
109
|