1b815c7f3Sopenharmony_ci[+ AutoGen5 template c +] 2b815c7f3Sopenharmony_ci/* 3b815c7f3Sopenharmony_ci** Copyright (C) 2010-2012 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 26b815c7f3Sopenharmony_ci#include <sys/stat.h> 27b815c7f3Sopenharmony_ci#include <math.h> 28b815c7f3Sopenharmony_ci 29b815c7f3Sopenharmony_ci#if HAVE_UNISTD_H 30b815c7f3Sopenharmony_ci#include <unistd.h> 31b815c7f3Sopenharmony_ci#endif 32b815c7f3Sopenharmony_ci 33b815c7f3Sopenharmony_ci#if (HAVE_DECL_S_IRGRP == 0) 34b815c7f3Sopenharmony_ci#include <sf_unistd.h> 35b815c7f3Sopenharmony_ci#endif 36b815c7f3Sopenharmony_ci 37b815c7f3Sopenharmony_ci#if (defined (WIN32) || defined (_WIN32)) 38b815c7f3Sopenharmony_ci#include <io.h> 39b815c7f3Sopenharmony_ci#include <direct.h> 40b815c7f3Sopenharmony_ci#endif 41b815c7f3Sopenharmony_ci 42b815c7f3Sopenharmony_ci#include <sndfile.h> 43b815c7f3Sopenharmony_ci 44b815c7f3Sopenharmony_ci#include "utils.h" 45b815c7f3Sopenharmony_ci 46b815c7f3Sopenharmony_ci[+ FOR data_type 47b815c7f3Sopenharmony_ci+]static void rdwr_[+ (get "name") +]_test (const char *filename) ; 48b815c7f3Sopenharmony_ci[+ ENDFOR data_type 49b815c7f3Sopenharmony_ci+] 50b815c7f3Sopenharmony_ci 51b815c7f3Sopenharmony_ciint 52b815c7f3Sopenharmony_cimain (void) 53b815c7f3Sopenharmony_ci{ 54b815c7f3Sopenharmony_ci rdwr_short_test ("rdwr_short.wav") ; 55b815c7f3Sopenharmony_ci rdwr_int_test ("rdwr_int.wav") ; 56b815c7f3Sopenharmony_ci rdwr_float_test ("rdwr_float.wav") ; 57b815c7f3Sopenharmony_ci rdwr_double_test ("rdwr_double.wav") ; 58b815c7f3Sopenharmony_ci rdwr_raw_test ("rdwr_raw.wav") ; 59b815c7f3Sopenharmony_ci 60b815c7f3Sopenharmony_ci return 0 ; 61b815c7f3Sopenharmony_ci} /* main */ 62b815c7f3Sopenharmony_ci 63b815c7f3Sopenharmony_ci 64b815c7f3Sopenharmony_ci/*============================================================================================ 65b815c7f3Sopenharmony_ci** Here are the test functions. 66b815c7f3Sopenharmony_ci*/ 67b815c7f3Sopenharmony_ci 68b815c7f3Sopenharmony_ci[+ FOR data_type 69b815c7f3Sopenharmony_ci+]static void 70b815c7f3Sopenharmony_cirdwr_[+ (get "name") +]_test (const char *filename) 71b815c7f3Sopenharmony_ci{ SNDFILE *file ; 72b815c7f3Sopenharmony_ci SF_INFO sfinfo ; 73b815c7f3Sopenharmony_ci sf_count_t frames ; 74b815c7f3Sopenharmony_ci [+ (get "type") +] buffer [160] ; 75b815c7f3Sopenharmony_ci 76b815c7f3Sopenharmony_ci print_test_name ("rdwr_[+ (get "name") +]_test", filename) ; 77b815c7f3Sopenharmony_ci 78b815c7f3Sopenharmony_ci memset (buffer, 0, sizeof (buffer)) ; 79b815c7f3Sopenharmony_ci 80b815c7f3Sopenharmony_ci /* Create sound file with no data. */ 81b815c7f3Sopenharmony_ci sfinfo.format = SF_FORMAT_WAV | [+ (get "format") +] ; 82b815c7f3Sopenharmony_ci sfinfo.samplerate = 16000 ; 83b815c7f3Sopenharmony_ci sfinfo.channels = 1 ; 84b815c7f3Sopenharmony_ci 85b815c7f3Sopenharmony_ci unlink (filename) ; 86b815c7f3Sopenharmony_ci 87b815c7f3Sopenharmony_ci frames = ARRAY_LEN (buffer) ; 88b815c7f3Sopenharmony_ci 89b815c7f3Sopenharmony_ci /* Open again for read/write. */ 90b815c7f3Sopenharmony_ci file = test_open_file_or_die (filename, SFM_RDWR, &sfinfo, SF_TRUE, __LINE__) ; 91b815c7f3Sopenharmony_ci 92b815c7f3Sopenharmony_ci test_write_[+ (get "name") +]_or_die (file, 0, buffer, frames, __LINE__) ; 93b815c7f3Sopenharmony_ci 94b815c7f3Sopenharmony_ci test_read_[+ (get "name") +]_or_die (file, 0, buffer, frames, __LINE__) ; 95b815c7f3Sopenharmony_ci 96b815c7f3Sopenharmony_ci sf_close (file) ; 97b815c7f3Sopenharmony_ci unlink (filename) ; 98b815c7f3Sopenharmony_ci 99b815c7f3Sopenharmony_ci puts ("ok") ; 100b815c7f3Sopenharmony_ci return ; 101b815c7f3Sopenharmony_ci} /* rdwr_[+ (get "name") +]_test */ 102b815c7f3Sopenharmony_ci 103b815c7f3Sopenharmony_ci[+ ENDFOR data_type 104b815c7f3Sopenharmony_ci+] 105b815c7f3Sopenharmony_ci 106