annotate src/libsndfile-1.0.27/tests/dwvw_test.c @ 83:ae30d91d2ffe

Replace these with versions built using an older toolset (so as to avoid ABI compatibilities when linking on Ubuntu 14.04 for packaging purposes)
author Chris Cannam
date Fri, 07 Feb 2020 11:51:13 +0000
parents 1df64224f5ac
children
rev   line source
Chris@40 1 /*
Chris@40 2 ** Copyright (C) 2002-2014 Erik de Castro Lopo <erikd@mega-nerd.com>
Chris@40 3 **
Chris@40 4 ** This program is free software; you can redistribute it and/or modify
Chris@40 5 ** it under the terms of the GNU General Public License as published by
Chris@40 6 ** the Free Software Foundation; either version 2 of the License, or
Chris@40 7 ** (at your option) any later version.
Chris@40 8 **
Chris@40 9 ** This program is distributed in the hope that it will be useful,
Chris@40 10 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@40 11 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@40 12 ** GNU General Public License for more details.
Chris@40 13 **
Chris@40 14 ** You should have received a copy of the GNU General Public License
Chris@40 15 ** along with this program; if not, write to the Free Software
Chris@40 16 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Chris@40 17 */
Chris@40 18
Chris@40 19 #include "sfconfig.h"
Chris@40 20
Chris@40 21 #include <stdio.h>
Chris@40 22 #include <stdlib.h>
Chris@40 23 #include <string.h>
Chris@40 24 #include <math.h>
Chris@40 25
Chris@40 26 #if HAVE_UNISTD_H
Chris@40 27 #include <unistd.h>
Chris@40 28 #endif
Chris@40 29
Chris@40 30 #include <sndfile.h>
Chris@40 31
Chris@40 32 #include "utils.h"
Chris@40 33
Chris@40 34 #define BUFFER_SIZE (10000)
Chris@40 35
Chris@40 36 #ifndef M_PI
Chris@40 37 #define M_PI 3.14159265358979323846264338
Chris@40 38 #endif
Chris@40 39
Chris@40 40 static void dwvw_test (const char *filename, int format, int bit_width) ;
Chris@40 41
Chris@40 42 int
Chris@40 43 main (void)
Chris@40 44 {
Chris@40 45 dwvw_test ("dwvw12.raw", SF_FORMAT_RAW | SF_FORMAT_DWVW_12, 12) ;
Chris@40 46 dwvw_test ("dwvw16.raw", SF_FORMAT_RAW | SF_FORMAT_DWVW_16, 16) ;
Chris@40 47 dwvw_test ("dwvw24.raw", SF_FORMAT_RAW | SF_FORMAT_DWVW_24, 24) ;
Chris@40 48
Chris@40 49 return 0 ;
Chris@40 50 } /* main */
Chris@40 51
Chris@40 52 static void
Chris@40 53 dwvw_test (const char *filename, int format, int bit_width)
Chris@40 54 { static int write_buf [BUFFER_SIZE] ;
Chris@40 55 static int read_buf [BUFFER_SIZE] ;
Chris@40 56
Chris@40 57 SNDFILE *file ;
Chris@40 58 SF_INFO sfinfo ;
Chris@40 59 double value ;
Chris@40 60 int k, bit_mask ;
Chris@40 61
Chris@40 62 srand (123456) ;
Chris@40 63
Chris@40 64 /* Only want to grab the top bit_width bits. */
Chris@40 65 bit_mask = arith_shift_left (-1, 32 - bit_width) ;
Chris@40 66
Chris@40 67 print_test_name ("dwvw_test", filename) ;
Chris@40 68
Chris@40 69 sf_info_setup (&sfinfo, format, 44100, 1) ;
Chris@40 70
Chris@40 71 file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
Chris@40 72
Chris@40 73 /* Generate random.frames. */
Chris@40 74 for (k = 0 ; k < BUFFER_SIZE / 2 ; k++)
Chris@40 75 { value = 0x7FFFFFFF * sin (123.0 / sfinfo.samplerate * 2 * k * M_PI) ;
Chris@40 76 write_buf [k] = bit_mask & lrint (value) ;
Chris@40 77 } ;
Chris@40 78
Chris@40 79 for ( ; k < BUFFER_SIZE ; k++)
Chris@40 80 write_buf [k] = bit_mask & (arith_shift_left (rand (), 11) ^ (rand () >> 11)) ;
Chris@40 81
Chris@40 82 sf_write_int (file, write_buf, BUFFER_SIZE) ;
Chris@40 83 sf_close (file) ;
Chris@40 84
Chris@40 85 file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
Chris@40 86
Chris@40 87 if ((k = sf_read_int (file, read_buf, BUFFER_SIZE)) != BUFFER_SIZE)
Chris@40 88 { printf ("Error (line %d) : Only read %d/%d.frames.\n", __LINE__, k, BUFFER_SIZE) ;
Chris@40 89 exit (1) ;
Chris@40 90 }
Chris@40 91
Chris@40 92 for (k = 0 ; k < BUFFER_SIZE ; k++)
Chris@40 93 { if (read_buf [k] != write_buf [k])
Chris@40 94 { printf ("Error (line %d) : %d != %d at position %d/%d\n", __LINE__,
Chris@40 95 write_buf [k] >> (32 - bit_width), read_buf [k] >> (32 - bit_width),
Chris@40 96 k, BUFFER_SIZE) ;
Chris@40 97 oct_save_int (write_buf, read_buf, BUFFER_SIZE) ;
Chris@40 98 exit (1) ;
Chris@40 99 } ;
Chris@40 100 } ;
Chris@40 101
Chris@40 102 sf_close (file) ;
Chris@40 103
Chris@40 104 unlink (filename) ;
Chris@40 105 printf ("ok\n") ;
Chris@40 106
Chris@40 107 return ;
Chris@40 108 } /* dwvw_test */
Chris@40 109