2007-05-14 09:55:24 +00:00
|
|
|
[+ AutoGen5 template h c +]
|
|
|
|
/*
|
2015-09-12 10:49:14 +00:00
|
|
|
** Copyright (C) 2002-2015 Erik de Castro Lopo <erikd@mega-nerd.com>
|
2007-05-14 09:55:24 +00:00
|
|
|
**
|
|
|
|
** This program is free software; you can redistribute it and/or modify
|
|
|
|
** it under the terms of the GNU General Public License as published by
|
|
|
|
** the Free Software Foundation; either version 2 of the License, or
|
|
|
|
** (at your option) any later version.
|
|
|
|
**
|
|
|
|
** This program is distributed in the hope that it will be useful,
|
|
|
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
** GNU General Public License for more details.
|
|
|
|
**
|
|
|
|
** You should have received a copy of the GNU General Public License
|
|
|
|
** along with this program; if not, write to the Free Software
|
|
|
|
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Utility functions to make writing the test suite easier.
|
|
|
|
**
|
|
|
|
** The .c and .h files were generated automagically with Autogen from
|
|
|
|
** the files utils.def and utils.tpl.
|
|
|
|
*/
|
|
|
|
|
|
|
|
[+ CASE (suffix) +]
|
|
|
|
[+ == h +]
|
2006-04-29 00:01:28 +00:00
|
|
|
|
2006-07-27 10:33:36 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif /* __cplusplus */
|
|
|
|
|
2007-12-07 22:28:59 +00:00
|
|
|
#include <stdint.h>
|
2006-04-29 00:01:28 +00:00
|
|
|
#include <stdarg.h>
|
|
|
|
|
2004-05-19 11:29:41 +00:00
|
|
|
#define ARRAY_LEN(x) ((int) (sizeof (x)) / (sizeof ((x) [0])))
|
2006-05-02 13:30:11 +00:00
|
|
|
#define SIGNED_SIZEOF(x) ((int64_t) (sizeof (x)))
|
2011-03-25 07:58:12 +00:00
|
|
|
#define NOT(x) (! (x))
|
2014-07-30 10:55:55 +00:00
|
|
|
#define ABS(x) ((x) >= 0 ? (x) : -(x))
|
2007-05-14 09:55:24 +00:00
|
|
|
|
|
|
|
#define PIPE_INDEX(x) ((x) + 500)
|
|
|
|
#define PIPE_TEST_LEN 12345
|
|
|
|
|
2011-03-15 09:37:58 +00:00
|
|
|
|
2004-09-30 11:44:04 +00:00
|
|
|
[+ FOR float_type
|
|
|
|
+]void gen_windowed_sine_[+ (get "name") +] ([+ (get "name") +] *data, int len, double maximum) ;
|
|
|
|
[+ ENDFOR float_type
|
|
|
|
+]
|
2007-05-14 09:55:24 +00:00
|
|
|
|
2008-08-16 06:28:59 +00:00
|
|
|
void create_short_sndfile (const char *filename, int format, int channels) ;
|
|
|
|
|
2008-10-05 04:02:07 +00:00
|
|
|
void check_file_hash_or_die (const char *filename, uint64_t target_hash, int line_num) ;
|
2007-05-14 09:55:24 +00:00
|
|
|
|
|
|
|
void print_test_name (const char *test, const char *filename) ;
|
|
|
|
|
2008-05-19 01:45:44 +00:00
|
|
|
void dump_data_to_file (const char *filename, const void *data, unsigned int datalen) ;
|
2005-12-10 02:27:32 +00:00
|
|
|
|
2007-06-10 02:16:42 +00:00
|
|
|
void write_mono_file (const char * filename, int format, int srate, float * output, int len) ;
|
2007-06-10 01:34:11 +00:00
|
|
|
|
2012-02-18 00:58:25 +00:00
|
|
|
#ifdef __GNUC__
|
|
|
|
static inline void
|
|
|
|
exit_if_true (int test, const char *format, ...)
|
2014-07-30 10:55:55 +00:00
|
|
|
#if (defined (__USE_MINGW_ANSI_STDIO) && __USE_MINGW_ANSI_STDIO)
|
2012-02-26 00:21:24 +00:00
|
|
|
__attribute__ ((format (gnu_printf, 2, 3))) ;
|
|
|
|
#else
|
2012-02-18 00:58:25 +00:00
|
|
|
__attribute__ ((format (printf, 2, 3))) ;
|
|
|
|
#endif
|
2012-02-26 00:21:24 +00:00
|
|
|
#endif
|
2012-02-18 00:58:25 +00:00
|
|
|
|
2006-04-29 00:01:28 +00:00
|
|
|
static inline void
|
|
|
|
exit_if_true (int test, const char *format, ...)
|
|
|
|
{ if (test)
|
|
|
|
{ va_list argptr ;
|
|
|
|
va_start (argptr, format) ;
|
|
|
|
vprintf (format, argptr) ;
|
|
|
|
va_end (argptr) ;
|
|
|
|
exit (1) ;
|
|
|
|
} ;
|
|
|
|
} /* exit_if_true */
|
|
|
|
|
2014-12-15 10:20:29 +00:00
|
|
|
static inline int32_t
|
|
|
|
arith_shift_left (int32_t x, int shift)
|
|
|
|
{ return (int32_t) (((uint32_t) x) << shift) ;
|
|
|
|
} /* arith_shift_left */
|
|
|
|
|
2007-05-14 09:55:24 +00:00
|
|
|
/*
|
|
|
|
** Functions for saving two vectors of data in an ascii text file which
|
|
|
|
** can then be loaded into GNU octave for comparison.
|
|
|
|
*/
|
|
|
|
|
|
|
|
[+ FOR io_type
|
2007-08-18 14:50:46 +00:00
|
|
|
+]int oct_save_[+ (get "io_element") +] (const [+ (get "io_element") +] *a, const [+ (get "io_element") +] *b, int len) ;
|
2007-05-14 09:55:24 +00:00
|
|
|
[+ ENDFOR io_type
|
|
|
|
+]
|
|
|
|
|
2004-10-29 10:10:29 +00:00
|
|
|
void delete_file (int format, const char *filename) ;
|
|
|
|
|
2004-10-31 09:28:42 +00:00
|
|
|
void count_open_files (void) ;
|
|
|
|
void increment_open_file_count (void) ;
|
|
|
|
void check_open_file_count_or_die (int lineno) ;
|
|
|
|
|
2007-05-14 09:55:24 +00:00
|
|
|
#ifdef SNDFILE_H
|
|
|
|
|
2011-03-18 07:27:22 +00:00
|
|
|
static inline void
|
|
|
|
sf_info_clear (SF_INFO * info)
|
|
|
|
{ memset (info, 0, sizeof (SF_INFO)) ;
|
|
|
|
} /* sf_info_clear */
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
sf_info_setup (SF_INFO * info, int format, int samplerate, int channels)
|
|
|
|
{ sf_info_clear (info) ;
|
|
|
|
|
|
|
|
info->format = format ;
|
|
|
|
info->samplerate = samplerate ;
|
|
|
|
info->channels = channels ;
|
|
|
|
} /* sf_info_setup */
|
|
|
|
|
|
|
|
|
2007-05-14 09:55:24 +00:00
|
|
|
void dump_log_buffer (SNDFILE *file) ;
|
2004-05-21 00:35:40 +00:00
|
|
|
void check_log_buffer_or_die (SNDFILE *file, int line_num) ;
|
2007-05-14 09:55:24 +00:00
|
|
|
int string_in_log_buffer (SNDFILE *file, const char *s) ;
|
2004-05-16 01:30:37 +00:00
|
|
|
void hexdump_file (const char * filename, sf_count_t offset, sf_count_t length) ;
|
2007-05-14 09:55:24 +00:00
|
|
|
|
2004-10-29 10:10:29 +00:00
|
|
|
|
2007-05-14 09:55:24 +00:00
|
|
|
SNDFILE *test_open_file_or_die
|
2004-10-28 09:49:28 +00:00
|
|
|
(const char *filename, int mode, SF_INFO *sfinfo, int allow_fd, int line_num) ;
|
2007-05-14 09:55:24 +00:00
|
|
|
|
|
|
|
void test_read_write_position_or_die
|
|
|
|
(SNDFILE *file, int line_num, int pass, sf_count_t read_pos, sf_count_t write_pos) ;
|
|
|
|
|
|
|
|
void test_seek_or_die
|
|
|
|
(SNDFILE *file, sf_count_t offset, int whence, sf_count_t new_pos, int channels, int line_num) ;
|
|
|
|
|
2005-09-22 10:52:36 +00:00
|
|
|
[+ FOR read_op +]
|
2007-05-14 09:55:24 +00:00
|
|
|
[+ FOR io_type
|
|
|
|
+]void test_[+ (get "op_element") +]_[+ (get "io_element") +]_or_die
|
|
|
|
(SNDFILE *file, int pass, [+ (get "io_element") +] *test, sf_count_t [+ (get "count_name") +], int line_num) ;
|
2005-09-22 10:52:36 +00:00
|
|
|
[+ ENDFOR io_type +][+ ENDFOR read_op +]
|
|
|
|
|
2010-02-28 02:23:56 +00:00
|
|
|
void
|
|
|
|
test_read_raw_or_die (SNDFILE *file, int pass, void *test, sf_count_t items, int line_num) ;
|
|
|
|
|
2005-09-22 10:52:36 +00:00
|
|
|
[+ FOR write_op +]
|
|
|
|
[+ FOR io_type
|
|
|
|
+]void test_[+ (get "op_element") +]_[+ (get "io_element") +]_or_die
|
|
|
|
(SNDFILE *file, int pass, const [+ (get "io_element") +] *test, sf_count_t [+ (get "count_name") +], int line_num) ;
|
|
|
|
[+ ENDFOR io_type +][+ ENDFOR write_op +]
|
2007-05-14 09:55:24 +00:00
|
|
|
|
2010-02-28 02:23:56 +00:00
|
|
|
void
|
|
|
|
test_write_raw_or_die (SNDFILE *file, int pass, const void *test, sf_count_t items, int line_num) ;
|
|
|
|
|
2007-12-14 09:41:33 +00:00
|
|
|
[+ FOR io_type
|
2012-10-11 08:38:50 +00:00
|
|
|
+]void compare_[+ (get "io_element") +]_or_die (const [+ (get "io_element") +] *expected, const [+ (get "io_element") +] *actual, unsigned count, int line_num) ;
|
2007-12-14 09:41:33 +00:00
|
|
|
[+ ENDFOR io_type +]
|
|
|
|
|
|
|
|
|
2012-06-20 11:30:07 +00:00
|
|
|
void gen_lowpass_signal_float (float *data, int len) ;
|
2007-11-03 10:46:57 +00:00
|
|
|
|
2008-01-08 07:11:02 +00:00
|
|
|
sf_count_t file_length (const char * fname) ;
|
|
|
|
sf_count_t file_length_fd (int fd) ;
|
2007-11-03 10:46:57 +00:00
|
|
|
|
2007-05-14 09:55:24 +00:00
|
|
|
#endif
|
|
|
|
|
2006-07-27 10:33:36 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
} /* extern "C" */
|
|
|
|
#endif /* __cplusplus */
|
|
|
|
|
2007-05-14 09:55:24 +00:00
|
|
|
[+ == c +]
|
|
|
|
|
2005-09-03 06:12:30 +00:00
|
|
|
#include "sfconfig.h"
|
2007-05-14 09:55:24 +00:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2008-10-05 04:02:07 +00:00
|
|
|
#include <inttypes.h>
|
2007-05-14 09:55:24 +00:00
|
|
|
|
2005-09-03 06:12:30 +00:00
|
|
|
#if HAVE_UNISTD_H
|
2007-05-14 09:55:24 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
2005-09-03 03:50:47 +00:00
|
|
|
#if (HAVE_DECL_S_IRGRP == 0)
|
2007-05-14 09:55:24 +00:00
|
|
|
#include <sf_unistd.h>
|
|
|
|
#endif
|
|
|
|
|
2004-05-16 01:30:37 +00:00
|
|
|
#include <errno.h>
|
2007-05-14 09:55:24 +00:00
|
|
|
#include <string.h>
|
2004-05-16 01:30:37 +00:00
|
|
|
#include <ctype.h>
|
2007-05-14 09:55:24 +00:00
|
|
|
#include <math.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
|
|
|
#include <sndfile.h>
|
|
|
|
|
|
|
|
#include "utils.h"
|
|
|
|
|
|
|
|
#ifndef M_PI
|
|
|
|
#define M_PI 3.14159265358979323846264338
|
|
|
|
#endif
|
|
|
|
|
2004-05-16 01:30:37 +00:00
|
|
|
#define LOG_BUFFER_SIZE 2048
|
2007-05-14 09:55:24 +00:00
|
|
|
|
2007-11-12 08:55:30 +00:00
|
|
|
/*
|
|
|
|
** Neat solution to the Win32/OS2 binary file flage requirement.
|
|
|
|
** If O_BINARY isn't already defined by the inclusion of the system
|
|
|
|
** headers, set it to zero.
|
|
|
|
*/
|
|
|
|
#ifndef O_BINARY
|
|
|
|
#define O_BINARY 0
|
|
|
|
#endif
|
|
|
|
|
2004-09-30 11:44:04 +00:00
|
|
|
[+ FOR float_type +]
|
2007-05-14 09:55:24 +00:00
|
|
|
void
|
2004-09-30 11:44:04 +00:00
|
|
|
gen_windowed_sine_[+ (get "name") +] ([+ (get "name") +] *data, int len, double maximum)
|
2007-05-14 09:55:24 +00:00
|
|
|
{ int k ;
|
|
|
|
|
2004-09-30 11:44:04 +00:00
|
|
|
memset (data, 0, len * sizeof ([+ (get "name") +])) ;
|
2015-09-12 10:49:14 +00:00
|
|
|
|
|
|
|
len = (5 * len) / 6 ;
|
2007-05-14 09:55:24 +00:00
|
|
|
|
|
|
|
for (k = 0 ; k < len ; k++)
|
|
|
|
{ data [k] = sin (2.0 * k * M_PI * 1.0 / 32.0 + 0.4) ;
|
|
|
|
|
|
|
|
/* Apply Hanning Window. */
|
|
|
|
data [k] *= maximum * (0.5 - 0.5 * cos (2.0 * M_PI * k / ((len) - 1))) ;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ;
|
2004-09-30 11:44:04 +00:00
|
|
|
} /* gen_windowed_sine_[+ (get "name") +] */
|
|
|
|
[+ ENDFOR float_type +]
|
2007-05-14 09:55:24 +00:00
|
|
|
|
2008-08-16 06:28:59 +00:00
|
|
|
void
|
|
|
|
create_short_sndfile (const char *filename, int format, int channels)
|
2008-08-18 11:53:16 +00:00
|
|
|
{ short data [2 * 3 * 4 * 5 * 6 * 7] = { 0, } ;
|
|
|
|
SNDFILE *file ;
|
2008-08-16 06:28:59 +00:00
|
|
|
SF_INFO sfinfo ;
|
|
|
|
|
|
|
|
sfinfo.samplerate = 44100 ;
|
|
|
|
sfinfo.channels = channels ;
|
|
|
|
sfinfo.format = format ;
|
|
|
|
|
|
|
|
if ((file = sf_open (filename, SFM_WRITE, &sfinfo)) == NULL)
|
|
|
|
{ printf ("Error (%s, %d) : sf_open failed : %s\n", __FILE__, __LINE__, sf_strerror (file)) ;
|
|
|
|
exit (1) ;
|
|
|
|
} ;
|
|
|
|
|
|
|
|
sf_write_short (file, data, ARRAY_LEN (data)) ;
|
|
|
|
|
|
|
|
sf_close (file) ;
|
|
|
|
} /* create_short_sndfile */
|
|
|
|
|
2007-05-14 09:55:24 +00:00
|
|
|
void
|
2008-10-05 04:02:07 +00:00
|
|
|
check_file_hash_or_die (const char *filename, uint64_t target_hash, int line_num)
|
|
|
|
{ static unsigned char buf [4096] ;
|
|
|
|
uint64_t cksum ;
|
|
|
|
FILE *file ;
|
|
|
|
int k, read_count ;
|
2007-05-14 09:55:24 +00:00
|
|
|
|
2008-10-05 04:02:07 +00:00
|
|
|
memset (buf, 0, sizeof (buf)) ;
|
2007-05-14 09:55:24 +00:00
|
|
|
|
|
|
|
/* The 'b' in the mode string means binary for Win32. */
|
2008-10-05 04:02:07 +00:00
|
|
|
if ((file = fopen (filename, "rb")) == NULL)
|
2004-05-19 11:29:41 +00:00
|
|
|
{ printf ("\n\nLine %d: could not open file '%s'\n\n", line_num, filename) ;
|
2007-05-14 09:55:24 +00:00
|
|
|
exit (1) ;
|
|
|
|
} ;
|
|
|
|
|
2008-10-05 04:02:07 +00:00
|
|
|
cksum = 0 ;
|
2007-05-14 09:55:24 +00:00
|
|
|
|
2008-10-05 04:02:07 +00:00
|
|
|
while ((read_count = fread (buf, 1, sizeof (buf), file)))
|
|
|
|
for (k = 0 ; k < read_count ; k++)
|
2013-07-14 00:21:27 +00:00
|
|
|
cksum = (cksum * 511 + buf [k]) & 0xfffffffffffff ;
|
2007-05-14 09:55:24 +00:00
|
|
|
|
|
|
|
fclose (file) ;
|
|
|
|
|
|
|
|
if (target_hash == 0)
|
2008-10-05 04:02:07 +00:00
|
|
|
{ printf (" 0x%016" PRIx64 "\n", cksum) ;
|
2007-05-14 09:55:24 +00:00
|
|
|
return ;
|
|
|
|
} ;
|
|
|
|
|
2008-10-05 04:02:07 +00:00
|
|
|
if (cksum != target_hash)
|
|
|
|
{ printf ("\n\nLine %d: incorrect hash value 0x%016" PRIx64 " should be 0x%016" PRIx64 ".\n\n", line_num, cksum, target_hash) ;
|
2007-05-14 09:55:24 +00:00
|
|
|
exit (1) ;
|
2008-10-05 04:02:07 +00:00
|
|
|
} ;
|
2007-05-14 09:55:24 +00:00
|
|
|
|
|
|
|
return ;
|
|
|
|
} /* check_file_hash_or_die */
|
|
|
|
|
|
|
|
void
|
|
|
|
print_test_name (const char *test, const char *filename)
|
|
|
|
{ int count ;
|
|
|
|
|
2008-05-19 01:38:23 +00:00
|
|
|
if (test == NULL)
|
2007-05-14 09:55:24 +00:00
|
|
|
{ printf (__FILE__ ": bad test of filename parameter.\n") ;
|
|
|
|
exit (1) ;
|
|
|
|
} ;
|
|
|
|
|
2008-05-19 01:38:23 +00:00
|
|
|
if (filename == NULL || strlen (filename) == 0)
|
|
|
|
{ printf (" %-30s : ", test) ;
|
|
|
|
count = 25 ;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{ printf (" %-30s : %s ", test, filename) ;
|
|
|
|
count = 24 - strlen (filename) ;
|
|
|
|
} ;
|
2007-05-14 09:55:24 +00:00
|
|
|
|
|
|
|
while (count -- > 0)
|
|
|
|
putchar ('.') ;
|
|
|
|
putchar (' ') ;
|
|
|
|
|
|
|
|
fflush (stdout) ;
|
|
|
|
} /* print_test_name */
|
|
|
|
|
2005-12-10 02:27:32 +00:00
|
|
|
void
|
2008-05-19 01:45:44 +00:00
|
|
|
dump_data_to_file (const char *filename, const void *data, unsigned int datalen)
|
2005-12-10 02:27:32 +00:00
|
|
|
{ FILE *file ;
|
|
|
|
|
|
|
|
if ((file = fopen (filename, "wb")) == NULL)
|
|
|
|
{ printf ("\n\nLine %d : could not open file : %s\n\n", __LINE__, filename) ;
|
|
|
|
exit (1) ;
|
|
|
|
} ;
|
|
|
|
|
|
|
|
if (fwrite (data, 1, datalen, file) != datalen)
|
|
|
|
{ printf ("\n\nLine %d : fwrite failed.\n\n", __LINE__) ;
|
|
|
|
exit (1) ;
|
|
|
|
} ;
|
|
|
|
|
|
|
|
fclose (file) ;
|
|
|
|
|
|
|
|
} /* dump_data_to_file */
|
|
|
|
|
2007-05-14 09:55:24 +00:00
|
|
|
/*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
|
|
|
|
*/
|
|
|
|
|
|
|
|
static char octfilename [] = "error.dat" ;
|
|
|
|
|
|
|
|
[+ FOR io_type
|
|
|
|
+]int
|
2007-08-18 14:50:46 +00:00
|
|
|
oct_save_[+ (get "io_element") +] (const [+ (get "io_element") +] *a, const [+ (get "io_element") +] *b, int len)
|
2007-05-14 09:55:24 +00:00
|
|
|
{ FILE *file ;
|
|
|
|
int k ;
|
|
|
|
|
|
|
|
if (! (file = fopen (octfilename, "w")))
|
|
|
|
return 1 ;
|
|
|
|
|
|
|
|
fprintf (file, "# Not created by Octave\n") ;
|
|
|
|
|
|
|
|
fprintf (file, "# name: a\n") ;
|
|
|
|
fprintf (file, "# type: matrix\n") ;
|
|
|
|
fprintf (file, "# rows: %d\n", len) ;
|
|
|
|
fprintf (file, "# columns: 1\n") ;
|
|
|
|
|
|
|
|
for (k = 0 ; k < len ; k++)
|
2007-12-14 09:41:33 +00:00
|
|
|
fprintf (file, [+ (get "format_str") +] "\n", a [k]) ;
|
2007-05-14 09:55:24 +00:00
|
|
|
|
|
|
|
fprintf (file, "# name: b\n") ;
|
|
|
|
fprintf (file, "# type: matrix\n") ;
|
|
|
|
fprintf (file, "# rows: %d\n", len) ;
|
|
|
|
fprintf (file, "# columns: 1\n") ;
|
|
|
|
|
|
|
|
for (k = 0 ; k < len ; k++)
|
2007-12-14 09:41:33 +00:00
|
|
|
fprintf (file, [+ (get "format_str") +] "\n", b [k]) ;
|
2007-05-14 09:55:24 +00:00
|
|
|
|
|
|
|
fclose (file) ;
|
|
|
|
return 0 ;
|
|
|
|
} /* oct_save_[+ (get "io_element") +] */
|
|
|
|
[+ ENDFOR io_type
|
|
|
|
+]
|
|
|
|
|
|
|
|
void
|
2004-05-21 00:35:40 +00:00
|
|
|
check_log_buffer_or_die (SNDFILE *file, int line_num)
|
2007-05-14 09:55:24 +00:00
|
|
|
{ static char buffer [LOG_BUFFER_SIZE] ;
|
|
|
|
int count ;
|
|
|
|
|
2011-07-06 10:12:10 +00:00
|
|
|
memset (buffer, 0, sizeof (buffer)) ;
|
2007-05-14 09:55:24 +00:00
|
|
|
|
|
|
|
/* Get the log buffer data. */
|
|
|
|
count = sf_command (file, SFC_GET_LOG_INFO, buffer, LOG_BUFFER_SIZE) ;
|
|
|
|
|
|
|
|
if (LOG_BUFFER_SIZE - count < 2)
|
2004-05-21 00:35:40 +00:00
|
|
|
{ printf ("\n\nLine %d : Possible long log buffer.\n", line_num) ;
|
2007-05-14 09:55:24 +00:00
|
|
|
exit (1) ;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Look for "Should" */
|
|
|
|
if (strstr (buffer, "ould"))
|
2004-05-21 00:35:40 +00:00
|
|
|
{ printf ("\n\nLine %d : Log buffer contains `ould'. Dumping.\n", line_num) ;
|
2007-05-14 09:55:24 +00:00
|
|
|
puts (buffer) ;
|
|
|
|
exit (1) ;
|
|
|
|
} ;
|
|
|
|
|
|
|
|
/* Look for "**" */
|
|
|
|
if (strstr (buffer, "*"))
|
2004-05-21 00:35:40 +00:00
|
|
|
{ printf ("\n\nLine %d : Log buffer contains `*'. Dumping.\n", line_num) ;
|
2007-05-14 09:55:24 +00:00
|
|
|
puts (buffer) ;
|
|
|
|
exit (1) ;
|
|
|
|
} ;
|
|
|
|
|
2006-03-18 11:13:47 +00:00
|
|
|
/* Look for "Should" */
|
|
|
|
if (strstr (buffer, "nknown marker"))
|
|
|
|
{ printf ("\n\nLine %d : Log buffer contains `nknown marker'. Dumping.\n", line_num) ;
|
|
|
|
puts (buffer) ;
|
|
|
|
exit (1) ;
|
|
|
|
} ;
|
|
|
|
|
2007-05-14 09:55:24 +00:00
|
|
|
return ;
|
|
|
|
} /* check_log_buffer_or_die */
|
|
|
|
|
|
|
|
int
|
|
|
|
string_in_log_buffer (SNDFILE *file, const char *s)
|
|
|
|
{ static char buffer [LOG_BUFFER_SIZE] ;
|
|
|
|
int count ;
|
|
|
|
|
2011-07-06 10:12:10 +00:00
|
|
|
memset (buffer, 0, sizeof (buffer)) ;
|
2007-05-14 09:55:24 +00:00
|
|
|
|
|
|
|
/* Get the log buffer data. */
|
|
|
|
count = sf_command (file, SFC_GET_LOG_INFO, buffer, LOG_BUFFER_SIZE) ;
|
|
|
|
|
|
|
|
if (LOG_BUFFER_SIZE - count < 2)
|
|
|
|
{ printf ("Possible long log buffer.\n") ;
|
|
|
|
exit (1) ;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Look for string */
|
|
|
|
return strstr (buffer, s) ? SF_TRUE : SF_FALSE ;
|
|
|
|
} /* string_in_log_buffer */
|
|
|
|
|
2004-05-16 01:30:37 +00:00
|
|
|
void
|
|
|
|
hexdump_file (const char * filename, sf_count_t offset, sf_count_t length)
|
|
|
|
{
|
|
|
|
FILE * file ;
|
|
|
|
char buffer [16] ;
|
|
|
|
int k, m, ch, readcount ;
|
|
|
|
|
|
|
|
if (length > 1000000)
|
2012-02-18 01:59:32 +00:00
|
|
|
{ printf ("\n\nError : length (%" PRId64 ") too long.\n\n", offset) ;
|
2004-05-16 01:30:37 +00:00
|
|
|
exit (1) ;
|
|
|
|
} ;
|
|
|
|
|
|
|
|
if ((file = fopen (filename, "r")) == NULL)
|
|
|
|
{ printf ("\n\nError : hexdump_file (%s) could not open file for read.\n\n", filename) ;
|
|
|
|
exit (1) ;
|
|
|
|
} ;
|
|
|
|
|
|
|
|
if (fseek (file, offset, SEEK_SET) != 0)
|
2012-02-18 01:59:32 +00:00
|
|
|
{ printf ("\n\nError : fseek(file, %" PRId64 ", SEEK_SET) failed : %s\n\n", offset, strerror (errno)) ;
|
2004-05-16 01:30:37 +00:00
|
|
|
exit (1) ;
|
|
|
|
} ;
|
|
|
|
|
|
|
|
puts ("\n\n") ;
|
|
|
|
|
|
|
|
for (k = 0 ; k < length ; k+= sizeof (buffer))
|
|
|
|
{ readcount = fread (buffer, 1, sizeof (buffer), file) ;
|
2004-05-19 11:29:41 +00:00
|
|
|
|
2012-02-18 01:59:32 +00:00
|
|
|
printf ("%08" PRIx64 " : ", offset + k) ;
|
2004-05-16 01:30:37 +00:00
|
|
|
|
|
|
|
for (m = 0 ; m < readcount ; m++)
|
|
|
|
printf ("%02x ", buffer [m] & 0xFF) ;
|
|
|
|
|
|
|
|
for (m = readcount ; m < SIGNED_SIZEOF (buffer) ; m++)
|
|
|
|
printf (" ") ;
|
|
|
|
|
|
|
|
printf (" ") ;
|
|
|
|
for (m = 0 ; m < readcount ; m++)
|
|
|
|
{ ch = isprint (buffer [m]) ? buffer [m] : '.' ;
|
|
|
|
putchar (ch) ;
|
|
|
|
} ;
|
2004-05-19 11:29:41 +00:00
|
|
|
|
2004-05-16 01:30:37 +00:00
|
|
|
if (readcount < SIGNED_SIZEOF (buffer))
|
|
|
|
break ;
|
|
|
|
|
|
|
|
putchar ('\n') ;
|
|
|
|
} ;
|
|
|
|
|
|
|
|
puts ("\n") ;
|
|
|
|
|
|
|
|
fclose (file) ;
|
|
|
|
} /* hexdump_file */
|
|
|
|
|
2007-05-14 09:55:24 +00:00
|
|
|
void
|
|
|
|
dump_log_buffer (SNDFILE *file)
|
|
|
|
{ static char buffer [LOG_BUFFER_SIZE] ;
|
|
|
|
|
2011-07-06 10:12:10 +00:00
|
|
|
memset (buffer, 0, sizeof (buffer)) ;
|
2007-05-14 09:55:24 +00:00
|
|
|
|
|
|
|
/* Get the log buffer data. */
|
2011-03-28 07:43:05 +00:00
|
|
|
sf_command (file, SFC_GET_LOG_INFO, buffer, LOG_BUFFER_SIZE) ;
|
2007-05-14 09:55:24 +00:00
|
|
|
|
|
|
|
if (strlen (buffer) < 1)
|
|
|
|
puts ("Log buffer empty.\n") ;
|
|
|
|
else
|
|
|
|
puts (buffer) ;
|
|
|
|
|
|
|
|
return ;
|
|
|
|
} /* dump_log_buffer */
|
|
|
|
|
|
|
|
SNDFILE *
|
2004-10-28 09:49:28 +00:00
|
|
|
test_open_file_or_die (const char *filename, int mode, SF_INFO *sfinfo, int allow_fd, int line_num)
|
2007-05-14 09:55:24 +00:00
|
|
|
{ static int count = 0 ;
|
|
|
|
|
|
|
|
SNDFILE *file ;
|
|
|
|
const char *modestr, *func_name ;
|
2009-04-12 11:38:59 +00:00
|
|
|
int oflags = 0, omode = 0, err ;
|
2007-05-14 09:55:24 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
** Need to test both sf_open() and sf_open_fd().
|
|
|
|
** Do so alternately.
|
|
|
|
*/
|
|
|
|
switch (mode)
|
|
|
|
{ case SFM_READ :
|
|
|
|
modestr = "SFM_READ" ;
|
2007-11-12 08:55:30 +00:00
|
|
|
oflags = O_RDONLY | O_BINARY ;
|
2007-05-14 09:55:24 +00:00
|
|
|
omode = 0 ;
|
|
|
|
break ;
|
|
|
|
|
|
|
|
case SFM_WRITE :
|
|
|
|
modestr = "SFM_WRITE" ;
|
2007-11-12 08:55:30 +00:00
|
|
|
oflags = O_WRONLY | O_CREAT | O_TRUNC | O_BINARY ;
|
2007-05-14 09:55:24 +00:00
|
|
|
omode = S_IRUSR | S_IWUSR | S_IRGRP ;
|
|
|
|
break ;
|
|
|
|
|
|
|
|
case SFM_RDWR :
|
|
|
|
modestr = "SFM_RDWR" ;
|
2007-11-12 08:55:30 +00:00
|
|
|
oflags = O_RDWR | O_CREAT | O_BINARY ;
|
2007-05-14 09:55:24 +00:00
|
|
|
omode = S_IRUSR | S_IWUSR | S_IRGRP ;
|
|
|
|
break ;
|
|
|
|
default :
|
|
|
|
printf ("\n\nLine %d: Bad mode.\n", line_num) ;
|
|
|
|
fflush (stdout) ;
|
|
|
|
exit (1) ;
|
|
|
|
} ;
|
|
|
|
|
2008-04-06 10:26:16 +00:00
|
|
|
if (OS_IS_WIN32)
|
2009-09-28 08:46:34 +00:00
|
|
|
{ /* Windows does not understand and ignores the S_IRGRP flag, but Wine
|
|
|
|
** gives a run time warning message, so just clear it.
|
|
|
|
*/
|
|
|
|
omode &= ~S_IRGRP ;
|
2008-04-06 10:26:16 +00:00
|
|
|
} ;
|
|
|
|
|
2004-10-28 09:49:28 +00:00
|
|
|
if (allow_fd && ((++count) & 1) == 1)
|
2007-05-14 09:55:24 +00:00
|
|
|
{ int fd ;
|
|
|
|
|
2009-09-28 08:46:34 +00:00
|
|
|
/* Only use the three argument open() function if omode != 0. */
|
|
|
|
fd = (omode == 0) ? open (filename, oflags) : open (filename, oflags, omode) ;
|
2007-05-14 09:55:24 +00:00
|
|
|
|
|
|
|
if (fd < 0)
|
2009-09-28 08:46:34 +00:00
|
|
|
{ printf ("\n\n%s : open failed : %s\n", __func__, strerror (errno)) ;
|
2007-05-14 09:55:24 +00:00
|
|
|
exit (1) ;
|
|
|
|
} ;
|
|
|
|
|
|
|
|
func_name = "sf_open_fd" ;
|
|
|
|
file = sf_open_fd (fd, mode, sfinfo, SF_TRUE) ;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{ func_name = "sf_open" ;
|
|
|
|
file = sf_open (filename, mode, sfinfo) ;
|
|
|
|
} ;
|
|
|
|
|
|
|
|
if (file == NULL)
|
2004-05-19 11:29:41 +00:00
|
|
|
{ printf ("\n\nLine %d: %s (%s) failed : %s\n\n", line_num, func_name, modestr, sf_strerror (NULL)) ;
|
2007-05-14 09:55:24 +00:00
|
|
|
dump_log_buffer (file) ;
|
|
|
|
exit (1) ;
|
|
|
|
} ;
|
|
|
|
|
2009-04-12 11:38:59 +00:00
|
|
|
err = sf_error (file) ;
|
|
|
|
if (err != SF_ERR_NO_ERROR)
|
|
|
|
{ printf ("\n\nLine %d : sf_error : %s\n\n", line_num, sf_error_number (err)) ;
|
|
|
|
dump_log_buffer (file) ;
|
|
|
|
exit (1) ;
|
|
|
|
} ;
|
|
|
|
|
2007-05-14 09:55:24 +00:00
|
|
|
return file ;
|
|
|
|
} /* test_open_file_or_die */
|
|
|
|
|
|
|
|
void
|
|
|
|
test_read_write_position_or_die (SNDFILE *file, int line_num, int pass, sf_count_t read_pos, sf_count_t write_pos)
|
|
|
|
{ sf_count_t pos ;
|
|
|
|
|
|
|
|
/* Check the current read position. */
|
|
|
|
if (read_pos >= 0 && (pos = sf_seek (file, 0, SEEK_CUR | SFM_READ)) != read_pos)
|
|
|
|
{ printf ("\n\nLine %d ", line_num) ;
|
|
|
|
if (pass > 0)
|
|
|
|
printf ("(pass %d): ", pass) ;
|
2012-02-18 01:59:32 +00:00
|
|
|
printf ("Read position (%" PRId64 ") should be %" PRId64 ".\n", pos, read_pos) ;
|
2007-05-14 09:55:24 +00:00
|
|
|
exit (1) ;
|
|
|
|
} ;
|
|
|
|
|
|
|
|
/* Check the current write position. */
|
|
|
|
if (write_pos >= 0 && (pos = sf_seek (file, 0, SEEK_CUR | SFM_WRITE)) != write_pos)
|
|
|
|
{ printf ("\n\nLine %d", line_num) ;
|
|
|
|
if (pass > 0)
|
|
|
|
printf (" (pass %d)", pass) ;
|
2012-02-18 01:59:32 +00:00
|
|
|
printf (" : Write position (%" PRId64 ") should be %" PRId64 ".\n", pos, write_pos) ;
|
2007-05-14 09:55:24 +00:00
|
|
|
exit (1) ;
|
|
|
|
} ;
|
|
|
|
|
|
|
|
return ;
|
|
|
|
} /* test_read_write_position */
|
|
|
|
|
|
|
|
void
|
|
|
|
test_seek_or_die (SNDFILE *file, sf_count_t offset, int whence, sf_count_t new_pos, int channels, int line_num)
|
|
|
|
{ sf_count_t position ;
|
|
|
|
const char *channel_name, *whence_name ;
|
|
|
|
|
|
|
|
switch (whence)
|
|
|
|
{ case SEEK_SET :
|
|
|
|
whence_name = "SEEK_SET" ;
|
|
|
|
break ;
|
|
|
|
case SEEK_CUR :
|
|
|
|
whence_name = "SEEK_CUR" ;
|
|
|
|
break ;
|
|
|
|
case SEEK_END :
|
|
|
|
whence_name = "SEEK_END" ;
|
|
|
|
break ;
|
|
|
|
|
|
|
|
/* SFM_READ */
|
|
|
|
case SEEK_SET | SFM_READ :
|
|
|
|
whence_name = "SFM_READ | SEEK_SET" ;
|
|
|
|
break ;
|
|
|
|
case SEEK_CUR | SFM_READ :
|
|
|
|
whence_name = "SFM_READ | SEEK_CUR" ;
|
|
|
|
break ;
|
|
|
|
case SEEK_END | SFM_READ :
|
|
|
|
whence_name = "SFM_READ | SEEK_END" ;
|
|
|
|
break ;
|
|
|
|
|
|
|
|
/* SFM_WRITE */
|
|
|
|
case SEEK_SET | SFM_WRITE :
|
|
|
|
whence_name = "SFM_WRITE | SEEK_SET" ;
|
|
|
|
break ;
|
|
|
|
case SEEK_CUR | SFM_WRITE :
|
|
|
|
whence_name = "SFM_WRITE | SEEK_CUR" ;
|
|
|
|
break ;
|
|
|
|
case SEEK_END | SFM_WRITE :
|
|
|
|
whence_name = "SFM_WRITE | SEEK_END" ;
|
|
|
|
break ;
|
|
|
|
|
|
|
|
default :
|
|
|
|
printf ("\n\nLine %d: bad whence parameter.\n", line_num) ;
|
|
|
|
exit (1) ;
|
|
|
|
} ;
|
|
|
|
|
|
|
|
channel_name = (channels == 1) ? "Mono" : "Stereo" ;
|
|
|
|
|
|
|
|
if ((position = sf_seek (file, offset, whence)) != new_pos)
|
2012-02-18 01:59:32 +00:00
|
|
|
{ printf ("\n\nLine %d : %s : sf_seek (file, %" PRId64 ", %s) returned %" PRId64 " (should be %" PRId64 ").\n\n",
|
|
|
|
line_num, channel_name, offset, whence_name, position, new_pos) ;
|
2007-05-14 09:55:24 +00:00
|
|
|
exit (1) ;
|
|
|
|
} ;
|
|
|
|
|
|
|
|
} /* test_seek_or_die */
|
|
|
|
|
2005-09-22 10:52:36 +00:00
|
|
|
[+ FOR read_op +]
|
2007-05-14 09:55:24 +00:00
|
|
|
[+ FOR io_type +]
|
|
|
|
void
|
|
|
|
test_[+ (get "op_element") +]_[+ (get "io_element") +]_or_die (SNDFILE *file, int pass, [+ (get "io_element") +] *test, sf_count_t [+ (get "count_name") +], int line_num)
|
|
|
|
{ sf_count_t count ;
|
|
|
|
|
|
|
|
if ((count = sf_[+ (get "op_element") +]_[+ (get "io_element") +] (file, test, [+ (get "count_name") +])) != [+ (get "count_name") +])
|
|
|
|
{ printf ("\n\nLine %d", line_num) ;
|
|
|
|
if (pass > 0)
|
|
|
|
printf (" (pass %d)", pass) ;
|
2012-02-18 01:59:32 +00:00
|
|
|
printf (" : sf_[+ (get "op_element") +]_[+ (get "io_element") +] failed with short [+ (get "op_element") +] (%" PRId64 " => %" PRId64 ").\n",
|
|
|
|
[+ (get "count_name") +], count) ;
|
2007-05-14 09:55:24 +00:00
|
|
|
fflush (stdout) ;
|
|
|
|
puts (sf_strerror (file)) ;
|
|
|
|
exit (1) ;
|
|
|
|
} ;
|
|
|
|
|
|
|
|
return ;
|
2010-02-28 02:23:56 +00:00
|
|
|
} /* test_[+ (get "op_element") +]_[+ (get "io_element") +]_or_die */
|
2005-09-22 10:52:36 +00:00
|
|
|
[+ ENDFOR io_type +][+ ENDFOR read_op +]
|
|
|
|
|
2010-02-28 02:23:56 +00:00
|
|
|
void
|
|
|
|
test_read_raw_or_die (SNDFILE *file, int pass, void *test, sf_count_t items, int line_num)
|
|
|
|
{ sf_count_t count ;
|
|
|
|
|
|
|
|
if ((count = sf_read_raw (file, test, items)) != items)
|
|
|
|
{ printf ("\n\nLine %d", line_num) ;
|
|
|
|
if (pass > 0)
|
|
|
|
printf (" (pass %d)", pass) ;
|
2012-02-18 01:59:32 +00:00
|
|
|
printf (" : sf_read_raw failed with short read (%" PRId64 " => %" PRId64 ").\n", items, count) ;
|
2010-02-28 02:23:56 +00:00
|
|
|
fflush (stdout) ;
|
|
|
|
puts (sf_strerror (file)) ;
|
|
|
|
exit (1) ;
|
|
|
|
} ;
|
|
|
|
|
|
|
|
return ;
|
|
|
|
} /* test_read_raw_or_die */
|
|
|
|
|
2005-09-22 10:52:36 +00:00
|
|
|
[+ FOR write_op +]
|
|
|
|
[+ FOR io_type +]
|
|
|
|
void
|
|
|
|
test_[+ (get "op_element") +]_[+ (get "io_element") +]_or_die (SNDFILE *file, int pass, const [+ (get "io_element") +] *test, sf_count_t [+ (get "count_name") +], int line_num)
|
|
|
|
{ sf_count_t count ;
|
|
|
|
|
|
|
|
if ((count = sf_[+ (get "op_element") +]_[+ (get "io_element") +] (file, test, [+ (get "count_name") +])) != [+ (get "count_name") +])
|
|
|
|
{ printf ("\n\nLine %d", line_num) ;
|
|
|
|
if (pass > 0)
|
|
|
|
printf (" (pass %d)", pass) ;
|
2012-02-18 01:59:32 +00:00
|
|
|
printf (" : sf_[+ (get "op_element") +]_[+ (get "io_element") +] failed with short [+ (get "op_element") +] (%" PRId64 " => %" PRId64 ").\n",
|
|
|
|
[+ (get "count_name") +], count) ;
|
2005-09-22 10:52:36 +00:00
|
|
|
fflush (stdout) ;
|
|
|
|
puts (sf_strerror (file)) ;
|
|
|
|
exit (1) ;
|
|
|
|
} ;
|
|
|
|
|
|
|
|
return ;
|
2010-02-28 02:23:56 +00:00
|
|
|
} /* test_[+ (get "op_element") +]_[+ (get "io_element") +]_or_die */
|
2005-09-22 10:52:36 +00:00
|
|
|
[+ ENDFOR io_type +][+ ENDFOR write_op +]
|
2007-05-14 09:55:24 +00:00
|
|
|
|
2010-02-28 02:23:56 +00:00
|
|
|
void
|
|
|
|
test_write_raw_or_die (SNDFILE *file, int pass, const void *test, sf_count_t items, int line_num)
|
|
|
|
{ sf_count_t count ;
|
|
|
|
|
|
|
|
if ((count = sf_write_raw (file, test, items)) != items)
|
|
|
|
{ printf ("\n\nLine %d", line_num) ;
|
|
|
|
if (pass > 0)
|
|
|
|
printf (" (pass %d)", pass) ;
|
2012-02-18 01:59:32 +00:00
|
|
|
printf (" : sf_write_raw failed with short write (%" PRId64 " => %" PRId64 ").\n", items, count) ;
|
2010-02-28 02:23:56 +00:00
|
|
|
fflush (stdout) ;
|
|
|
|
puts (sf_strerror (file)) ;
|
|
|
|
exit (1) ;
|
|
|
|
} ;
|
|
|
|
|
|
|
|
return ;
|
|
|
|
} /* test_write_raw_or_die */
|
|
|
|
|
|
|
|
|
2007-12-14 09:41:33 +00:00
|
|
|
[+ FOR io_type
|
|
|
|
+]void
|
2012-10-11 08:38:50 +00:00
|
|
|
compare_[+ (get "io_element") +]_or_die (const [+ (get "io_element") +] *expected, const [+ (get "io_element") +] *actual, unsigned count, int line_num)
|
2007-12-14 09:41:33 +00:00
|
|
|
{
|
|
|
|
unsigned k ;
|
|
|
|
|
2012-01-20 11:44:47 +00:00
|
|
|
for (k = 0 ; k < count ; k++)
|
2012-10-11 08:38:50 +00:00
|
|
|
if (expected [k] != actual [k])
|
|
|
|
{ printf ("\n\nLine %d : Error at index %d, got " [+ (get "format_str") +] ", should be " [+ (get "format_str") +] ".\n\n", line_num, k, actual [k], expected [k]) ;
|
2007-12-14 09:41:33 +00:00
|
|
|
exit (1) ;
|
|
|
|
} ;
|
|
|
|
|
|
|
|
return ;
|
|
|
|
} /* compare_[+ (get "io_element") +]_or_die */
|
|
|
|
[+ ENDFOR io_type +]
|
|
|
|
|
|
|
|
|
2004-10-29 10:10:29 +00:00
|
|
|
void
|
|
|
|
delete_file (int format, const char *filename)
|
|
|
|
{ char rsrc_name [512], *fname ;
|
|
|
|
|
|
|
|
unlink (filename) ;
|
|
|
|
|
|
|
|
if ((format & SF_FORMAT_TYPEMASK) != SF_FORMAT_SD2)
|
|
|
|
return ;
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Now try for a resource fork stored as a separate file.
|
|
|
|
** Grab the un-adulterated filename again.
|
|
|
|
*/
|
|
|
|
snprintf (rsrc_name, sizeof (rsrc_name), "%s", filename) ;
|
|
|
|
|
|
|
|
if ((fname = strrchr (rsrc_name, '/')) != NULL)
|
|
|
|
fname ++ ;
|
|
|
|
else if ((fname = strrchr (rsrc_name, '\\')) != NULL)
|
|
|
|
fname ++ ;
|
|
|
|
else
|
|
|
|
fname = rsrc_name ;
|
|
|
|
|
|
|
|
memmove (fname + 2, fname, strlen (fname) + 1) ;
|
|
|
|
fname [0] = '.' ;
|
|
|
|
fname [1] = '_' ;
|
|
|
|
|
|
|
|
unlink (rsrc_name) ;
|
|
|
|
} /* delete_file */
|
|
|
|
|
2006-04-01 23:40:07 +00:00
|
|
|
static int allowed_open_files = -1 ;
|
2004-10-31 09:28:42 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
count_open_files (void)
|
|
|
|
{
|
2009-09-28 08:46:34 +00:00
|
|
|
#if OS_IS_WIN32
|
2004-10-31 09:28:42 +00:00
|
|
|
return ;
|
|
|
|
#else
|
|
|
|
int k, count = 0 ;
|
|
|
|
struct stat statbuf ;
|
|
|
|
|
|
|
|
if (allowed_open_files > 0)
|
|
|
|
return ;
|
|
|
|
|
|
|
|
for (k = 0 ; k < 1024 ; k++)
|
|
|
|
if (fstat (k, &statbuf) == 0)
|
|
|
|
count ++ ;
|
|
|
|
|
|
|
|
allowed_open_files = count ;
|
|
|
|
#endif
|
|
|
|
} /* count_open_files */
|
|
|
|
|
|
|
|
void
|
|
|
|
increment_open_file_count (void)
|
|
|
|
{ allowed_open_files ++ ;
|
|
|
|
} /* increment_open_file_count */
|
|
|
|
|
|
|
|
void
|
|
|
|
check_open_file_count_or_die (int lineno)
|
|
|
|
{
|
2009-09-28 08:46:34 +00:00
|
|
|
#if OS_IS_WIN32
|
2011-10-28 08:15:22 +00:00
|
|
|
(void) lineno ;
|
2004-10-31 09:28:42 +00:00
|
|
|
return ;
|
|
|
|
#else
|
|
|
|
int k, count = 0 ;
|
|
|
|
struct stat statbuf ;
|
|
|
|
|
|
|
|
if (allowed_open_files < 0)
|
|
|
|
count_open_files () ;
|
|
|
|
|
|
|
|
for (k = 0 ; k < 1024 ; k++)
|
|
|
|
if (fstat (k, &statbuf) == 0)
|
|
|
|
count ++ ;
|
|
|
|
|
|
|
|
if (count > allowed_open_files)
|
|
|
|
{ printf ("\nLine %d : number of open files (%d) > allowed (%d).\n\n", lineno, count, allowed_open_files) ;
|
|
|
|
exit (1) ;
|
|
|
|
} ;
|
|
|
|
#endif
|
|
|
|
} /* check_open_file_count_or_die */
|
|
|
|
|
2007-06-10 01:34:11 +00:00
|
|
|
void
|
2007-06-10 02:16:42 +00:00
|
|
|
write_mono_file (const char * filename, int format, int srate, float * output, int len)
|
2007-06-10 01:34:11 +00:00
|
|
|
{ SNDFILE * file ;
|
|
|
|
SF_INFO sfinfo ;
|
|
|
|
|
|
|
|
memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
|
|
|
|
|
|
|
sfinfo.samplerate = srate ;
|
|
|
|
sfinfo.channels = 1 ;
|
2007-06-10 02:16:42 +00:00
|
|
|
sfinfo.format = format ;
|
2007-06-10 01:34:11 +00:00
|
|
|
|
|
|
|
if ((file = sf_open (filename, SFM_WRITE, &sfinfo)) == NULL)
|
|
|
|
{ printf ("sf_open (%s) : %s\n", filename, sf_strerror (NULL)) ;
|
|
|
|
exit (1) ;
|
|
|
|
} ;
|
|
|
|
|
|
|
|
sf_write_float (file, output, len) ;
|
2008-04-19 09:19:24 +00:00
|
|
|
|
2007-06-10 01:34:11 +00:00
|
|
|
sf_close (file) ;
|
|
|
|
} /* write_mono_file */
|
|
|
|
|
2007-11-03 10:46:57 +00:00
|
|
|
void
|
2012-06-20 11:30:07 +00:00
|
|
|
gen_lowpass_signal_float (float *data, int len)
|
2013-07-14 00:21:27 +00:00
|
|
|
{ int64_t value = 0x1243456 ;
|
2007-11-03 10:46:57 +00:00
|
|
|
double sample, last_val = 0.0 ;
|
|
|
|
int k ;
|
|
|
|
|
|
|
|
for (k = 0 ; k < len ; k++)
|
|
|
|
{ /* Not a crypto quality RNG. */
|
2013-07-14 00:21:27 +00:00
|
|
|
value = (11117 * value + 211231) & 0xffffffff ;
|
|
|
|
value = (11117 * value + 211231) & 0xffffffff ;
|
|
|
|
value = (11117 * value + 211231) & 0xffffffff ;
|
2007-11-03 10:46:57 +00:00
|
|
|
|
|
|
|
sample = value / (0x7fffffff * 1.000001) ;
|
|
|
|
sample = 0.2 * sample - 0.9 * last_val ;
|
|
|
|
|
2012-06-20 11:30:07 +00:00
|
|
|
last_val = sample ;
|
|
|
|
|
|
|
|
data [k] = 0.5 * (sample + sin (2.0 * k * M_PI * 1.0 / 32.0)) ;
|
2007-11-03 10:46:57 +00:00
|
|
|
} ;
|
|
|
|
|
2012-06-20 11:30:07 +00:00
|
|
|
} /* gen_lowpass_signal_float */
|
2007-11-03 10:46:57 +00:00
|
|
|
|
2008-01-08 07:11:02 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
** Windows is fucked.
|
|
|
|
** If a file is opened R/W and data is written to it, then fstat will return
|
|
|
|
** the correct file length, but stat will return zero.
|
|
|
|
*/
|
|
|
|
|
|
|
|
sf_count_t
|
2007-11-03 10:46:57 +00:00
|
|
|
file_length (const char * fname)
|
|
|
|
{ struct stat data ;
|
|
|
|
|
|
|
|
if (stat (fname, &data) != 0)
|
|
|
|
return 0 ;
|
|
|
|
|
2008-01-08 07:11:02 +00:00
|
|
|
return (sf_count_t) data.st_size ;
|
2007-11-03 10:46:57 +00:00
|
|
|
} /* file_length */
|
|
|
|
|
2008-01-08 07:11:02 +00:00
|
|
|
sf_count_t
|
|
|
|
file_length_fd (int fd)
|
|
|
|
{ struct stat data ;
|
|
|
|
|
2008-09-29 08:32:55 +00:00
|
|
|
memset (&data, 0, sizeof (data)) ;
|
2008-01-08 07:11:02 +00:00
|
|
|
if (fstat (fd, &data) != 0)
|
|
|
|
return 0 ;
|
|
|
|
|
|
|
|
return (sf_count_t) data.st_size ;
|
|
|
|
} /* file_length_fd */
|
|
|
|
|
2007-11-03 10:46:57 +00:00
|
|
|
|
2007-05-14 09:55:24 +00:00
|
|
|
[+ ESAC +]
|
|
|
|
|