Chris@0: /* Chris@0: ** Copyright (C) 2002-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: #include "sfconfig.h" Chris@0: Chris@0: #include Chris@0: #include Chris@0: #include Chris@0: #include Chris@0: Chris@0: #if HAVE_UNISTD_H Chris@0: #include Chris@0: #endif Chris@0: Chris@0: #include Chris@0: Chris@0: #include "utils.h" Chris@0: Chris@0: #define BUFFER_SIZE (10000) Chris@0: Chris@0: #ifndef M_PI Chris@0: #define M_PI 3.14159265358979323846264338 Chris@0: #endif Chris@0: Chris@0: static void dwvw_test (const char *filename, int format, int bit_width) ; Chris@0: Chris@0: int Chris@0: main (void) Chris@0: { Chris@0: dwvw_test ("dwvw12.raw", SF_FORMAT_RAW | SF_FORMAT_DWVW_12, 12) ; Chris@0: dwvw_test ("dwvw16.raw", SF_FORMAT_RAW | SF_FORMAT_DWVW_16, 16) ; Chris@0: dwvw_test ("dwvw24.raw", SF_FORMAT_RAW | SF_FORMAT_DWVW_24, 24) ; Chris@0: Chris@0: return 0 ; Chris@0: } /* main */ Chris@0: Chris@0: static void Chris@0: dwvw_test (const char *filename, int format, int bit_width) Chris@0: { static int write_buf [BUFFER_SIZE] ; Chris@0: static int read_buf [BUFFER_SIZE] ; Chris@0: Chris@0: SNDFILE *file ; Chris@0: SF_INFO sfinfo ; Chris@0: double value ; Chris@0: int k, bit_mask ; Chris@0: Chris@0: srand (123456) ; Chris@0: Chris@0: /* Only want to grab the top bit_width bits. */ Chris@0: bit_mask = (-1 << (32 - bit_width)) ; Chris@0: Chris@0: print_test_name ("dwvw_test", filename) ; Chris@0: Chris@0: sf_info_setup (&sfinfo, format, 44100, 1) ; Chris@0: Chris@0: file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ; Chris@0: Chris@0: /* Generate random.frames. */ Chris@0: for (k = 0 ; k < BUFFER_SIZE / 2 ; k++) Chris@0: { value = 0x7FFFFFFF * sin (123.0 / sfinfo.samplerate * 2 * k * M_PI) ; Chris@0: write_buf [k] = bit_mask & lrint (value) ; Chris@0: } ; Chris@0: Chris@0: for ( ; k < BUFFER_SIZE ; k++) Chris@0: write_buf [k] = bit_mask & ((rand () << 11) ^ (rand () >> 11)) ; Chris@0: Chris@0: sf_write_int (file, write_buf, BUFFER_SIZE) ; 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 ((k = sf_read_int (file, read_buf, BUFFER_SIZE)) != BUFFER_SIZE) Chris@0: { printf ("Error (line %d) : Only read %d/%d.frames.\n", __LINE__, k, BUFFER_SIZE) ; Chris@0: exit (1) ; Chris@0: } Chris@0: Chris@0: for (k = 0 ; k < BUFFER_SIZE ; k++) Chris@0: { if (read_buf [k] != write_buf [k]) Chris@0: { printf ("Error (line %d) : %d != %d at position %d/%d\n", __LINE__, Chris@0: write_buf [k] >> (32 - bit_width), read_buf [k] >> (32 - bit_width), Chris@0: k, BUFFER_SIZE) ; Chris@0: oct_save_int (write_buf, read_buf, BUFFER_SIZE) ; Chris@0: exit (1) ; Chris@0: } ; Chris@0: } ; Chris@0: Chris@0: sf_close (file) ; Chris@0: Chris@0: unlink (filename) ; Chris@0: printf ("ok\n") ; Chris@0: Chris@0: return ; Chris@0: } /* dwvw_test */ Chris@0: