Editing and cleaning of Makefiles of all levels.
[Faustine.git] / interpretor / lib / src / libsndfile-1.0.25 / tests / checksum_test.c
1 /*
2 ** Copyright (C) 2008-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
3 **
4 ** This program is free software; you can redistribute it and/or modify
5 ** it under the terms of the GNU General Public License as published by
6 ** the Free Software Foundation; either version 2 of the License, or
7 ** (at your option) any later version.
8 **
9 ** This program is distributed in the hope that it will be useful,
10 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 ** GNU General Public License for more details.
13 **
14 ** You should have received a copy of the GNU General Public License
15 ** along with this program; if not, write to the Free Software
16 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 */
18
19 #include "sfconfig.h"
20
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <string.h>
24 #include <math.h>
25
26 #include <sndfile.h>
27
28 #include "utils.h"
29
30 #define SAMPLE_RATE 8000
31
32 typedef struct
33 { int enc_fmt ;
34
35 const char * enc_name ;
36 const char * dec_name ;
37
38 uint64_t enc_cksum ;
39 uint64_t dec_cksum ;
40 } CHECKSUM ;
41
42 static CHECKSUM
43 checksum_orig [] =
44 {
45 { SF_FORMAT_RAW | SF_FORMAT_ULAW,
46 "checksum.ulaw", "cksum_ulaw.pcm16",
47 0x33aefae029e0c888LL, 0x595cd6e47edd0cffLL
48 },
49 { SF_FORMAT_RAW | SF_FORMAT_ALAW,
50 "checksum.alaw", "cksum_alaw.pcm16",
51 0x48c798da3572d468LL, 0x6837d74869af5bb6LL
52 },
53 { SF_FORMAT_RAW | SF_FORMAT_GSM610,
54 "checksum.gsm", "cksum_gsm.pcm16",
55 0x1b1f64ff2acf858fLL, 0x504179dbadd4bce6LL
56 },
57 { SF_FORMAT_RAW | SF_FORMAT_VOX_ADPCM,
58 "checksum.vox", "cksum_vox.pcm16",
59 0xf1147fb3a298f4dfLL, 0xfc9c0cb8b12cb0abLL
60 },
61 } ;
62
63 static void checksum_test (const CHECKSUM * cksum) ;
64
65 static float orig [1 << 14] ;
66 static short data [1 << 14] ;
67
68 int
69 main (void)
70 { unsigned k ;
71
72 gen_windowed_sine_float (orig, ARRAY_LEN (orig), 0.9) ;
73
74 for (k = 0 ; k < ARRAY_LEN (checksum_orig) ; k++)
75 checksum_test (&checksum_orig [k]) ;
76
77 return 0 ;
78 } /* main */
79
80 /*==============================================================================
81 */
82
83 static void
84 checksum_test (const CHECKSUM * cksum)
85 { SNDFILE * file ;
86 SF_INFO info ;
87
88 print_test_name (__func__, cksum->enc_name) ;
89
90 info.format = cksum->enc_fmt ;
91 info.channels = 1 ;
92 info.samplerate = SAMPLE_RATE ;
93
94 file = test_open_file_or_die (cksum->enc_name, SFM_WRITE, &info, 0, __LINE__) ;
95 test_write_float_or_die (file, 0, orig, ARRAY_LEN (orig), __LINE__) ;
96 sf_close (file) ;
97
98 check_file_hash_or_die (cksum->enc_name, cksum->enc_cksum, __LINE__) ;
99 puts ("ok") ;
100
101 /*------------------------------------------------------------------------*/
102
103 print_test_name (__func__, cksum->dec_name) ;
104
105 info.format = cksum->enc_fmt ;
106 info.channels = 1 ;
107 info.samplerate = SAMPLE_RATE ;
108
109 file = test_open_file_or_die (cksum->enc_name, SFM_READ, &info, 0, __LINE__) ;
110 test_read_short_or_die (file, 0, data, ARRAY_LEN (data), __LINE__) ;
111 sf_close (file) ;
112
113 info.format = SF_ENDIAN_LITTLE | SF_FORMAT_RAW | SF_FORMAT_PCM_16 ;
114 info.channels = 1 ;
115 info.samplerate = SAMPLE_RATE ;
116
117 file = test_open_file_or_die (cksum->dec_name, SFM_WRITE, &info, 0, __LINE__) ;
118 test_write_short_or_die (file, 0, data, ARRAY_LEN (data), __LINE__) ;
119 sf_close (file) ;
120
121 check_file_hash_or_die (cksum->dec_name, cksum->dec_cksum, __LINE__) ;
122
123 remove (cksum->enc_name) ;
124 remove (cksum->dec_name) ;
125
126 puts ("ok") ;
127 } /* checksum_test */
128