1b815c7f3Sopenharmony_ci/* 2b815c7f3Sopenharmony_ci** Copyright (C) 2001-2014 Erik de Castro Lopo <erikd@mega-nerd.com> 3b815c7f3Sopenharmony_ci** 4b815c7f3Sopenharmony_ci** This program is free software; you can redistribute it and/or modify 5b815c7f3Sopenharmony_ci** it under the terms of the GNU General Public License as published by 6b815c7f3Sopenharmony_ci** the Free Software Foundation; either version 2 of the License, or 7b815c7f3Sopenharmony_ci** (at your option) any later version. 8b815c7f3Sopenharmony_ci** 9b815c7f3Sopenharmony_ci** This program is distributed in the hope that it will be useful, 10b815c7f3Sopenharmony_ci** but WITHOUT ANY WARRANTY; without even the implied warranty of 11b815c7f3Sopenharmony_ci** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12b815c7f3Sopenharmony_ci** GNU General Public License for more details. 13b815c7f3Sopenharmony_ci** 14b815c7f3Sopenharmony_ci** You should have received a copy of the GNU General Public License 15b815c7f3Sopenharmony_ci** along with this program; if not, write to the Free Software 16b815c7f3Sopenharmony_ci** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17b815c7f3Sopenharmony_ci*/ 18b815c7f3Sopenharmony_ci 19b815c7f3Sopenharmony_ci#include "sfconfig.h" 20b815c7f3Sopenharmony_ci 21b815c7f3Sopenharmony_ci#include <stdio.h> 22b815c7f3Sopenharmony_ci#include <stdlib.h> 23b815c7f3Sopenharmony_ci#include <string.h> 24b815c7f3Sopenharmony_ci#include <math.h> 25b815c7f3Sopenharmony_ci 26b815c7f3Sopenharmony_ci#if HAVE_UNISTD_H 27b815c7f3Sopenharmony_ci#include <unistd.h> 28b815c7f3Sopenharmony_ci#else 29b815c7f3Sopenharmony_ci#include "sf_unistd.h" 30b815c7f3Sopenharmony_ci#endif 31b815c7f3Sopenharmony_ci 32b815c7f3Sopenharmony_ci#include <sndfile.h> 33b815c7f3Sopenharmony_ci 34b815c7f3Sopenharmony_ci#include "utils.h" 35b815c7f3Sopenharmony_ci 36b815c7f3Sopenharmony_cistatic void stdout_test (int typemajor, int count) ; 37b815c7f3Sopenharmony_ci 38b815c7f3Sopenharmony_ciint 39b815c7f3Sopenharmony_cimain (int argc, char *argv []) 40b815c7f3Sopenharmony_ci{ int do_all, test_count = 0 ; 41b815c7f3Sopenharmony_ci 42b815c7f3Sopenharmony_ci if (argc != 2) 43b815c7f3Sopenharmony_ci { fprintf (stderr, "This program cannot be run by itself. It needs\n") ; 44b815c7f3Sopenharmony_ci fprintf (stderr, "to be run from the stdio_test program.\n") ; 45b815c7f3Sopenharmony_ci exit (1) ; 46b815c7f3Sopenharmony_ci } ; 47b815c7f3Sopenharmony_ci 48b815c7f3Sopenharmony_ci do_all = ! strcmp (argv [1], "all") ; 49b815c7f3Sopenharmony_ci 50b815c7f3Sopenharmony_ci if (do_all || ! strcmp (argv [1], "raw")) 51b815c7f3Sopenharmony_ci { stdout_test (SF_FORMAT_RAW, PIPE_TEST_LEN) ; 52b815c7f3Sopenharmony_ci test_count ++ ; 53b815c7f3Sopenharmony_ci } ; 54b815c7f3Sopenharmony_ci 55b815c7f3Sopenharmony_ci if (do_all || ! strcmp (argv [1], "wav")) 56b815c7f3Sopenharmony_ci { stdout_test (SF_FORMAT_WAV, PIPE_TEST_LEN) ; 57b815c7f3Sopenharmony_ci test_count ++ ; 58b815c7f3Sopenharmony_ci } ; 59b815c7f3Sopenharmony_ci 60b815c7f3Sopenharmony_ci if (do_all || ! strcmp (argv [1], "aiff")) 61b815c7f3Sopenharmony_ci { stdout_test (SF_FORMAT_AIFF, PIPE_TEST_LEN) ; 62b815c7f3Sopenharmony_ci test_count ++ ; 63b815c7f3Sopenharmony_ci } ; 64b815c7f3Sopenharmony_ci 65b815c7f3Sopenharmony_ci if (do_all || ! strcmp (argv [1], "au")) 66b815c7f3Sopenharmony_ci { stdout_test (SF_FORMAT_AU, PIPE_TEST_LEN) ; 67b815c7f3Sopenharmony_ci test_count ++ ; 68b815c7f3Sopenharmony_ci } ; 69b815c7f3Sopenharmony_ci 70b815c7f3Sopenharmony_ci if (do_all || ! strcmp (argv [1], "paf")) 71b815c7f3Sopenharmony_ci { stdout_test (SF_FORMAT_PAF, PIPE_TEST_LEN) ; 72b815c7f3Sopenharmony_ci test_count ++ ; 73b815c7f3Sopenharmony_ci } ; 74b815c7f3Sopenharmony_ci 75b815c7f3Sopenharmony_ci if (do_all || ! strcmp (argv [1], "svx")) 76b815c7f3Sopenharmony_ci { stdout_test (SF_FORMAT_SVX, PIPE_TEST_LEN) ; 77b815c7f3Sopenharmony_ci test_count ++ ; 78b815c7f3Sopenharmony_ci } ; 79b815c7f3Sopenharmony_ci 80b815c7f3Sopenharmony_ci if (do_all || ! strcmp (argv [1], "nist")) 81b815c7f3Sopenharmony_ci { stdout_test (SF_FORMAT_NIST, PIPE_TEST_LEN) ; 82b815c7f3Sopenharmony_ci test_count ++ ; 83b815c7f3Sopenharmony_ci } ; 84b815c7f3Sopenharmony_ci 85b815c7f3Sopenharmony_ci if (do_all || ! strcmp (argv [1], "ircam")) 86b815c7f3Sopenharmony_ci { stdout_test (SF_FORMAT_IRCAM, PIPE_TEST_LEN) ; 87b815c7f3Sopenharmony_ci test_count ++ ; 88b815c7f3Sopenharmony_ci } ; 89b815c7f3Sopenharmony_ci 90b815c7f3Sopenharmony_ci if (do_all || ! strcmp (argv [1], "voc")) 91b815c7f3Sopenharmony_ci { stdout_test (SF_FORMAT_VOC, PIPE_TEST_LEN) ; 92b815c7f3Sopenharmony_ci test_count ++ ; 93b815c7f3Sopenharmony_ci } ; 94b815c7f3Sopenharmony_ci 95b815c7f3Sopenharmony_ci if (do_all || ! strcmp (argv [1], "w64")) 96b815c7f3Sopenharmony_ci { stdout_test (SF_FORMAT_W64, PIPE_TEST_LEN) ; 97b815c7f3Sopenharmony_ci test_count ++ ; 98b815c7f3Sopenharmony_ci } ; 99b815c7f3Sopenharmony_ci 100b815c7f3Sopenharmony_ci if (do_all || ! strcmp (argv [1], "mat4")) 101b815c7f3Sopenharmony_ci { stdout_test (SF_FORMAT_MAT4, PIPE_TEST_LEN) ; 102b815c7f3Sopenharmony_ci test_count ++ ; 103b815c7f3Sopenharmony_ci } ; 104b815c7f3Sopenharmony_ci 105b815c7f3Sopenharmony_ci if (do_all || ! strcmp (argv [1], "mat5")) 106b815c7f3Sopenharmony_ci { stdout_test (SF_FORMAT_MAT5, PIPE_TEST_LEN) ; 107b815c7f3Sopenharmony_ci test_count ++ ; 108b815c7f3Sopenharmony_ci } ; 109b815c7f3Sopenharmony_ci 110b815c7f3Sopenharmony_ci if (do_all || ! strcmp (argv [1], "pvf")) 111b815c7f3Sopenharmony_ci { stdout_test (SF_FORMAT_PVF, PIPE_TEST_LEN) ; 112b815c7f3Sopenharmony_ci test_count ++ ; 113b815c7f3Sopenharmony_ci } ; 114b815c7f3Sopenharmony_ci 115b815c7f3Sopenharmony_ci if (test_count == 0) 116b815c7f3Sopenharmony_ci { fprintf (stderr, "\n******************************************\n") ; 117b815c7f3Sopenharmony_ci fprintf (stderr, "* stdout_test : No '%s' test defined.\n", argv [1]) ; 118b815c7f3Sopenharmony_ci fprintf (stderr, "******************************************\n") ; 119b815c7f3Sopenharmony_ci return 1 ; 120b815c7f3Sopenharmony_ci } ; 121b815c7f3Sopenharmony_ci 122b815c7f3Sopenharmony_ci return 0 ; 123b815c7f3Sopenharmony_ci} /* main */ 124b815c7f3Sopenharmony_ci 125b815c7f3Sopenharmony_cistatic void 126b815c7f3Sopenharmony_cistdout_test (int typemajor, int count) 127b815c7f3Sopenharmony_ci{ static short data [PIPE_TEST_LEN] ; 128b815c7f3Sopenharmony_ci 129b815c7f3Sopenharmony_ci SNDFILE *file ; 130b815c7f3Sopenharmony_ci SF_INFO sfinfo ; 131b815c7f3Sopenharmony_ci int k, total, this_write ; 132b815c7f3Sopenharmony_ci 133b815c7f3Sopenharmony_ci sfinfo.samplerate = 44100 ; 134b815c7f3Sopenharmony_ci sfinfo.format = (typemajor | SF_FORMAT_PCM_16) ; 135b815c7f3Sopenharmony_ci sfinfo.channels = 1 ; 136b815c7f3Sopenharmony_ci sfinfo.frames = 0 ; 137b815c7f3Sopenharmony_ci 138b815c7f3Sopenharmony_ci /* Create some random data. */ 139b815c7f3Sopenharmony_ci for (k = 0 ; k < PIPE_TEST_LEN ; k++) 140b815c7f3Sopenharmony_ci data [k] = PIPE_INDEX (k) ; 141b815c7f3Sopenharmony_ci 142b815c7f3Sopenharmony_ci if ((file = sf_open ("-", SFM_WRITE, &sfinfo)) == NULL) 143b815c7f3Sopenharmony_ci { fprintf (stderr, "%s % d: sf_open_write failed with error : %s\n", 144b815c7f3Sopenharmony_ci __func__, __LINE__, sf_strerror (NULL)) ; 145b815c7f3Sopenharmony_ci exit (1) ; 146b815c7f3Sopenharmony_ci } ; 147b815c7f3Sopenharmony_ci 148b815c7f3Sopenharmony_ci if (sfinfo.frames != 0) 149b815c7f3Sopenharmony_ci { fprintf (stderr, "%s % d: Frames is %d (should be 0).\n", 150b815c7f3Sopenharmony_ci __func__, __LINE__, (int) sfinfo.frames) ; 151b815c7f3Sopenharmony_ci exit (1) ; 152b815c7f3Sopenharmony_ci } ; 153b815c7f3Sopenharmony_ci 154b815c7f3Sopenharmony_ci total = 0 ; 155b815c7f3Sopenharmony_ci 156b815c7f3Sopenharmony_ci while (total < count) 157b815c7f3Sopenharmony_ci { this_write = (count - total > 1024) ? 1024 : count - total ; 158b815c7f3Sopenharmony_ci if ((k = (int) sf_write_short (file, data + total, this_write)) != this_write) 159b815c7f3Sopenharmony_ci { fprintf (stderr, "sf_write_short # %d failed with short write (%d -> %d)\n", count, this_write, k) ; 160b815c7f3Sopenharmony_ci exit (1) ; 161b815c7f3Sopenharmony_ci } ; 162b815c7f3Sopenharmony_ci total += k ; 163b815c7f3Sopenharmony_ci } ; 164b815c7f3Sopenharmony_ci 165b815c7f3Sopenharmony_ci sf_close (file) ; 166b815c7f3Sopenharmony_ci 167b815c7f3Sopenharmony_ci return ; 168b815c7f3Sopenharmony_ci} /* stdout_test */ 169b815c7f3Sopenharmony_ci 170