Chris@40: /* Chris@40: ** Copyright (C) 2002-2014 Erik de Castro Lopo Chris@40: ** Chris@40: ** This program is free software; you can redistribute it and/or modify Chris@40: ** it under the terms of the GNU General Public License as published by Chris@40: ** the Free Software Foundation; either version 2 of the License, or Chris@40: ** (at your option) any later version. Chris@40: ** Chris@40: ** This program is distributed in the hope that it will be useful, Chris@40: ** but WITHOUT ANY WARRANTY; without even the implied warranty of Chris@40: ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Chris@40: ** GNU General Public License for more details. Chris@40: ** Chris@40: ** You should have received a copy of the GNU General Public License Chris@40: ** along with this program; if not, write to the Free Software Chris@40: ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. Chris@40: */ Chris@40: Chris@40: #include "sfconfig.h" Chris@40: Chris@40: #include Chris@40: #include Chris@40: #include Chris@40: #include Chris@40: Chris@40: #if HAVE_UNISTD_H Chris@40: #include Chris@40: #endif Chris@40: Chris@40: #include Chris@40: Chris@40: #include "utils.h" Chris@40: Chris@40: #define BUFFER_SIZE (10000) Chris@40: Chris@40: #ifndef M_PI Chris@40: #define M_PI 3.14159265358979323846264338 Chris@40: #endif Chris@40: Chris@40: static void dwvw_test (const char *filename, int format, int bit_width) ; Chris@40: Chris@40: int Chris@40: main (void) Chris@40: { Chris@40: dwvw_test ("dwvw12.raw", SF_FORMAT_RAW | SF_FORMAT_DWVW_12, 12) ; Chris@40: dwvw_test ("dwvw16.raw", SF_FORMAT_RAW | SF_FORMAT_DWVW_16, 16) ; Chris@40: dwvw_test ("dwvw24.raw", SF_FORMAT_RAW | SF_FORMAT_DWVW_24, 24) ; Chris@40: Chris@40: return 0 ; Chris@40: } /* main */ Chris@40: Chris@40: static void Chris@40: dwvw_test (const char *filename, int format, int bit_width) Chris@40: { static int write_buf [BUFFER_SIZE] ; Chris@40: static int read_buf [BUFFER_SIZE] ; Chris@40: Chris@40: SNDFILE *file ; Chris@40: SF_INFO sfinfo ; Chris@40: double value ; Chris@40: int k, bit_mask ; Chris@40: Chris@40: srand (123456) ; Chris@40: Chris@40: /* Only want to grab the top bit_width bits. */ Chris@40: bit_mask = arith_shift_left (-1, 32 - bit_width) ; Chris@40: Chris@40: print_test_name ("dwvw_test", filename) ; Chris@40: Chris@40: sf_info_setup (&sfinfo, format, 44100, 1) ; Chris@40: Chris@40: file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ; Chris@40: Chris@40: /* Generate random.frames. */ Chris@40: for (k = 0 ; k < BUFFER_SIZE / 2 ; k++) Chris@40: { value = 0x7FFFFFFF * sin (123.0 / sfinfo.samplerate * 2 * k * M_PI) ; Chris@40: write_buf [k] = bit_mask & lrint (value) ; Chris@40: } ; Chris@40: Chris@40: for ( ; k < BUFFER_SIZE ; k++) Chris@40: write_buf [k] = bit_mask & (arith_shift_left (rand (), 11) ^ (rand () >> 11)) ; Chris@40: Chris@40: sf_write_int (file, write_buf, BUFFER_SIZE) ; Chris@40: sf_close (file) ; Chris@40: Chris@40: file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ; Chris@40: Chris@40: if ((k = sf_read_int (file, read_buf, BUFFER_SIZE)) != BUFFER_SIZE) Chris@40: { printf ("Error (line %d) : Only read %d/%d.frames.\n", __LINE__, k, BUFFER_SIZE) ; Chris@40: exit (1) ; Chris@40: } Chris@40: Chris@40: for (k = 0 ; k < BUFFER_SIZE ; k++) Chris@40: { if (read_buf [k] != write_buf [k]) Chris@40: { printf ("Error (line %d) : %d != %d at position %d/%d\n", __LINE__, Chris@40: write_buf [k] >> (32 - bit_width), read_buf [k] >> (32 - bit_width), Chris@40: k, BUFFER_SIZE) ; Chris@40: oct_save_int (write_buf, read_buf, BUFFER_SIZE) ; Chris@40: exit (1) ; Chris@40: } ; Chris@40: } ; Chris@40: Chris@40: sf_close (file) ; Chris@40: Chris@40: unlink (filename) ; Chris@40: printf ("ok\n") ; Chris@40: Chris@40: return ; Chris@40: } /* dwvw_test */ Chris@40: