• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 ** Copyright (C) 2008-2017 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 		0xbd99d34ccbe2fLL, 0xda82168ed82e9LL
48 		},
49 	{	SF_FORMAT_RAW | SF_FORMAT_ALAW,
50 		"checksum.alaw", "cksum_alaw.pcm16",
51 		0x0004afddc0fcf4bdLL, 0x2e7320230b88LL
52 		},
53 	{	SF_FORMAT_RAW | SF_FORMAT_GSM610,
54 		"checksum.gsm", "cksum_gsm.pcm16",
55 		0xa06a3faaaf684LL, 0x2d7ff668efeb9LL
56 		},
57 	{	SF_FORMAT_RAW | SF_FORMAT_VOX_ADPCM,
58 		"checksum.vox", "cksum_vox.pcm16",
59 		0x7c9d7afdb96a1LL, 0xe540df74a4b14LL
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
main(void)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
checksum_test(const CHECKSUM * cksum)84 checksum_test (const CHECKSUM * cksum)
85 {	SNDFILE * file ;
86 	SF_INFO info ;
87 
88 	print_test_name (__func__, cksum->enc_name) ;
89 
90 	memset (&info, 0, sizeof (info)) ;
91 	info.format = cksum->enc_fmt ;
92 	info.channels = 1 ;
93 	info.samplerate	= SAMPLE_RATE ;
94 
95 	file = test_open_file_or_die (cksum->enc_name, SFM_WRITE, &info, 0, __LINE__) ;
96 	test_write_float_or_die (file, 0, orig, ARRAY_LEN (orig), __LINE__) ;
97 	sf_close (file) ;
98 
99 	check_file_hash_or_die (cksum->enc_name, cksum->enc_cksum, __LINE__) ;
100 	puts ("ok") ;
101 
102 	/*------------------------------------------------------------------------*/
103 
104 	print_test_name (__func__, cksum->dec_name) ;
105 
106 	info.format = cksum->enc_fmt ;
107 	info.channels = 1 ;
108 	info.samplerate	= SAMPLE_RATE ;
109 
110 	file = test_open_file_or_die (cksum->enc_name, SFM_READ, &info, 0, __LINE__) ;
111 	test_read_short_or_die (file, 0, data, ARRAY_LEN (data), __LINE__) ;
112 	sf_close (file) ;
113 
114 	info.format = SF_ENDIAN_LITTLE | SF_FORMAT_RAW | SF_FORMAT_PCM_16 ;
115 	info.channels = 1 ;
116 	info.samplerate	= SAMPLE_RATE ;
117 
118 	file = test_open_file_or_die (cksum->dec_name, SFM_WRITE, &info, 0, __LINE__) ;
119 	test_write_short_or_die (file, 0, data, ARRAY_LEN (data), __LINE__) ;
120 	sf_close (file) ;
121 
122 	check_file_hash_or_die (cksum->dec_name, cksum->dec_cksum, __LINE__) ;
123 
124 	remove (cksum->enc_name) ;
125 	remove (cksum->dec_name) ;
126 
127 	puts ("ok") ;
128 } /* checksum_test */
129 
130