annotate src/libsndfile-1.0.27/tests/dwvw_test.c @ 168:ceec0dd9ec9c

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