1b815c7f3Sopenharmony_ci[+ AutoGen5 template c +] 2b815c7f3Sopenharmony_ci/* 3b815c7f3Sopenharmony_ci** Copyright (C) 1999-2017 Erik de Castro Lopo <erikd@mega-nerd.com> 4b815c7f3Sopenharmony_ci** 5b815c7f3Sopenharmony_ci** This program is free software; you can redistribute it and/or modify 6b815c7f3Sopenharmony_ci** it under the terms of the GNU General Public License as published by 7b815c7f3Sopenharmony_ci** the Free Software Foundation; either version 2 of the License, or 8b815c7f3Sopenharmony_ci** (at your option) any later version. 9b815c7f3Sopenharmony_ci** 10b815c7f3Sopenharmony_ci** This program is distributed in the hope that it will be useful, 11b815c7f3Sopenharmony_ci** but WITHOUT ANY WARRANTY; without even the implied warranty of 12b815c7f3Sopenharmony_ci** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13b815c7f3Sopenharmony_ci** GNU General Public License for more details. 14b815c7f3Sopenharmony_ci** 15b815c7f3Sopenharmony_ci** You should have received a copy of the GNU General Public License 16b815c7f3Sopenharmony_ci** along with this program; if not, write to the Free Software 17b815c7f3Sopenharmony_ci** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18b815c7f3Sopenharmony_ci*/ 19b815c7f3Sopenharmony_ci 20b815c7f3Sopenharmony_ci#include "sfconfig.h" 21b815c7f3Sopenharmony_ci 22b815c7f3Sopenharmony_ci#include <stdio.h> 23b815c7f3Sopenharmony_ci#include <stdlib.h> 24b815c7f3Sopenharmony_ci#include <string.h> 25b815c7f3Sopenharmony_ci#include <math.h> 26b815c7f3Sopenharmony_ci#include <inttypes.h> 27b815c7f3Sopenharmony_ci 28b815c7f3Sopenharmony_ci 29b815c7f3Sopenharmony_ci#if HAVE_UNISTD_H 30b815c7f3Sopenharmony_ci#include <unistd.h> 31b815c7f3Sopenharmony_ci#else 32b815c7f3Sopenharmony_ci#include "sf_unistd.h" 33b815c7f3Sopenharmony_ci#endif 34b815c7f3Sopenharmony_ci 35b815c7f3Sopenharmony_ci#include <sndfile.h> 36b815c7f3Sopenharmony_ci 37b815c7f3Sopenharmony_ci#include "utils.h" 38b815c7f3Sopenharmony_ci#include "generate.h" 39b815c7f3Sopenharmony_ci 40b815c7f3Sopenharmony_ci#define SAMPLE_RATE 11025 41b815c7f3Sopenharmony_ci#define DATA_LENGTH (1 << 12) 42b815c7f3Sopenharmony_ci 43b815c7f3Sopenharmony_ci#define SILLY_WRITE_COUNT (234) 44b815c7f3Sopenharmony_ci 45b815c7f3Sopenharmony_cistatic const char WRT_TEST_PREFIX[] = "wrt" ; 46b815c7f3Sopenharmony_ci 47b815c7f3Sopenharmony_ci[+ FOR data_type 48b815c7f3Sopenharmony_ci+]static void pcm_test_[+ (get "type_name") +] (const char *str, int format, int long_file_ok) ; 49b815c7f3Sopenharmony_ci[+ ENDFOR data_type 50b815c7f3Sopenharmony_ci+] 51b815c7f3Sopenharmony_cistatic void empty_file_test (const char *filename, int format) ; 52b815c7f3Sopenharmony_ci 53b815c7f3Sopenharmony_citypedef union 54b815c7f3Sopenharmony_ci{ double d [DATA_LENGTH] ; 55b815c7f3Sopenharmony_ci float f [DATA_LENGTH] ; 56b815c7f3Sopenharmony_ci int i [DATA_LENGTH] ; 57b815c7f3Sopenharmony_ci short s [DATA_LENGTH] ; 58b815c7f3Sopenharmony_ci char c [DATA_LENGTH] ; 59b815c7f3Sopenharmony_ci} BUFFER ; 60b815c7f3Sopenharmony_ci 61b815c7f3Sopenharmony_cistatic BUFFER orig_data ; 62b815c7f3Sopenharmony_cistatic BUFFER test_data ; 63b815c7f3Sopenharmony_ci 64b815c7f3Sopenharmony_ciint 65b815c7f3Sopenharmony_cimain (int argc, char **argv) 66b815c7f3Sopenharmony_ci{ int do_all = 0 ; 67b815c7f3Sopenharmony_ci int test_count = 0 ; 68b815c7f3Sopenharmony_ci 69b815c7f3Sopenharmony_ci count_open_files () ; 70b815c7f3Sopenharmony_ci 71b815c7f3Sopenharmony_ci if (argc != 2) 72b815c7f3Sopenharmony_ci { printf ("Usage : %s <test>\n", argv [0]) ; 73b815c7f3Sopenharmony_ci printf (" Where <test> is one of the following:\n") ; 74b815c7f3Sopenharmony_ci printf (" wav - test WAV file functions (little endian)\n") ; 75b815c7f3Sopenharmony_ci printf (" aiff - test AIFF file functions (big endian)\n") ; 76b815c7f3Sopenharmony_ci printf (" au - test AU file functions\n") ; 77b815c7f3Sopenharmony_ci printf (" avr - test AVR file functions\n") ; 78b815c7f3Sopenharmony_ci printf (" caf - test CAF file functions\n") ; 79b815c7f3Sopenharmony_ci printf (" raw - test RAW header-less PCM file functions\n") ; 80b815c7f3Sopenharmony_ci printf (" paf - test PAF file functions\n") ; 81b815c7f3Sopenharmony_ci printf (" svx - test 8SVX/16SV file functions\n") ; 82b815c7f3Sopenharmony_ci printf (" nist - test NIST Sphere file functions\n") ; 83b815c7f3Sopenharmony_ci printf (" ircam - test IRCAM file functions\n") ; 84b815c7f3Sopenharmony_ci printf (" voc - Create Voice file functions\n") ; 85b815c7f3Sopenharmony_ci printf (" w64 - Sonic Foundry's W64 file functions\n") ; 86b815c7f3Sopenharmony_ci printf (" flac - test FLAC file functions\n") ; 87b815c7f3Sopenharmony_ci printf (" mpc2k - test MPC 2000 file functions\n") ; 88b815c7f3Sopenharmony_ci printf (" rf64 - test RF64 file functions\n") ; 89b815c7f3Sopenharmony_ci printf (" all - perform all tests\n") ; 90b815c7f3Sopenharmony_ci exit (1) ; 91b815c7f3Sopenharmony_ci } ; 92b815c7f3Sopenharmony_ci 93b815c7f3Sopenharmony_ci do_all = !strcmp (argv [1], "all") ; 94b815c7f3Sopenharmony_ci 95b815c7f3Sopenharmony_ci if (do_all || ! strcmp (argv [1], "wav")) 96b815c7f3Sopenharmony_ci { pcm_test_char ("char.wav" , SF_FORMAT_WAV | SF_FORMAT_PCM_U8, SF_FALSE) ; 97b815c7f3Sopenharmony_ci pcm_test_short ("short.wav" , SF_FORMAT_WAV | SF_FORMAT_PCM_16, SF_FALSE) ; 98b815c7f3Sopenharmony_ci pcm_test_24bit ("24bit.wav" , SF_FORMAT_WAV | SF_FORMAT_PCM_24, SF_FALSE) ; 99b815c7f3Sopenharmony_ci pcm_test_int ("int.wav" , SF_FORMAT_WAV | SF_FORMAT_PCM_32, SF_FALSE) ; 100b815c7f3Sopenharmony_ci 101b815c7f3Sopenharmony_ci pcm_test_char ("char.rifx" , SF_ENDIAN_BIG | SF_FORMAT_WAV | SF_FORMAT_PCM_U8, SF_FALSE) ; 102b815c7f3Sopenharmony_ci pcm_test_short ("short.rifx" , SF_ENDIAN_BIG | SF_FORMAT_WAV | SF_FORMAT_PCM_16, SF_FALSE) ; 103b815c7f3Sopenharmony_ci pcm_test_24bit ("24bit.rifx" , SF_ENDIAN_BIG | SF_FORMAT_WAV | SF_FORMAT_PCM_24, SF_FALSE) ; 104b815c7f3Sopenharmony_ci pcm_test_int ("int.rifx" , SF_ENDIAN_BIG | SF_FORMAT_WAV | SF_FORMAT_PCM_32, SF_FALSE) ; 105b815c7f3Sopenharmony_ci 106b815c7f3Sopenharmony_ci pcm_test_24bit ("24bit.wavex" , SF_FORMAT_WAVEX | SF_FORMAT_PCM_24, SF_FALSE) ; 107b815c7f3Sopenharmony_ci pcm_test_int ("int.wavex" , SF_FORMAT_WAVEX | SF_FORMAT_PCM_32, SF_FALSE) ; 108b815c7f3Sopenharmony_ci 109b815c7f3Sopenharmony_ci /* Lite remove start */ 110b815c7f3Sopenharmony_ci pcm_test_float ("float.wav" , SF_FORMAT_WAV | SF_FORMAT_FLOAT , SF_FALSE) ; 111b815c7f3Sopenharmony_ci pcm_test_double ("double.wav" , SF_FORMAT_WAV | SF_FORMAT_DOUBLE, SF_FALSE) ; 112b815c7f3Sopenharmony_ci 113b815c7f3Sopenharmony_ci pcm_test_float ("float.rifx" , SF_ENDIAN_BIG | SF_FORMAT_WAV | SF_FORMAT_FLOAT , SF_FALSE) ; 114b815c7f3Sopenharmony_ci pcm_test_double ("double.rifx" , SF_ENDIAN_BIG | SF_FORMAT_WAV | SF_FORMAT_DOUBLE, SF_FALSE) ; 115b815c7f3Sopenharmony_ci 116b815c7f3Sopenharmony_ci pcm_test_float ("float.wavex" , SF_FORMAT_WAVEX | SF_FORMAT_FLOAT , SF_FALSE) ; 117b815c7f3Sopenharmony_ci pcm_test_double ("double.wavex" , SF_FORMAT_WAVEX | SF_FORMAT_DOUBLE, SF_FALSE) ; 118b815c7f3Sopenharmony_ci /* Lite remove end */ 119b815c7f3Sopenharmony_ci 120b815c7f3Sopenharmony_ci empty_file_test ("empty_char.wav", SF_FORMAT_WAV | SF_FORMAT_PCM_U8) ; 121b815c7f3Sopenharmony_ci empty_file_test ("empty_short.wav", SF_FORMAT_WAV | SF_FORMAT_PCM_16) ; 122b815c7f3Sopenharmony_ci empty_file_test ("empty_float.wav", SF_FORMAT_WAV | SF_FORMAT_FLOAT) ; 123b815c7f3Sopenharmony_ci 124b815c7f3Sopenharmony_ci test_count++ ; 125b815c7f3Sopenharmony_ci } ; 126b815c7f3Sopenharmony_ci 127b815c7f3Sopenharmony_ci if (do_all || ! strcmp (argv [1], "aiff")) 128b815c7f3Sopenharmony_ci { pcm_test_char ("char_u8.aiff" , SF_FORMAT_AIFF | SF_FORMAT_PCM_U8, SF_FALSE) ; 129b815c7f3Sopenharmony_ci pcm_test_char ("char_s8.aiff" , SF_FORMAT_AIFF | SF_FORMAT_PCM_S8, SF_FALSE) ; 130b815c7f3Sopenharmony_ci pcm_test_short ("short.aiff" , SF_FORMAT_AIFF | SF_FORMAT_PCM_16, SF_FALSE) ; 131b815c7f3Sopenharmony_ci pcm_test_24bit ("24bit.aiff" , SF_FORMAT_AIFF | SF_FORMAT_PCM_24, SF_FALSE) ; 132b815c7f3Sopenharmony_ci pcm_test_int ("int.aiff" , SF_FORMAT_AIFF | SF_FORMAT_PCM_32, SF_FALSE) ; 133b815c7f3Sopenharmony_ci 134b815c7f3Sopenharmony_ci pcm_test_short ("short_sowt.aifc" , SF_ENDIAN_LITTLE | SF_FORMAT_AIFF | SF_FORMAT_PCM_16, SF_FALSE) ; 135b815c7f3Sopenharmony_ci pcm_test_24bit ("24bit_sowt.aifc" , SF_ENDIAN_LITTLE | SF_FORMAT_AIFF | SF_FORMAT_PCM_24, SF_FALSE) ; 136b815c7f3Sopenharmony_ci pcm_test_int ("int_sowt.aifc" , SF_ENDIAN_LITTLE | SF_FORMAT_AIFF | SF_FORMAT_PCM_32, SF_FALSE) ; 137b815c7f3Sopenharmony_ci 138b815c7f3Sopenharmony_ci pcm_test_short ("short_twos.aifc" , SF_ENDIAN_BIG | SF_FORMAT_AIFF | SF_FORMAT_PCM_16, SF_FALSE) ; 139b815c7f3Sopenharmony_ci pcm_test_24bit ("24bit_twos.aifc" , SF_ENDIAN_BIG | SF_FORMAT_AIFF | SF_FORMAT_PCM_24, SF_FALSE) ; 140b815c7f3Sopenharmony_ci pcm_test_int ("int_twos.aifc" , SF_ENDIAN_BIG | SF_FORMAT_AIFF | SF_FORMAT_PCM_32, SF_FALSE) ; 141b815c7f3Sopenharmony_ci 142b815c7f3Sopenharmony_ci /* Lite remove start */ 143b815c7f3Sopenharmony_ci pcm_test_short ("dwvw16.aifc", SF_FORMAT_AIFF | SF_FORMAT_DWVW_16, SF_TRUE) ; 144b815c7f3Sopenharmony_ci pcm_test_24bit ("dwvw24.aifc", SF_FORMAT_AIFF | SF_FORMAT_DWVW_24, SF_TRUE) ; 145b815c7f3Sopenharmony_ci 146b815c7f3Sopenharmony_ci pcm_test_float ("float.aifc" , SF_FORMAT_AIFF | SF_FORMAT_FLOAT , SF_FALSE) ; 147b815c7f3Sopenharmony_ci pcm_test_double ("double.aifc" , SF_FORMAT_AIFF | SF_FORMAT_DOUBLE, SF_FALSE) ; 148b815c7f3Sopenharmony_ci /* Lite remove end */ 149b815c7f3Sopenharmony_ci 150b815c7f3Sopenharmony_ci empty_file_test ("empty_char.aiff", SF_FORMAT_AIFF | SF_FORMAT_PCM_U8) ; 151b815c7f3Sopenharmony_ci empty_file_test ("empty_short.aiff", SF_FORMAT_AIFF | SF_FORMAT_PCM_16) ; 152b815c7f3Sopenharmony_ci empty_file_test ("empty_float.aiff", SF_FORMAT_AIFF | SF_FORMAT_FLOAT) ; 153b815c7f3Sopenharmony_ci 154b815c7f3Sopenharmony_ci test_count++ ; 155b815c7f3Sopenharmony_ci } ; 156b815c7f3Sopenharmony_ci 157b815c7f3Sopenharmony_ci if (do_all || ! strcmp (argv [1], "au")) 158b815c7f3Sopenharmony_ci { pcm_test_char ("char.au" , SF_FORMAT_AU | SF_FORMAT_PCM_S8, SF_FALSE) ; 159b815c7f3Sopenharmony_ci pcm_test_short ("short.au" , SF_FORMAT_AU | SF_FORMAT_PCM_16, SF_FALSE) ; 160b815c7f3Sopenharmony_ci pcm_test_24bit ("24bit.au" , SF_FORMAT_AU | SF_FORMAT_PCM_24, SF_FALSE) ; 161b815c7f3Sopenharmony_ci pcm_test_int ("int.au" , SF_FORMAT_AU | SF_FORMAT_PCM_32, SF_FALSE) ; 162b815c7f3Sopenharmony_ci /* Lite remove start */ 163b815c7f3Sopenharmony_ci pcm_test_float ("float.au" , SF_FORMAT_AU | SF_FORMAT_FLOAT , SF_FALSE) ; 164b815c7f3Sopenharmony_ci pcm_test_double ("double.au", SF_FORMAT_AU | SF_FORMAT_DOUBLE, SF_FALSE) ; 165b815c7f3Sopenharmony_ci /* Lite remove end */ 166b815c7f3Sopenharmony_ci 167b815c7f3Sopenharmony_ci pcm_test_char ("char_le.au" , SF_ENDIAN_LITTLE | SF_FORMAT_AU | SF_FORMAT_PCM_S8, SF_FALSE) ; 168b815c7f3Sopenharmony_ci pcm_test_short ("short_le.au" , SF_ENDIAN_LITTLE | SF_FORMAT_AU | SF_FORMAT_PCM_16, SF_FALSE) ; 169b815c7f3Sopenharmony_ci pcm_test_24bit ("24bit_le.au" , SF_ENDIAN_LITTLE | SF_FORMAT_AU | SF_FORMAT_PCM_24, SF_FALSE) ; 170b815c7f3Sopenharmony_ci pcm_test_int ("int_le.au" , SF_ENDIAN_LITTLE | SF_FORMAT_AU | SF_FORMAT_PCM_32, SF_FALSE) ; 171b815c7f3Sopenharmony_ci /* Lite remove start */ 172b815c7f3Sopenharmony_ci pcm_test_float ("float_le.au" , SF_ENDIAN_LITTLE | SF_FORMAT_AU | SF_FORMAT_FLOAT , SF_FALSE) ; 173b815c7f3Sopenharmony_ci pcm_test_double ("double_le.au" , SF_ENDIAN_LITTLE | SF_FORMAT_AU | SF_FORMAT_DOUBLE, SF_FALSE) ; 174b815c7f3Sopenharmony_ci /* Lite remove end */ 175b815c7f3Sopenharmony_ci test_count++ ; 176b815c7f3Sopenharmony_ci } ; 177b815c7f3Sopenharmony_ci 178b815c7f3Sopenharmony_ci if (do_all || ! strcmp (argv [1], "caf")) 179b815c7f3Sopenharmony_ci { pcm_test_char ("char.caf" , SF_FORMAT_CAF | SF_FORMAT_PCM_S8, SF_FALSE) ; 180b815c7f3Sopenharmony_ci pcm_test_short ("short.caf" , SF_FORMAT_CAF | SF_FORMAT_PCM_16, SF_FALSE) ; 181b815c7f3Sopenharmony_ci pcm_test_24bit ("24bit.caf" , SF_FORMAT_CAF | SF_FORMAT_PCM_24, SF_FALSE) ; 182b815c7f3Sopenharmony_ci pcm_test_int ("int.caf" , SF_FORMAT_CAF | SF_FORMAT_PCM_32, SF_FALSE) ; 183b815c7f3Sopenharmony_ci /* Lite remove start */ 184b815c7f3Sopenharmony_ci pcm_test_float ("float.caf" , SF_FORMAT_CAF | SF_FORMAT_FLOAT , SF_FALSE) ; 185b815c7f3Sopenharmony_ci pcm_test_double ("double.caf" , SF_FORMAT_CAF | SF_FORMAT_DOUBLE, SF_FALSE) ; 186b815c7f3Sopenharmony_ci /* Lite remove end */ 187b815c7f3Sopenharmony_ci 188b815c7f3Sopenharmony_ci pcm_test_short ("short_le.caf" , SF_ENDIAN_LITTLE | SF_FORMAT_CAF | SF_FORMAT_PCM_16, SF_FALSE) ; 189b815c7f3Sopenharmony_ci pcm_test_24bit ("24bit_le.caf" , SF_ENDIAN_LITTLE | SF_FORMAT_CAF | SF_FORMAT_PCM_24, SF_FALSE) ; 190b815c7f3Sopenharmony_ci pcm_test_int ("int_le.caf" , SF_ENDIAN_LITTLE | SF_FORMAT_CAF | SF_FORMAT_PCM_32, SF_FALSE) ; 191b815c7f3Sopenharmony_ci /* Lite remove start */ 192b815c7f3Sopenharmony_ci pcm_test_float ("float_le.caf" , SF_ENDIAN_LITTLE | SF_FORMAT_CAF | SF_FORMAT_FLOAT , SF_FALSE) ; 193b815c7f3Sopenharmony_ci pcm_test_double ("double_le.caf", SF_ENDIAN_LITTLE | SF_FORMAT_CAF | SF_FORMAT_DOUBLE, SF_FALSE) ; 194b815c7f3Sopenharmony_ci 195b815c7f3Sopenharmony_ci pcm_test_short ("alac16.caf" , SF_FORMAT_CAF | SF_FORMAT_ALAC_16, SF_FALSE) ; 196b815c7f3Sopenharmony_ci pcm_test_20bit ("alac20.caf" , SF_FORMAT_CAF | SF_FORMAT_ALAC_20, SF_FALSE) ; 197b815c7f3Sopenharmony_ci pcm_test_24bit ("alac24.caf" , SF_FORMAT_CAF | SF_FORMAT_ALAC_24, SF_FALSE) ; 198b815c7f3Sopenharmony_ci pcm_test_int ("alac32.caf" , SF_FORMAT_CAF | SF_FORMAT_ALAC_32, SF_FALSE) ; 199b815c7f3Sopenharmony_ci 200b815c7f3Sopenharmony_ci /* Lite remove end */ 201b815c7f3Sopenharmony_ci test_count++ ; 202b815c7f3Sopenharmony_ci } ; 203b815c7f3Sopenharmony_ci 204b815c7f3Sopenharmony_ci if (do_all || ! strcmp (argv [1], "raw")) 205b815c7f3Sopenharmony_ci { pcm_test_char ("char_s8.raw" , SF_FORMAT_RAW | SF_FORMAT_PCM_S8, SF_FALSE) ; 206b815c7f3Sopenharmony_ci pcm_test_char ("char_u8.raw" , SF_FORMAT_RAW | SF_FORMAT_PCM_U8, SF_FALSE) ; 207b815c7f3Sopenharmony_ci 208b815c7f3Sopenharmony_ci pcm_test_short ("short_le.raw" , SF_ENDIAN_LITTLE | SF_FORMAT_RAW | SF_FORMAT_PCM_16, SF_FALSE) ; 209b815c7f3Sopenharmony_ci pcm_test_short ("short_be.raw" , SF_ENDIAN_BIG | SF_FORMAT_RAW | SF_FORMAT_PCM_16, SF_FALSE) ; 210b815c7f3Sopenharmony_ci pcm_test_24bit ("24bit_le.raw" , SF_ENDIAN_LITTLE | SF_FORMAT_RAW | SF_FORMAT_PCM_24, SF_FALSE) ; 211b815c7f3Sopenharmony_ci pcm_test_24bit ("24bit_be.raw" , SF_ENDIAN_BIG | SF_FORMAT_RAW | SF_FORMAT_PCM_24, SF_FALSE) ; 212b815c7f3Sopenharmony_ci pcm_test_int ("int_le.raw" , SF_ENDIAN_LITTLE | SF_FORMAT_RAW | SF_FORMAT_PCM_32, SF_FALSE) ; 213b815c7f3Sopenharmony_ci pcm_test_int ("int_be.raw" , SF_ENDIAN_BIG | SF_FORMAT_RAW | SF_FORMAT_PCM_32, SF_FALSE) ; 214b815c7f3Sopenharmony_ci 215b815c7f3Sopenharmony_ci /* Lite remove start */ 216b815c7f3Sopenharmony_ci pcm_test_float ("float_le.raw" , SF_ENDIAN_LITTLE | SF_FORMAT_RAW | SF_FORMAT_FLOAT , SF_FALSE) ; 217b815c7f3Sopenharmony_ci pcm_test_float ("float_be.raw" , SF_ENDIAN_BIG | SF_FORMAT_RAW | SF_FORMAT_FLOAT , SF_FALSE) ; 218b815c7f3Sopenharmony_ci 219b815c7f3Sopenharmony_ci pcm_test_double ("double_le.raw", SF_ENDIAN_LITTLE | SF_FORMAT_RAW | SF_FORMAT_DOUBLE, SF_FALSE) ; 220b815c7f3Sopenharmony_ci pcm_test_double ("double_be.raw", SF_ENDIAN_BIG | SF_FORMAT_RAW | SF_FORMAT_DOUBLE, SF_FALSE) ; 221b815c7f3Sopenharmony_ci /* Lite remove end */ 222b815c7f3Sopenharmony_ci test_count++ ; 223b815c7f3Sopenharmony_ci } ; 224b815c7f3Sopenharmony_ci 225b815c7f3Sopenharmony_ci /* Lite remove start */ 226b815c7f3Sopenharmony_ci if (do_all || ! strcmp (argv [1], "paf")) 227b815c7f3Sopenharmony_ci { pcm_test_char ("char_le.paf", SF_ENDIAN_LITTLE | SF_FORMAT_PAF | SF_FORMAT_PCM_S8, SF_FALSE) ; 228b815c7f3Sopenharmony_ci pcm_test_char ("char_be.paf", SF_ENDIAN_BIG | SF_FORMAT_PAF | SF_FORMAT_PCM_S8, SF_FALSE) ; 229b815c7f3Sopenharmony_ci pcm_test_short ("short_le.paf", SF_ENDIAN_LITTLE | SF_FORMAT_PAF | SF_FORMAT_PCM_16, SF_FALSE) ; 230b815c7f3Sopenharmony_ci pcm_test_short ("short_be.paf", SF_ENDIAN_BIG | SF_FORMAT_PAF | SF_FORMAT_PCM_16, SF_FALSE) ; 231b815c7f3Sopenharmony_ci pcm_test_24bit ("24bit_le.paf", SF_ENDIAN_LITTLE | SF_FORMAT_PAF | SF_FORMAT_PCM_24, SF_TRUE) ; 232b815c7f3Sopenharmony_ci pcm_test_24bit ("24bit_be.paf", SF_ENDIAN_BIG | SF_FORMAT_PAF | SF_FORMAT_PCM_24, SF_TRUE) ; 233b815c7f3Sopenharmony_ci test_count++ ; 234b815c7f3Sopenharmony_ci } ; 235b815c7f3Sopenharmony_ci 236b815c7f3Sopenharmony_ci if (do_all || ! strcmp (argv [1], "svx")) 237b815c7f3Sopenharmony_ci { pcm_test_char ("char.svx" , SF_FORMAT_SVX | SF_FORMAT_PCM_S8, SF_FALSE) ; 238b815c7f3Sopenharmony_ci pcm_test_short ("short.svx", SF_FORMAT_SVX | SF_FORMAT_PCM_16, SF_FALSE) ; 239b815c7f3Sopenharmony_ci 240b815c7f3Sopenharmony_ci empty_file_test ("empty_char.svx", SF_FORMAT_SVX | SF_FORMAT_PCM_S8) ; 241b815c7f3Sopenharmony_ci empty_file_test ("empty_short.svx", SF_FORMAT_SVX | SF_FORMAT_PCM_16) ; 242b815c7f3Sopenharmony_ci 243b815c7f3Sopenharmony_ci test_count++ ; 244b815c7f3Sopenharmony_ci } ; 245b815c7f3Sopenharmony_ci 246b815c7f3Sopenharmony_ci if (do_all || ! strcmp (argv [1], "nist")) 247b815c7f3Sopenharmony_ci { pcm_test_short ("short_le.nist", SF_ENDIAN_LITTLE | SF_FORMAT_NIST | SF_FORMAT_PCM_16, SF_FALSE) ; 248b815c7f3Sopenharmony_ci pcm_test_short ("short_be.nist", SF_ENDIAN_BIG | SF_FORMAT_NIST | SF_FORMAT_PCM_16, SF_FALSE) ; 249b815c7f3Sopenharmony_ci pcm_test_24bit ("24bit_le.nist", SF_ENDIAN_LITTLE | SF_FORMAT_NIST | SF_FORMAT_PCM_24, SF_FALSE) ; 250b815c7f3Sopenharmony_ci pcm_test_24bit ("24bit_be.nist", SF_ENDIAN_BIG | SF_FORMAT_NIST | SF_FORMAT_PCM_24, SF_FALSE) ; 251b815c7f3Sopenharmony_ci pcm_test_int ("int_le.nist" , SF_ENDIAN_LITTLE | SF_FORMAT_NIST | SF_FORMAT_PCM_32, SF_FALSE) ; 252b815c7f3Sopenharmony_ci pcm_test_int ("int_be.nist" , SF_ENDIAN_BIG | SF_FORMAT_NIST | SF_FORMAT_PCM_32, SF_FALSE) ; 253b815c7f3Sopenharmony_ci 254b815c7f3Sopenharmony_ci test_count++ ; 255b815c7f3Sopenharmony_ci } ; 256b815c7f3Sopenharmony_ci 257b815c7f3Sopenharmony_ci if (do_all || ! strcmp (argv [1], "ircam")) 258b815c7f3Sopenharmony_ci { pcm_test_short ("short_be.ircam" , SF_ENDIAN_BIG | SF_FORMAT_IRCAM | SF_FORMAT_PCM_16, SF_FALSE) ; 259b815c7f3Sopenharmony_ci pcm_test_short ("short_le.ircam" , SF_ENDIAN_LITTLE | SF_FORMAT_IRCAM | SF_FORMAT_PCM_16, SF_FALSE) ; 260b815c7f3Sopenharmony_ci pcm_test_int ("int_be.ircam" , SF_ENDIAN_BIG | SF_FORMAT_IRCAM | SF_FORMAT_PCM_32, SF_FALSE) ; 261b815c7f3Sopenharmony_ci pcm_test_int ("int_le.ircam" , SF_ENDIAN_LITTLE | SF_FORMAT_IRCAM | SF_FORMAT_PCM_32, SF_FALSE) ; 262b815c7f3Sopenharmony_ci pcm_test_float ("float_be.ircam" , SF_ENDIAN_BIG | SF_FORMAT_IRCAM | SF_FORMAT_FLOAT , SF_FALSE) ; 263b815c7f3Sopenharmony_ci pcm_test_float ("float_le.ircam" , SF_ENDIAN_LITTLE | SF_FORMAT_IRCAM | SF_FORMAT_FLOAT , SF_FALSE) ; 264b815c7f3Sopenharmony_ci 265b815c7f3Sopenharmony_ci test_count++ ; 266b815c7f3Sopenharmony_ci } ; 267b815c7f3Sopenharmony_ci 268b815c7f3Sopenharmony_ci if (do_all || ! strcmp (argv [1], "voc")) 269b815c7f3Sopenharmony_ci { pcm_test_char ("char.voc" , SF_FORMAT_VOC | SF_FORMAT_PCM_U8, SF_FALSE) ; 270b815c7f3Sopenharmony_ci pcm_test_short ("short.voc", SF_FORMAT_VOC | SF_FORMAT_PCM_16, SF_FALSE) ; 271b815c7f3Sopenharmony_ci 272b815c7f3Sopenharmony_ci test_count++ ; 273b815c7f3Sopenharmony_ci } ; 274b815c7f3Sopenharmony_ci 275b815c7f3Sopenharmony_ci if (do_all || ! strcmp (argv [1], "mat4")) 276b815c7f3Sopenharmony_ci { pcm_test_short ("short_be.mat4" , SF_ENDIAN_BIG | SF_FORMAT_MAT4 | SF_FORMAT_PCM_16, SF_FALSE) ; 277b815c7f3Sopenharmony_ci pcm_test_short ("short_le.mat4" , SF_ENDIAN_LITTLE | SF_FORMAT_MAT4 | SF_FORMAT_PCM_16, SF_FALSE) ; 278b815c7f3Sopenharmony_ci pcm_test_int ("int_be.mat4" , SF_ENDIAN_BIG | SF_FORMAT_MAT4 | SF_FORMAT_PCM_32, SF_FALSE) ; 279b815c7f3Sopenharmony_ci pcm_test_int ("int_le.mat4" , SF_ENDIAN_LITTLE | SF_FORMAT_MAT4 | SF_FORMAT_PCM_32, SF_FALSE) ; 280b815c7f3Sopenharmony_ci pcm_test_float ("float_be.mat4" , SF_ENDIAN_BIG | SF_FORMAT_MAT4 | SF_FORMAT_FLOAT , SF_FALSE) ; 281b815c7f3Sopenharmony_ci pcm_test_float ("float_le.mat4" , SF_ENDIAN_LITTLE | SF_FORMAT_MAT4 | SF_FORMAT_FLOAT , SF_FALSE) ; 282b815c7f3Sopenharmony_ci pcm_test_double ("double_be.mat4" , SF_ENDIAN_BIG | SF_FORMAT_MAT4 | SF_FORMAT_DOUBLE, SF_FALSE) ; 283b815c7f3Sopenharmony_ci pcm_test_double ("double_le.mat4" , SF_ENDIAN_LITTLE | SF_FORMAT_MAT4 | SF_FORMAT_DOUBLE, SF_FALSE) ; 284b815c7f3Sopenharmony_ci 285b815c7f3Sopenharmony_ci empty_file_test ("empty_short.mat4", SF_FORMAT_MAT4 | SF_FORMAT_PCM_16) ; 286b815c7f3Sopenharmony_ci empty_file_test ("empty_float.mat4", SF_FORMAT_MAT4 | SF_FORMAT_FLOAT) ; 287b815c7f3Sopenharmony_ci test_count++ ; 288b815c7f3Sopenharmony_ci } ; 289b815c7f3Sopenharmony_ci 290b815c7f3Sopenharmony_ci if (do_all || ! strcmp (argv [1], "mat5")) 291b815c7f3Sopenharmony_ci { pcm_test_char ("char_be.mat5" , SF_ENDIAN_BIG | SF_FORMAT_MAT5 | SF_FORMAT_PCM_U8, SF_FALSE) ; 292b815c7f3Sopenharmony_ci pcm_test_char ("char_le.mat5" , SF_ENDIAN_LITTLE | SF_FORMAT_MAT5 | SF_FORMAT_PCM_U8, SF_FALSE) ; 293b815c7f3Sopenharmony_ci pcm_test_short ("short_be.mat5" , SF_ENDIAN_BIG | SF_FORMAT_MAT5 | SF_FORMAT_PCM_16, SF_FALSE) ; 294b815c7f3Sopenharmony_ci pcm_test_short ("short_le.mat5" , SF_ENDIAN_LITTLE | SF_FORMAT_MAT5 | SF_FORMAT_PCM_16, SF_FALSE) ; 295b815c7f3Sopenharmony_ci pcm_test_int ("int_be.mat5" , SF_ENDIAN_BIG | SF_FORMAT_MAT5 | SF_FORMAT_PCM_32, SF_FALSE) ; 296b815c7f3Sopenharmony_ci pcm_test_int ("int_le.mat5" , SF_ENDIAN_LITTLE | SF_FORMAT_MAT5 | SF_FORMAT_PCM_32, SF_FALSE) ; 297b815c7f3Sopenharmony_ci pcm_test_float ("float_be.mat5" , SF_ENDIAN_BIG | SF_FORMAT_MAT5 | SF_FORMAT_FLOAT , SF_FALSE) ; 298b815c7f3Sopenharmony_ci pcm_test_float ("float_le.mat5" , SF_ENDIAN_LITTLE | SF_FORMAT_MAT5 | SF_FORMAT_FLOAT , SF_FALSE) ; 299b815c7f3Sopenharmony_ci pcm_test_double ("double_be.mat5" , SF_ENDIAN_BIG | SF_FORMAT_MAT5 | SF_FORMAT_DOUBLE, SF_FALSE) ; 300b815c7f3Sopenharmony_ci pcm_test_double ("double_le.mat5" , SF_ENDIAN_LITTLE | SF_FORMAT_MAT5 | SF_FORMAT_DOUBLE, SF_FALSE) ; 301b815c7f3Sopenharmony_ci 302b815c7f3Sopenharmony_ci increment_open_file_count () ; 303b815c7f3Sopenharmony_ci 304b815c7f3Sopenharmony_ci empty_file_test ("empty_char.mat5", SF_FORMAT_MAT5 | SF_FORMAT_PCM_U8) ; 305b815c7f3Sopenharmony_ci empty_file_test ("empty_short.mat5", SF_FORMAT_MAT5 | SF_FORMAT_PCM_16) ; 306b815c7f3Sopenharmony_ci empty_file_test ("empty_float.mat5", SF_FORMAT_MAT5 | SF_FORMAT_FLOAT) ; 307b815c7f3Sopenharmony_ci 308b815c7f3Sopenharmony_ci test_count++ ; 309b815c7f3Sopenharmony_ci } ; 310b815c7f3Sopenharmony_ci 311b815c7f3Sopenharmony_ci if (do_all || ! strcmp (argv [1], "pvf")) 312b815c7f3Sopenharmony_ci { pcm_test_char ("char.pvf" , SF_FORMAT_PVF | SF_FORMAT_PCM_S8, SF_FALSE) ; 313b815c7f3Sopenharmony_ci pcm_test_short ("short.pvf", SF_FORMAT_PVF | SF_FORMAT_PCM_16, SF_FALSE) ; 314b815c7f3Sopenharmony_ci pcm_test_int ("int.pvf" , SF_FORMAT_PVF | SF_FORMAT_PCM_32, SF_FALSE) ; 315b815c7f3Sopenharmony_ci test_count++ ; 316b815c7f3Sopenharmony_ci } ; 317b815c7f3Sopenharmony_ci 318b815c7f3Sopenharmony_ci if (do_all || ! strcmp (argv [1], "htk")) 319b815c7f3Sopenharmony_ci { pcm_test_short ("short.htk", SF_FORMAT_HTK | SF_FORMAT_PCM_16, SF_FALSE) ; 320b815c7f3Sopenharmony_ci test_count++ ; 321b815c7f3Sopenharmony_ci } ; 322b815c7f3Sopenharmony_ci 323b815c7f3Sopenharmony_ci if (do_all || ! strcmp (argv [1], "mpc2k")) 324b815c7f3Sopenharmony_ci { pcm_test_short ("short.mpc", SF_FORMAT_MPC2K | SF_FORMAT_PCM_16, SF_FALSE) ; 325b815c7f3Sopenharmony_ci test_count++ ; 326b815c7f3Sopenharmony_ci } ; 327b815c7f3Sopenharmony_ci 328b815c7f3Sopenharmony_ci if (do_all || ! strcmp (argv [1], "avr")) 329b815c7f3Sopenharmony_ci { pcm_test_char ("char_u8.avr" , SF_FORMAT_AVR | SF_FORMAT_PCM_U8, SF_FALSE) ; 330b815c7f3Sopenharmony_ci pcm_test_char ("char_s8.avr" , SF_FORMAT_AVR | SF_FORMAT_PCM_S8, SF_FALSE) ; 331b815c7f3Sopenharmony_ci pcm_test_short ("short.avr" , SF_FORMAT_AVR | SF_FORMAT_PCM_16, SF_FALSE) ; 332b815c7f3Sopenharmony_ci test_count++ ; 333b815c7f3Sopenharmony_ci } ; 334b815c7f3Sopenharmony_ci /* Lite remove end */ 335b815c7f3Sopenharmony_ci 336b815c7f3Sopenharmony_ci if (do_all || ! strcmp (argv [1], "w64")) 337b815c7f3Sopenharmony_ci { pcm_test_char ("char.w64" , SF_FORMAT_W64 | SF_FORMAT_PCM_U8, SF_FALSE) ; 338b815c7f3Sopenharmony_ci pcm_test_short ("short.w64" , SF_FORMAT_W64 | SF_FORMAT_PCM_16, SF_FALSE) ; 339b815c7f3Sopenharmony_ci pcm_test_24bit ("24bit.w64" , SF_FORMAT_W64 | SF_FORMAT_PCM_24, SF_FALSE) ; 340b815c7f3Sopenharmony_ci pcm_test_int ("int.w64" , SF_FORMAT_W64 | SF_FORMAT_PCM_32, SF_FALSE) ; 341b815c7f3Sopenharmony_ci /* Lite remove start */ 342b815c7f3Sopenharmony_ci pcm_test_float ("float.w64" , SF_FORMAT_W64 | SF_FORMAT_FLOAT , SF_FALSE) ; 343b815c7f3Sopenharmony_ci pcm_test_double ("double.w64" , SF_FORMAT_W64 | SF_FORMAT_DOUBLE, SF_FALSE) ; 344b815c7f3Sopenharmony_ci /* Lite remove end */ 345b815c7f3Sopenharmony_ci 346b815c7f3Sopenharmony_ci empty_file_test ("empty_char.w64", SF_FORMAT_W64 | SF_FORMAT_PCM_U8) ; 347b815c7f3Sopenharmony_ci empty_file_test ("empty_short.w64", SF_FORMAT_W64 | SF_FORMAT_PCM_16) ; 348b815c7f3Sopenharmony_ci empty_file_test ("empty_float.w64", SF_FORMAT_W64 | SF_FORMAT_FLOAT) ; 349b815c7f3Sopenharmony_ci 350b815c7f3Sopenharmony_ci test_count++ ; 351b815c7f3Sopenharmony_ci } ; 352b815c7f3Sopenharmony_ci 353b815c7f3Sopenharmony_ci if (do_all || ! strcmp (argv [1], "sds")) 354b815c7f3Sopenharmony_ci { pcm_test_char ("char.sds" , SF_FORMAT_SDS | SF_FORMAT_PCM_S8, SF_FALSE) ; 355b815c7f3Sopenharmony_ci pcm_test_short ("short.sds" , SF_FORMAT_SDS | SF_FORMAT_PCM_16, SF_FALSE) ; 356b815c7f3Sopenharmony_ci pcm_test_24bit ("24bit.sds" , SF_FORMAT_SDS | SF_FORMAT_PCM_24, SF_FALSE) ; 357b815c7f3Sopenharmony_ci 358b815c7f3Sopenharmony_ci empty_file_test ("empty_char.sds", SF_FORMAT_SDS | SF_FORMAT_PCM_S8) ; 359b815c7f3Sopenharmony_ci empty_file_test ("empty_short.sds", SF_FORMAT_SDS | SF_FORMAT_PCM_16) ; 360b815c7f3Sopenharmony_ci 361b815c7f3Sopenharmony_ci test_count++ ; 362b815c7f3Sopenharmony_ci } ; 363b815c7f3Sopenharmony_ci 364b815c7f3Sopenharmony_ci if (do_all || ! strcmp (argv [1], "sd2")) 365b815c7f3Sopenharmony_ci { pcm_test_char ("char.sd2" , SF_FORMAT_SD2 | SF_FORMAT_PCM_S8, SF_TRUE) ; 366b815c7f3Sopenharmony_ci pcm_test_short ("short.sd2" , SF_FORMAT_SD2 | SF_FORMAT_PCM_16, SF_TRUE) ; 367b815c7f3Sopenharmony_ci pcm_test_24bit ("24bit.sd2" , SF_FORMAT_SD2 | SF_FORMAT_PCM_24, SF_TRUE) ; 368b815c7f3Sopenharmony_ci pcm_test_int ("32bit.sd2" , SF_FORMAT_SD2 | SF_FORMAT_PCM_32, SF_TRUE) ; 369b815c7f3Sopenharmony_ci test_count++ ; 370b815c7f3Sopenharmony_ci } ; 371b815c7f3Sopenharmony_ci 372b815c7f3Sopenharmony_ci if (do_all || ! strcmp (argv [1], "flac")) 373b815c7f3Sopenharmony_ci { if (HAVE_EXTERNAL_XIPH_LIBS) 374b815c7f3Sopenharmony_ci { pcm_test_char ("char.flac" , SF_FORMAT_FLAC | SF_FORMAT_PCM_S8, SF_TRUE) ; 375b815c7f3Sopenharmony_ci pcm_test_short ("short.flac" , SF_FORMAT_FLAC | SF_FORMAT_PCM_16, SF_TRUE) ; 376b815c7f3Sopenharmony_ci pcm_test_24bit ("24bit.flac" , SF_FORMAT_FLAC | SF_FORMAT_PCM_24, SF_TRUE) ; 377b815c7f3Sopenharmony_ci } 378b815c7f3Sopenharmony_ci else 379b815c7f3Sopenharmony_ci puts (" No FLAC tests because FLAC support was not compiled in.") ; 380b815c7f3Sopenharmony_ci test_count++ ; 381b815c7f3Sopenharmony_ci } ; 382b815c7f3Sopenharmony_ci 383b815c7f3Sopenharmony_ci if (do_all || ! strcmp (argv [1], "rf64")) 384b815c7f3Sopenharmony_ci { pcm_test_char ("char.rf64" , SF_FORMAT_RF64 | SF_FORMAT_PCM_U8, SF_FALSE) ; 385b815c7f3Sopenharmony_ci pcm_test_short ("short.rf64" , SF_FORMAT_RF64 | SF_FORMAT_PCM_16, SF_FALSE) ; 386b815c7f3Sopenharmony_ci pcm_test_24bit ("24bit.rf64" , SF_FORMAT_RF64 | SF_FORMAT_PCM_24, SF_FALSE) ; 387b815c7f3Sopenharmony_ci pcm_test_int ("int.rf64" , SF_FORMAT_RF64 | SF_FORMAT_PCM_32, SF_FALSE) ; 388b815c7f3Sopenharmony_ci 389b815c7f3Sopenharmony_ci /* Lite remove start */ 390b815c7f3Sopenharmony_ci pcm_test_float ("float.rf64" , SF_FORMAT_RF64 | SF_FORMAT_FLOAT , SF_FALSE) ; 391b815c7f3Sopenharmony_ci pcm_test_double ("double.rf64" , SF_FORMAT_RF64 | SF_FORMAT_DOUBLE, SF_FALSE) ; 392b815c7f3Sopenharmony_ci empty_file_test ("empty_char.rf64", SF_FORMAT_RF64 | SF_FORMAT_PCM_U8) ; 393b815c7f3Sopenharmony_ci empty_file_test ("empty_short.rf64", SF_FORMAT_RF64 | SF_FORMAT_PCM_16) ; 394b815c7f3Sopenharmony_ci empty_file_test ("empty_float.rf64", SF_FORMAT_RF64 | SF_FORMAT_FLOAT) ; 395b815c7f3Sopenharmony_ci /* Lite remove end */ 396b815c7f3Sopenharmony_ci 397b815c7f3Sopenharmony_ci test_count++ ; 398b815c7f3Sopenharmony_ci } ; 399b815c7f3Sopenharmony_ci 400b815c7f3Sopenharmony_ci if (test_count == 0) 401b815c7f3Sopenharmony_ci { printf ("Mono : ************************************\n") ; 402b815c7f3Sopenharmony_ci printf ("Mono : * No '%s' test defined.\n", argv [1]) ; 403b815c7f3Sopenharmony_ci printf ("Mono : ************************************\n") ; 404b815c7f3Sopenharmony_ci return 1 ; 405b815c7f3Sopenharmony_ci } ; 406b815c7f3Sopenharmony_ci 407b815c7f3Sopenharmony_ci /* Only open file descriptors should be stdin, stdout and stderr. */ 408b815c7f3Sopenharmony_ci check_open_file_count_or_die (__LINE__) ; 409b815c7f3Sopenharmony_ci 410b815c7f3Sopenharmony_ci return 0 ; 411b815c7f3Sopenharmony_ci} /* main */ 412b815c7f3Sopenharmony_ci 413b815c7f3Sopenharmony_ci/*============================================================================================ 414b815c7f3Sopenharmony_ci** Helper functions and macros. 415b815c7f3Sopenharmony_ci*/ 416b815c7f3Sopenharmony_ci 417b815c7f3Sopenharmony_cistatic void create_short_file (const char *filename) ; 418b815c7f3Sopenharmony_ci 419b815c7f3Sopenharmony_ci#define CHAR_ERROR(x, y) (abs ((x) - (y)) > 255) 420b815c7f3Sopenharmony_ci#define INT_ERROR(x, y) (((x) - (y)) != 0) 421b815c7f3Sopenharmony_ci#define BIT_20_ERROR(x, y) (abs ((x) - (y)) > 4095) 422b815c7f3Sopenharmony_ci#define TRIBYTE_ERROR(x, y) (abs ((x) - (y)) > 255) 423b815c7f3Sopenharmony_ci#define FLOAT_ERROR(x, y) (fabs ((x) - (y)) > 1e-5) 424b815c7f3Sopenharmony_ci 425b815c7f3Sopenharmony_ci#define CONVERT_DATA(k, len, new, orig) \ 426b815c7f3Sopenharmony_ci { for ((k) = 0 ; (k) < (len) ; (k) ++) \ 427b815c7f3Sopenharmony_ci (new) [k] = (orig) [k] ; \ 428b815c7f3Sopenharmony_ci } 429b815c7f3Sopenharmony_ci 430b815c7f3Sopenharmony_ci[+ FOR data_type 431b815c7f3Sopenharmony_ci+] 432b815c7f3Sopenharmony_ci/*====================================================================================== 433b815c7f3Sopenharmony_ci*/ 434b815c7f3Sopenharmony_ci 435b815c7f3Sopenharmony_cistatic void mono_[+ (get "type_name") +]_test (const char *filename, int format, int long_file_ok, int allow_fd) ; 436b815c7f3Sopenharmony_cistatic void stereo_[+ (get "type_name") +]_test (const char *filename, int format, int long_file_ok, int allow_fd) ; 437b815c7f3Sopenharmony_cistatic void mono_rdwr_[+ (get "type_name") +]_test (const char *filename, int format, int long_file_ok, int allow_fd) ; 438b815c7f3Sopenharmony_cistatic void new_rdwr_[+ (get "type_name") +]_test (const char *filename, int format, int allow_fd) ; 439b815c7f3Sopenharmony_cistatic void multi_seek_test (const char * filename, int format) ; 440b815c7f3Sopenharmony_cistatic void write_seek_extend_test (const char * filename, int format) ; 441b815c7f3Sopenharmony_ci 442b815c7f3Sopenharmony_cistatic void 443b815c7f3Sopenharmony_cipcm_test_[+ (get "type_name") +] (const char *filename, int format, int long_file_ok) 444b815c7f3Sopenharmony_ci{ SF_INFO sfinfo ; 445b815c7f3Sopenharmony_ci [+ (get "data_type") +] *orig ; 446b815c7f3Sopenharmony_ci int k, allow_fd ; 447b815c7f3Sopenharmony_ci 448b815c7f3Sopenharmony_ci /* Sd2 files cannot be opened from an existing file descriptor. */ 449b815c7f3Sopenharmony_ci allow_fd = ((format & SF_FORMAT_TYPEMASK) == SF_FORMAT_SD2) ? SF_FALSE : SF_TRUE ; 450b815c7f3Sopenharmony_ci 451b815c7f3Sopenharmony_ci get_unique_test_name (&filename, WRT_TEST_PREFIX) ; 452b815c7f3Sopenharmony_ci print_test_name ("pcm_test_[+ (get "type_name") +]", filename) ; 453b815c7f3Sopenharmony_ci 454b815c7f3Sopenharmony_ci sfinfo.samplerate = 44100 ; 455b815c7f3Sopenharmony_ci sfinfo.frames = SILLY_WRITE_COUNT ; /* Wrong length. Library should correct this on sf_close. */ 456b815c7f3Sopenharmony_ci sfinfo.channels = 1 ; 457b815c7f3Sopenharmony_ci sfinfo.format = format ; 458b815c7f3Sopenharmony_ci 459b815c7f3Sopenharmony_ci test_sf_format_or_die (&sfinfo, __LINE__) ; 460b815c7f3Sopenharmony_ci 461b815c7f3Sopenharmony_ci gen_windowed_sine_double (orig_data.d, DATA_LENGTH, [+ (get "max_val") +]) ; 462b815c7f3Sopenharmony_ci 463b815c7f3Sopenharmony_ci orig = orig_data.[+ (get "data_field") +] ; 464b815c7f3Sopenharmony_ci 465b815c7f3Sopenharmony_ci /* Make this a macro so gdb steps over it in one go. */ 466b815c7f3Sopenharmony_ci CONVERT_DATA (k, DATA_LENGTH, orig, orig_data.d) ; 467b815c7f3Sopenharmony_ci 468b815c7f3Sopenharmony_ci /* Some test broken out here. */ 469b815c7f3Sopenharmony_ci 470b815c7f3Sopenharmony_ci mono_[+ (get "type_name") +]_test (filename, format, long_file_ok, allow_fd) ; 471b815c7f3Sopenharmony_ci 472b815c7f3Sopenharmony_ci /* Sub format DWVW does not allow seeking. */ 473b815c7f3Sopenharmony_ci if ((format & SF_FORMAT_SUBMASK) == SF_FORMAT_DWVW_16 || 474b815c7f3Sopenharmony_ci (format & SF_FORMAT_SUBMASK) == SF_FORMAT_DWVW_24) 475b815c7f3Sopenharmony_ci { unlink (filename) ; 476b815c7f3Sopenharmony_ci printf ("no seek : ok\n") ; 477b815c7f3Sopenharmony_ci return ; 478b815c7f3Sopenharmony_ci } ; 479b815c7f3Sopenharmony_ci 480b815c7f3Sopenharmony_ci if ((format & SF_FORMAT_TYPEMASK) != SF_FORMAT_FLAC 481b815c7f3Sopenharmony_ci && (format & SF_FORMAT_SUBMASK) != SF_FORMAT_ALAC_16 482b815c7f3Sopenharmony_ci && (format & SF_FORMAT_SUBMASK) != SF_FORMAT_ALAC_20 483b815c7f3Sopenharmony_ci && (format & SF_FORMAT_SUBMASK) != SF_FORMAT_ALAC_24 484b815c7f3Sopenharmony_ci && (format & SF_FORMAT_SUBMASK) != SF_FORMAT_ALAC_32 485b815c7f3Sopenharmony_ci ) 486b815c7f3Sopenharmony_ci mono_rdwr_[+ (get "type_name") +]_test (filename, format, long_file_ok, allow_fd) ; 487b815c7f3Sopenharmony_ci 488b815c7f3Sopenharmony_ci /* If the format doesn't support stereo we're done. */ 489b815c7f3Sopenharmony_ci sfinfo.channels = 2 ; 490b815c7f3Sopenharmony_ci if (sf_format_check (&sfinfo) == 0) 491b815c7f3Sopenharmony_ci { unlink (filename) ; 492b815c7f3Sopenharmony_ci puts ("no stereo : ok") ; 493b815c7f3Sopenharmony_ci return ; 494b815c7f3Sopenharmony_ci } ; 495b815c7f3Sopenharmony_ci 496b815c7f3Sopenharmony_ci stereo_[+ (get "type_name") +]_test (filename, format, long_file_ok, allow_fd) ; 497b815c7f3Sopenharmony_ci 498b815c7f3Sopenharmony_ci /* New read/write test. Not sure if this is needed yet. */ 499b815c7f3Sopenharmony_ci 500b815c7f3Sopenharmony_ci if ((format & SF_FORMAT_TYPEMASK) != SF_FORMAT_PAF 501b815c7f3Sopenharmony_ci && (format & SF_FORMAT_TYPEMASK) != SF_FORMAT_VOC 502b815c7f3Sopenharmony_ci && (format & SF_FORMAT_TYPEMASK) != SF_FORMAT_FLAC 503b815c7f3Sopenharmony_ci && (format & SF_FORMAT_SUBMASK) != SF_FORMAT_ALAC_16 504b815c7f3Sopenharmony_ci && (format & SF_FORMAT_SUBMASK) != SF_FORMAT_ALAC_20 505b815c7f3Sopenharmony_ci && (format & SF_FORMAT_SUBMASK) != SF_FORMAT_ALAC_24 506b815c7f3Sopenharmony_ci && (format & SF_FORMAT_SUBMASK) != SF_FORMAT_ALAC_32 507b815c7f3Sopenharmony_ci ) 508b815c7f3Sopenharmony_ci new_rdwr_[+ (get "type_name") +]_test (filename, format, allow_fd) ; 509b815c7f3Sopenharmony_ci 510b815c7f3Sopenharmony_ci delete_file (format, filename) ; 511b815c7f3Sopenharmony_ci 512b815c7f3Sopenharmony_ci puts ("ok") ; 513b815c7f3Sopenharmony_ci return ; 514b815c7f3Sopenharmony_ci} /* pcm_test_[+ (get "type_name") +] */ 515b815c7f3Sopenharmony_ci 516b815c7f3Sopenharmony_cistatic void 517b815c7f3Sopenharmony_cimono_[+ (get "type_name") +]_test (const char *filename, int format, int long_file_ok, int allow_fd) 518b815c7f3Sopenharmony_ci{ SNDFILE *file ; 519b815c7f3Sopenharmony_ci SF_INFO sfinfo ; 520b815c7f3Sopenharmony_ci [+ (get "data_type") +] *orig, *test ; 521b815c7f3Sopenharmony_ci sf_count_t count ; 522b815c7f3Sopenharmony_ci int k, items, total ; 523b815c7f3Sopenharmony_ci 524b815c7f3Sopenharmony_ci sfinfo.samplerate = 44100 ; 525b815c7f3Sopenharmony_ci sfinfo.frames = SILLY_WRITE_COUNT ; /* Wrong length. Library should correct this on sf_close. */ 526b815c7f3Sopenharmony_ci sfinfo.channels = 1 ; 527b815c7f3Sopenharmony_ci sfinfo.format = format ; 528b815c7f3Sopenharmony_ci 529b815c7f3Sopenharmony_ci orig = orig_data.[+ (get "data_field") +] ; 530b815c7f3Sopenharmony_ci test = test_data.[+ (get "data_field") +] ; 531b815c7f3Sopenharmony_ci 532b815c7f3Sopenharmony_ci items = DATA_LENGTH ; 533b815c7f3Sopenharmony_ci 534b815c7f3Sopenharmony_ci file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, allow_fd, __LINE__) ; 535b815c7f3Sopenharmony_ci 536b815c7f3Sopenharmony_ci if (sfinfo.frames || sfinfo.sections || sfinfo.seekable) 537b815c7f3Sopenharmony_ci { printf ("\n\nLine %d : Weird SF_INFO fields.\n", __LINE__) ; 538b815c7f3Sopenharmony_ci exit (1) ; 539b815c7f3Sopenharmony_ci } ; 540b815c7f3Sopenharmony_ci 541b815c7f3Sopenharmony_ci sf_set_string (file, SF_STR_ARTIST, "Your name here") ; 542b815c7f3Sopenharmony_ci 543b815c7f3Sopenharmony_ci test_write_[+ (get "data_type") +]_or_die (file, 0, orig, items, __LINE__) ; 544b815c7f3Sopenharmony_ci sf_write_sync (file) ; 545b815c7f3Sopenharmony_ci test_write_[+ (get "data_type") +]_or_die (file, 0, orig, items, __LINE__) ; 546b815c7f3Sopenharmony_ci sf_write_sync (file) ; 547b815c7f3Sopenharmony_ci 548b815c7f3Sopenharmony_ci /* Add non-audio data after the audio. */ 549b815c7f3Sopenharmony_ci sf_set_string (file, SF_STR_COPYRIGHT, "Copyright (c) 2003") ; 550b815c7f3Sopenharmony_ci 551b815c7f3Sopenharmony_ci sf_close (file) ; 552b815c7f3Sopenharmony_ci 553b815c7f3Sopenharmony_ci memset (test, 0, items * sizeof ([+ (get "data_type") +])) ; 554b815c7f3Sopenharmony_ci 555b815c7f3Sopenharmony_ci if ((format & SF_FORMAT_TYPEMASK) != SF_FORMAT_RAW) 556b815c7f3Sopenharmony_ci memset (&sfinfo, 0, sizeof (sfinfo)) ; 557b815c7f3Sopenharmony_ci 558b815c7f3Sopenharmony_ci file = test_open_file_or_die (filename, SFM_READ, &sfinfo, allow_fd, __LINE__) ; 559b815c7f3Sopenharmony_ci 560b815c7f3Sopenharmony_ci if (sfinfo.format != format) 561b815c7f3Sopenharmony_ci { printf ("\n\nLine %d : Mono : Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, format, sfinfo.format) ; 562b815c7f3Sopenharmony_ci exit (1) ; 563b815c7f3Sopenharmony_ci } ; 564b815c7f3Sopenharmony_ci 565b815c7f3Sopenharmony_ci if (sfinfo.frames < 2 * items) 566b815c7f3Sopenharmony_ci { printf ("\n\nLine %d : Mono : Incorrect number of frames in file (too short). (%" PRId64 " should be %d)\n", __LINE__, sfinfo.frames, items) ; 567b815c7f3Sopenharmony_ci exit (1) ; 568b815c7f3Sopenharmony_ci } ; 569b815c7f3Sopenharmony_ci 570b815c7f3Sopenharmony_ci if (! long_file_ok && sfinfo.frames > 2 * items) 571b815c7f3Sopenharmony_ci { printf ("\n\nLine %d : Mono : Incorrect number of frames in file (too long). (%" PRId64 " should be %d)\n", __LINE__, sfinfo.frames, items) ; 572b815c7f3Sopenharmony_ci exit (1) ; 573b815c7f3Sopenharmony_ci } ; 574b815c7f3Sopenharmony_ci 575b815c7f3Sopenharmony_ci if (sfinfo.channels != 1) 576b815c7f3Sopenharmony_ci { printf ("\n\nLine %d : Mono : Incorrect number of channels in file.\n", __LINE__) ; 577b815c7f3Sopenharmony_ci exit (1) ; 578b815c7f3Sopenharmony_ci } ; 579b815c7f3Sopenharmony_ci 580b815c7f3Sopenharmony_ci if (sfinfo.seekable != 1) 581b815c7f3Sopenharmony_ci { printf ("\n\nLine %d : File should be seekable.\n", __LINE__) ; 582b815c7f3Sopenharmony_ci exit (1) ; 583b815c7f3Sopenharmony_ci } ; 584b815c7f3Sopenharmony_ci 585b815c7f3Sopenharmony_ci check_log_buffer_or_die (file, __LINE__) ; 586b815c7f3Sopenharmony_ci 587b815c7f3Sopenharmony_ci test_read_[+ (get "data_type") +]_or_die (file, 0, test, items, __LINE__) ; 588b815c7f3Sopenharmony_ci for (k = 0 ; k < items ; k++) 589b815c7f3Sopenharmony_ci if ([+ (get "error_func") +] (orig [k], test [k])) 590b815c7f3Sopenharmony_ci { printf ("\n\nLine %d: Mono : Incorrect sample A (#%d : [+ (get "format_char") +] => [+ (get "format_char") +]).\n", __LINE__, k, orig [k], test [k]) ; 591b815c7f3Sopenharmony_ci oct_save_[+ (get "data_type") +] (orig, test, items) ; 592b815c7f3Sopenharmony_ci exit (1) ; 593b815c7f3Sopenharmony_ci } ; 594b815c7f3Sopenharmony_ci 595b815c7f3Sopenharmony_ci /* Test multiple short reads. */ 596b815c7f3Sopenharmony_ci test_seek_or_die (file, 0, SEEK_SET, 0, sfinfo.channels, __LINE__) ; 597b815c7f3Sopenharmony_ci 598b815c7f3Sopenharmony_ci total = 0 ; 599b815c7f3Sopenharmony_ci for (k = 1 ; k <= 32 ; k++) 600b815c7f3Sopenharmony_ci { int ik ; 601b815c7f3Sopenharmony_ci 602b815c7f3Sopenharmony_ci test_read_[+ (get "data_type") +]_or_die (file, 0, test + total, k, __LINE__) ; 603b815c7f3Sopenharmony_ci total += k ; 604b815c7f3Sopenharmony_ci 605b815c7f3Sopenharmony_ci for (ik = 0 ; ik < total ; ik++) 606b815c7f3Sopenharmony_ci if ([+ (get "error_func") +] (orig [ik], test [ik])) 607b815c7f3Sopenharmony_ci { printf ("\n\nLine %d : Mono : Incorrect sample A (#%d : [+ (get "format_char") +] => [+ (get "format_char") +]).\n", __LINE__, ik, orig [ik], test [ik]) ; 608b815c7f3Sopenharmony_ci exit (1) ; 609b815c7f3Sopenharmony_ci } ; 610b815c7f3Sopenharmony_ci } ; 611b815c7f3Sopenharmony_ci 612b815c7f3Sopenharmony_ci /* Seek to start of file. */ 613b815c7f3Sopenharmony_ci test_seek_or_die (file, 0, SEEK_SET, 0, sfinfo.channels, __LINE__) ; 614b815c7f3Sopenharmony_ci 615b815c7f3Sopenharmony_ci test_read_[+ (get "data_type") +]_or_die (file, 0, test, 4, __LINE__) ; 616b815c7f3Sopenharmony_ci for (k = 0 ; k < 4 ; k++) 617b815c7f3Sopenharmony_ci if ([+ (get "error_func") +] (orig [k], test [k])) 618b815c7f3Sopenharmony_ci { printf ("\n\nLine %d : Mono : Incorrect sample A (#%d : [+ (get "format_char") +] => [+ (get "format_char") +]).\n", __LINE__, k, orig [k], test [k]) ; 619b815c7f3Sopenharmony_ci exit (1) ; 620b815c7f3Sopenharmony_ci } ; 621b815c7f3Sopenharmony_ci 622b815c7f3Sopenharmony_ci /* For some codecs we can't go past here. */ 623b815c7f3Sopenharmony_ci if ((format & SF_FORMAT_SUBMASK) == SF_FORMAT_DWVW_16 || 624b815c7f3Sopenharmony_ci (format & SF_FORMAT_SUBMASK) == SF_FORMAT_DWVW_24) 625b815c7f3Sopenharmony_ci { sf_close (file) ; 626b815c7f3Sopenharmony_ci unlink (filename) ; 627b815c7f3Sopenharmony_ci printf ("no seek : ") ; 628b815c7f3Sopenharmony_ci return ; 629b815c7f3Sopenharmony_ci } ; 630b815c7f3Sopenharmony_ci 631b815c7f3Sopenharmony_ci /* Seek to offset from start of file. */ 632b815c7f3Sopenharmony_ci test_seek_or_die (file, items + 10, SEEK_SET, items + 10, sfinfo.channels, __LINE__) ; 633b815c7f3Sopenharmony_ci 634b815c7f3Sopenharmony_ci test_read_[+ (get "data_type") +]_or_die (file, 0, test + 10, 4, __LINE__) ; 635b815c7f3Sopenharmony_ci for (k = 10 ; k < 14 ; k++) 636b815c7f3Sopenharmony_ci if ([+ (get "error_func") +] (orig [k], test [k])) 637b815c7f3Sopenharmony_ci { printf ("\n\nLine %d : Mono : Incorrect sample A (#%d : [+ (get "format_char") +] => [+ (get "format_char") +]).\n", __LINE__, k, test [k], orig [k]) ; 638b815c7f3Sopenharmony_ci exit (1) ; 639b815c7f3Sopenharmony_ci } ; 640b815c7f3Sopenharmony_ci 641b815c7f3Sopenharmony_ci /* Seek to offset from current position. */ 642b815c7f3Sopenharmony_ci test_seek_or_die (file, 6, SEEK_CUR, items + 20, sfinfo.channels, __LINE__) ; 643b815c7f3Sopenharmony_ci 644b815c7f3Sopenharmony_ci test_read_[+ (get "data_type") +]_or_die (file, 0, test + 20, 4, __LINE__) ; 645b815c7f3Sopenharmony_ci for (k = 20 ; k < 24 ; k++) 646b815c7f3Sopenharmony_ci if ([+ (get "error_func") +] (orig [k], test [k])) 647b815c7f3Sopenharmony_ci { printf ("\n\nLine %d : Mono : Incorrect sample A (#%d : [+ (get "format_char") +] => [+ (get "format_char") +]).\n", __LINE__, k, test [k], orig [k]) ; 648b815c7f3Sopenharmony_ci exit (1) ; 649b815c7f3Sopenharmony_ci } ; 650b815c7f3Sopenharmony_ci 651b815c7f3Sopenharmony_ci /* Seek to offset from end of file. */ 652b815c7f3Sopenharmony_ci test_seek_or_die (file, -1 * (sfinfo.frames - 10), SEEK_END, 10, sfinfo.channels, __LINE__) ; 653b815c7f3Sopenharmony_ci 654b815c7f3Sopenharmony_ci test_read_[+ (get "data_type") +]_or_die (file, 0, test + 10, 4, __LINE__) ; 655b815c7f3Sopenharmony_ci for (k = 10 ; k < 14 ; k++) 656b815c7f3Sopenharmony_ci if ([+ (get "error_func") +] (orig [k], test [k])) 657b815c7f3Sopenharmony_ci { printf ("\n\nLine %d : Mono : Incorrect sample D (#%d : [+ (get "format_char") +] => [+ (get "format_char") +]).\n", __LINE__, k, test [k], orig [k]) ; 658b815c7f3Sopenharmony_ci exit (1) ; 659b815c7f3Sopenharmony_ci } ; 660b815c7f3Sopenharmony_ci 661b815c7f3Sopenharmony_ci /* Check read past end of file followed by sf_seek (sndfile, 0, SEEK_CUR). */ 662b815c7f3Sopenharmony_ci test_seek_or_die (file, 0, SEEK_SET, 0, sfinfo.channels, __LINE__) ; 663b815c7f3Sopenharmony_ci 664b815c7f3Sopenharmony_ci count = 0 ; 665b815c7f3Sopenharmony_ci while (count < sfinfo.frames) 666b815c7f3Sopenharmony_ci count += sf_read_[+ (get "data_type") +] (file, test, 311) ; 667b815c7f3Sopenharmony_ci 668b815c7f3Sopenharmony_ci /* Check that no error has occurred. */ 669b815c7f3Sopenharmony_ci if (sf_error (file)) 670b815c7f3Sopenharmony_ci { printf ("\n\nLine %d : Mono : error where there shouldn't have been one.\n", __LINE__) ; 671b815c7f3Sopenharmony_ci puts (sf_strerror (file)) ; 672b815c7f3Sopenharmony_ci exit (1) ; 673b815c7f3Sopenharmony_ci } ; 674b815c7f3Sopenharmony_ci 675b815c7f3Sopenharmony_ci /* Check that we haven't read beyond EOF. */ 676b815c7f3Sopenharmony_ci if (count > sfinfo.frames) 677b815c7f3Sopenharmony_ci { printf ("\n\nLines %d : read past end of file (%" PRId64 " should be %" PRId64 ")\n", __LINE__, count, sfinfo.frames) ; 678b815c7f3Sopenharmony_ci exit (1) ; 679b815c7f3Sopenharmony_ci } ; 680b815c7f3Sopenharmony_ci 681b815c7f3Sopenharmony_ci test_seek_or_die (file, 0, SEEK_CUR, sfinfo.frames, sfinfo.channels, __LINE__) ; 682b815c7f3Sopenharmony_ci 683b815c7f3Sopenharmony_ci sf_close (file) ; 684b815c7f3Sopenharmony_ci 685b815c7f3Sopenharmony_ci multi_seek_test (filename, format) ; 686b815c7f3Sopenharmony_ci write_seek_extend_test (filename, format) ; 687b815c7f3Sopenharmony_ci 688b815c7f3Sopenharmony_ci} /* mono_[+ (get "type_name") +]_test */ 689b815c7f3Sopenharmony_ci 690b815c7f3Sopenharmony_cistatic void 691b815c7f3Sopenharmony_cistereo_[+ (get "type_name") +]_test (const char *filename, int format, int long_file_ok, int allow_fd) 692b815c7f3Sopenharmony_ci{ SNDFILE *file ; 693b815c7f3Sopenharmony_ci SF_INFO sfinfo ; 694b815c7f3Sopenharmony_ci [+ (get "data_type") +] *orig, *test ; 695b815c7f3Sopenharmony_ci int k, items, frames ; 696b815c7f3Sopenharmony_ci 697b815c7f3Sopenharmony_ci sfinfo.samplerate = 44100 ; 698b815c7f3Sopenharmony_ci sfinfo.frames = SILLY_WRITE_COUNT ; /* Wrong length. Library should correct this on sf_close. */ 699b815c7f3Sopenharmony_ci sfinfo.channels = 2 ; 700b815c7f3Sopenharmony_ci sfinfo.format = format ; 701b815c7f3Sopenharmony_ci 702b815c7f3Sopenharmony_ci gen_windowed_sine_double (orig_data.d, DATA_LENGTH, [+ (get "max_val") +]) ; 703b815c7f3Sopenharmony_ci 704b815c7f3Sopenharmony_ci orig = orig_data.[+ (get "data_field") +] ; 705b815c7f3Sopenharmony_ci test = test_data.[+ (get "data_field") +] ; 706b815c7f3Sopenharmony_ci 707b815c7f3Sopenharmony_ci /* Make this a macro so gdb steps over it in one go. */ 708b815c7f3Sopenharmony_ci CONVERT_DATA (k, DATA_LENGTH, orig, orig_data.d) ; 709b815c7f3Sopenharmony_ci 710b815c7f3Sopenharmony_ci items = DATA_LENGTH ; 711b815c7f3Sopenharmony_ci frames = items / sfinfo.channels ; 712b815c7f3Sopenharmony_ci 713b815c7f3Sopenharmony_ci file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, allow_fd, __LINE__) ; 714b815c7f3Sopenharmony_ci 715b815c7f3Sopenharmony_ci sf_set_string (file, SF_STR_ARTIST, "Your name here") ; 716b815c7f3Sopenharmony_ci 717b815c7f3Sopenharmony_ci test_writef_[+ (get "data_type") +]_or_die (file, 0, orig, frames, __LINE__) ; 718b815c7f3Sopenharmony_ci 719b815c7f3Sopenharmony_ci sf_set_string (file, SF_STR_COPYRIGHT, "Copyright (c) 2003") ; 720b815c7f3Sopenharmony_ci 721b815c7f3Sopenharmony_ci sf_close (file) ; 722b815c7f3Sopenharmony_ci 723b815c7f3Sopenharmony_ci memset (test, 0, items * sizeof ([+ (get "data_type") +])) ; 724b815c7f3Sopenharmony_ci 725b815c7f3Sopenharmony_ci if ((format & SF_FORMAT_TYPEMASK) != SF_FORMAT_RAW) 726b815c7f3Sopenharmony_ci memset (&sfinfo, 0, sizeof (sfinfo)) ; 727b815c7f3Sopenharmony_ci 728b815c7f3Sopenharmony_ci file = test_open_file_or_die (filename, SFM_READ, &sfinfo, allow_fd, __LINE__) ; 729b815c7f3Sopenharmony_ci 730b815c7f3Sopenharmony_ci if (sfinfo.format != format) 731b815c7f3Sopenharmony_ci { printf ("\n\nLine %d : Stereo : Returned format incorrect (0x%08X => 0x%08X).\n", 732b815c7f3Sopenharmony_ci __LINE__, format, sfinfo.format) ; 733b815c7f3Sopenharmony_ci exit (1) ; 734b815c7f3Sopenharmony_ci } ; 735b815c7f3Sopenharmony_ci 736b815c7f3Sopenharmony_ci if (sfinfo.frames < frames) 737b815c7f3Sopenharmony_ci { printf ("\n\nLine %d : Stereo : Incorrect number of frames in file (too short). (%" PRId64 " should be %d)\n", 738b815c7f3Sopenharmony_ci __LINE__, sfinfo.frames, frames) ; 739b815c7f3Sopenharmony_ci exit (1) ; 740b815c7f3Sopenharmony_ci } ; 741b815c7f3Sopenharmony_ci 742b815c7f3Sopenharmony_ci if (! long_file_ok && sfinfo.frames > frames) 743b815c7f3Sopenharmony_ci { printf ("\n\nLine %d : Stereo : Incorrect number of frames in file (too long). (%" PRId64 " should be %d)\n", 744b815c7f3Sopenharmony_ci __LINE__, sfinfo.frames, frames) ; 745b815c7f3Sopenharmony_ci exit (1) ; 746b815c7f3Sopenharmony_ci } ; 747b815c7f3Sopenharmony_ci 748b815c7f3Sopenharmony_ci if (sfinfo.channels != 2) 749b815c7f3Sopenharmony_ci { printf ("\n\nLine %d : Stereo : Incorrect number of channels in file.\n", __LINE__) ; 750b815c7f3Sopenharmony_ci exit (1) ; 751b815c7f3Sopenharmony_ci } ; 752b815c7f3Sopenharmony_ci 753b815c7f3Sopenharmony_ci check_log_buffer_or_die (file, __LINE__) ; 754b815c7f3Sopenharmony_ci 755b815c7f3Sopenharmony_ci test_readf_[+ (get "data_type") +]_or_die (file, 0, test, frames, __LINE__) ; 756b815c7f3Sopenharmony_ci for (k = 0 ; k < items ; k++) 757b815c7f3Sopenharmony_ci if ([+ (get "error_func") +] (test [k], orig [k])) 758b815c7f3Sopenharmony_ci { printf ("\n\nLine %d : Stereo : Incorrect sample (#%d : [+ (get "format_char") +] => [+ (get "format_char") +]).\n", __LINE__, k, orig [k], test [k]) ; 759b815c7f3Sopenharmony_ci exit (1) ; 760b815c7f3Sopenharmony_ci } ; 761b815c7f3Sopenharmony_ci 762b815c7f3Sopenharmony_ci /* Seek to start of file. */ 763b815c7f3Sopenharmony_ci test_seek_or_die (file, 0, SEEK_SET, 0, sfinfo.channels, __LINE__) ; 764b815c7f3Sopenharmony_ci 765b815c7f3Sopenharmony_ci test_readf_[+ (get "data_type") +]_or_die (file, 0, test, 2, __LINE__) ; 766b815c7f3Sopenharmony_ci for (k = 0 ; k < 4 ; k++) 767b815c7f3Sopenharmony_ci if ([+ (get "error_func") +] (test [k], orig [k])) 768b815c7f3Sopenharmony_ci { printf ("\n\nLine %d : Stereo : Incorrect sample (#%d : [+ (get "format_char") +] => [+ (get "format_char") +]).\n", __LINE__, k, orig [k], test [k]) ; 769b815c7f3Sopenharmony_ci exit (1) ; 770b815c7f3Sopenharmony_ci } ; 771b815c7f3Sopenharmony_ci 772b815c7f3Sopenharmony_ci /* Seek to offset from start of file. */ 773b815c7f3Sopenharmony_ci test_seek_or_die (file, 10, SEEK_SET, 10, sfinfo.channels, __LINE__) ; 774b815c7f3Sopenharmony_ci 775b815c7f3Sopenharmony_ci /* Check for errors here. */ 776b815c7f3Sopenharmony_ci if (sf_error (file)) 777b815c7f3Sopenharmony_ci { printf ("Line %d: Should NOT return an error.\n", __LINE__) ; 778b815c7f3Sopenharmony_ci puts (sf_strerror (file)) ; 779b815c7f3Sopenharmony_ci exit (1) ; 780b815c7f3Sopenharmony_ci } ; 781b815c7f3Sopenharmony_ci 782b815c7f3Sopenharmony_ci if (sf_read_[+ (get "data_type") +] (file, test, 1) > 0) 783b815c7f3Sopenharmony_ci { printf ("Line %d: Should return 0.\n", __LINE__) ; 784b815c7f3Sopenharmony_ci exit (1) ; 785b815c7f3Sopenharmony_ci } ; 786b815c7f3Sopenharmony_ci 787b815c7f3Sopenharmony_ci if (! sf_error (file)) 788b815c7f3Sopenharmony_ci { printf ("Line %d: Should return an error.\n", __LINE__) ; 789b815c7f3Sopenharmony_ci exit (1) ; 790b815c7f3Sopenharmony_ci } ; 791b815c7f3Sopenharmony_ci /*-----------------------*/ 792b815c7f3Sopenharmony_ci 793b815c7f3Sopenharmony_ci test_readf_[+ (get "data_type") +]_or_die (file, 0, test + 10, 2, __LINE__) ; 794b815c7f3Sopenharmony_ci for (k = 20 ; k < 24 ; k++) 795b815c7f3Sopenharmony_ci if ([+ (get "error_func") +] (test [k], orig [k])) 796b815c7f3Sopenharmony_ci { printf ("\n\nLine %d : Stereo : Incorrect sample (#%d : [+ (get "format_char") +] => [+ (get "format_char") +]).\n", __LINE__, k, orig [k], test [k]) ; 797b815c7f3Sopenharmony_ci exit (1) ; 798b815c7f3Sopenharmony_ci } ; 799b815c7f3Sopenharmony_ci 800b815c7f3Sopenharmony_ci /* Seek to offset from current position. */ 801b815c7f3Sopenharmony_ci test_seek_or_die (file, 8, SEEK_CUR, 20, sfinfo.channels, __LINE__) ; 802b815c7f3Sopenharmony_ci 803b815c7f3Sopenharmony_ci test_readf_[+ (get "data_type") +]_or_die (file, 0, test + 20, 2, __LINE__) ; 804b815c7f3Sopenharmony_ci for (k = 40 ; k < 44 ; k++) 805b815c7f3Sopenharmony_ci if ([+ (get "error_func") +] (test [k], orig [k])) 806b815c7f3Sopenharmony_ci { printf ("\n\nLine %d : Stereo : Incorrect sample (#%d : [+ (get "format_char") +] => [+ (get "format_char") +]).\n", __LINE__, k, orig [k], test [k]) ; 807b815c7f3Sopenharmony_ci exit (1) ; 808b815c7f3Sopenharmony_ci } ; 809b815c7f3Sopenharmony_ci 810b815c7f3Sopenharmony_ci /* Seek to offset from end of file. */ 811b815c7f3Sopenharmony_ci test_seek_or_die (file, -1 * (sfinfo.frames - 10), SEEK_END, 10, sfinfo.channels, __LINE__) ; 812b815c7f3Sopenharmony_ci 813b815c7f3Sopenharmony_ci test_readf_[+ (get "data_type") +]_or_die (file, 0, test + 20, 2, __LINE__) ; 814b815c7f3Sopenharmony_ci for (k = 20 ; k < 24 ; k++) 815b815c7f3Sopenharmony_ci if ([+ (get "error_func") +] (test [k], orig [k])) 816b815c7f3Sopenharmony_ci { printf ("\n\nLine %d : Stereo : Incorrect sample (#%d : [+ (get "format_char") +] => [+ (get "format_char") +]).\n", __LINE__, k, orig [k], test [k]) ; 817b815c7f3Sopenharmony_ci exit (1) ; 818b815c7f3Sopenharmony_ci } ; 819b815c7f3Sopenharmony_ci 820b815c7f3Sopenharmony_ci sf_close (file) ; 821b815c7f3Sopenharmony_ci} /* stereo_[+ (get "type_name") +]_test */ 822b815c7f3Sopenharmony_ci 823b815c7f3Sopenharmony_cistatic void 824b815c7f3Sopenharmony_cimono_rdwr_[+ (get "type_name") +]_test (const char *filename, int format, int long_file_ok, int allow_fd) 825b815c7f3Sopenharmony_ci{ SNDFILE *file ; 826b815c7f3Sopenharmony_ci SF_INFO sfinfo ; 827b815c7f3Sopenharmony_ci [+ (get "data_type") +] *orig, *test ; 828b815c7f3Sopenharmony_ci int k, pass ; 829b815c7f3Sopenharmony_ci 830b815c7f3Sopenharmony_ci switch (format & SF_FORMAT_SUBMASK) 831b815c7f3Sopenharmony_ci { case SF_FORMAT_ALAC_16 : 832b815c7f3Sopenharmony_ci case SF_FORMAT_ALAC_20 : 833b815c7f3Sopenharmony_ci case SF_FORMAT_ALAC_24 : 834b815c7f3Sopenharmony_ci case SF_FORMAT_ALAC_32 : 835b815c7f3Sopenharmony_ci allow_fd = 0 ; 836b815c7f3Sopenharmony_ci break ; 837b815c7f3Sopenharmony_ci 838b815c7f3Sopenharmony_ci default : 839b815c7f3Sopenharmony_ci break ; 840b815c7f3Sopenharmony_ci } ; 841b815c7f3Sopenharmony_ci 842b815c7f3Sopenharmony_ci orig = orig_data.[+ (get "data_field") +] ; 843b815c7f3Sopenharmony_ci test = test_data.[+ (get "data_field") +] ; 844b815c7f3Sopenharmony_ci 845b815c7f3Sopenharmony_ci sfinfo.samplerate = SAMPLE_RATE ; 846b815c7f3Sopenharmony_ci sfinfo.frames = DATA_LENGTH ; 847b815c7f3Sopenharmony_ci sfinfo.channels = 1 ; 848b815c7f3Sopenharmony_ci sfinfo.format = format ; 849b815c7f3Sopenharmony_ci 850b815c7f3Sopenharmony_ci if ((format & SF_FORMAT_TYPEMASK) == SF_FORMAT_RAW 851b815c7f3Sopenharmony_ci || (format & SF_FORMAT_TYPEMASK) == SF_FORMAT_AU 852b815c7f3Sopenharmony_ci || (format & SF_FORMAT_TYPEMASK) == SF_FORMAT_SD2) 853b815c7f3Sopenharmony_ci unlink (filename) ; 854b815c7f3Sopenharmony_ci else 855b815c7f3Sopenharmony_ci { /* Create a short file. */ 856b815c7f3Sopenharmony_ci create_short_file (filename) ; 857b815c7f3Sopenharmony_ci 858b815c7f3Sopenharmony_ci /* Opening a already existing short file (ie invalid header) RDWR is disallowed. 859b815c7f3Sopenharmony_ci ** If this returns a valif pointer sf_open() screwed up. 860b815c7f3Sopenharmony_ci */ 861b815c7f3Sopenharmony_ci if ((file = sf_open (filename, SFM_RDWR, &sfinfo))) 862b815c7f3Sopenharmony_ci { printf ("\n\nLine %d: sf_open should (SFM_RDWR) have failed but didn't.\n", __LINE__) ; 863b815c7f3Sopenharmony_ci exit (1) ; 864b815c7f3Sopenharmony_ci } ; 865b815c7f3Sopenharmony_ci 866b815c7f3Sopenharmony_ci /* Truncate the file to zero bytes. */ 867b815c7f3Sopenharmony_ci if (truncate_file_to_zero (filename) < 0) 868b815c7f3Sopenharmony_ci { printf ("\n\nLine %d: truncate_file_to_zero (%s) failed", __LINE__, filename) ; 869b815c7f3Sopenharmony_ci perror (NULL) ; 870b815c7f3Sopenharmony_ci exit (1) ; 871b815c7f3Sopenharmony_ci } ; 872b815c7f3Sopenharmony_ci } ; 873b815c7f3Sopenharmony_ci 874b815c7f3Sopenharmony_ci /* Opening a zero length file RDWR is allowed, but the SF_INFO struct must contain 875b815c7f3Sopenharmony_ci ** all the usual data required when opening the file in WRITE mode. 876b815c7f3Sopenharmony_ci */ 877b815c7f3Sopenharmony_ci sfinfo.samplerate = SAMPLE_RATE ; 878b815c7f3Sopenharmony_ci sfinfo.frames = DATA_LENGTH ; 879b815c7f3Sopenharmony_ci sfinfo.channels = 1 ; 880b815c7f3Sopenharmony_ci sfinfo.format = format ; 881b815c7f3Sopenharmony_ci 882b815c7f3Sopenharmony_ci file = test_open_file_or_die (filename, SFM_RDWR, &sfinfo, allow_fd, __LINE__) ; 883b815c7f3Sopenharmony_ci 884b815c7f3Sopenharmony_ci /* Do 3 writes followed by reads. After each, check the data and the current 885b815c7f3Sopenharmony_ci ** read and write offsets. 886b815c7f3Sopenharmony_ci */ 887b815c7f3Sopenharmony_ci for (pass = 1 ; pass <= 3 ; pass ++) 888b815c7f3Sopenharmony_ci { orig [20] = pass * 2 ; 889b815c7f3Sopenharmony_ci 890b815c7f3Sopenharmony_ci /* Write some data. */ 891b815c7f3Sopenharmony_ci test_write_[+ (get "data_type") +]_or_die (file, pass, orig, DATA_LENGTH, __LINE__) ; 892b815c7f3Sopenharmony_ci 893b815c7f3Sopenharmony_ci test_read_write_position_or_die (file, __LINE__, pass, (pass - 1) * DATA_LENGTH, pass * DATA_LENGTH) ; 894b815c7f3Sopenharmony_ci 895b815c7f3Sopenharmony_ci /* Read what we just wrote. */ 896b815c7f3Sopenharmony_ci test_read_[+ (get "data_type") +]_or_die (file, 0, test, DATA_LENGTH, __LINE__) ; 897b815c7f3Sopenharmony_ci 898b815c7f3Sopenharmony_ci /* Check the data. */ 899b815c7f3Sopenharmony_ci for (k = 0 ; k < DATA_LENGTH ; k++) 900b815c7f3Sopenharmony_ci if ([+ (get "error_func") +] (orig [k], test [k])) 901b815c7f3Sopenharmony_ci { printf ("\n\nLine %d (pass %d) A : Error at sample %d ([+ (get "format_char") +] => [+ (get "format_char") +]).\n", __LINE__, pass, k, orig [k], test [k]) ; 902b815c7f3Sopenharmony_ci oct_save_[+ (get "data_type") +] (orig, test, DATA_LENGTH) ; 903b815c7f3Sopenharmony_ci exit (1) ; 904b815c7f3Sopenharmony_ci } ; 905b815c7f3Sopenharmony_ci 906b815c7f3Sopenharmony_ci test_read_write_position_or_die (file, __LINE__, pass, pass * DATA_LENGTH, pass * DATA_LENGTH) ; 907b815c7f3Sopenharmony_ci } ; /* for (pass ...) */ 908b815c7f3Sopenharmony_ci 909b815c7f3Sopenharmony_ci sf_close (file) ; 910b815c7f3Sopenharmony_ci 911b815c7f3Sopenharmony_ci /* Open the file again to check the data. */ 912b815c7f3Sopenharmony_ci file = test_open_file_or_die (filename, SFM_RDWR, &sfinfo, allow_fd, __LINE__) ; 913b815c7f3Sopenharmony_ci 914b815c7f3Sopenharmony_ci if (sfinfo.format != format) 915b815c7f3Sopenharmony_ci { printf ("\n\nLine %d : Returned format incorrect (0x%08X => 0x%08X).\n", __LINE__, format, sfinfo.format) ; 916b815c7f3Sopenharmony_ci exit (1) ; 917b815c7f3Sopenharmony_ci } ; 918b815c7f3Sopenharmony_ci 919b815c7f3Sopenharmony_ci if (sfinfo.frames < 3 * DATA_LENGTH) 920b815c7f3Sopenharmony_ci { printf ("\n\nLine %d : Not enough frames in file. (%" PRId64 " < %d)\n", __LINE__, sfinfo.frames, 3 * DATA_LENGTH) ; 921b815c7f3Sopenharmony_ci exit (1) ; 922b815c7f3Sopenharmony_ci } 923b815c7f3Sopenharmony_ci 924b815c7f3Sopenharmony_ci if (! long_file_ok && sfinfo.frames != 3 * DATA_LENGTH) 925b815c7f3Sopenharmony_ci { printf ("\n\nLine %d : Incorrect number of frames in file. (%" PRId64 " should be %d)\n", __LINE__, sfinfo.frames, 3 * DATA_LENGTH) ; 926b815c7f3Sopenharmony_ci exit (1) ; 927b815c7f3Sopenharmony_ci } ; 928b815c7f3Sopenharmony_ci 929b815c7f3Sopenharmony_ci if (sfinfo.channels != 1) 930b815c7f3Sopenharmony_ci { printf ("\n\nLine %d : Incorrect number of channels in file.\n", __LINE__) ; 931b815c7f3Sopenharmony_ci exit (1) ; 932b815c7f3Sopenharmony_ci } ; 933b815c7f3Sopenharmony_ci 934b815c7f3Sopenharmony_ci if (! long_file_ok) 935b815c7f3Sopenharmony_ci test_read_write_position_or_die (file, __LINE__, 0, 0, 3 * DATA_LENGTH) ; 936b815c7f3Sopenharmony_ci else 937b815c7f3Sopenharmony_ci test_seek_or_die (file, 3 * DATA_LENGTH, SFM_WRITE | SEEK_SET, 3 * DATA_LENGTH, sfinfo.channels, __LINE__) ; 938b815c7f3Sopenharmony_ci 939b815c7f3Sopenharmony_ci for (pass = 1 ; pass <= 3 ; pass ++) 940b815c7f3Sopenharmony_ci { orig [20] = pass * 2 ; 941b815c7f3Sopenharmony_ci 942b815c7f3Sopenharmony_ci test_read_write_position_or_die (file, __LINE__, pass, (pass - 1) * DATA_LENGTH, 3 * DATA_LENGTH) ; 943b815c7f3Sopenharmony_ci 944b815c7f3Sopenharmony_ci /* Read what we just wrote. */ 945b815c7f3Sopenharmony_ci test_read_[+ (get "data_type") +]_or_die (file, pass, test, DATA_LENGTH, __LINE__) ; 946b815c7f3Sopenharmony_ci 947b815c7f3Sopenharmony_ci /* Check the data. */ 948b815c7f3Sopenharmony_ci for (k = 0 ; k < DATA_LENGTH ; k++) 949b815c7f3Sopenharmony_ci if ([+ (get "error_func") +] (orig [k], test [k])) 950b815c7f3Sopenharmony_ci { printf ("\n\nLine %d (pass %d) B : Error at sample %d ([+ (get "format_char") +] => [+ (get "format_char") +]).\n", __LINE__, pass, k, orig [k], test [k]) ; 951b815c7f3Sopenharmony_ci oct_save_[+ (get "data_type") +] (orig, test, DATA_LENGTH) ; 952b815c7f3Sopenharmony_ci exit (1) ; 953b815c7f3Sopenharmony_ci } ; 954b815c7f3Sopenharmony_ci 955b815c7f3Sopenharmony_ci } ; /* for (pass ...) */ 956b815c7f3Sopenharmony_ci 957b815c7f3Sopenharmony_ci sf_close (file) ; 958b815c7f3Sopenharmony_ci} /* mono_rdwr_[+ (get "data_type") +]_test */ 959b815c7f3Sopenharmony_ci 960b815c7f3Sopenharmony_cistatic void 961b815c7f3Sopenharmony_cinew_rdwr_[+ (get "type_name") +]_test (const char *filename, int format, int allow_fd) 962b815c7f3Sopenharmony_ci{ SNDFILE *wfile, *rwfile ; 963b815c7f3Sopenharmony_ci SF_INFO sfinfo ; 964b815c7f3Sopenharmony_ci [+ (get "data_type") +] *orig, *test ; 965b815c7f3Sopenharmony_ci int items, frames ; 966b815c7f3Sopenharmony_ci 967b815c7f3Sopenharmony_ci orig = orig_data.[+ (get "data_field") +] ; 968b815c7f3Sopenharmony_ci test = test_data.[+ (get "data_field") +] ; 969b815c7f3Sopenharmony_ci 970b815c7f3Sopenharmony_ci sfinfo.samplerate = 44100 ; 971b815c7f3Sopenharmony_ci sfinfo.frames = SILLY_WRITE_COUNT ; /* Wrong length. Library should correct this on sf_close. */ 972b815c7f3Sopenharmony_ci sfinfo.channels = 2 ; 973b815c7f3Sopenharmony_ci sfinfo.format = format ; 974b815c7f3Sopenharmony_ci 975b815c7f3Sopenharmony_ci items = DATA_LENGTH ; 976b815c7f3Sopenharmony_ci frames = items / sfinfo.channels ; 977b815c7f3Sopenharmony_ci 978b815c7f3Sopenharmony_ci wfile = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, allow_fd, __LINE__) ; 979b815c7f3Sopenharmony_ci sf_command (wfile, SFC_SET_UPDATE_HEADER_AUTO, NULL, SF_TRUE) ; 980b815c7f3Sopenharmony_ci test_writef_[+ (get "data_type") +]_or_die (wfile, 1, orig, frames, __LINE__) ; 981b815c7f3Sopenharmony_ci sf_write_sync (wfile) ; 982b815c7f3Sopenharmony_ci test_writef_[+ (get "data_type") +]_or_die (wfile, 2, orig, frames, __LINE__) ; 983b815c7f3Sopenharmony_ci sf_write_sync (wfile) ; 984b815c7f3Sopenharmony_ci 985b815c7f3Sopenharmony_ci rwfile = test_open_file_or_die (filename, SFM_RDWR, &sfinfo, allow_fd, __LINE__) ; 986b815c7f3Sopenharmony_ci if (sfinfo.frames != 2 * frames) 987b815c7f3Sopenharmony_ci { printf ("\n\nLine %d : incorrect number of frames in file (%" PRId64 " should be %d)\n\n", __LINE__, sfinfo.frames, 2 * frames) ; 988b815c7f3Sopenharmony_ci exit (1) ; 989b815c7f3Sopenharmony_ci } ; 990b815c7f3Sopenharmony_ci 991b815c7f3Sopenharmony_ci test_writef_[+ (get "data_type") +]_or_die (wfile, 3, orig, frames, __LINE__) ; 992b815c7f3Sopenharmony_ci 993b815c7f3Sopenharmony_ci test_readf_[+ (get "data_type") +]_or_die (rwfile, 1, test, frames, __LINE__) ; 994b815c7f3Sopenharmony_ci test_readf_[+ (get "data_type") +]_or_die (rwfile, 2, test, frames, __LINE__) ; 995b815c7f3Sopenharmony_ci 996b815c7f3Sopenharmony_ci sf_close (wfile) ; 997b815c7f3Sopenharmony_ci sf_close (rwfile) ; 998b815c7f3Sopenharmony_ci} /* new_rdwr_[+ (get "type_name") +]_test */ 999b815c7f3Sopenharmony_ci 1000b815c7f3Sopenharmony_ci[+ ENDFOR data_type +] 1001b815c7f3Sopenharmony_ci 1002b815c7f3Sopenharmony_ci/*---------------------------------------------------------------------------------------- 1003b815c7f3Sopenharmony_ci*/ 1004b815c7f3Sopenharmony_ci 1005b815c7f3Sopenharmony_cistatic void 1006b815c7f3Sopenharmony_ciempty_file_test (const char *filename, int format) 1007b815c7f3Sopenharmony_ci{ SNDFILE *file ; 1008b815c7f3Sopenharmony_ci SF_INFO info ; 1009b815c7f3Sopenharmony_ci int allow_fd ; 1010b815c7f3Sopenharmony_ci 1011b815c7f3Sopenharmony_ci /* Sd2 files cannot be opened from an existing file descriptor. */ 1012b815c7f3Sopenharmony_ci allow_fd = ((format & SF_FORMAT_TYPEMASK) == SF_FORMAT_SD2) ? SF_FALSE : SF_TRUE ; 1013b815c7f3Sopenharmony_ci 1014b815c7f3Sopenharmony_ci get_unique_test_name (&filename, WRT_TEST_PREFIX) ; 1015b815c7f3Sopenharmony_ci print_test_name ("empty_file_test", filename) ; 1016b815c7f3Sopenharmony_ci 1017b815c7f3Sopenharmony_ci unlink (filename) ; 1018b815c7f3Sopenharmony_ci 1019b815c7f3Sopenharmony_ci info.samplerate = 48000 ; 1020b815c7f3Sopenharmony_ci info.channels = 2 ; 1021b815c7f3Sopenharmony_ci info.format = format ; 1022b815c7f3Sopenharmony_ci info.frames = 0 ; 1023b815c7f3Sopenharmony_ci 1024b815c7f3Sopenharmony_ci if (sf_format_check (&info) == SF_FALSE) 1025b815c7f3Sopenharmony_ci { info.channels = 1 ; 1026b815c7f3Sopenharmony_ci if (sf_format_check (&info) == SF_FALSE) 1027b815c7f3Sopenharmony_ci { puts ("invalid file format") ; 1028b815c7f3Sopenharmony_ci return ; 1029b815c7f3Sopenharmony_ci } ; 1030b815c7f3Sopenharmony_ci } ; 1031b815c7f3Sopenharmony_ci 1032b815c7f3Sopenharmony_ci /* Create an empty file. */ 1033b815c7f3Sopenharmony_ci file = test_open_file_or_die (filename, SFM_WRITE, &info, allow_fd, __LINE__) ; 1034b815c7f3Sopenharmony_ci sf_close (file) ; 1035b815c7f3Sopenharmony_ci 1036b815c7f3Sopenharmony_ci /* Open for read and check the length. */ 1037b815c7f3Sopenharmony_ci file = test_open_file_or_die (filename, SFM_READ, &info, allow_fd, __LINE__) ; 1038b815c7f3Sopenharmony_ci 1039b815c7f3Sopenharmony_ci if (info.frames != 0) 1040b815c7f3Sopenharmony_ci { printf ("\n\nError : frame count (%" PRId64 ") should be zero.\n", info.frames) ; 1041b815c7f3Sopenharmony_ci exit (1) ; 1042b815c7f3Sopenharmony_ci } ; 1043b815c7f3Sopenharmony_ci 1044b815c7f3Sopenharmony_ci sf_close (file) ; 1045b815c7f3Sopenharmony_ci 1046b815c7f3Sopenharmony_ci /* Open for read/write and check the length. */ 1047b815c7f3Sopenharmony_ci file = test_open_file_or_die (filename, SFM_RDWR, &info, allow_fd, __LINE__) ; 1048b815c7f3Sopenharmony_ci 1049b815c7f3Sopenharmony_ci if (info.frames != 0) 1050b815c7f3Sopenharmony_ci { printf ("\n\nError : frame count (%" PRId64 ") should be zero.\n", info.frames) ; 1051b815c7f3Sopenharmony_ci exit (1) ; 1052b815c7f3Sopenharmony_ci } ; 1053b815c7f3Sopenharmony_ci 1054b815c7f3Sopenharmony_ci sf_close (file) ; 1055b815c7f3Sopenharmony_ci 1056b815c7f3Sopenharmony_ci /* Open for read and check the length. */ 1057b815c7f3Sopenharmony_ci file = test_open_file_or_die (filename, SFM_READ, &info, allow_fd, __LINE__) ; 1058b815c7f3Sopenharmony_ci 1059b815c7f3Sopenharmony_ci if (info.frames != 0) 1060b815c7f3Sopenharmony_ci { printf ("\n\nError : frame count (%" PRId64 ") should be zero.\n", info.frames) ; 1061b815c7f3Sopenharmony_ci exit (1) ; 1062b815c7f3Sopenharmony_ci } ; 1063b815c7f3Sopenharmony_ci 1064b815c7f3Sopenharmony_ci sf_close (file) ; 1065b815c7f3Sopenharmony_ci 1066b815c7f3Sopenharmony_ci check_open_file_count_or_die (__LINE__) ; 1067b815c7f3Sopenharmony_ci 1068b815c7f3Sopenharmony_ci unlink (filename) ; 1069b815c7f3Sopenharmony_ci puts ("ok") ; 1070b815c7f3Sopenharmony_ci 1071b815c7f3Sopenharmony_ci return ; 1072b815c7f3Sopenharmony_ci} /* empty_file_test */ 1073b815c7f3Sopenharmony_ci 1074b815c7f3Sopenharmony_ci 1075b815c7f3Sopenharmony_ci/*---------------------------------------------------------------------------------------- 1076b815c7f3Sopenharmony_ci*/ 1077b815c7f3Sopenharmony_ci 1078b815c7f3Sopenharmony_cistatic void 1079b815c7f3Sopenharmony_cicreate_short_file (const char *filename) 1080b815c7f3Sopenharmony_ci{ FILE *file ; 1081b815c7f3Sopenharmony_ci 1082b815c7f3Sopenharmony_ci if (! (file = fopen (filename, "w"))) 1083b815c7f3Sopenharmony_ci { printf ("create_short_file : fopen (%s, \"w\") failed.", filename) ; 1084b815c7f3Sopenharmony_ci fflush (stdout) ; 1085b815c7f3Sopenharmony_ci perror (NULL) ; 1086b815c7f3Sopenharmony_ci exit (1) ; 1087b815c7f3Sopenharmony_ci } ; 1088b815c7f3Sopenharmony_ci 1089b815c7f3Sopenharmony_ci fprintf (file, "This is the file data.\n") ; 1090b815c7f3Sopenharmony_ci 1091b815c7f3Sopenharmony_ci fclose (file) ; 1092b815c7f3Sopenharmony_ci} /* create_short_file */ 1093b815c7f3Sopenharmony_ci 1094b815c7f3Sopenharmony_ci 1095b815c7f3Sopenharmony_cistatic void 1096b815c7f3Sopenharmony_cimulti_seek_test (const char * filename, int format) 1097b815c7f3Sopenharmony_ci{ SNDFILE * file ; 1098b815c7f3Sopenharmony_ci SF_INFO info ; 1099b815c7f3Sopenharmony_ci sf_count_t pos ; 1100b815c7f3Sopenharmony_ci int k ; 1101b815c7f3Sopenharmony_ci 1102b815c7f3Sopenharmony_ci /* This test doesn't work on the following. */ 1103b815c7f3Sopenharmony_ci switch (format & SF_FORMAT_TYPEMASK) 1104b815c7f3Sopenharmony_ci { case SF_FORMAT_RAW : 1105b815c7f3Sopenharmony_ci return ; 1106b815c7f3Sopenharmony_ci 1107b815c7f3Sopenharmony_ci default : 1108b815c7f3Sopenharmony_ci break ; 1109b815c7f3Sopenharmony_ci } ; 1110b815c7f3Sopenharmony_ci 1111b815c7f3Sopenharmony_ci memset (&info, 0, sizeof (info)) ; 1112b815c7f3Sopenharmony_ci 1113b815c7f3Sopenharmony_ci generate_file (filename, format, 88200) ; 1114b815c7f3Sopenharmony_ci 1115b815c7f3Sopenharmony_ci file = test_open_file_or_die (filename, SFM_READ, &info, SF_FALSE, __LINE__) ; 1116b815c7f3Sopenharmony_ci 1117b815c7f3Sopenharmony_ci for (k = 0 ; k < 10 ; k++) 1118b815c7f3Sopenharmony_ci { pos = info.frames / (k + 2) ; 1119b815c7f3Sopenharmony_ci test_seek_or_die (file, pos, SEEK_SET, pos, info.channels, __LINE__) ; 1120b815c7f3Sopenharmony_ci } ; 1121b815c7f3Sopenharmony_ci 1122b815c7f3Sopenharmony_ci sf_close (file) ; 1123b815c7f3Sopenharmony_ci} /* multi_seek_test */ 1124b815c7f3Sopenharmony_ci 1125b815c7f3Sopenharmony_cistatic void 1126b815c7f3Sopenharmony_ciwrite_seek_extend_test (const char * filename, int format) 1127b815c7f3Sopenharmony_ci{ SNDFILE * file ; 1128b815c7f3Sopenharmony_ci SF_INFO info ; 1129b815c7f3Sopenharmony_ci short *orig, *test ; 1130b815c7f3Sopenharmony_ci unsigned items, k ; 1131b815c7f3Sopenharmony_ci 1132b815c7f3Sopenharmony_ci /* This test doesn't work on the following container formats. */ 1133b815c7f3Sopenharmony_ci switch (format & SF_FORMAT_TYPEMASK) 1134b815c7f3Sopenharmony_ci { case SF_FORMAT_FLAC : 1135b815c7f3Sopenharmony_ci case SF_FORMAT_HTK : 1136b815c7f3Sopenharmony_ci case SF_FORMAT_PAF : 1137b815c7f3Sopenharmony_ci case SF_FORMAT_SDS : 1138b815c7f3Sopenharmony_ci case SF_FORMAT_SVX : 1139b815c7f3Sopenharmony_ci return ; 1140b815c7f3Sopenharmony_ci 1141b815c7f3Sopenharmony_ci default : 1142b815c7f3Sopenharmony_ci break ; 1143b815c7f3Sopenharmony_ci } ; 1144b815c7f3Sopenharmony_ci 1145b815c7f3Sopenharmony_ci /* This test doesn't work on the following codec formats. */ 1146b815c7f3Sopenharmony_ci switch (format & SF_FORMAT_SUBMASK) 1147b815c7f3Sopenharmony_ci { case SF_FORMAT_ALAC_16 : 1148b815c7f3Sopenharmony_ci case SF_FORMAT_ALAC_20 : 1149b815c7f3Sopenharmony_ci case SF_FORMAT_ALAC_24 : 1150b815c7f3Sopenharmony_ci case SF_FORMAT_ALAC_32 : 1151b815c7f3Sopenharmony_ci return ; 1152b815c7f3Sopenharmony_ci 1153b815c7f3Sopenharmony_ci default : 1154b815c7f3Sopenharmony_ci break ; 1155b815c7f3Sopenharmony_ci } ; 1156b815c7f3Sopenharmony_ci 1157b815c7f3Sopenharmony_ci memset (&info, 0, sizeof (info)) ; 1158b815c7f3Sopenharmony_ci 1159b815c7f3Sopenharmony_ci info.samplerate = 48000 ; 1160b815c7f3Sopenharmony_ci info.channels = 1 ; 1161b815c7f3Sopenharmony_ci info.format = format ; 1162b815c7f3Sopenharmony_ci 1163b815c7f3Sopenharmony_ci items = 512 ; 1164b815c7f3Sopenharmony_ci exit_if_true (items > ARRAY_LEN (orig_data.s), "Line %d : Bad assumption.\n", __LINE__) ; 1165b815c7f3Sopenharmony_ci 1166b815c7f3Sopenharmony_ci orig = orig_data.s ; 1167b815c7f3Sopenharmony_ci test = test_data.s ; 1168b815c7f3Sopenharmony_ci 1169b815c7f3Sopenharmony_ci for (k = 0 ; k < ARRAY_LEN (orig_data.s) ; k++) 1170b815c7f3Sopenharmony_ci orig [k] = 0x3fff ; 1171b815c7f3Sopenharmony_ci 1172b815c7f3Sopenharmony_ci file = test_open_file_or_die (filename, SFM_WRITE, &info, SF_FALSE, __LINE__) ; 1173b815c7f3Sopenharmony_ci test_write_short_or_die (file, 0, orig, items, __LINE__) ; 1174b815c7f3Sopenharmony_ci 1175b815c7f3Sopenharmony_ci /* Extend the file using a seek. */ 1176b815c7f3Sopenharmony_ci test_seek_or_die (file, 2 * items, SEEK_SET, 2 * items, info.channels, __LINE__) ; 1177b815c7f3Sopenharmony_ci 1178b815c7f3Sopenharmony_ci test_writef_short_or_die (file, 0, orig, items, __LINE__) ; 1179b815c7f3Sopenharmony_ci sf_close (file) ; 1180b815c7f3Sopenharmony_ci 1181b815c7f3Sopenharmony_ci file = test_open_file_or_die (filename, SFM_READ, &info, SF_FALSE, __LINE__) ; 1182b815c7f3Sopenharmony_ci test_read_short_or_die (file, 0, test, 3 * items, __LINE__) ; 1183b815c7f3Sopenharmony_ci sf_close (file) ; 1184b815c7f3Sopenharmony_ci 1185b815c7f3Sopenharmony_ci if (info.frames < 3 * items) 1186b815c7f3Sopenharmony_ci { printf ("\n\nLine %d : Incorrect number of frames in file (too short). (%" PRId64 " should be %d)\n", __LINE__, info.frames, 3 * items) ; 1187b815c7f3Sopenharmony_ci exit (1) ; 1188b815c7f3Sopenharmony_ci } ; 1189b815c7f3Sopenharmony_ci 1190b815c7f3Sopenharmony_ci /* Can't do these formats due to scaling. */ 1191b815c7f3Sopenharmony_ci switch (format & SF_FORMAT_SUBMASK) 1192b815c7f3Sopenharmony_ci { case SF_FORMAT_PCM_S8 : 1193b815c7f3Sopenharmony_ci case SF_FORMAT_PCM_U8 : 1194b815c7f3Sopenharmony_ci return ; 1195b815c7f3Sopenharmony_ci default : 1196b815c7f3Sopenharmony_ci break ; 1197b815c7f3Sopenharmony_ci } ; 1198b815c7f3Sopenharmony_ci 1199b815c7f3Sopenharmony_ci for (k = 0 ; k < items ; k++) 1200b815c7f3Sopenharmony_ci { exit_if_true (test [k] != 0x3fff, "Line %d : test [%d] == %d, should be 0x3fff.\n", __LINE__, k, test [k]) ; 1201b815c7f3Sopenharmony_ci exit_if_true (test [items + k] != 0, "Line %d : test [%d] == %d, should be 0.\n", __LINE__, items + k, test [items + k]) ; 1202b815c7f3Sopenharmony_ci exit_if_true (test [2 * items + k] != 0x3fff, "Line %d : test [%d] == %d, should be 0x3fff.\n", __LINE__, 2 * items + k, test [2 * items + k]) ; 1203b815c7f3Sopenharmony_ci } ; 1204b815c7f3Sopenharmony_ci 1205b815c7f3Sopenharmony_ci return ; 1206b815c7f3Sopenharmony_ci} /* write_seek_extend_test */ 1207b815c7f3Sopenharmony_ci 1208b815c7f3Sopenharmony_ci 1209