Chris@0: /* Chris@0: ** Copyright (C) 2003-2011 Erik de Castro Lopo Chris@0: ** Chris@0: ** This program is free software; you can redistribute it and/or modify Chris@0: ** it under the terms of the GNU General Public License as published by Chris@0: ** the Free Software Foundation; either version 2 of the License, or Chris@0: ** (at your option) any later version. Chris@0: ** Chris@0: ** This program is distributed in the hope that it will be useful, Chris@0: ** but WITHOUT ANY WARRANTY; without even the implied warranty of Chris@0: ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Chris@0: ** GNU General Public License for more details. Chris@0: ** Chris@0: ** You should have received a copy of the GNU General Public License Chris@0: ** along with this program; if not, write to the Free Software Chris@0: ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. Chris@0: */ Chris@0: Chris@0: Chris@0: Chris@0: #include Chris@0: #include Chris@0: #include Chris@0: #include Chris@0: #include Chris@0: Chris@0: #include Chris@0: Chris@0: #include "utils.h" Chris@0: Chris@0: #define BUFFER_LEN (1<<16) Chris@0: #define LOG_BUFFER_SIZE 1024 Chris@0: Chris@0: static void dither_test (const char *filename, int filetype) ; Chris@0: Chris@0: /* Force the start of this buffer to be double aligned. Sparc-solaris will Chris@0: ** choke if its not. Chris@0: */ Chris@0: static short data_out [BUFFER_LEN] ; Chris@0: Chris@0: int Chris@0: main (int argc, char *argv []) Chris@0: { int do_all = 0 ; Chris@0: int test_count = 0 ; Chris@0: Chris@0: if (argc != 2) Chris@0: { printf ("Usage : %s \n", argv [0]) ; Chris@0: printf (" Where is one of the following:\n") ; Chris@0: printf (" wav - test WAV file peak chunk\n") ; Chris@0: printf (" aiff - test AIFF file PEAK chunk\n") ; Chris@0: printf (" all - perform all tests\n") ; Chris@0: exit (1) ; Chris@0: } ; Chris@0: Chris@0: do_all=!strcmp (argv [1], "all") ; Chris@0: Chris@0: if (do_all || ! strcmp (argv [1], "wav")) Chris@0: { dither_test ("dither.wav", SF_FORMAT_WAV | SF_FORMAT_PCM_U8) ; Chris@0: test_count++ ; Chris@0: } ; Chris@0: Chris@0: if (do_all || ! strcmp (argv [1], "aiff")) Chris@0: { dither_test ("dither.aiff", SF_FORMAT_AIFF | SF_FORMAT_PCM_S8) ; Chris@0: test_count++ ; Chris@0: } ; Chris@0: Chris@0: if (do_all || ! strcmp (argv [1], "au")) Chris@0: { dither_test ("dither.au", SF_FORMAT_AU | SF_FORMAT_PCM_S8) ; Chris@0: test_count++ ; Chris@0: } ; Chris@0: Chris@0: if (do_all || ! strcmp (argv [1], "svx")) Chris@0: { dither_test ("dither.svx", SF_FORMAT_SVX | SF_FORMAT_PCM_S8) ; Chris@0: test_count++ ; Chris@0: } ; Chris@0: Chris@0: if (do_all || ! strcmp (argv [1], "nist")) Chris@0: { dither_test ("dither.nist", SF_FORMAT_NIST | SF_FORMAT_PCM_S8) ; Chris@0: test_count++ ; Chris@0: } ; Chris@0: Chris@0: if (do_all || ! strcmp (argv [1], "paf")) Chris@0: { dither_test ("dither.paf", SF_FORMAT_PAF | SF_FORMAT_PCM_S8) ; Chris@0: test_count++ ; Chris@0: } ; Chris@0: Chris@0: if (do_all || ! strcmp (argv [1], "ircam")) Chris@0: { dither_test ("dither.ircam", SF_FORMAT_IRCAM | SF_FORMAT_PCM_S8) ; Chris@0: test_count++ ; Chris@0: } ; Chris@0: Chris@0: if (do_all || ! strcmp (argv [1], "voc")) Chris@0: { dither_test ("dither.voc", SF_FORMAT_VOC | SF_FORMAT_PCM_S8) ; Chris@0: test_count++ ; Chris@0: } ; Chris@0: Chris@0: if (do_all || ! strcmp (argv [1], "w64")) Chris@0: { dither_test ("dither.w64", SF_FORMAT_W64 | SF_FORMAT_PCM_S8) ; Chris@0: test_count++ ; Chris@0: } ; Chris@0: Chris@0: if (do_all || ! strcmp (argv [1], "mat4")) Chris@0: { dither_test ("dither.mat4", SF_FORMAT_MAT4 | SF_FORMAT_PCM_S8) ; Chris@0: test_count++ ; Chris@0: } ; Chris@0: Chris@0: if (do_all || ! strcmp (argv [1], "mat5")) Chris@0: { dither_test ("dither.mat5", SF_FORMAT_MAT5 | SF_FORMAT_PCM_S8) ; Chris@0: test_count++ ; Chris@0: } ; Chris@0: Chris@0: if (do_all || ! strcmp (argv [1], "pvf")) Chris@0: { dither_test ("dither.pvf", SF_FORMAT_PVF | SF_FORMAT_PCM_S8) ; Chris@0: test_count++ ; Chris@0: } ; Chris@0: Chris@0: if (test_count == 0) Chris@0: { printf ("Mono : ************************************\n") ; Chris@0: printf ("Mono : * No '%s' test defined.\n", argv [1]) ; Chris@0: printf ("Mono : ************************************\n") ; Chris@0: return 1 ; Chris@0: } ; Chris@0: Chris@0: return 0 ; Chris@0: } /* main */ Chris@0: Chris@0: Chris@0: /*============================================================================================ Chris@0: ** Here are the test functions. Chris@0: */ Chris@0: Chris@0: static void Chris@0: dither_test (const char *filename, int filetype) Chris@0: { SNDFILE *file ; Chris@0: SF_INFO sfinfo ; Chris@0: SF_DITHER_INFO dither ; Chris@0: Chris@0: filetype = filetype ; Chris@0: Chris@0: print_test_name ("dither_test", filename) ; Chris@0: Chris@0: sfinfo.samplerate = 44100 ; Chris@0: sfinfo.format = filetype ; Chris@0: sfinfo.channels = 1 ; Chris@0: sfinfo.frames = 0 ; Chris@0: Chris@0: file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ; Chris@0: Chris@0: /* Check for old version of the dither API. */ Chris@0: if (sf_command (file, SFC_SET_DITHER_ON_WRITE, NULL, SF_TRUE) == 0) Chris@0: { printf ("\n\nLine %d: Should have an error here but don't.\n\n", __LINE__) ; Chris@0: exit (1) ; Chris@0: } ; Chris@0: Chris@0: memset (&dither, 0, sizeof (dither)) ; Chris@0: dither.type = SFD_WHITE ; Chris@0: dither.level = 0 ; Chris@0: Chris@0: if (sf_command (file, SFC_SET_DITHER_ON_WRITE, &dither, sizeof (dither)) != 0) Chris@0: { printf ("\n\nLine %d: sf_command (SFC_SET_DITHER_ON_WRITE) returned error : %s\n\n", Chris@0: __LINE__, sf_strerror (file)) ; Chris@0: exit (1) ; Chris@0: } ; Chris@0: Chris@0: /* Write data to file. */ Chris@0: test_write_short_or_die (file, 0, data_out, BUFFER_LEN, __LINE__) ; Chris@0: test_seek_or_die (file, 0, SEEK_SET, 0, sfinfo.channels, __LINE__) ; Chris@0: Chris@0: sf_close (file) ; Chris@0: Chris@0: file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ; Chris@0: Chris@0: if (sfinfo.frames != BUFFER_LEN) Chris@0: { printf ("\n\nLine %d: Bad frame count %d (should be %d)\n\n", __LINE__, (int) sfinfo.frames, BUFFER_LEN) ; Chris@0: } ; Chris@0: Chris@0: sf_close (file) ; Chris@0: /*-unlink (filename) ;-*/ Chris@0: Chris@0: puts ("ok") ; Chris@0: } /* dither_test */ Chris@0: