~ubuntu-branches/ubuntu/gutsy/audacity/gutsy-backports

« back to all changes in this revision

Viewing changes to lib-src/libsndfile/tests/dither_test.c

  • Committer: Bazaar Package Importer
  • Author(s): John Dong
  • Date: 2008-02-18 21:58:19 UTC
  • mfrom: (13.1.2 hardy)
  • Revision ID: james.westby@ubuntu.com-20080218215819-tmbcf1rx238r8gdv
Tags: 1.3.4-1.1ubuntu1~gutsy1
Automated backport upload; no source changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
** Copyright (C) 2003,2004 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
 
 
20
 
 
21
 
#include        <stdio.h>
22
 
#include        <stdlib.h>
23
 
#include        <unistd.h>
24
 
#include        <string.h>
25
 
#include        <math.h>
26
 
 
27
 
#include        <sndfile.h>
28
 
 
29
 
#include        "utils.h"
30
 
 
31
 
#define BUFFER_LEN              (1<<16)
32
 
#define LOG_BUFFER_SIZE 1024
33
 
 
34
 
static void     dither_test (const char *filename, int filetype) ;
35
 
 
36
 
/* Force the start of this buffer to be double aligned. Sparc-solaris will
37
 
** choke if its not.
38
 
*/
39
 
static  short   data_out [BUFFER_LEN] ;
40
 
 
41
 
int
42
 
main (int argc, char *argv [])
43
 
{       int             do_all = 0 ;
44
 
        int             test_count = 0 ;
45
 
 
46
 
        if (argc != 2)
47
 
        {       printf ("Usage : %s <test>\n", argv [0]) ;
48
 
                printf ("    Where <test> is one of the following:\n") ;
49
 
                printf ("           wav  - test WAV file peak chunk\n") ;
50
 
                printf ("           aiff - test AIFF file PEAK chunk\n") ;
51
 
                printf ("           all  - perform all tests\n") ;
52
 
                exit (1) ;
53
 
                } ;
54
 
 
55
 
        do_all=!strcmp (argv [1], "all") ;
56
 
 
57
 
        if (do_all || ! strcmp (argv [1], "wav"))
58
 
        {       dither_test ("dither.wav", SF_FORMAT_WAV | SF_FORMAT_PCM_U8) ;
59
 
                test_count++ ;
60
 
                } ;
61
 
 
62
 
        if (do_all || ! strcmp (argv [1], "aiff"))
63
 
        {       dither_test ("dither.aiff", SF_FORMAT_AIFF | SF_FORMAT_PCM_S8) ;
64
 
                test_count++ ;
65
 
                } ;
66
 
 
67
 
        if (do_all || ! strcmp (argv [1], "au"))
68
 
        {       dither_test ("dither.au", SF_FORMAT_AU | SF_FORMAT_PCM_S8) ;
69
 
                test_count++ ;
70
 
                } ;
71
 
 
72
 
        if (do_all || ! strcmp (argv [1], "svx"))
73
 
        {       dither_test ("dither.svx", SF_FORMAT_SVX | SF_FORMAT_PCM_S8) ;
74
 
                test_count++ ;
75
 
                } ;
76
 
 
77
 
        if (do_all || ! strcmp (argv [1], "nist"))
78
 
        {       dither_test ("dither.nist", SF_FORMAT_NIST | SF_FORMAT_PCM_S8) ;
79
 
                test_count++ ;
80
 
                } ;
81
 
 
82
 
        if (do_all || ! strcmp (argv [1], "paf"))
83
 
        {       dither_test ("dither.paf", SF_FORMAT_PAF | SF_FORMAT_PCM_S8) ;
84
 
                test_count++ ;
85
 
                } ;
86
 
 
87
 
        if (do_all || ! strcmp (argv [1], "ircam"))
88
 
        {       dither_test ("dither.ircam", SF_FORMAT_IRCAM | SF_FORMAT_PCM_S8) ;
89
 
                test_count++ ;
90
 
                } ;
91
 
 
92
 
        if (do_all || ! strcmp (argv [1], "voc"))
93
 
        {       dither_test ("dither.voc", SF_FORMAT_VOC | SF_FORMAT_PCM_S8) ;
94
 
                test_count++ ;
95
 
                } ;
96
 
 
97
 
        if (do_all || ! strcmp (argv [1], "w64"))
98
 
        {       dither_test ("dither.w64", SF_FORMAT_W64 | SF_FORMAT_PCM_S8) ;
99
 
                test_count++ ;
100
 
                } ;
101
 
 
102
 
        if (do_all || ! strcmp (argv [1], "mat4"))
103
 
        {       dither_test ("dither.mat4", SF_FORMAT_MAT4 | SF_FORMAT_PCM_S8) ;
104
 
                test_count++ ;
105
 
                } ;
106
 
 
107
 
        if (do_all || ! strcmp (argv [1], "mat5"))
108
 
        {       dither_test ("dither.mat5", SF_FORMAT_MAT5 | SF_FORMAT_PCM_S8) ;
109
 
                test_count++ ;
110
 
                } ;
111
 
 
112
 
        if (do_all || ! strcmp (argv [1], "pvf"))
113
 
        {       dither_test ("dither.pvf", SF_FORMAT_PVF | SF_FORMAT_PCM_S8) ;
114
 
                test_count++ ;
115
 
                } ;
116
 
 
117
 
        if (test_count == 0)
118
 
        {       printf ("Mono : ************************************\n") ;
119
 
                printf ("Mono : *  No '%s' test defined.\n", argv [1]) ;
120
 
                printf ("Mono : ************************************\n") ;
121
 
                return 1 ;
122
 
                } ;
123
 
 
124
 
        return 0 ;
125
 
} /* main */
126
 
 
127
 
 
128
 
/*============================================================================================
129
 
**      Here are the test functions.
130
 
*/
131
 
 
132
 
static void
133
 
dither_test (const char *filename, int filetype)
134
 
{       SNDFILE                 *file ;
135
 
        SF_INFO                 sfinfo ;
136
 
        SF_DITHER_INFO  dither ;
137
 
        int                             frames ;
138
 
 
139
 
        filetype = filetype ;
140
 
 
141
 
        print_test_name ("dither_test", filename) ;
142
 
 
143
 
        sfinfo.samplerate       = 44100 ;
144
 
        sfinfo.format           = filetype ;
145
 
        sfinfo.channels         = 1 ;
146
 
        sfinfo.frames           = 0 ;
147
 
 
148
 
        frames = BUFFER_LEN / sfinfo.channels ;
149
 
 
150
 
        file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
151
 
 
152
 
        /* Check for old version of the dither API. */
153
 
        if (sf_command (file, SFC_SET_DITHER_ON_WRITE, NULL, SF_TRUE) == 0)
154
 
        {       printf ("\n\nLine %d: Should have an error here but don't.\n\n", __LINE__) ;
155
 
                exit (1) ;
156
 
                } ;
157
 
 
158
 
        memset (&dither, 0, sizeof (dither)) ;
159
 
        dither.type = SFD_WHITE ;
160
 
        dither.level = 0 ;
161
 
 
162
 
        if (sf_command (file, SFC_SET_DITHER_ON_WRITE, &dither, sizeof (dither)) != 0)
163
 
        {       printf ("\n\nLine %d: sf_command (SFC_SET_DITHER_ON_WRITE) returned error : %s\n\n",
164
 
                        __LINE__, sf_strerror (file)) ;
165
 
                exit (1) ;
166
 
                } ;
167
 
 
168
 
        /* Write data to file. */
169
 
        test_write_short_or_die (file, 0, data_out, BUFFER_LEN, __LINE__) ;
170
 
        test_seek_or_die (file, 0, SEEK_SET, 0, sfinfo.channels, __LINE__) ;
171
 
 
172
 
        sf_close (file) ;
173
 
 
174
 
        file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
175
 
 
176
 
        if (sfinfo.frames != BUFFER_LEN)
177
 
        {       printf ("\n\nLine %d: Bad frame count %d (should be %d)\n\n", __LINE__, (int) sfinfo.frames, BUFFER_LEN) ;
178
 
                } ;
179
 
 
180
 
        sf_close (file) ;
181
 
        /*-unlink (filename) ;-*/
182
 
 
183
 
        puts ("ok") ;
184
 
} /* dither_test */
185
 
 
186
 
/*
187
 
** Do not edit or modify anything in this comment block.
188
 
** The arch-tag line is a file identity tag for the GNU Arch 
189
 
** revision control system.
190
 
**
191
 
** arch-tag: ad688dd9-5211-48ef-b82d-089eafb1e7ad
192
 
*/