mirror of
https://github.com/cookiengineer/audacity
synced 2025-11-21 16:37:12 +01:00
Update libsndfile to 1.0.29pre2+git
This pulls in MANY (over 890) changes compared to our from our current 1.0.24 version.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
** Copyright (C) 2001-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
|
||||
** Copyright (C) 2001-2019 Erik de Castro Lopo <erikd@mega-nerd.com>
|
||||
**
|
||||
** 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
|
||||
@@ -20,28 +20,36 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <inttypes.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
#if HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#else
|
||||
#include "sf_unistd.h"
|
||||
#endif
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include <sndfile.h>
|
||||
|
||||
#include "sfendian.h"
|
||||
#include "utils.h"
|
||||
|
||||
#define BUFFER_LEN (1<<10)
|
||||
#define BUFFER_LEN (1 << 10)
|
||||
#define LOG_BUFFER_SIZE 1024
|
||||
#define data_MARKER MAKE_MARKER ('d', 'a', 't', 'a')
|
||||
|
||||
static void float_norm_test (const char *filename) ;
|
||||
static void double_norm_test (const char *filename) ;
|
||||
static void format_tests (void) ;
|
||||
static void calc_peak_test (int filetype, const char *filename) ;
|
||||
static void calc_peak_test (int filetype, const char *filename, int channels) ;
|
||||
static void truncate_test (const char *filename, int filetype) ;
|
||||
static void instrument_test (const char *filename, int filetype) ;
|
||||
static void cue_test (const char *filename, int filetype) ;
|
||||
static void cue_test_var (const char *filename, int filetype, int count) ;
|
||||
static void channel_map_test (const char *filename, int filetype) ;
|
||||
static void current_sf_info_test (const char *filename) ;
|
||||
static void raw_needs_endswap_test (const char *filename, int filetype) ;
|
||||
@@ -51,6 +59,10 @@ static void broadcast_rdwr_test (const char *filename, int filetype) ;
|
||||
static void broadcast_coding_history_test (const char *filename) ;
|
||||
static void broadcast_coding_history_size (const char *filename) ;
|
||||
|
||||
/* Cart Chunk tests */
|
||||
static void cart_test (const char *filename, int filetype) ;
|
||||
static void cart_rdwr_test (const char *filename, int filetype) ;
|
||||
|
||||
/* Force the start of this buffer to be double aligned. Sparc-solaris will
|
||||
** choke if its not.
|
||||
*/
|
||||
@@ -73,15 +85,17 @@ main (int argc, char *argv [])
|
||||
printf (" peak - test peak calculation\n") ;
|
||||
printf (" trunc - test file truncation\n") ;
|
||||
printf (" inst - test set/get of SF_INSTRUMENT.\n") ;
|
||||
printf (" cue - test set/get of SF_CUES.\n") ;
|
||||
printf (" chanmap - test set/get of channel map data..\n") ;
|
||||
printf (" bext - test set/get of SF_BROADCAST_INFO.\n") ;
|
||||
printf (" bextch - test set/get of SF_BROADCAST_INFO coding_history.\n") ;
|
||||
printf (" cart - test set/get of SF_CART_INFO.\n") ;
|
||||
printf (" rawend - test SFC_RAW_NEEDS_ENDSWAP.\n") ;
|
||||
printf (" all - perform all tests\n") ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
do_all =! strcmp (argv [1], "all") ;
|
||||
do_all = ! strcmp (argv [1], "all") ;
|
||||
|
||||
if (do_all || strcmp (argv [1], "ver") == 0)
|
||||
{ char buffer [128] ;
|
||||
@@ -107,8 +121,10 @@ main (int argc, char *argv [])
|
||||
} ;
|
||||
|
||||
if (do_all || strcmp (argv [1], "peak") == 0)
|
||||
{ calc_peak_test (SF_ENDIAN_BIG | SF_FORMAT_RAW, "be-peak.raw") ;
|
||||
calc_peak_test (SF_ENDIAN_LITTLE | SF_FORMAT_RAW, "le-peak.raw") ;
|
||||
{ calc_peak_test (SF_ENDIAN_BIG | SF_FORMAT_RAW, "be-peak.raw", 1) ;
|
||||
calc_peak_test (SF_ENDIAN_LITTLE | SF_FORMAT_RAW, "le-peak.raw", 1) ;
|
||||
calc_peak_test (SF_ENDIAN_BIG | SF_FORMAT_RAW, "be-peak.raw", 7) ;
|
||||
calc_peak_test (SF_ENDIAN_LITTLE | SF_FORMAT_RAW, "le-peak.raw", 7) ;
|
||||
test_count ++ ;
|
||||
} ;
|
||||
|
||||
@@ -125,11 +141,27 @@ main (int argc, char *argv [])
|
||||
|
||||
if (do_all || strcmp (argv [1], "inst") == 0)
|
||||
{ instrument_test ("instrument.wav", SF_FORMAT_WAV | SF_FORMAT_PCM_16) ;
|
||||
instrument_test ("instrument.aiff" , SF_FORMAT_AIFF | SF_FORMAT_PCM_24) ;
|
||||
/*-instrument_test ("instrument.aiff" , SF_FORMAT_AIFF | SF_FORMAT_PCM_24) ;-*/
|
||||
/*-instrument_test ("instrument.xi", SF_FORMAT_XI | SF_FORMAT_DPCM_16) ;-*/
|
||||
test_count ++ ;
|
||||
} ;
|
||||
|
||||
if (do_all || strcmp (argv [1], "cue") == 0)
|
||||
{ /* 2500 is close to the largest number of cues possible because of block sizes (enforced in aiff.c, wav.c) */
|
||||
int cuecounts [] = { 0, 1, 10, 100, 101, 1000, 1001, 2500 } ;
|
||||
unsigned int i ;
|
||||
|
||||
cue_test ("cue.wav", SF_FORMAT_WAV | SF_FORMAT_PCM_16) ;
|
||||
cue_test ("cue.aiff" , SF_FORMAT_AIFF | SF_FORMAT_PCM_24) ;
|
||||
|
||||
for (i = 0 ; i < ARRAY_LEN (cuecounts) ; i++)
|
||||
{ cue_test_var ("cue.wav", SF_FORMAT_WAV | SF_FORMAT_PCM_16, cuecounts [i]) ;
|
||||
cue_test_var ("cue.aiff", SF_FORMAT_AIFF | SF_FORMAT_PCM_24, cuecounts [i]) ;
|
||||
} ;
|
||||
|
||||
test_count ++ ;
|
||||
} ;
|
||||
|
||||
if (do_all || strcmp (argv [1], "current_sf_info") == 0)
|
||||
{ current_sf_info_test ("current.wav") ;
|
||||
test_count ++ ;
|
||||
@@ -147,6 +179,14 @@ main (int argc, char *argv [])
|
||||
test_count ++ ;
|
||||
} ;
|
||||
|
||||
if (do_all || strcmp (argv [1], "cart") == 0)
|
||||
{ cart_test ("cart.wav", SF_FORMAT_WAV | SF_FORMAT_PCM_16) ;
|
||||
cart_rdwr_test ("cart.wav", SF_FORMAT_WAV | SF_FORMAT_PCM_16) ;
|
||||
cart_test ("cart.rf64", SF_FORMAT_RF64 | SF_FORMAT_PCM_16) ;
|
||||
cart_rdwr_test ("cart.rf64", SF_FORMAT_RF64 | SF_FORMAT_PCM_16) ;
|
||||
test_count ++ ;
|
||||
} ;
|
||||
|
||||
if (do_all || strcmp (argv [1], "bextch") == 0)
|
||||
{ broadcast_coding_history_test ("coding_history.wav") ;
|
||||
broadcast_coding_history_size ("coding_hist_size.wav") ;
|
||||
@@ -241,7 +281,7 @@ float_norm_test (const char *filename)
|
||||
} ;
|
||||
|
||||
if (sfinfo.frames != BUFFER_LEN)
|
||||
{ printf ("\n\nLine %d: Incorrect number of.frames in file. (%d => %ld)\n", __LINE__, BUFFER_LEN, SF_COUNT_TO_LONG (sfinfo.frames)) ;
|
||||
{ printf ("\n\nLine %d: Incorrect number of.frames in file. (%d => %" PRId64 ")\n", __LINE__, BUFFER_LEN, sfinfo.frames) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
@@ -357,7 +397,7 @@ double_norm_test (const char *filename)
|
||||
} ;
|
||||
|
||||
if (sfinfo.frames != BUFFER_LEN)
|
||||
{ printf ("\n\nLine %d: Incorrect number of.frames in file. (%d => %ld)\n", __LINE__, BUFFER_LEN, SF_COUNT_TO_LONG (sfinfo.frames)) ;
|
||||
{ printf ("\n\nLine %d: Incorrect number of.frames in file. (%d => %" PRId64 ")\n", __LINE__, BUFFER_LEN, sfinfo.frames) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
@@ -513,28 +553,34 @@ format_tests (void)
|
||||
} /* format_tests */
|
||||
|
||||
static void
|
||||
calc_peak_test (int filetype, const char *filename)
|
||||
calc_peak_test (int filetype, const char *filename, int channels)
|
||||
{ SNDFILE *file ;
|
||||
SF_INFO sfinfo ;
|
||||
char label [128] ;
|
||||
int k, format ;
|
||||
sf_count_t buffer_len, frame_count ;
|
||||
double peak ;
|
||||
|
||||
print_test_name ("calc_peak_test", filename) ;
|
||||
snprintf (label, sizeof (label), "calc_peak_test (%d channels)", channels) ;
|
||||
print_test_name (label, filename) ;
|
||||
|
||||
format = (filetype | SF_FORMAT_PCM_16) ;
|
||||
format = filetype | SF_FORMAT_PCM_16 ;
|
||||
|
||||
buffer_len = BUFFER_LEN - (BUFFER_LEN % channels) ;
|
||||
frame_count = buffer_len / channels ;
|
||||
|
||||
sfinfo.samplerate = 44100 ;
|
||||
sfinfo.format = format ;
|
||||
sfinfo.channels = 1 ;
|
||||
sfinfo.frames = BUFFER_LEN ;
|
||||
sfinfo.channels = channels ;
|
||||
sfinfo.frames = frame_count ;
|
||||
|
||||
/* Create double_data with max value of 0.5. */
|
||||
for (k = 0 ; k < BUFFER_LEN ; k++)
|
||||
double_data [k] = (k + 1) / (2.0 * BUFFER_LEN) ;
|
||||
for (k = 0 ; k < buffer_len ; k++)
|
||||
double_data [k] = (k + 1) / (2.0 * buffer_len) ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
|
||||
|
||||
test_write_double_or_die (file, 0, double_data, BUFFER_LEN, __LINE__) ;
|
||||
test_writef_double_or_die (file, 0, double_data, frame_count, __LINE__) ;
|
||||
|
||||
sf_close (file) ;
|
||||
|
||||
@@ -545,12 +591,12 @@ calc_peak_test (int filetype, const char *filename)
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (sfinfo.frames != BUFFER_LEN)
|
||||
{ printf ("\n\nLine %d: Incorrect number of.frames in file. (%d => %ld)\n", __LINE__, BUFFER_LEN, SF_COUNT_TO_LONG (sfinfo.frames)) ;
|
||||
if (sfinfo.frames != frame_count)
|
||||
{ printf ("\n\nLine %d: Incorrect number of frames in file. (%" PRId64 " => %" PRId64 ")\n", __LINE__, frame_count, sfinfo.frames) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (sfinfo.channels != 1)
|
||||
if (sfinfo.channels != channels)
|
||||
{ printf ("Line %d: Incorrect number of channels in file.\n", __LINE__) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
@@ -572,16 +618,16 @@ calc_peak_test (int filetype, const char *filename)
|
||||
format = (filetype | SF_FORMAT_FLOAT) ;
|
||||
sfinfo.samplerate = 44100 ;
|
||||
sfinfo.format = format ;
|
||||
sfinfo.channels = 1 ;
|
||||
sfinfo.frames = BUFFER_LEN ;
|
||||
sfinfo.channels = channels ;
|
||||
sfinfo.frames = frame_count ;
|
||||
|
||||
/* Create double_data with max value of 0.5. */
|
||||
for (k = 0 ; k < BUFFER_LEN ; k++)
|
||||
double_data [k] = (k + 1) / (2.0 * BUFFER_LEN) ;
|
||||
for (k = 0 ; k < buffer_len ; k++)
|
||||
double_data [k] = (k + 1) / (2.0 * buffer_len) ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
|
||||
|
||||
test_write_double_or_die (file, 0, double_data, BUFFER_LEN, __LINE__) ;
|
||||
test_writef_double_or_die (file, 0, double_data, frame_count, __LINE__) ;
|
||||
|
||||
sf_close (file) ;
|
||||
|
||||
@@ -592,12 +638,12 @@ calc_peak_test (int filetype, const char *filename)
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (sfinfo.frames != BUFFER_LEN)
|
||||
{ printf ("\n\nLine %d: Incorrect number of.frames in file. (%d => %ld)\n", __LINE__, BUFFER_LEN, SF_COUNT_TO_LONG (sfinfo.frames)) ;
|
||||
if (sfinfo.frames != frame_count)
|
||||
{ printf ("\n\nLine %d: Incorrect number of.frames in file. (%" PRId64 " => %" PRId64 ")\n", __LINE__, frame_count, sfinfo.frames) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
if (sfinfo.channels != 1)
|
||||
if (sfinfo.channels != channels)
|
||||
{ printf ("Line %d: Incorrect number of channels in file.\n", __LINE__) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
@@ -699,8 +745,8 @@ instrument_test (const char *filename, int filetype)
|
||||
}
|
||||
} ;
|
||||
SF_INSTRUMENT read_inst ;
|
||||
SNDFILE *file ;
|
||||
SF_INFO sfinfo ;
|
||||
SNDFILE *file ;
|
||||
SF_INFO sfinfo ;
|
||||
|
||||
print_test_name ("instrument_test", filename) ;
|
||||
|
||||
@@ -733,7 +779,6 @@ instrument_test (const char *filename, int filetype)
|
||||
** write_inst struct to hold the default value that the WAV
|
||||
** module should hold.
|
||||
*/
|
||||
write_inst.detune = 0 ;
|
||||
write_inst.key_lo = write_inst.velocity_lo = 0 ;
|
||||
write_inst.key_hi = write_inst.velocity_hi = 127 ;
|
||||
write_inst.gain = 1 ;
|
||||
@@ -801,11 +846,214 @@ instrument_test (const char *filename, int filetype)
|
||||
puts ("ok") ;
|
||||
} /* instrument_test */
|
||||
|
||||
static void
|
||||
print_cue (SF_CUES *cue, int i)
|
||||
{
|
||||
printf (" indx[%d] : %d\n"
|
||||
" position : %u\n"
|
||||
" fcc_chunk : %x\n"
|
||||
" chunk_start : %d\n"
|
||||
" block_start : %d\n"
|
||||
" sample_offset : %u\n"
|
||||
" name : %s\n",
|
||||
i,
|
||||
cue->cue_points [i].indx,
|
||||
cue->cue_points [i].position,
|
||||
cue->cue_points [i].fcc_chunk,
|
||||
cue->cue_points [i].chunk_start,
|
||||
cue->cue_points [i].block_start,
|
||||
cue->cue_points [i].sample_offset,
|
||||
cue->cue_points [i].name) ;
|
||||
}
|
||||
|
||||
static int
|
||||
cue_compare (SF_CUES *write_cue, SF_CUES *read_cue, size_t cue_size, int line)
|
||||
{
|
||||
if (memcmp (write_cue, read_cue, cue_size) != 0)
|
||||
{
|
||||
printf ("\n\nLine %d : cue comparison failed.\n\n", line) ;
|
||||
printf ("W Cue count : %d\n", write_cue->cue_count) ;
|
||||
if (write_cue->cue_count > 0)
|
||||
print_cue (write_cue, 0) ;
|
||||
if (write_cue->cue_count > 2) /* print last if at least 2 */
|
||||
print_cue (write_cue, write_cue->cue_count - 1) ;
|
||||
|
||||
printf ("R Cue count : %d\n", read_cue->cue_count) ;
|
||||
if (read_cue->cue_count > 0)
|
||||
print_cue (read_cue, 0) ;
|
||||
if (read_cue->cue_count > 2) /* print last if at least 2 */
|
||||
print_cue (read_cue, read_cue->cue_count - 1) ;
|
||||
|
||||
return SF_FALSE ;
|
||||
} ;
|
||||
|
||||
return SF_TRUE ;
|
||||
} /* cue_compare */
|
||||
|
||||
static void
|
||||
cue_rw_test (const char *filename)
|
||||
{ SNDFILE *sndfile ;
|
||||
SF_INFO sfinfo ;
|
||||
SF_CUES cues ;
|
||||
memset (&sfinfo, 0, sizeof (SF_INFO)) ;
|
||||
|
||||
sndfile = test_open_file_or_die (filename, SFM_RDWR, &sfinfo, SF_FALSE, __LINE__) ;
|
||||
|
||||
exit_if_true (
|
||||
sf_command (sndfile, SFC_GET_CUE_COUNT, &cues.cue_count, sizeof (cues.cue_count)) != SF_TRUE,
|
||||
"\nLine %d: SFC_GET_CUE_COUNT command failed.\n\n", __LINE__
|
||||
) ;
|
||||
|
||||
exit_if_true (
|
||||
cues.cue_count != 3,
|
||||
"\nLine %d: Expected cue_count (%u) to be 3.\n\n", __LINE__, cues.cue_count
|
||||
) ;
|
||||
|
||||
if (sf_command (sndfile, SFC_GET_CUE, &cues, sizeof (cues)) == SF_TRUE)
|
||||
{ cues.cue_points [1].sample_offset = 3 ;
|
||||
|
||||
if (sf_command (sndfile, SFC_SET_CUE, &cues, sizeof (cues)) == SF_TRUE)
|
||||
printf ("Sucess: [%s] updated\n", filename) ;
|
||||
else
|
||||
printf ("Error: SFC_SET_CUE on [%s] [%s]\n", filename, sf_strerror (sndfile)) ;
|
||||
}
|
||||
else
|
||||
printf ("Error: SFC_GET_CUE on [%s] [%s]\n", filename, sf_strerror (sndfile)) ;
|
||||
|
||||
|
||||
if (sf_command (sndfile, SFC_UPDATE_HEADER_NOW, NULL, 0) != 0)
|
||||
printf ("Error: SFC_UPDATE_HEADER_NOW on [%s] [%s]\n", filename, sf_strerror (sndfile)) ;
|
||||
|
||||
sf_write_sync (sndfile) ;
|
||||
sf_close (sndfile) ;
|
||||
|
||||
return ;
|
||||
} /* cue_rw_test */
|
||||
|
||||
static void
|
||||
cue_test (const char *filename, int filetype)
|
||||
{ SF_CUES write_cue ;
|
||||
SF_CUES read_cue ;
|
||||
SNDFILE *file ;
|
||||
SF_INFO sfinfo ;
|
||||
|
||||
if (filetype == (SF_FORMAT_WAV | SF_FORMAT_PCM_16))
|
||||
{ write_cue = (SF_CUES)
|
||||
{ 2, /* cue_count */
|
||||
{ { 1, 0, data_MARKER, 0, 0, 1, "" },
|
||||
{ 2, 0, data_MARKER, 0, 0, 2, "" },
|
||||
}
|
||||
} ;
|
||||
}
|
||||
else
|
||||
{ write_cue = (SF_CUES)
|
||||
{ 2, /* cue_count */
|
||||
{ { 1, 0, data_MARKER, 0, 0, 1, "Cue1" },
|
||||
{ 2, 0, data_MARKER, 0, 0, 2, "Cue2" },
|
||||
}
|
||||
} ;
|
||||
}
|
||||
|
||||
print_test_name ("cue_test", filename) ;
|
||||
|
||||
sfinfo.samplerate = 11025 ;
|
||||
sfinfo.format = filetype ;
|
||||
sfinfo.channels = 1 ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
|
||||
if (sf_command (file, SFC_SET_CUE, &write_cue, sizeof (write_cue)) == SF_FALSE)
|
||||
{ printf ("\n\nLine %d : sf_command (SFC_SET_CUE) failed.\n\n", __LINE__) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
test_write_double_or_die (file, 0, double_data, BUFFER_LEN, __LINE__) ;
|
||||
sf_close (file) ;
|
||||
|
||||
memset (&read_cue, 0, sizeof (read_cue)) ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
|
||||
if (sf_command (file, SFC_GET_CUE, &read_cue, sizeof (read_cue)) == SF_FALSE)
|
||||
{ printf ("\n\nLine %d : sf_command (SFC_GET_CUE) failed.\n\n", __LINE__) ;
|
||||
exit (1) ;
|
||||
return ;
|
||||
} ;
|
||||
check_log_buffer_or_die (file, __LINE__) ;
|
||||
sf_close (file) ;
|
||||
|
||||
if (cue_compare (&write_cue, &read_cue, sizeof (write_cue), __LINE__) == SF_FALSE)
|
||||
exit (1) ;
|
||||
|
||||
if (0) cue_rw_test (filename) ;
|
||||
|
||||
unlink (filename) ;
|
||||
puts ("ok") ;
|
||||
} /* cue_test */
|
||||
|
||||
/* calculate size of SF_CUES struct given number of cues */
|
||||
#define SF_CUES_SIZE(count) (sizeof (uint32_t) + sizeof (SF_CUE_POINT) * (count))
|
||||
|
||||
static void
|
||||
cue_test_var (const char *filename, int filetype, int count)
|
||||
{ size_t cues_size = SF_CUES_SIZE (count) ;
|
||||
SF_CUES *write_cue = calloc (1, cues_size) ;
|
||||
SF_CUES *read_cue = calloc (1, cues_size) ;
|
||||
SNDFILE *file ;
|
||||
SF_INFO sfinfo ;
|
||||
char name [40] ;
|
||||
int i ;
|
||||
|
||||
snprintf (name, sizeof (name), "cue_test_var %d", count) ;
|
||||
print_test_name (name, filename) ;
|
||||
|
||||
if (write_cue == NULL || read_cue == NULL)
|
||||
{ printf ("ok (can't alloc)\n") ;
|
||||
return ;
|
||||
} ;
|
||||
|
||||
write_cue->cue_count = count ;
|
||||
for (i = 0 ; i < count ; i++)
|
||||
{ write_cue->cue_points [i] = (SF_CUE_POINT) { i, 0, data_MARKER, 0, 0, i, "" } ;
|
||||
if (filetype == (SF_FORMAT_AIFF | SF_FORMAT_PCM_24))
|
||||
snprintf (write_cue->cue_points [i].name, sizeof (write_cue->cue_points [i].name), "Cue%03d", i) ;
|
||||
} ;
|
||||
|
||||
sfinfo.samplerate = 11025 ;
|
||||
sfinfo.format = filetype ;
|
||||
sfinfo.channels = 1 ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
|
||||
if (sf_command (file, SFC_SET_CUE, write_cue, cues_size) == SF_FALSE)
|
||||
{ printf ("\n\nLine %d : sf_command (SFC_SET_CUE) failed with %d cues, datasize %zu --> error: %s\n\n", __LINE__, count, cues_size, sf_strerror (file)) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
test_write_double_or_die (file, 0, double_data, BUFFER_LEN, __LINE__) ;
|
||||
sf_close (file) ;
|
||||
|
||||
memset (read_cue, 0, cues_size) ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
|
||||
|
||||
if (sf_command (file, SFC_GET_CUE, read_cue, cues_size) == SF_FALSE)
|
||||
{ printf ("\n\nLine %d : sf_command (SFC_GET_CUE) failed with %d cues, datasize %zu --> error: %s\n\n", __LINE__, count, cues_size, sf_strerror (file)) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
check_log_buffer_or_die (file, __LINE__) ;
|
||||
sf_close (file) ;
|
||||
|
||||
if (cue_compare (write_cue, read_cue, cues_size, __LINE__) == SF_FALSE)
|
||||
{ printf ("\n\nLine %d : cue_compare failed.\n\n", __LINE__) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
|
||||
free (write_cue) ;
|
||||
free (read_cue) ;
|
||||
unlink (filename) ;
|
||||
puts ("ok") ;
|
||||
} /* cue_test_var */
|
||||
|
||||
static void
|
||||
current_sf_info_test (const char *filename)
|
||||
{ SNDFILE *outfile, *infile ;
|
||||
SF_INFO outinfo, ininfo ;
|
||||
sf_count_t last_count ;
|
||||
|
||||
print_test_name ("current_sf_info_test", filename) ;
|
||||
|
||||
@@ -825,23 +1073,21 @@ current_sf_info_test (const char *filename)
|
||||
sf_command (outfile, SFC_GET_CURRENT_SF_INFO, &outinfo, sizeof (outinfo)) ;
|
||||
|
||||
exit_if_true (outinfo.frames != BUFFER_LEN,
|
||||
"\n\nLine %d : Initial sfinfo.frames (%ld) should be %d.\n\n", __LINE__,
|
||||
SF_COUNT_TO_LONG (outinfo.frames), BUFFER_LEN
|
||||
"\n\nLine %d : Initial sfinfo.frames (%" PRId64 ") should be %d.\n\n", __LINE__,
|
||||
outinfo.frames, BUFFER_LEN
|
||||
) ;
|
||||
|
||||
/* Read file making sure no channel map exists. */
|
||||
memset (&ininfo, 0, sizeof (ininfo)) ;
|
||||
infile = test_open_file_or_die (filename, SFM_READ, &ininfo, SF_TRUE, __LINE__) ;
|
||||
|
||||
last_count = ininfo.frames ;
|
||||
|
||||
test_write_double_or_die (outfile, 0, double_data, BUFFER_LEN, __LINE__) ;
|
||||
|
||||
sf_command (infile, SFC_GET_CURRENT_SF_INFO, &ininfo, sizeof (ininfo)) ;
|
||||
|
||||
exit_if_true (ininfo.frames != BUFFER_LEN,
|
||||
"\n\nLine %d : Initial sfinfo.frames (%ld) should be %d.\n\n", __LINE__,
|
||||
SF_COUNT_TO_LONG (ininfo.frames), BUFFER_LEN
|
||||
"\n\nLine %d : Initial sfinfo.frames (%" PRId64 ") should be %d.\n\n", __LINE__,
|
||||
ininfo.frames, BUFFER_LEN
|
||||
) ;
|
||||
|
||||
sf_close (outfile) ;
|
||||
@@ -854,12 +1100,13 @@ current_sf_info_test (const char *filename)
|
||||
static void
|
||||
broadcast_test (const char *filename, int filetype)
|
||||
{ static SF_BROADCAST_INFO bc_write, bc_read ;
|
||||
SNDFILE *file ;
|
||||
SF_INFO sfinfo ;
|
||||
SNDFILE *file ;
|
||||
SF_INFO sfinfo ;
|
||||
int errors = 0 ;
|
||||
|
||||
print_test_name ("broadcast_test", filename) ;
|
||||
|
||||
memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
||||
sfinfo.samplerate = 11025 ;
|
||||
sfinfo.format = filetype ;
|
||||
sfinfo.channels = 1 ;
|
||||
@@ -893,7 +1140,7 @@ broadcast_test (const char *filename, int filetype)
|
||||
check_log_buffer_or_die (file, __LINE__) ;
|
||||
sf_close (file) ;
|
||||
|
||||
if (bc_read.version != 1)
|
||||
if (bc_read.version != 2)
|
||||
{ printf ("\n\nLine %d : Read bad version number %d.\n\n", __LINE__, bc_read.version) ;
|
||||
exit (1) ;
|
||||
return ;
|
||||
@@ -970,7 +1217,7 @@ broadcast_rdwr_test (const char *filename, int filetype)
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
|
||||
sf_close (file) ;
|
||||
exit_if_true (frames != sfinfo.frames, "\n\nLine %d : Frame count %lld should be %lld.\n", __LINE__, sfinfo.frames, frames) ;
|
||||
exit_if_true (frames != sfinfo.frames, "\n\nLine %d : Frame count %" PRId64 " should be %" PRId64 ".\n", __LINE__, sfinfo.frames, frames) ;
|
||||
|
||||
unlink (filename) ;
|
||||
puts ("ok") ;
|
||||
@@ -979,8 +1226,8 @@ broadcast_rdwr_test (const char *filename, int filetype)
|
||||
static void
|
||||
check_coding_history_newlines (const char *filename)
|
||||
{ static SF_BROADCAST_INFO bc_write, bc_read ;
|
||||
SNDFILE *file ;
|
||||
SF_INFO sfinfo ;
|
||||
SNDFILE *file ;
|
||||
SF_INFO sfinfo ;
|
||||
unsigned k ;
|
||||
|
||||
sfinfo.samplerate = 22050 ;
|
||||
@@ -1049,8 +1296,8 @@ check_coding_history_newlines (const char *filename)
|
||||
static void
|
||||
broadcast_coding_history_test (const char *filename)
|
||||
{ static SF_BROADCAST_INFO bc_write, bc_read ;
|
||||
SNDFILE *file ;
|
||||
SF_INFO sfinfo ;
|
||||
SNDFILE *file ;
|
||||
SF_INFO sfinfo ;
|
||||
const char *default_history = "A=PCM,F=22050,W=16,M=mono" ;
|
||||
const char *supplied_history =
|
||||
"A=PCM,F=44100,W=24,M=mono,T=other\r\n"
|
||||
@@ -1153,8 +1400,8 @@ broadcast_coding_history_size (const char *filename)
|
||||
{ /* SF_BROADCAST_INFO struct with coding_history field of 1024 bytes. */
|
||||
static SF_BROADCAST_INFO_VAR (1024) bc_write ;
|
||||
static SF_BROADCAST_INFO_VAR (1024) bc_read ;
|
||||
SNDFILE *file ;
|
||||
SF_INFO sfinfo ;
|
||||
SNDFILE *file ;
|
||||
SF_INFO sfinfo ;
|
||||
int k ;
|
||||
|
||||
print_test_name (__func__, filename) ;
|
||||
@@ -1211,13 +1458,225 @@ broadcast_coding_history_size (const char *filename)
|
||||
puts ("ok") ;
|
||||
} /* broadcast_coding_history_size */
|
||||
|
||||
/*==============================================================================
|
||||
*/
|
||||
static void
|
||||
cart_test (const char *filename, int filetype)
|
||||
{ static SF_CART_INFO ca_write, ca_read ;
|
||||
SNDFILE *file ;
|
||||
SF_INFO sfinfo ;
|
||||
int errors = 0 ;
|
||||
|
||||
print_test_name ("cart_test", filename) ;
|
||||
|
||||
memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
||||
sfinfo.samplerate = 11025 ;
|
||||
sfinfo.format = filetype ;
|
||||
sfinfo.channels = 1 ;
|
||||
memset (&ca_write, 0, sizeof (ca_write)) ;
|
||||
|
||||
// example test data
|
||||
snprintf (ca_write.artist, sizeof (ca_write.artist), "Test artist") ;
|
||||
snprintf (ca_write.version, sizeof (ca_write.version), "Test version") ;
|
||||
snprintf (ca_write.cut_id, sizeof (ca_write.cut_id), "Test cut ID") ;
|
||||
snprintf (ca_write.client_id, sizeof (ca_write.client_id), "Test client ID") ;
|
||||
snprintf (ca_write.category, sizeof (ca_write.category), "Test category") ;
|
||||
snprintf (ca_write.classification, sizeof (ca_write.classification), "Test classification") ;
|
||||
snprintf (ca_write.out_cue, sizeof (ca_write.out_cue), "Test out cue") ;
|
||||
snprintf (ca_write.start_date, sizeof (ca_write.start_date), "%d/%02d/%02d", 2006, 3, 30) ;
|
||||
snprintf (ca_write.start_time, sizeof (ca_write.start_time), "%02d:%02d:%02d", 20, 27, 0) ;
|
||||
snprintf (ca_write.end_date, sizeof (ca_write.end_date), "%d/%02d/%02d", 2006, 3, 30) ;
|
||||
snprintf (ca_write.end_time, sizeof (ca_write.end_time), "%02d:%02d:%02d", 20, 27, 0) ;
|
||||
snprintf (ca_write.producer_app_id, sizeof (ca_write.producer_app_id), "Test producer app id") ;
|
||||
snprintf (ca_write.producer_app_version, sizeof (ca_write.producer_app_version), "Test producer app version") ;
|
||||
snprintf (ca_write.user_def, sizeof (ca_write.user_def), "test user def test test") ;
|
||||
ca_write.level_reference = 42 ;
|
||||
snprintf (ca_write.url, sizeof (ca_write.url), "http://www.test.com/test_url") ;
|
||||
snprintf (ca_write.tag_text, sizeof (ca_write.tag_text), "tag text test! \r\n") ; // must be terminated \r\n to be valid
|
||||
ca_write.tag_text_size = strlen (ca_write.tag_text) ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_WRITE, &sfinfo, SF_TRUE, __LINE__) ;
|
||||
if (sf_command (file, SFC_SET_CART_INFO, &ca_write, sizeof (ca_write)) == SF_FALSE)
|
||||
exit (1) ;
|
||||
|
||||
test_write_double_or_die (file, 0, double_data, BUFFER_LEN, __LINE__) ;
|
||||
sf_close (file) ;
|
||||
|
||||
memset (&ca_read, 0, sizeof (ca_read)) ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
|
||||
if (sf_command (file, SFC_GET_CART_INFO, &ca_read, sizeof (ca_read)) == SF_FALSE)
|
||||
{ printf ("\n\nLine %d : sf_command (SFC_GET_CART_INFO) failed.\n\n", __LINE__) ;
|
||||
exit (1) ;
|
||||
return ;
|
||||
} ;
|
||||
check_log_buffer_or_die (file, __LINE__) ;
|
||||
sf_close (file) ;
|
||||
|
||||
|
||||
if (memcmp (ca_write.artist, ca_read.artist, sizeof (ca_write.artist)) != 0)
|
||||
{ printf ("\n\nLine %d : artist mismatch :\n\twrite : '%s'\n\tread : '%s'\n\n", __LINE__, ca_write.artist, ca_read.artist) ;
|
||||
errors ++ ;
|
||||
} ;
|
||||
|
||||
if (memcmp (ca_write.version, ca_read.version, sizeof (ca_write.version)) != 0)
|
||||
{ printf ("\n\nLine %d : version mismatch :\n\twrite : '%s'\n\tread : '%s'\n\n", __LINE__, ca_write.version, ca_read.version) ;
|
||||
errors ++ ;
|
||||
} ;
|
||||
|
||||
if (memcmp (ca_write.title, ca_read.title, sizeof (ca_write.title)) != 0)
|
||||
{ printf ("\n\nLine %d : title mismatch :\n\twrite : '%s'\n\tread : '%s'\n\n", __LINE__, ca_write.title, ca_read.title) ;
|
||||
errors ++ ;
|
||||
} ;
|
||||
|
||||
if (memcmp (ca_write.cut_id, ca_read.cut_id, sizeof (ca_write.cut_id)) != 0)
|
||||
{ printf ("\n\nLine %d : cut_id mismatch :\n\twrite : '%s'\n\tread : '%s'\n\n", __LINE__, ca_write.cut_id, ca_read.cut_id) ;
|
||||
errors ++ ;
|
||||
} ;
|
||||
|
||||
if (memcmp (ca_write.client_id, ca_read.client_id, sizeof (ca_write.client_id)) != 0)
|
||||
{ printf ("\n\nLine %d : client_id mismatch :\n\twrite : '%s'\n\tread : '%s'\n\n", __LINE__, ca_write.client_id, ca_read.client_id) ;
|
||||
errors ++ ;
|
||||
} ;
|
||||
|
||||
if (memcmp (ca_write.category, ca_read.category, sizeof (ca_write.category)) != 0)
|
||||
{ printf ("\n\nLine %d : category mismatch :\n\twrite : '%s'\n\tread : '%s'\n\n", __LINE__, ca_write.category, ca_read.category) ;
|
||||
errors ++ ;
|
||||
} ;
|
||||
|
||||
if (memcmp (ca_write.out_cue, ca_read.out_cue, sizeof (ca_write.out_cue)) != 0)
|
||||
{ printf ("\n\nLine %d : out_cue mismatch :\n\twrite : '%s'\n\tread : '%s'\n\n", __LINE__, ca_write.out_cue, ca_read.out_cue) ;
|
||||
errors ++ ;
|
||||
} ;
|
||||
|
||||
if (memcmp (ca_write.start_date, ca_read.start_date, sizeof (ca_write.start_date)) != 0)
|
||||
{ printf ("\n\nLine %d : start_date mismatch :\n\twrite : '%s'\n\tread : '%s'\n\n", __LINE__, ca_write.start_date, ca_read.start_date) ;
|
||||
errors ++ ;
|
||||
} ;
|
||||
|
||||
|
||||
if (memcmp (ca_write.start_time, ca_read.start_time, sizeof (ca_write.start_time)) != 0)
|
||||
{ printf ("\n\nLine %d : start_time mismatch :\n\twrite : '%s'\n\tread : '%s'\n\n", __LINE__, ca_write.start_time, ca_read.start_time) ;
|
||||
errors ++ ;
|
||||
} ;
|
||||
|
||||
|
||||
if (memcmp (ca_write.end_date, ca_read.end_date, sizeof (ca_write.end_date)) != 0)
|
||||
{ printf ("\n\nLine %d : end_date mismatch :\n\twrite : '%s'\n\tread : '%s'\n\n", __LINE__, ca_write.end_date, ca_read.end_date) ;
|
||||
errors ++ ;
|
||||
} ;
|
||||
|
||||
|
||||
if (memcmp (ca_write.end_time, ca_read.end_time, sizeof (ca_write.end_time)) != 0)
|
||||
{ printf ("\n\nLine %d : end_time mismatch :\n\twrite : '%s'\n\tread : '%s'\n\n", __LINE__, ca_write.end_time, ca_read.end_time) ;
|
||||
errors ++ ;
|
||||
} ;
|
||||
|
||||
|
||||
if (memcmp (ca_write.producer_app_id, ca_read.producer_app_id, sizeof (ca_write.producer_app_id)) != 0)
|
||||
{ printf ("\n\nLine %d : producer_app_id mismatch :\n\twrite : '%s'\n\tread : '%s'\n\n", __LINE__, ca_write.producer_app_id, ca_read.producer_app_id) ;
|
||||
errors ++ ;
|
||||
} ;
|
||||
|
||||
|
||||
if (memcmp (ca_write.producer_app_version, ca_read.producer_app_version, sizeof (ca_write.producer_app_version)) != 0)
|
||||
{ printf ("\n\nLine %d : producer_app_version mismatch :\n\twrite : '%s'\n\tread : '%s'\n\n", __LINE__, ca_write.producer_app_version, ca_read.producer_app_version) ;
|
||||
errors ++ ;
|
||||
} ;
|
||||
|
||||
|
||||
if (memcmp (ca_write.user_def, ca_read.user_def, sizeof (ca_write.user_def)) != 0)
|
||||
{ printf ("\n\nLine %d : user_def mismatch :\n\twrite : '%s'\n\tread : '%s'\n\n", __LINE__, ca_write.user_def, ca_read.user_def) ;
|
||||
errors ++ ;
|
||||
} ;
|
||||
|
||||
|
||||
if (ca_write.level_reference != ca_read.level_reference)
|
||||
{ printf ("\n\nLine %d : level_reference mismatch :\n\twrite : '%d'\n\tread : '%d'\n\n", __LINE__, ca_write.level_reference, ca_read.level_reference) ;
|
||||
errors ++ ;
|
||||
} ;
|
||||
|
||||
// TODO: make this more helpful
|
||||
if (memcmp (ca_write.post_timers, ca_read.post_timers, sizeof (ca_write.post_timers)) != 0)
|
||||
{ printf ("\n\nLine %d : post_timers mismatch :\n'\n\n", __LINE__) ;
|
||||
errors ++ ;
|
||||
} ;
|
||||
|
||||
if (memcmp (ca_write.url, ca_read.url, sizeof (ca_write.url)) != 0)
|
||||
{ printf ("\n\nLine %d : url mismatch :\n\twrite : '%s'\n\tread : '%s'\n\n", __LINE__, ca_write.url, ca_read.url) ;
|
||||
errors ++ ;
|
||||
} ;
|
||||
|
||||
|
||||
if (memcmp (ca_write.tag_text, ca_read.tag_text, (size_t) (ca_read.tag_text_size)) != 0)
|
||||
{ printf ("\n\nLine %d : tag_text mismatch :\n\twrite : '%s'\n\tread : '%s'\n\n", __LINE__, ca_write.tag_text, ca_read.tag_text) ;
|
||||
errors ++ ;
|
||||
} ;
|
||||
|
||||
|
||||
if (errors)
|
||||
exit (1) ;
|
||||
|
||||
unlink (filename) ;
|
||||
puts ("ok") ;
|
||||
} /* cart_test */
|
||||
|
||||
static void
|
||||
cart_rdwr_test (const char *filename, int filetype)
|
||||
{ SF_CART_INFO cinfo ;
|
||||
SNDFILE *file ;
|
||||
SF_INFO sfinfo ;
|
||||
sf_count_t frames ;
|
||||
|
||||
print_test_name (__func__, filename) ;
|
||||
|
||||
create_short_sndfile (filename, filetype, 2) ;
|
||||
|
||||
memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
||||
memset (&cinfo, 0, sizeof (cinfo)) ;
|
||||
|
||||
snprintf (cinfo.artist, sizeof (cinfo.artist), "Test artist") ;
|
||||
snprintf (cinfo.version, sizeof (cinfo.version), "Test version") ;
|
||||
snprintf (cinfo.cut_id, sizeof (cinfo.cut_id), "Test cut ID") ;
|
||||
snprintf (cinfo.client_id, sizeof (cinfo.client_id), "Test client ID") ;
|
||||
snprintf (cinfo.category, sizeof (cinfo.category), "Test category") ;
|
||||
snprintf (cinfo.classification, sizeof (cinfo.classification), "Test classification") ;
|
||||
snprintf (cinfo.out_cue, sizeof (cinfo.out_cue), "Test out cue") ;
|
||||
snprintf (cinfo.start_date, sizeof (cinfo.start_date), "%d/%02d/%02d", 2006, 3, 30) ;
|
||||
snprintf (cinfo.start_time, sizeof (cinfo.start_time), "%02d:%02d:%02d", 20, 27, 0) ;
|
||||
snprintf (cinfo.end_date, sizeof (cinfo.end_date), "%d/%02d/%02d", 2006, 3, 30) ;
|
||||
snprintf (cinfo.end_time, sizeof (cinfo.end_time), "%02d:%02d:%02d", 20, 27, 0) ;
|
||||
snprintf (cinfo.producer_app_id, sizeof (cinfo.producer_app_id), "Test producer app id") ;
|
||||
snprintf (cinfo.producer_app_version, sizeof (cinfo.producer_app_version), "Test producer app version") ;
|
||||
snprintf (cinfo.user_def, sizeof (cinfo.user_def), "test user def test test") ;
|
||||
cinfo.level_reference = 42 ;
|
||||
snprintf (cinfo.url, sizeof (cinfo.url), "http://www.test.com/test_url") ;
|
||||
snprintf (cinfo.tag_text, sizeof (cinfo.tag_text), "tag text test!\r\n") ;
|
||||
cinfo.tag_text_size = strlen (cinfo.tag_text) ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_RDWR, &sfinfo, SF_TRUE, __LINE__) ;
|
||||
frames = sfinfo.frames ;
|
||||
if (sf_command (file, SFC_SET_CART_INFO, &cinfo, sizeof (cinfo)) != SF_FALSE)
|
||||
{ printf ("\n\nLine %d : sf_command (SFC_SET_CART_INFO) should have failed but didn't.\n\n", __LINE__) ;
|
||||
exit (1) ;
|
||||
} ;
|
||||
sf_close (file) ;
|
||||
|
||||
file = test_open_file_or_die (filename, SFM_READ, &sfinfo, SF_TRUE, __LINE__) ;
|
||||
sf_close (file) ;
|
||||
exit_if_true (frames != sfinfo.frames, "\n\nLine %d : Frame count %" PRId64 " should be %" PRId64 ".\n", __LINE__, sfinfo.frames, frames) ;
|
||||
|
||||
unlink (filename) ;
|
||||
puts ("ok") ;
|
||||
} /* cart_rdwr_test */
|
||||
|
||||
/*==============================================================================
|
||||
*/
|
||||
|
||||
static void
|
||||
channel_map_test (const char *filename, int filetype)
|
||||
{ SNDFILE *file ;
|
||||
SF_INFO sfinfo ;
|
||||
{ SNDFILE *file ;
|
||||
SF_INFO sfinfo ;
|
||||
int channel_map_read [4], channel_map_write [4] =
|
||||
{ SF_CHANNEL_MAP_LEFT, SF_CHANNEL_MAP_RIGHT, SF_CHANNEL_MAP_LFE,
|
||||
SF_CHANNEL_MAP_REAR_CENTER
|
||||
@@ -1286,8 +1745,8 @@ raw_needs_endswap_test (const char *filename, int filetype)
|
||||
{ SF_FORMAT_FLOAT, SF_FORMAT_DOUBLE,
|
||||
SF_FORMAT_PCM_16, SF_FORMAT_PCM_24, SF_FORMAT_PCM_32
|
||||
} ;
|
||||
SNDFILE *file ;
|
||||
SF_INFO sfinfo ;
|
||||
SNDFILE *file ;
|
||||
SF_INFO sfinfo ;
|
||||
unsigned k ;
|
||||
int needs_endswap ;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user