annotate src/libsndfile-1.0.27/tests/stdin_test.c @ 84:08ae793730bd

Add null config files
author Chris Cannam
date Mon, 02 Mar 2020 14:03:47 +0000
parents 1df64224f5ac
children
rev   line source
Chris@40 1 /*
Chris@40 2 ** Copyright (C) 2001-2012 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_LEN (1 << 16)
Chris@40 35
Chris@40 36 static void stdin_test (int typemajor, int count) ;
Chris@40 37
Chris@40 38 int
Chris@40 39 main (int argc, char *argv [])
Chris@40 40 { int do_all = 0, test_count = 0 ;
Chris@40 41
Chris@40 42 if (BUFFER_LEN < PIPE_TEST_LEN)
Chris@40 43 { fprintf (stderr, "Error : BUFFER_LEN < PIPE_TEST_LEN.\n\n") ;
Chris@40 44 exit (1) ;
Chris@40 45 } ;
Chris@40 46
Chris@40 47 if (argc != 2)
Chris@40 48 { fprintf (stderr, "This program cannot be run by itself. It needs\n") ;
Chris@40 49 fprintf (stderr, "to be run from the stdio_test program.\n") ;
Chris@40 50 exit (1) ;
Chris@40 51 } ;
Chris@40 52
Chris@40 53 do_all = ! strcmp (argv [1], "all") ;
Chris@40 54
Chris@40 55 if (do_all || ! strcmp (argv [1], "raw"))
Chris@40 56 { stdin_test (SF_FORMAT_RAW, PIPE_TEST_LEN) ;
Chris@40 57 test_count++ ;
Chris@40 58 } ;
Chris@40 59
Chris@40 60 if (do_all || ! strcmp (argv [1], "wav"))
Chris@40 61 { stdin_test (SF_FORMAT_WAV, PIPE_TEST_LEN) ;
Chris@40 62 test_count++ ;
Chris@40 63 } ;
Chris@40 64
Chris@40 65 if (do_all || ! strcmp (argv [1], "aiff"))
Chris@40 66 { stdin_test (SF_FORMAT_AIFF, PIPE_TEST_LEN) ;
Chris@40 67 test_count++ ;
Chris@40 68 } ;
Chris@40 69
Chris@40 70 if (do_all || ! strcmp (argv [1], "au"))
Chris@40 71 { stdin_test (SF_FORMAT_AU, PIPE_TEST_LEN) ;
Chris@40 72 test_count++ ;
Chris@40 73 } ;
Chris@40 74
Chris@40 75 if (do_all || ! strcmp (argv [1], "paf"))
Chris@40 76 { stdin_test (SF_FORMAT_PAF, PIPE_TEST_LEN) ;
Chris@40 77 test_count++ ;
Chris@40 78 } ;
Chris@40 79
Chris@40 80 if (do_all || ! strcmp (argv [1], "svx"))
Chris@40 81 { stdin_test (SF_FORMAT_SVX, PIPE_TEST_LEN) ;
Chris@40 82 test_count++ ;
Chris@40 83 } ;
Chris@40 84
Chris@40 85 if (do_all || ! strcmp (argv [1], "nist"))
Chris@40 86 { stdin_test (SF_FORMAT_NIST, PIPE_TEST_LEN) ;
Chris@40 87 test_count++ ;
Chris@40 88 } ;
Chris@40 89
Chris@40 90 if (do_all || ! strcmp (argv [1], "ircam"))
Chris@40 91 { stdin_test (SF_FORMAT_IRCAM, PIPE_TEST_LEN) ;
Chris@40 92 test_count++ ;
Chris@40 93 } ;
Chris@40 94
Chris@40 95 if (do_all || ! strcmp (argv [1], "voc"))
Chris@40 96 { stdin_test (SF_FORMAT_VOC, PIPE_TEST_LEN) ;
Chris@40 97 test_count++ ;
Chris@40 98 } ;
Chris@40 99
Chris@40 100 if (do_all || ! strcmp (argv [1], "w64"))
Chris@40 101 { stdin_test (SF_FORMAT_W64, PIPE_TEST_LEN) ;
Chris@40 102 test_count++ ;
Chris@40 103 } ;
Chris@40 104
Chris@40 105 if (do_all || ! strcmp (argv [1], "mat4"))
Chris@40 106 { stdin_test (SF_FORMAT_MAT4, PIPE_TEST_LEN) ;
Chris@40 107 test_count++ ;
Chris@40 108 } ;
Chris@40 109
Chris@40 110 if (do_all || ! strcmp (argv [1], "mat5"))
Chris@40 111 { stdin_test (SF_FORMAT_MAT5, PIPE_TEST_LEN) ;
Chris@40 112 test_count++ ;
Chris@40 113 } ;
Chris@40 114
Chris@40 115 if (do_all || ! strcmp (argv [1], "pvf"))
Chris@40 116 { stdin_test (SF_FORMAT_PVF, PIPE_TEST_LEN) ;
Chris@40 117 test_count++ ;
Chris@40 118 } ;
Chris@40 119
Chris@40 120 if (do_all || ! strcmp (argv [1], "htk"))
Chris@40 121 { stdin_test (SF_FORMAT_HTK, PIPE_TEST_LEN) ;
Chris@40 122 test_count++ ;
Chris@40 123 } ;
Chris@40 124
Chris@40 125 if (test_count == 0)
Chris@40 126 { fprintf (stderr, "\n*****************************************\n") ;
Chris@40 127 fprintf (stderr, "* stdin_test : No '%s' test defined.\n", argv [1]) ;
Chris@40 128 fprintf (stderr, "*****************************************\n") ;
Chris@40 129 return 1 ;
Chris@40 130 } ;
Chris@40 131
Chris@40 132 return 0 ;
Chris@40 133 } /* main */
Chris@40 134
Chris@40 135 static void
Chris@40 136 stdin_test (int typemajor, int count)
Chris@40 137 { static short data [BUFFER_LEN] ;
Chris@40 138
Chris@40 139 SNDFILE *file ;
Chris@40 140 SF_INFO sfinfo ;
Chris@40 141 int k, total, err ;
Chris@40 142
Chris@40 143 if (typemajor == SF_FORMAT_RAW)
Chris@40 144 { sfinfo.samplerate = 44100 ;
Chris@40 145 sfinfo.format = SF_FORMAT_RAW | SF_FORMAT_PCM_16 ;
Chris@40 146 sfinfo.channels = 1 ;
Chris@40 147 sfinfo.frames = 0 ;
Chris@40 148 }
Chris@40 149 else
Chris@40 150 memset (&sfinfo, 0, sizeof (sfinfo)) ;
Chris@40 151
Chris@40 152 if ((file = sf_open_fd (STDIN_FILENO, SFM_READ, &sfinfo, SF_TRUE)) == NULL)
Chris@40 153 { fprintf (stderr, "sf_open_fd failed with error : ") ;
Chris@40 154 puts (sf_strerror (NULL)) ;
Chris@40 155 dump_log_buffer (NULL) ;
Chris@40 156 exit (1) ;
Chris@40 157 } ;
Chris@40 158
Chris@40 159 err = sf_error (file) ;
Chris@40 160 if (err != SF_ERR_NO_ERROR)
Chris@40 161 { printf ("Line %d : unexpected error : %s\n", __LINE__, sf_error_number (err)) ;
Chris@40 162 exit (1) ;
Chris@40 163 } ;
Chris@40 164
Chris@40 165 if ((sfinfo.format & SF_FORMAT_TYPEMASK) != typemajor)
Chris@40 166 { fprintf (stderr, "\n\nError : File type doesn't match.\n") ;
Chris@40 167 exit (1) ;
Chris@40 168 } ;
Chris@40 169
Chris@40 170 if (sfinfo.samplerate != 44100)
Chris@40 171 { fprintf (stderr, "\n\nError : Sample rate (%d) should be 44100\n", sfinfo.samplerate) ;
Chris@40 172 exit (1) ;
Chris@40 173 } ;
Chris@40 174
Chris@40 175 if (sfinfo.channels != 1)
Chris@40 176 { fprintf (stderr, "\n\nError : Channels (%d) should be 1\n", sfinfo.channels) ;
Chris@40 177 exit (1) ;
Chris@40 178 } ;
Chris@40 179
Chris@40 180 if (sfinfo.frames < count)
Chris@40 181 { fprintf (stderr, "\n\nError : Sample count (%ld) should be %d\n", (long) sfinfo.frames, count) ;
Chris@40 182 exit (1) ;
Chris@40 183 } ;
Chris@40 184
Chris@40 185 total = 0 ;
Chris@40 186 while ((k = sf_read_short (file, data + total, BUFFER_LEN - total)) > 0)
Chris@40 187 total += k ;
Chris@40 188
Chris@40 189 if (total != count)
Chris@40 190 { fprintf (stderr, "\n\nError : Expected %d frames, read %d.\n", count, total) ;
Chris@40 191 exit (1) ;
Chris@40 192 } ;
Chris@40 193
Chris@40 194 for (k = 0 ; k < total ; k++)
Chris@40 195 if (data [k] != PIPE_INDEX (k))
Chris@40 196 { printf ("\n\nError : data [%d] == %d, should have been %d.\n\n", k, data [k], k) ;
Chris@40 197 exit (1) ;
Chris@40 198 } ;
Chris@40 199
Chris@40 200 sf_close (file) ;
Chris@40 201
Chris@40 202 return ;
Chris@40 203 } /* stdin_test */
Chris@40 204