Chris@0: /* Chris@0: ** Copyright (C) 2002-2011 Erik de Castro Lopo Chris@0: ** Chris@0: ** This program is free software; you can redistribute it and/or modify Chris@0: ** it under the terms of the GNU General Public License as published by Chris@0: ** the Free Software Foundation; either version 2 of the License, or Chris@0: ** (at your option) any later version. Chris@0: ** Chris@0: ** This program is distributed in the hope that it will be useful, Chris@0: ** but WITHOUT ANY WARRANTY; without even the implied warranty of Chris@0: ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Chris@0: ** GNU General Public License for more details. Chris@0: ** Chris@0: ** You should have received a copy of the GNU General Public License Chris@0: ** along with this program; if not, write to the Free Software Chris@0: ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. Chris@0: */ Chris@0: Chris@0: /* Chris@0: ** Utility functions to make writing the test suite easier. Chris@0: ** Chris@0: ** The .c and .h files were generated automagically with Autogen from Chris@0: ** the files utils.def and utils.tpl. Chris@0: */ Chris@0: Chris@0: Chris@0: Chris@0: #include "sfconfig.h" Chris@0: Chris@0: #include Chris@0: #include Chris@0: #include Chris@0: Chris@0: #if HAVE_UNISTD_H Chris@0: #include Chris@0: #endif Chris@0: Chris@0: #if (HAVE_DECL_S_IRGRP == 0) Chris@0: #include Chris@0: #endif Chris@0: Chris@0: #include Chris@0: #include Chris@0: #include Chris@0: #include Chris@0: #include Chris@0: #include Chris@0: Chris@0: #include Chris@0: Chris@0: #include "utils.h" Chris@0: Chris@0: #ifndef M_PI Chris@0: #define M_PI 3.14159265358979323846264338 Chris@0: #endif Chris@0: Chris@0: #define LOG_BUFFER_SIZE 2048 Chris@0: Chris@0: /* Chris@0: ** Neat solution to the Win32/OS2 binary file flage requirement. Chris@0: ** If O_BINARY isn't already defined by the inclusion of the system Chris@0: ** headers, set it to zero. Chris@0: */ Chris@0: #ifndef O_BINARY Chris@0: #define O_BINARY 0 Chris@0: #endif Chris@0: Chris@0: Chris@0: void Chris@0: gen_windowed_sine_float (float *data, int len, double maximum) Chris@0: { int k ; Chris@0: Chris@0: memset (data, 0, len * sizeof (float)) ; Chris@0: /* Chris@0: ** Choose a frequency of 1/32 so that it aligns perfectly with a DFT Chris@0: ** bucket to minimise spreading of energy over more than one bucket. Chris@0: ** Also do not want to make the frequency too high as some of the Chris@0: ** codecs (ie gsm610) have a quite severe high frequency roll off. Chris@0: */ Chris@0: len /= 2 ; Chris@0: Chris@0: for (k = 0 ; k < len ; k++) Chris@0: { data [k] = sin (2.0 * k * M_PI * 1.0 / 32.0 + 0.4) ; Chris@0: Chris@0: /* Apply Hanning Window. */ Chris@0: data [k] *= maximum * (0.5 - 0.5 * cos (2.0 * M_PI * k / ((len) - 1))) ; Chris@0: } Chris@0: Chris@0: return ; Chris@0: } /* gen_windowed_sine_float */ Chris@0: Chris@0: void Chris@0: gen_windowed_sine_double (double *data, int len, double maximum) Chris@0: { int k ; Chris@0: Chris@0: memset (data, 0, len * sizeof (double)) ; Chris@0: /* Chris@0: ** Choose a frequency of 1/32 so that it aligns perfectly with a DFT Chris@0: ** bucket to minimise spreading of energy over more than one bucket. Chris@0: ** Also do not want to make the frequency too high as some of the Chris@0: ** codecs (ie gsm610) have a quite severe high frequency roll off. Chris@0: */ Chris@0: len /= 2 ; Chris@0: Chris@0: for (k = 0 ; k < len ; k++) Chris@0: { data [k] = sin (2.0 * k * M_PI * 1.0 / 32.0 + 0.4) ; Chris@0: Chris@0: /* Apply Hanning Window. */ Chris@0: data [k] *= maximum * (0.5 - 0.5 * cos (2.0 * M_PI * k / ((len) - 1))) ; Chris@0: } Chris@0: Chris@0: return ; Chris@0: } /* gen_windowed_sine_double */ Chris@0: Chris@0: Chris@0: void Chris@0: create_short_sndfile (const char *filename, int format, int channels) Chris@0: { short data [2 * 3 * 4 * 5 * 6 * 7] = { 0, } ; Chris@0: SNDFILE *file ; Chris@0: SF_INFO sfinfo ; Chris@0: Chris@0: sfinfo.samplerate = 44100 ; Chris@0: sfinfo.channels = channels ; Chris@0: sfinfo.format = format ; Chris@0: Chris@0: if ((file = sf_open (filename, SFM_WRITE, &sfinfo)) == NULL) Chris@0: { printf ("Error (%s, %d) : sf_open failed : %s\n", __FILE__, __LINE__, sf_strerror (file)) ; Chris@0: exit (1) ; Chris@0: } ; Chris@0: Chris@0: sf_write_short (file, data, ARRAY_LEN (data)) ; Chris@0: Chris@0: sf_close (file) ; Chris@0: } /* create_short_sndfile */ Chris@0: Chris@0: void Chris@0: check_file_hash_or_die (const char *filename, uint64_t target_hash, int line_num) Chris@0: { static unsigned char buf [4096] ; Chris@0: uint64_t cksum ; Chris@0: FILE *file ; Chris@0: int k, read_count ; Chris@0: Chris@0: memset (buf, 0, sizeof (buf)) ; Chris@0: Chris@0: /* The 'b' in the mode string means binary for Win32. */ Chris@0: if ((file = fopen (filename, "rb")) == NULL) Chris@0: { printf ("\n\nLine %d: could not open file '%s'\n\n", line_num, filename) ; Chris@0: exit (1) ; Chris@0: } ; Chris@0: Chris@0: cksum = 0 ; Chris@0: Chris@0: while ((read_count = fread (buf, 1, sizeof (buf), file))) Chris@0: for (k = 0 ; k < read_count ; k++) Chris@0: cksum = cksum * 511 + buf [k] ; Chris@0: Chris@0: fclose (file) ; Chris@0: Chris@0: if (target_hash == 0) Chris@0: { printf (" 0x%016" PRIx64 "\n", cksum) ; Chris@0: return ; Chris@0: } ; Chris@0: Chris@0: if (cksum != target_hash) Chris@0: { printf ("\n\nLine %d: incorrect hash value 0x%016" PRIx64 " should be 0x%016" PRIx64 ".\n\n", line_num, cksum, target_hash) ; Chris@0: exit (1) ; Chris@0: } ; Chris@0: Chris@0: return ; Chris@0: } /* check_file_hash_or_die */ Chris@0: Chris@0: void Chris@0: print_test_name (const char *test, const char *filename) Chris@0: { int count ; Chris@0: Chris@0: if (test == NULL) Chris@0: { printf (__FILE__ ": bad test of filename parameter.\n") ; Chris@0: exit (1) ; Chris@0: } ; Chris@0: Chris@0: if (filename == NULL || strlen (filename) == 0) Chris@0: { printf (" %-30s : ", test) ; Chris@0: count = 25 ; Chris@0: } Chris@0: else Chris@0: { printf (" %-30s : %s ", test, filename) ; Chris@0: count = 24 - strlen (filename) ; Chris@0: } ; Chris@0: Chris@0: while (count -- > 0) Chris@0: putchar ('.') ; Chris@0: putchar (' ') ; Chris@0: Chris@0: fflush (stdout) ; Chris@0: } /* print_test_name */ Chris@0: Chris@0: void Chris@0: dump_data_to_file (const char *filename, const void *data, unsigned int datalen) Chris@0: { FILE *file ; Chris@0: Chris@0: if ((file = fopen (filename, "wb")) == NULL) Chris@0: { printf ("\n\nLine %d : could not open file : %s\n\n", __LINE__, filename) ; Chris@0: exit (1) ; Chris@0: } ; Chris@0: Chris@0: if (fwrite (data, 1, datalen, file) != datalen) Chris@0: { printf ("\n\nLine %d : fwrite failed.\n\n", __LINE__) ; Chris@0: exit (1) ; Chris@0: } ; Chris@0: Chris@0: fclose (file) ; Chris@0: Chris@0: } /* dump_data_to_file */ Chris@0: Chris@0: /*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Chris@0: */ Chris@0: Chris@0: static char octfilename [] = "error.dat" ; Chris@0: Chris@0: int Chris@0: oct_save_short (const short *a, const short *b, int len) Chris@0: { FILE *file ; Chris@0: int k ; Chris@0: Chris@0: if (! (file = fopen (octfilename, "w"))) Chris@0: return 1 ; Chris@0: Chris@0: fprintf (file, "# Not created by Octave\n") ; Chris@0: Chris@0: fprintf (file, "# name: a\n") ; Chris@0: fprintf (file, "# type: matrix\n") ; Chris@0: fprintf (file, "# rows: %d\n", len) ; Chris@0: fprintf (file, "# columns: 1\n") ; Chris@0: Chris@0: for (k = 0 ; k < len ; k++) Chris@0: fprintf (file, "% d" "\n", a [k]) ; Chris@0: Chris@0: fprintf (file, "# name: b\n") ; Chris@0: fprintf (file, "# type: matrix\n") ; Chris@0: fprintf (file, "# rows: %d\n", len) ; Chris@0: fprintf (file, "# columns: 1\n") ; Chris@0: Chris@0: for (k = 0 ; k < len ; k++) Chris@0: fprintf (file, "% d" "\n", b [k]) ; Chris@0: Chris@0: fclose (file) ; Chris@0: return 0 ; Chris@0: } /* oct_save_short */ Chris@0: int Chris@0: oct_save_int (const int *a, const int *b, int len) Chris@0: { FILE *file ; Chris@0: int k ; Chris@0: Chris@0: if (! (file = fopen (octfilename, "w"))) Chris@0: return 1 ; Chris@0: Chris@0: fprintf (file, "# Not created by Octave\n") ; Chris@0: Chris@0: fprintf (file, "# name: a\n") ; Chris@0: fprintf (file, "# type: matrix\n") ; Chris@0: fprintf (file, "# rows: %d\n", len) ; Chris@0: fprintf (file, "# columns: 1\n") ; Chris@0: Chris@0: for (k = 0 ; k < len ; k++) Chris@0: fprintf (file, "% d" "\n", a [k]) ; Chris@0: Chris@0: fprintf (file, "# name: b\n") ; Chris@0: fprintf (file, "# type: matrix\n") ; Chris@0: fprintf (file, "# rows: %d\n", len) ; Chris@0: fprintf (file, "# columns: 1\n") ; Chris@0: Chris@0: for (k = 0 ; k < len ; k++) Chris@0: fprintf (file, "% d" "\n", b [k]) ; Chris@0: Chris@0: fclose (file) ; Chris@0: return 0 ; Chris@0: } /* oct_save_int */ Chris@0: int Chris@0: oct_save_float (const float *a, const float *b, int len) Chris@0: { FILE *file ; Chris@0: int k ; Chris@0: Chris@0: if (! (file = fopen (octfilename, "w"))) Chris@0: return 1 ; Chris@0: Chris@0: fprintf (file, "# Not created by Octave\n") ; Chris@0: Chris@0: fprintf (file, "# name: a\n") ; Chris@0: fprintf (file, "# type: matrix\n") ; Chris@0: fprintf (file, "# rows: %d\n", len) ; Chris@0: fprintf (file, "# columns: 1\n") ; Chris@0: Chris@0: for (k = 0 ; k < len ; k++) Chris@0: fprintf (file, "% g" "\n", a [k]) ; Chris@0: Chris@0: fprintf (file, "# name: b\n") ; Chris@0: fprintf (file, "# type: matrix\n") ; Chris@0: fprintf (file, "# rows: %d\n", len) ; Chris@0: fprintf (file, "# columns: 1\n") ; Chris@0: Chris@0: for (k = 0 ; k < len ; k++) Chris@0: fprintf (file, "% g" "\n", b [k]) ; Chris@0: Chris@0: fclose (file) ; Chris@0: return 0 ; Chris@0: } /* oct_save_float */ Chris@0: int Chris@0: oct_save_double (const double *a, const double *b, int len) Chris@0: { FILE *file ; Chris@0: int k ; Chris@0: Chris@0: if (! (file = fopen (octfilename, "w"))) Chris@0: return 1 ; Chris@0: Chris@0: fprintf (file, "# Not created by Octave\n") ; Chris@0: Chris@0: fprintf (file, "# name: a\n") ; Chris@0: fprintf (file, "# type: matrix\n") ; Chris@0: fprintf (file, "# rows: %d\n", len) ; Chris@0: fprintf (file, "# columns: 1\n") ; Chris@0: Chris@0: for (k = 0 ; k < len ; k++) Chris@0: fprintf (file, "% g" "\n", a [k]) ; Chris@0: Chris@0: fprintf (file, "# name: b\n") ; Chris@0: fprintf (file, "# type: matrix\n") ; Chris@0: fprintf (file, "# rows: %d\n", len) ; Chris@0: fprintf (file, "# columns: 1\n") ; Chris@0: Chris@0: for (k = 0 ; k < len ; k++) Chris@0: fprintf (file, "% g" "\n", b [k]) ; Chris@0: Chris@0: fclose (file) ; Chris@0: return 0 ; Chris@0: } /* oct_save_double */ Chris@0: Chris@0: Chris@0: void Chris@0: check_log_buffer_or_die (SNDFILE *file, int line_num) Chris@0: { static char buffer [LOG_BUFFER_SIZE] ; Chris@0: int count ; Chris@0: Chris@0: memset (buffer, 0, sizeof (buffer)) ; Chris@0: Chris@0: /* Get the log buffer data. */ Chris@0: count = sf_command (file, SFC_GET_LOG_INFO, buffer, LOG_BUFFER_SIZE) ; Chris@0: Chris@0: if (LOG_BUFFER_SIZE - count < 2) Chris@0: { printf ("\n\nLine %d : Possible long log buffer.\n", line_num) ; Chris@0: exit (1) ; Chris@0: } Chris@0: Chris@0: /* Look for "Should" */ Chris@0: if (strstr (buffer, "ould")) Chris@0: { printf ("\n\nLine %d : Log buffer contains `ould'. Dumping.\n", line_num) ; Chris@0: puts (buffer) ; Chris@0: exit (1) ; Chris@0: } ; Chris@0: Chris@0: /* Look for "**" */ Chris@0: if (strstr (buffer, "*")) Chris@0: { printf ("\n\nLine %d : Log buffer contains `*'. Dumping.\n", line_num) ; Chris@0: puts (buffer) ; Chris@0: exit (1) ; Chris@0: } ; Chris@0: Chris@0: /* Look for "Should" */ Chris@0: if (strstr (buffer, "nknown marker")) Chris@0: { printf ("\n\nLine %d : Log buffer contains `nknown marker'. Dumping.\n", line_num) ; Chris@0: puts (buffer) ; Chris@0: exit (1) ; Chris@0: } ; Chris@0: Chris@0: return ; Chris@0: } /* check_log_buffer_or_die */ Chris@0: Chris@0: int Chris@0: string_in_log_buffer (SNDFILE *file, const char *s) Chris@0: { static char buffer [LOG_BUFFER_SIZE] ; Chris@0: int count ; Chris@0: Chris@0: memset (buffer, 0, sizeof (buffer)) ; Chris@0: Chris@0: /* Get the log buffer data. */ Chris@0: count = sf_command (file, SFC_GET_LOG_INFO, buffer, LOG_BUFFER_SIZE) ; Chris@0: Chris@0: if (LOG_BUFFER_SIZE - count < 2) Chris@0: { printf ("Possible long log buffer.\n") ; Chris@0: exit (1) ; Chris@0: } Chris@0: Chris@0: /* Look for string */ Chris@0: return strstr (buffer, s) ? SF_TRUE : SF_FALSE ; Chris@0: } /* string_in_log_buffer */ Chris@0: Chris@0: void Chris@0: hexdump_file (const char * filename, sf_count_t offset, sf_count_t length) Chris@0: { Chris@0: FILE * file ; Chris@0: char buffer [16] ; Chris@0: int k, m, ch, readcount ; Chris@0: Chris@0: if (length > 1000000) Chris@0: { printf ("\n\nError : length (%ld) too long.\n\n", SF_COUNT_TO_LONG (offset)) ; Chris@0: exit (1) ; Chris@0: } ; Chris@0: Chris@0: if ((file = fopen (filename, "r")) == NULL) Chris@0: { printf ("\n\nError : hexdump_file (%s) could not open file for read.\n\n", filename) ; Chris@0: exit (1) ; Chris@0: } ; Chris@0: Chris@0: if (fseek (file, offset, SEEK_SET) != 0) Chris@0: { printf ("\n\nError : fseek(file, %ld, SEEK_SET) failed : %s\n\n", SF_COUNT_TO_LONG (offset), strerror (errno)) ; Chris@0: exit (1) ; Chris@0: } ; Chris@0: Chris@0: puts ("\n\n") ; Chris@0: Chris@0: for (k = 0 ; k < length ; k+= sizeof (buffer)) Chris@0: { readcount = fread (buffer, 1, sizeof (buffer), file) ; Chris@0: Chris@0: printf ("%08lx : ", SF_COUNT_TO_LONG (offset + k)) ; Chris@0: Chris@0: for (m = 0 ; m < readcount ; m++) Chris@0: printf ("%02x ", buffer [m] & 0xFF) ; Chris@0: Chris@0: for (m = readcount ; m < SIGNED_SIZEOF (buffer) ; m++) Chris@0: printf (" ") ; Chris@0: Chris@0: printf (" ") ; Chris@0: for (m = 0 ; m < readcount ; m++) Chris@0: { ch = isprint (buffer [m]) ? buffer [m] : '.' ; Chris@0: putchar (ch) ; Chris@0: } ; Chris@0: Chris@0: if (readcount < SIGNED_SIZEOF (buffer)) Chris@0: break ; Chris@0: Chris@0: putchar ('\n') ; Chris@0: } ; Chris@0: Chris@0: puts ("\n") ; Chris@0: Chris@0: fclose (file) ; Chris@0: } /* hexdump_file */ Chris@0: Chris@0: void Chris@0: dump_log_buffer (SNDFILE *file) Chris@0: { static char buffer [LOG_BUFFER_SIZE] ; Chris@0: Chris@0: memset (buffer, 0, sizeof (buffer)) ; Chris@0: Chris@0: /* Get the log buffer data. */ Chris@0: sf_command (file, SFC_GET_LOG_INFO, buffer, LOG_BUFFER_SIZE) ; Chris@0: Chris@0: if (strlen (buffer) < 1) Chris@0: puts ("Log buffer empty.\n") ; Chris@0: else Chris@0: puts (buffer) ; Chris@0: Chris@0: return ; Chris@0: } /* dump_log_buffer */ Chris@0: Chris@0: SNDFILE * Chris@0: test_open_file_or_die (const char *filename, int mode, SF_INFO *sfinfo, int allow_fd, int line_num) Chris@0: { static int count = 0 ; Chris@0: Chris@0: SNDFILE *file ; Chris@0: const char *modestr, *func_name ; Chris@0: int oflags = 0, omode = 0, err ; Chris@0: Chris@0: /* Chris@0: ** Need to test both sf_open() and sf_open_fd(). Chris@0: ** Do so alternately. Chris@0: */ Chris@0: switch (mode) Chris@0: { case SFM_READ : Chris@0: modestr = "SFM_READ" ; Chris@0: oflags = O_RDONLY | O_BINARY ; Chris@0: omode = 0 ; Chris@0: break ; Chris@0: Chris@0: case SFM_WRITE : Chris@0: modestr = "SFM_WRITE" ; Chris@0: oflags = O_WRONLY | O_CREAT | O_TRUNC | O_BINARY ; Chris@0: omode = S_IRUSR | S_IWUSR | S_IRGRP ; Chris@0: break ; Chris@0: Chris@0: case SFM_RDWR : Chris@0: modestr = "SFM_RDWR" ; Chris@0: oflags = O_RDWR | O_CREAT | O_BINARY ; Chris@0: omode = S_IRUSR | S_IWUSR | S_IRGRP ; Chris@0: break ; Chris@0: default : Chris@0: printf ("\n\nLine %d: Bad mode.\n", line_num) ; Chris@0: fflush (stdout) ; Chris@0: exit (1) ; Chris@0: } ; Chris@0: Chris@0: if (OS_IS_WIN32) Chris@0: { /* Windows does not understand and ignores the S_IRGRP flag, but Wine Chris@0: ** gives a run time warning message, so just clear it. Chris@0: */ Chris@0: omode &= ~S_IRGRP ; Chris@0: } ; Chris@0: Chris@0: if (allow_fd && ((++count) & 1) == 1) Chris@0: { int fd ; Chris@0: Chris@0: /* Only use the three argument open() function if omode != 0. */ Chris@0: fd = (omode == 0) ? open (filename, oflags) : open (filename, oflags, omode) ; Chris@0: Chris@0: if (fd < 0) Chris@0: { printf ("\n\n%s : open failed : %s\n", __func__, strerror (errno)) ; Chris@0: exit (1) ; Chris@0: } ; Chris@0: Chris@0: func_name = "sf_open_fd" ; Chris@0: file = sf_open_fd (fd, mode, sfinfo, SF_TRUE) ; Chris@0: } Chris@0: else Chris@0: { func_name = "sf_open" ; Chris@0: file = sf_open (filename, mode, sfinfo) ; Chris@0: } ; Chris@0: Chris@0: if (file == NULL) Chris@0: { printf ("\n\nLine %d: %s (%s) failed : %s\n\n", line_num, func_name, modestr, sf_strerror (NULL)) ; Chris@0: dump_log_buffer (file) ; Chris@0: exit (1) ; Chris@0: } ; Chris@0: Chris@0: err = sf_error (file) ; Chris@0: if (err != SF_ERR_NO_ERROR) Chris@0: { printf ("\n\nLine %d : sf_error : %s\n\n", line_num, sf_error_number (err)) ; Chris@0: dump_log_buffer (file) ; Chris@0: exit (1) ; Chris@0: } ; Chris@0: Chris@0: return file ; Chris@0: } /* test_open_file_or_die */ Chris@0: Chris@0: void Chris@0: test_read_write_position_or_die (SNDFILE *file, int line_num, int pass, sf_count_t read_pos, sf_count_t write_pos) Chris@0: { sf_count_t pos ; Chris@0: Chris@0: /* Check the current read position. */ Chris@0: if (read_pos >= 0 && (pos = sf_seek (file, 0, SEEK_CUR | SFM_READ)) != read_pos) Chris@0: { printf ("\n\nLine %d ", line_num) ; Chris@0: if (pass > 0) Chris@0: printf ("(pass %d): ", pass) ; Chris@0: printf ("Read position (%ld) should be %ld.\n", SF_COUNT_TO_LONG (pos), SF_COUNT_TO_LONG (read_pos)) ; Chris@0: exit (1) ; Chris@0: } ; Chris@0: Chris@0: /* Check the current write position. */ Chris@0: if (write_pos >= 0 && (pos = sf_seek (file, 0, SEEK_CUR | SFM_WRITE)) != write_pos) Chris@0: { printf ("\n\nLine %d", line_num) ; Chris@0: if (pass > 0) Chris@0: printf (" (pass %d)", pass) ; Chris@0: printf (" : Write position (%ld) should be %ld.\n", Chris@0: SF_COUNT_TO_LONG (pos), SF_COUNT_TO_LONG (write_pos)) ; Chris@0: exit (1) ; Chris@0: } ; Chris@0: Chris@0: return ; Chris@0: } /* test_read_write_position */ Chris@0: Chris@0: void Chris@0: test_seek_or_die (SNDFILE *file, sf_count_t offset, int whence, sf_count_t new_pos, int channels, int line_num) Chris@0: { sf_count_t position ; Chris@0: const char *channel_name, *whence_name ; Chris@0: Chris@0: switch (whence) Chris@0: { case SEEK_SET : Chris@0: whence_name = "SEEK_SET" ; Chris@0: break ; Chris@0: case SEEK_CUR : Chris@0: whence_name = "SEEK_CUR" ; Chris@0: break ; Chris@0: case SEEK_END : Chris@0: whence_name = "SEEK_END" ; Chris@0: break ; Chris@0: Chris@0: /* SFM_READ */ Chris@0: case SEEK_SET | SFM_READ : Chris@0: whence_name = "SFM_READ | SEEK_SET" ; Chris@0: break ; Chris@0: case SEEK_CUR | SFM_READ : Chris@0: whence_name = "SFM_READ | SEEK_CUR" ; Chris@0: break ; Chris@0: case SEEK_END | SFM_READ : Chris@0: whence_name = "SFM_READ | SEEK_END" ; Chris@0: break ; Chris@0: Chris@0: /* SFM_WRITE */ Chris@0: case SEEK_SET | SFM_WRITE : Chris@0: whence_name = "SFM_WRITE | SEEK_SET" ; Chris@0: break ; Chris@0: case SEEK_CUR | SFM_WRITE : Chris@0: whence_name = "SFM_WRITE | SEEK_CUR" ; Chris@0: break ; Chris@0: case SEEK_END | SFM_WRITE : Chris@0: whence_name = "SFM_WRITE | SEEK_END" ; Chris@0: break ; Chris@0: Chris@0: default : Chris@0: printf ("\n\nLine %d: bad whence parameter.\n", line_num) ; Chris@0: exit (1) ; Chris@0: } ; Chris@0: Chris@0: channel_name = (channels == 1) ? "Mono" : "Stereo" ; Chris@0: Chris@0: if ((position = sf_seek (file, offset, whence)) != new_pos) Chris@0: { printf ("\n\nLine %d : %s : sf_seek (file, %ld, %s) returned %ld (should be %ld).\n\n", Chris@0: line_num, channel_name, SF_COUNT_TO_LONG (offset), whence_name, Chris@0: SF_COUNT_TO_LONG (position), SF_COUNT_TO_LONG (new_pos)) ; Chris@0: exit (1) ; Chris@0: } ; Chris@0: Chris@0: } /* test_seek_or_die */ Chris@0: Chris@0: Chris@0: Chris@0: void Chris@0: test_read_short_or_die (SNDFILE *file, int pass, short *test, sf_count_t items, int line_num) Chris@0: { sf_count_t count ; Chris@0: Chris@0: if ((count = sf_read_short (file, test, items)) != items) Chris@0: { printf ("\n\nLine %d", line_num) ; Chris@0: if (pass > 0) Chris@0: printf (" (pass %d)", pass) ; Chris@0: printf (" : sf_read_short failed with short read (%ld => %ld).\n", Chris@0: SF_COUNT_TO_LONG (items), SF_COUNT_TO_LONG (count)) ; Chris@0: fflush (stdout) ; Chris@0: puts (sf_strerror (file)) ; Chris@0: exit (1) ; Chris@0: } ; Chris@0: Chris@0: return ; Chris@0: } /* test_read_short_or_die */ Chris@0: Chris@0: void Chris@0: test_read_int_or_die (SNDFILE *file, int pass, int *test, sf_count_t items, int line_num) Chris@0: { sf_count_t count ; Chris@0: Chris@0: if ((count = sf_read_int (file, test, items)) != items) Chris@0: { printf ("\n\nLine %d", line_num) ; Chris@0: if (pass > 0) Chris@0: printf (" (pass %d)", pass) ; Chris@0: printf (" : sf_read_int failed with short read (%ld => %ld).\n", Chris@0: SF_COUNT_TO_LONG (items), SF_COUNT_TO_LONG (count)) ; Chris@0: fflush (stdout) ; Chris@0: puts (sf_strerror (file)) ; Chris@0: exit (1) ; Chris@0: } ; Chris@0: Chris@0: return ; Chris@0: } /* test_read_int_or_die */ Chris@0: Chris@0: void Chris@0: test_read_float_or_die (SNDFILE *file, int pass, float *test, sf_count_t items, int line_num) Chris@0: { sf_count_t count ; Chris@0: Chris@0: if ((count = sf_read_float (file, test, items)) != items) Chris@0: { printf ("\n\nLine %d", line_num) ; Chris@0: if (pass > 0) Chris@0: printf (" (pass %d)", pass) ; Chris@0: printf (" : sf_read_float failed with short read (%ld => %ld).\n", Chris@0: SF_COUNT_TO_LONG (items), SF_COUNT_TO_LONG (count)) ; Chris@0: fflush (stdout) ; Chris@0: puts (sf_strerror (file)) ; Chris@0: exit (1) ; Chris@0: } ; Chris@0: Chris@0: return ; Chris@0: } /* test_read_float_or_die */ Chris@0: Chris@0: void Chris@0: test_read_double_or_die (SNDFILE *file, int pass, double *test, sf_count_t items, int line_num) Chris@0: { sf_count_t count ; Chris@0: Chris@0: if ((count = sf_read_double (file, test, items)) != items) Chris@0: { printf ("\n\nLine %d", line_num) ; Chris@0: if (pass > 0) Chris@0: printf (" (pass %d)", pass) ; Chris@0: printf (" : sf_read_double failed with short read (%ld => %ld).\n", Chris@0: SF_COUNT_TO_LONG (items), SF_COUNT_TO_LONG (count)) ; Chris@0: fflush (stdout) ; Chris@0: puts (sf_strerror (file)) ; Chris@0: exit (1) ; Chris@0: } ; Chris@0: Chris@0: return ; Chris@0: } /* test_read_double_or_die */ Chris@0: Chris@0: Chris@0: void Chris@0: test_readf_short_or_die (SNDFILE *file, int pass, short *test, sf_count_t frames, int line_num) Chris@0: { sf_count_t count ; Chris@0: Chris@0: if ((count = sf_readf_short (file, test, frames)) != frames) Chris@0: { printf ("\n\nLine %d", line_num) ; Chris@0: if (pass > 0) Chris@0: printf (" (pass %d)", pass) ; Chris@0: printf (" : sf_readf_short failed with short readf (%ld => %ld).\n", Chris@0: SF_COUNT_TO_LONG (frames), SF_COUNT_TO_LONG (count)) ; Chris@0: fflush (stdout) ; Chris@0: puts (sf_strerror (file)) ; Chris@0: exit (1) ; Chris@0: } ; Chris@0: Chris@0: return ; Chris@0: } /* test_readf_short_or_die */ Chris@0: Chris@0: void Chris@0: test_readf_int_or_die (SNDFILE *file, int pass, int *test, sf_count_t frames, int line_num) Chris@0: { sf_count_t count ; Chris@0: Chris@0: if ((count = sf_readf_int (file, test, frames)) != frames) Chris@0: { printf ("\n\nLine %d", line_num) ; Chris@0: if (pass > 0) Chris@0: printf (" (pass %d)", pass) ; Chris@0: printf (" : sf_readf_int failed with short readf (%ld => %ld).\n", Chris@0: SF_COUNT_TO_LONG (frames), SF_COUNT_TO_LONG (count)) ; Chris@0: fflush (stdout) ; Chris@0: puts (sf_strerror (file)) ; Chris@0: exit (1) ; Chris@0: } ; Chris@0: Chris@0: return ; Chris@0: } /* test_readf_int_or_die */ Chris@0: Chris@0: void Chris@0: test_readf_float_or_die (SNDFILE *file, int pass, float *test, sf_count_t frames, int line_num) Chris@0: { sf_count_t count ; Chris@0: Chris@0: if ((count = sf_readf_float (file, test, frames)) != frames) Chris@0: { printf ("\n\nLine %d", line_num) ; Chris@0: if (pass > 0) Chris@0: printf (" (pass %d)", pass) ; Chris@0: printf (" : sf_readf_float failed with short readf (%ld => %ld).\n", Chris@0: SF_COUNT_TO_LONG (frames), SF_COUNT_TO_LONG (count)) ; Chris@0: fflush (stdout) ; Chris@0: puts (sf_strerror (file)) ; Chris@0: exit (1) ; Chris@0: } ; Chris@0: Chris@0: return ; Chris@0: } /* test_readf_float_or_die */ Chris@0: Chris@0: void Chris@0: test_readf_double_or_die (SNDFILE *file, int pass, double *test, sf_count_t frames, int line_num) Chris@0: { sf_count_t count ; Chris@0: Chris@0: if ((count = sf_readf_double (file, test, frames)) != frames) Chris@0: { printf ("\n\nLine %d", line_num) ; Chris@0: if (pass > 0) Chris@0: printf (" (pass %d)", pass) ; Chris@0: printf (" : sf_readf_double failed with short readf (%ld => %ld).\n", Chris@0: SF_COUNT_TO_LONG (frames), SF_COUNT_TO_LONG (count)) ; Chris@0: fflush (stdout) ; Chris@0: puts (sf_strerror (file)) ; Chris@0: exit (1) ; Chris@0: } ; Chris@0: Chris@0: return ; Chris@0: } /* test_readf_double_or_die */ Chris@0: Chris@0: Chris@0: void Chris@0: test_read_raw_or_die (SNDFILE *file, int pass, void *test, sf_count_t items, int line_num) Chris@0: { sf_count_t count ; Chris@0: Chris@0: if ((count = sf_read_raw (file, test, items)) != items) Chris@0: { printf ("\n\nLine %d", line_num) ; Chris@0: if (pass > 0) Chris@0: printf (" (pass %d)", pass) ; Chris@0: printf (" : sf_read_raw failed with short read (%ld => %ld).\n", Chris@0: SF_COUNT_TO_LONG (items), SF_COUNT_TO_LONG (count)) ; Chris@0: fflush (stdout) ; Chris@0: puts (sf_strerror (file)) ; Chris@0: exit (1) ; Chris@0: } ; Chris@0: Chris@0: return ; Chris@0: } /* test_read_raw_or_die */ Chris@0: Chris@0: Chris@0: Chris@0: void Chris@0: test_write_short_or_die (SNDFILE *file, int pass, const short *test, sf_count_t items, int line_num) Chris@0: { sf_count_t count ; Chris@0: Chris@0: if ((count = sf_write_short (file, test, items)) != items) Chris@0: { printf ("\n\nLine %d", line_num) ; Chris@0: if (pass > 0) Chris@0: printf (" (pass %d)", pass) ; Chris@0: printf (" : sf_write_short failed with short write (%ld => %ld).\n", Chris@0: SF_COUNT_TO_LONG (items), SF_COUNT_TO_LONG (count)) ; Chris@0: fflush (stdout) ; Chris@0: puts (sf_strerror (file)) ; Chris@0: exit (1) ; Chris@0: } ; Chris@0: Chris@0: return ; Chris@0: } /* test_write_short_or_die */ Chris@0: Chris@0: void Chris@0: test_write_int_or_die (SNDFILE *file, int pass, const int *test, sf_count_t items, int line_num) Chris@0: { sf_count_t count ; Chris@0: Chris@0: if ((count = sf_write_int (file, test, items)) != items) Chris@0: { printf ("\n\nLine %d", line_num) ; Chris@0: if (pass > 0) Chris@0: printf (" (pass %d)", pass) ; Chris@0: printf (" : sf_write_int failed with short write (%ld => %ld).\n", Chris@0: SF_COUNT_TO_LONG (items), SF_COUNT_TO_LONG (count)) ; Chris@0: fflush (stdout) ; Chris@0: puts (sf_strerror (file)) ; Chris@0: exit (1) ; Chris@0: } ; Chris@0: Chris@0: return ; Chris@0: } /* test_write_int_or_die */ Chris@0: Chris@0: void Chris@0: test_write_float_or_die (SNDFILE *file, int pass, const float *test, sf_count_t items, int line_num) Chris@0: { sf_count_t count ; Chris@0: Chris@0: if ((count = sf_write_float (file, test, items)) != items) Chris@0: { printf ("\n\nLine %d", line_num) ; Chris@0: if (pass > 0) Chris@0: printf (" (pass %d)", pass) ; Chris@0: printf (" : sf_write_float failed with short write (%ld => %ld).\n", Chris@0: SF_COUNT_TO_LONG (items), SF_COUNT_TO_LONG (count)) ; Chris@0: fflush (stdout) ; Chris@0: puts (sf_strerror (file)) ; Chris@0: exit (1) ; Chris@0: } ; Chris@0: Chris@0: return ; Chris@0: } /* test_write_float_or_die */ Chris@0: Chris@0: void Chris@0: test_write_double_or_die (SNDFILE *file, int pass, const double *test, sf_count_t items, int line_num) Chris@0: { sf_count_t count ; Chris@0: Chris@0: if ((count = sf_write_double (file, test, items)) != items) Chris@0: { printf ("\n\nLine %d", line_num) ; Chris@0: if (pass > 0) Chris@0: printf (" (pass %d)", pass) ; Chris@0: printf (" : sf_write_double failed with short write (%ld => %ld).\n", Chris@0: SF_COUNT_TO_LONG (items), SF_COUNT_TO_LONG (count)) ; Chris@0: fflush (stdout) ; Chris@0: puts (sf_strerror (file)) ; Chris@0: exit (1) ; Chris@0: } ; Chris@0: Chris@0: return ; Chris@0: } /* test_write_double_or_die */ Chris@0: Chris@0: Chris@0: void Chris@0: test_writef_short_or_die (SNDFILE *file, int pass, const short *test, sf_count_t frames, int line_num) Chris@0: { sf_count_t count ; Chris@0: Chris@0: if ((count = sf_writef_short (file, test, frames)) != frames) Chris@0: { printf ("\n\nLine %d", line_num) ; Chris@0: if (pass > 0) Chris@0: printf (" (pass %d)", pass) ; Chris@0: printf (" : sf_writef_short failed with short writef (%ld => %ld).\n", Chris@0: SF_COUNT_TO_LONG (frames), SF_COUNT_TO_LONG (count)) ; Chris@0: fflush (stdout) ; Chris@0: puts (sf_strerror (file)) ; Chris@0: exit (1) ; Chris@0: } ; Chris@0: Chris@0: return ; Chris@0: } /* test_writef_short_or_die */ Chris@0: Chris@0: void Chris@0: test_writef_int_or_die (SNDFILE *file, int pass, const int *test, sf_count_t frames, int line_num) Chris@0: { sf_count_t count ; Chris@0: Chris@0: if ((count = sf_writef_int (file, test, frames)) != frames) Chris@0: { printf ("\n\nLine %d", line_num) ; Chris@0: if (pass > 0) Chris@0: printf (" (pass %d)", pass) ; Chris@0: printf (" : sf_writef_int failed with short writef (%ld => %ld).\n", Chris@0: SF_COUNT_TO_LONG (frames), SF_COUNT_TO_LONG (count)) ; Chris@0: fflush (stdout) ; Chris@0: puts (sf_strerror (file)) ; Chris@0: exit (1) ; Chris@0: } ; Chris@0: Chris@0: return ; Chris@0: } /* test_writef_int_or_die */ Chris@0: Chris@0: void Chris@0: test_writef_float_or_die (SNDFILE *file, int pass, const float *test, sf_count_t frames, int line_num) Chris@0: { sf_count_t count ; Chris@0: Chris@0: if ((count = sf_writef_float (file, test, frames)) != frames) Chris@0: { printf ("\n\nLine %d", line_num) ; Chris@0: if (pass > 0) Chris@0: printf (" (pass %d)", pass) ; Chris@0: printf (" : sf_writef_float failed with short writef (%ld => %ld).\n", Chris@0: SF_COUNT_TO_LONG (frames), SF_COUNT_TO_LONG (count)) ; Chris@0: fflush (stdout) ; Chris@0: puts (sf_strerror (file)) ; Chris@0: exit (1) ; Chris@0: } ; Chris@0: Chris@0: return ; Chris@0: } /* test_writef_float_or_die */ Chris@0: Chris@0: void Chris@0: test_writef_double_or_die (SNDFILE *file, int pass, const double *test, sf_count_t frames, int line_num) Chris@0: { sf_count_t count ; Chris@0: Chris@0: if ((count = sf_writef_double (file, test, frames)) != frames) Chris@0: { printf ("\n\nLine %d", line_num) ; Chris@0: if (pass > 0) Chris@0: printf (" (pass %d)", pass) ; Chris@0: printf (" : sf_writef_double failed with short writef (%ld => %ld).\n", Chris@0: SF_COUNT_TO_LONG (frames), SF_COUNT_TO_LONG (count)) ; Chris@0: fflush (stdout) ; Chris@0: puts (sf_strerror (file)) ; Chris@0: exit (1) ; Chris@0: } ; Chris@0: Chris@0: return ; Chris@0: } /* test_writef_double_or_die */ Chris@0: Chris@0: Chris@0: void Chris@0: test_write_raw_or_die (SNDFILE *file, int pass, const void *test, sf_count_t items, int line_num) Chris@0: { sf_count_t count ; Chris@0: Chris@0: if ((count = sf_write_raw (file, test, items)) != items) Chris@0: { printf ("\n\nLine %d", line_num) ; Chris@0: if (pass > 0) Chris@0: printf (" (pass %d)", pass) ; Chris@0: printf (" : sf_write_raw failed with short write (%ld => %ld).\n", Chris@0: SF_COUNT_TO_LONG (items), SF_COUNT_TO_LONG (count)) ; Chris@0: fflush (stdout) ; Chris@0: puts (sf_strerror (file)) ; Chris@0: exit (1) ; Chris@0: } ; Chris@0: Chris@0: return ; Chris@0: } /* test_write_raw_or_die */ Chris@0: Chris@0: Chris@0: void Chris@0: compare_short_or_die (const short *left, const short *right, unsigned count, int line_num) Chris@0: { Chris@0: unsigned k ; Chris@0: Chris@0: for (k = 0 ; k < count ;k++) Chris@0: if (left [k] != right [k]) Chris@0: { printf ("\n\nLine %d : Error at index %d, " "% d" " should be " "% d" ".\n\n", line_num, k, left [k], right [k]) ; Chris@0: exit (1) ; Chris@0: } ; Chris@0: Chris@0: return ; Chris@0: } /* compare_short_or_die */ Chris@0: void Chris@0: compare_int_or_die (const int *left, const int *right, unsigned count, int line_num) Chris@0: { Chris@0: unsigned k ; Chris@0: Chris@0: for (k = 0 ; k < count ;k++) Chris@0: if (left [k] != right [k]) Chris@0: { printf ("\n\nLine %d : Error at index %d, " "% d" " should be " "% d" ".\n\n", line_num, k, left [k], right [k]) ; Chris@0: exit (1) ; Chris@0: } ; Chris@0: Chris@0: return ; Chris@0: } /* compare_int_or_die */ Chris@0: void Chris@0: compare_float_or_die (const float *left, const float *right, unsigned count, int line_num) Chris@0: { Chris@0: unsigned k ; Chris@0: Chris@0: for (k = 0 ; k < count ;k++) Chris@0: if (left [k] != right [k]) Chris@0: { printf ("\n\nLine %d : Error at index %d, " "% g" " should be " "% g" ".\n\n", line_num, k, left [k], right [k]) ; Chris@0: exit (1) ; Chris@0: } ; Chris@0: Chris@0: return ; Chris@0: } /* compare_float_or_die */ Chris@0: void Chris@0: compare_double_or_die (const double *left, const double *right, unsigned count, int line_num) Chris@0: { Chris@0: unsigned k ; Chris@0: Chris@0: for (k = 0 ; k < count ;k++) Chris@0: if (left [k] != right [k]) Chris@0: { printf ("\n\nLine %d : Error at index %d, " "% g" " should be " "% g" ".\n\n", line_num, k, left [k], right [k]) ; Chris@0: exit (1) ; Chris@0: } ; Chris@0: Chris@0: return ; Chris@0: } /* compare_double_or_die */ Chris@0: Chris@0: Chris@0: Chris@0: void Chris@0: delete_file (int format, const char *filename) Chris@0: { char rsrc_name [512], *fname ; Chris@0: Chris@0: unlink (filename) ; Chris@0: Chris@0: if ((format & SF_FORMAT_TYPEMASK) != SF_FORMAT_SD2) Chris@0: return ; Chris@0: Chris@0: /* Chris@0: ** Now try for a resource fork stored as a separate file. Chris@0: ** Grab the un-adulterated filename again. Chris@0: */ Chris@0: snprintf (rsrc_name, sizeof (rsrc_name), "%s", filename) ; Chris@0: Chris@0: if ((fname = strrchr (rsrc_name, '/')) != NULL) Chris@0: fname ++ ; Chris@0: else if ((fname = strrchr (rsrc_name, '\\')) != NULL) Chris@0: fname ++ ; Chris@0: else Chris@0: fname = rsrc_name ; Chris@0: Chris@0: memmove (fname + 2, fname, strlen (fname) + 1) ; Chris@0: fname [0] = '.' ; Chris@0: fname [1] = '_' ; Chris@0: Chris@0: unlink (rsrc_name) ; Chris@0: } /* delete_file */ Chris@0: Chris@0: static int allowed_open_files = -1 ; Chris@0: Chris@0: void Chris@0: count_open_files (void) Chris@0: { Chris@0: #if OS_IS_WIN32 Chris@0: return ; Chris@0: #else Chris@0: int k, count = 0 ; Chris@0: struct stat statbuf ; Chris@0: Chris@0: if (allowed_open_files > 0) Chris@0: return ; Chris@0: Chris@0: for (k = 0 ; k < 1024 ; k++) Chris@0: if (fstat (k, &statbuf) == 0) Chris@0: count ++ ; Chris@0: Chris@0: allowed_open_files = count ; Chris@0: #endif Chris@0: } /* count_open_files */ Chris@0: Chris@0: void Chris@0: increment_open_file_count (void) Chris@0: { allowed_open_files ++ ; Chris@0: } /* increment_open_file_count */ Chris@0: Chris@0: void Chris@0: check_open_file_count_or_die (int lineno) Chris@0: { Chris@0: #if OS_IS_WIN32 Chris@0: lineno = 0 ; Chris@0: return ; Chris@0: #else Chris@0: int k, count = 0 ; Chris@0: struct stat statbuf ; Chris@0: Chris@0: if (allowed_open_files < 0) Chris@0: count_open_files () ; Chris@0: Chris@0: for (k = 0 ; k < 1024 ; k++) Chris@0: if (fstat (k, &statbuf) == 0) Chris@0: count ++ ; Chris@0: Chris@0: if (count > allowed_open_files) Chris@0: { printf ("\nLine %d : number of open files (%d) > allowed (%d).\n\n", lineno, count, allowed_open_files) ; Chris@0: exit (1) ; Chris@0: } ; Chris@0: #endif Chris@0: } /* check_open_file_count_or_die */ Chris@0: Chris@0: void Chris@0: write_mono_file (const char * filename, int format, int srate, float * output, int len) Chris@0: { SNDFILE * file ; Chris@0: SF_INFO sfinfo ; Chris@0: Chris@0: memset (&sfinfo, 0, sizeof (sfinfo)) ; Chris@0: Chris@0: sfinfo.samplerate = srate ; Chris@0: sfinfo.channels = 1 ; Chris@0: sfinfo.format = format ; Chris@0: Chris@0: if ((file = sf_open (filename, SFM_WRITE, &sfinfo)) == NULL) Chris@0: { printf ("sf_open (%s) : %s\n", filename, sf_strerror (NULL)) ; Chris@0: exit (1) ; Chris@0: } ; Chris@0: Chris@0: sf_write_float (file, output, len) ; Chris@0: Chris@0: sf_close (file) ; Chris@0: } /* write_mono_file */ Chris@0: Chris@0: void Chris@0: gen_lowpass_noise_float (float *data, int len) Chris@0: { int32_t value = 0x1243456 ; Chris@0: double sample, last_val = 0.0 ; Chris@0: int k ; Chris@0: Chris@0: for (k = 0 ; k < len ; k++) Chris@0: { /* Not a crypto quality RNG. */ Chris@0: value = 11117 * value + 211231 ; Chris@0: value = 11117 * value + 211231 ; Chris@0: value = 11117 * value + 211231 ; Chris@0: Chris@0: sample = value / (0x7fffffff * 1.000001) ; Chris@0: sample = 0.2 * sample - 0.9 * last_val ; Chris@0: Chris@0: data [k] = last_val = sample ; Chris@0: } ; Chris@0: Chris@0: } /* gen_lowpass_noise_float */ Chris@0: Chris@0: Chris@0: /* Chris@0: ** Windows is fucked. Chris@0: ** If a file is opened R/W and data is written to it, then fstat will return Chris@0: ** the correct file length, but stat will return zero. Chris@0: */ Chris@0: Chris@0: sf_count_t Chris@0: file_length (const char * fname) Chris@0: { struct stat data ; Chris@0: Chris@0: if (stat (fname, &data) != 0) Chris@0: return 0 ; Chris@0: Chris@0: return (sf_count_t) data.st_size ; Chris@0: } /* file_length */ Chris@0: Chris@0: sf_count_t Chris@0: file_length_fd (int fd) Chris@0: { struct stat data ; Chris@0: Chris@0: memset (&data, 0, sizeof (data)) ; Chris@0: if (fstat (fd, &data) != 0) Chris@0: return 0 ; Chris@0: Chris@0: return (sf_count_t) data.st_size ; Chris@0: } /* file_length_fd */ Chris@0: Chris@0: Chris@0: Chris@0: