third_party_libsnd/examples/sndfile-info.c

380 lines
11 KiB
C
Raw Normal View History

2007-05-14 09:55:24 +00:00
/*
** Copyright (C) 1999-2008 Erik de Castro Lopo <erikd@mega-nerd.com>
2007-05-14 09:55:24 +00:00
**
** All rights reserved.
2007-05-14 09:55:24 +00:00
**
** Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
** met:
2007-05-14 09:55:24 +00:00
**
** * Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in
** the documentation and/or other materials provided with the
** distribution.
** * Neither the author nor the names of any contributors may be used
** to endorse or promote products derived from this software without
** specific prior written permission.
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
** TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
** PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
** CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
** EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
** PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
** OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
** WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
** OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
** ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2007-05-14 09:55:24 +00:00
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
2007-05-14 09:55:24 +00:00
#include <ctype.h>
#include <math.h>
#include <sndfile.h>
2004-05-30 03:03:47 +00:00
#define BUFFER_LEN (1 << 16)
2007-05-14 09:55:24 +00:00
#if (defined (WIN32) || defined (_WIN32))
#include <windows.h>
2007-05-14 09:55:24 +00:00
#define snprintf _snprintf
#endif
static void print_version (void) ;
static void print_usage (const char *progname) ;
static void info_dump (const char *filename) ;
static void instrument_dump (const char *filename) ;
Merge in changes from broadcast WAV branch. Patches applied: * erikd@miles--2004/libsndfile--bext--0--base-0 tag of erikd@miles--2004/libsndfile--mdev--1.0--patch-625 * erikd@miles--2004/libsndfile--bext--0--patch-1 Add BEXT patch from Paul Davis. * erikd@miles--2004/libsndfile--bext--0--patch-2 Make it actually compile. * erikd@miles--2004/libsndfile--bext--0--patch-3 Fix formatting of new code. * erikd@miles--2004/libsndfile--bext--0--patch-4 Fix minor bugs after cleanup. * erikd@miles--2004/libsndfile--bext--0--patch-5 Merge from --mdev branch. * erikd@miles--2004/libsndfile--bext--0--patch-6 sndfile.h.in : Clean up formatting of SF_BROADCAST_INFO struct. * erikd@miles--2004/libsndfile--bext--0--patch-7 wav.c : Cleanup of broadcast WAV stuff. * erikd@miles--2004/libsndfile--bext--0--patch-8 wav.c : Fix minor bug in broadcast WAV stuff. * erikd@miles--2004/libsndfile--bext--0--patch-9 sndfile-info.c : Minor cleanup. * erikd@miles--2004/libsndfile--bext--0--patch-10 sndfile.c : More cleanups. * erikd@miles--2004/libsndfile--bext--0--patch-11 sndfile.h.in : Fix whitespace. * erikd@miles--2004/libsndfile--bext--0--patch-12 Merge from --mdev branch. * erikd@miles--2004/libsndfile--bext--0--patch-13 Change coding_history field from char pointer to char array. * erikd@miles--2004/libsndfile--bext--0--patch-14 Remove function broadcast_info_free. * erikd@miles--2004/libsndfile--bext--0--patch-15 sndfile-info.c : Clean up output of broadcast_dump function. * erikd@miles--2004/libsndfile--bext--0--patch-16 command_test.c : Start work on broadcast chunk tests. * erikd@miles--2004/libsndfile--bext--0--patch-17 wav.c : Jump and ignore the 'levl' chunk. * erikd@miles--2004/libsndfile--bext--0--patch-18 sndfile.h.in : Add block of reserved characters to SF_BROADCAST_INFO. * erikd@miles--2004/libsndfile--bext--0--patch-19 Cleanup of broadcast WAV stuff. * erikd@miles--2004/libsndfile--bext--0--patch-20 sndfile-info.c : Fix print message. * erikd@miles--2004/libsndfile--bext--0--patch-21 Complete bext tests, hook test in test suite.
2006-03-30 22:43:51 +00:00
static void broadcast_dump (const char *filename) ;
int
main (int argc, char *argv [])
{ int k ;
print_version () ;
if (argc < 2 || strcmp (argv [1], "--help") == 0 || strcmp (argv [1], "-h") == 0)
{ char *progname ;
progname = strrchr (argv [0], '/') ;
progname = progname ? progname + 1 : argv [0] ;
print_usage (progname) ;
return 1 ;
} ;
if (strcmp (argv [1], "-i") == 0)
{ for (k = 2 ; k < argc ; k++)
instrument_dump (argv [k]) ;
return 0 ;
} ;
Merge in changes from broadcast WAV branch. Patches applied: * erikd@miles--2004/libsndfile--bext--0--base-0 tag of erikd@miles--2004/libsndfile--mdev--1.0--patch-625 * erikd@miles--2004/libsndfile--bext--0--patch-1 Add BEXT patch from Paul Davis. * erikd@miles--2004/libsndfile--bext--0--patch-2 Make it actually compile. * erikd@miles--2004/libsndfile--bext--0--patch-3 Fix formatting of new code. * erikd@miles--2004/libsndfile--bext--0--patch-4 Fix minor bugs after cleanup. * erikd@miles--2004/libsndfile--bext--0--patch-5 Merge from --mdev branch. * erikd@miles--2004/libsndfile--bext--0--patch-6 sndfile.h.in : Clean up formatting of SF_BROADCAST_INFO struct. * erikd@miles--2004/libsndfile--bext--0--patch-7 wav.c : Cleanup of broadcast WAV stuff. * erikd@miles--2004/libsndfile--bext--0--patch-8 wav.c : Fix minor bug in broadcast WAV stuff. * erikd@miles--2004/libsndfile--bext--0--patch-9 sndfile-info.c : Minor cleanup. * erikd@miles--2004/libsndfile--bext--0--patch-10 sndfile.c : More cleanups. * erikd@miles--2004/libsndfile--bext--0--patch-11 sndfile.h.in : Fix whitespace. * erikd@miles--2004/libsndfile--bext--0--patch-12 Merge from --mdev branch. * erikd@miles--2004/libsndfile--bext--0--patch-13 Change coding_history field from char pointer to char array. * erikd@miles--2004/libsndfile--bext--0--patch-14 Remove function broadcast_info_free. * erikd@miles--2004/libsndfile--bext--0--patch-15 sndfile-info.c : Clean up output of broadcast_dump function. * erikd@miles--2004/libsndfile--bext--0--patch-16 command_test.c : Start work on broadcast chunk tests. * erikd@miles--2004/libsndfile--bext--0--patch-17 wav.c : Jump and ignore the 'levl' chunk. * erikd@miles--2004/libsndfile--bext--0--patch-18 sndfile.h.in : Add block of reserved characters to SF_BROADCAST_INFO. * erikd@miles--2004/libsndfile--bext--0--patch-19 Cleanup of broadcast WAV stuff. * erikd@miles--2004/libsndfile--bext--0--patch-20 sndfile-info.c : Fix print message. * erikd@miles--2004/libsndfile--bext--0--patch-21 Complete bext tests, hook test in test suite.
2006-03-30 22:43:51 +00:00
if (strcmp (argv [1], "-b") == 0)
{ for (k = 2 ; k < argc ; k++)
broadcast_dump (argv [k]) ;
Merge in changes from broadcast WAV branch. Patches applied: * erikd@miles--2004/libsndfile--bext--0--base-0 tag of erikd@miles--2004/libsndfile--mdev--1.0--patch-625 * erikd@miles--2004/libsndfile--bext--0--patch-1 Add BEXT patch from Paul Davis. * erikd@miles--2004/libsndfile--bext--0--patch-2 Make it actually compile. * erikd@miles--2004/libsndfile--bext--0--patch-3 Fix formatting of new code. * erikd@miles--2004/libsndfile--bext--0--patch-4 Fix minor bugs after cleanup. * erikd@miles--2004/libsndfile--bext--0--patch-5 Merge from --mdev branch. * erikd@miles--2004/libsndfile--bext--0--patch-6 sndfile.h.in : Clean up formatting of SF_BROADCAST_INFO struct. * erikd@miles--2004/libsndfile--bext--0--patch-7 wav.c : Cleanup of broadcast WAV stuff. * erikd@miles--2004/libsndfile--bext--0--patch-8 wav.c : Fix minor bug in broadcast WAV stuff. * erikd@miles--2004/libsndfile--bext--0--patch-9 sndfile-info.c : Minor cleanup. * erikd@miles--2004/libsndfile--bext--0--patch-10 sndfile.c : More cleanups. * erikd@miles--2004/libsndfile--bext--0--patch-11 sndfile.h.in : Fix whitespace. * erikd@miles--2004/libsndfile--bext--0--patch-12 Merge from --mdev branch. * erikd@miles--2004/libsndfile--bext--0--patch-13 Change coding_history field from char pointer to char array. * erikd@miles--2004/libsndfile--bext--0--patch-14 Remove function broadcast_info_free. * erikd@miles--2004/libsndfile--bext--0--patch-15 sndfile-info.c : Clean up output of broadcast_dump function. * erikd@miles--2004/libsndfile--bext--0--patch-16 command_test.c : Start work on broadcast chunk tests. * erikd@miles--2004/libsndfile--bext--0--patch-17 wav.c : Jump and ignore the 'levl' chunk. * erikd@miles--2004/libsndfile--bext--0--patch-18 sndfile.h.in : Add block of reserved characters to SF_BROADCAST_INFO. * erikd@miles--2004/libsndfile--bext--0--patch-19 Cleanup of broadcast WAV stuff. * erikd@miles--2004/libsndfile--bext--0--patch-20 sndfile-info.c : Fix print message. * erikd@miles--2004/libsndfile--bext--0--patch-21 Complete bext tests, hook test in test suite.
2006-03-30 22:43:51 +00:00
return 0 ;
} ;
for (k = 1 ; k < argc ; k++)
info_dump (argv [k]) ;
return 0 ;
} /* main */
/*==============================================================================
** Print version and usage.
*/
2007-05-14 09:55:24 +00:00
static double data [BUFFER_LEN] ;
static void
print_version (void)
{ char buffer [256] ;
sf_command (NULL, SFC_GET_LIB_VERSION, buffer, sizeof (buffer)) ;
printf ("\nVersion : %s\n\n", buffer) ;
} /* print_version */
2007-05-14 09:55:24 +00:00
static void
print_usage (const char *progname)
{ printf ("Usage :\n %s <file> ...\n", progname) ;
printf (" Prints out information about one or more sound files.\n\n") ;
printf (" %s -i <file>\n", progname) ;
printf (" Prints out the instrument data for the given file.\n\n") ;
Merge in changes from broadcast WAV branch. Patches applied: * erikd@miles--2004/libsndfile--bext--0--base-0 tag of erikd@miles--2004/libsndfile--mdev--1.0--patch-625 * erikd@miles--2004/libsndfile--bext--0--patch-1 Add BEXT patch from Paul Davis. * erikd@miles--2004/libsndfile--bext--0--patch-2 Make it actually compile. * erikd@miles--2004/libsndfile--bext--0--patch-3 Fix formatting of new code. * erikd@miles--2004/libsndfile--bext--0--patch-4 Fix minor bugs after cleanup. * erikd@miles--2004/libsndfile--bext--0--patch-5 Merge from --mdev branch. * erikd@miles--2004/libsndfile--bext--0--patch-6 sndfile.h.in : Clean up formatting of SF_BROADCAST_INFO struct. * erikd@miles--2004/libsndfile--bext--0--patch-7 wav.c : Cleanup of broadcast WAV stuff. * erikd@miles--2004/libsndfile--bext--0--patch-8 wav.c : Fix minor bug in broadcast WAV stuff. * erikd@miles--2004/libsndfile--bext--0--patch-9 sndfile-info.c : Minor cleanup. * erikd@miles--2004/libsndfile--bext--0--patch-10 sndfile.c : More cleanups. * erikd@miles--2004/libsndfile--bext--0--patch-11 sndfile.h.in : Fix whitespace. * erikd@miles--2004/libsndfile--bext--0--patch-12 Merge from --mdev branch. * erikd@miles--2004/libsndfile--bext--0--patch-13 Change coding_history field from char pointer to char array. * erikd@miles--2004/libsndfile--bext--0--patch-14 Remove function broadcast_info_free. * erikd@miles--2004/libsndfile--bext--0--patch-15 sndfile-info.c : Clean up output of broadcast_dump function. * erikd@miles--2004/libsndfile--bext--0--patch-16 command_test.c : Start work on broadcast chunk tests. * erikd@miles--2004/libsndfile--bext--0--patch-17 wav.c : Jump and ignore the 'levl' chunk. * erikd@miles--2004/libsndfile--bext--0--patch-18 sndfile.h.in : Add block of reserved characters to SF_BROADCAST_INFO. * erikd@miles--2004/libsndfile--bext--0--patch-19 Cleanup of broadcast WAV stuff. * erikd@miles--2004/libsndfile--bext--0--patch-20 sndfile-info.c : Fix print message. * erikd@miles--2004/libsndfile--bext--0--patch-21 Complete bext tests, hook test in test suite.
2006-03-30 22:43:51 +00:00
printf (" %s -b <file>\n", progname) ;
printf (" Prints out the broadcast WAV info for the given file.\n\n") ;
2007-05-14 09:55:24 +00:00
#if (defined (_WIN32) || defined (WIN32))
printf ("This is a Unix style command line application which\n"
"should be run in a MSDOS box or Command Shell window.\n\n") ;
printf ("Sleeping for 5 seconds before exiting.\n\n") ;
2004-09-30 09:04:23 +00:00
fflush (stdout) ;
2007-05-14 09:55:24 +00:00
/* This is the officially blessed by microsoft way but I can't get
** it to link.
** Sleep (15) ;
** Instead, use this:
*/
Sleep (5 * 1000) ;
2007-05-14 09:55:24 +00:00
#endif
} /* print_usage */
/*==============================================================================
** Dumping of sndfile info.
*/
static double data [BUFFER_LEN] ;
2007-05-14 09:55:24 +00:00
static double
get_signal_max (SNDFILE *file)
{ double max, temp ;
int readcount, k, save_state ;
save_state = sf_command (file, SFC_GET_NORM_DOUBLE, NULL, 0) ;
sf_command (file, SFC_SET_NORM_DOUBLE, NULL, SF_FALSE) ;
max = 0.0 ;
while ((readcount = sf_read_double (file, data, BUFFER_LEN)))
{ for (k = 0 ; k < readcount ; k++)
{ temp = fabs (data [k]) ;
if (temp > max)
max = temp ;
} ;
} ;
sf_command (file, SFC_SET_NORM_DOUBLE, NULL, save_state) ;
return max ;
} /* get_signal_max */
static double
calc_decibels (SF_INFO * sfinfo, double max)
{ double decibels ;
switch (sfinfo->format & SF_FORMAT_SUBMASK)
{ case SF_FORMAT_PCM_U8 :
case SF_FORMAT_PCM_S8 :
decibels = max / 0x80 ;
break ;
case SF_FORMAT_PCM_16 :
decibels = max / 0x8000 ;
break ;
case SF_FORMAT_PCM_24 :
decibels = max / 0x800000 ;
break ;
case SF_FORMAT_PCM_32 :
decibels = max / 0x80000000 ;
break ;
case SF_FORMAT_FLOAT :
case SF_FORMAT_DOUBLE :
decibels = max / 1.0 ;
break ;
default :
decibels = max / 0x8000 ;
break ;
} ;
return 20.0 * log10 (decibels) ;
} /* calc_decibels */
2007-05-14 09:55:24 +00:00
static const char *
generate_duration_str (SF_INFO *sfinfo)
{ static char str [128] ;
int seconds ;
memset (str, 0, sizeof (str)) ;
if (sfinfo->samplerate < 1)
return NULL ;
if (sfinfo->frames / sfinfo->samplerate > 0x7FFFFFFF)
return "unknown" ;
seconds = sfinfo->frames / sfinfo->samplerate ;
2007-05-14 09:55:24 +00:00
snprintf (str, sizeof (str) - 1, "%02d:", seconds / 60 / 60) ;
seconds = seconds % (60 * 60) ;
snprintf (str + strlen (str), sizeof (str) - strlen (str) - 1, "%02d:", seconds / 60) ;
seconds = seconds % 60 ;
snprintf (str + strlen (str), sizeof (str) - strlen (str) - 1, "%02d.", seconds) ;
seconds = ((1000 * sfinfo->frames) / sfinfo->samplerate) % 1000 ;
snprintf (str + strlen (str), sizeof (str) - strlen (str) - 1, "%03d", seconds) ;
return str ;
} /* generate_duration_str */
static void
info_dump (const char *filename)
2007-05-14 09:55:24 +00:00
{ static char strbuffer [BUFFER_LEN] ;
SNDFILE *file ;
2007-05-14 09:55:24 +00:00
SF_INFO sfinfo ;
double signal_max, decibels ;
2007-05-14 09:55:24 +00:00
memset (&sfinfo, 0, sizeof (sfinfo)) ;
2007-05-14 09:55:24 +00:00
if ((file = sf_open (filename, SFM_READ, &sfinfo)) == NULL)
{ printf ("Error : Not able to open input file %s.\n", filename) ;
fflush (stdout) ;
memset (data, 0, sizeof (data)) ;
sf_command (file, SFC_GET_LOG_INFO, strbuffer, BUFFER_LEN) ;
puts (strbuffer) ;
puts (sf_strerror (NULL)) ;
return ;
} ;
2007-05-14 09:55:24 +00:00
printf ("========================================\n") ;
sf_command (file, SFC_GET_LOG_INFO, strbuffer, BUFFER_LEN) ;
puts (strbuffer) ;
printf ("----------------------------------------\n") ;
if (file == NULL)
{ printf ("Error : Not able to open input file %s.\n", filename) ;
fflush (stdout) ;
memset (data, 0, sizeof (data)) ;
puts (sf_strerror (NULL)) ;
}
else
{ printf ("Sample Rate : %d\n", sfinfo.samplerate) ;
printf ("Frames : %" PRId64 "\n", sfinfo.frames) ;
printf ("Channels : %d\n", sfinfo.channels) ;
printf ("Format : 0x%08X\n", sfinfo.format) ;
printf ("Sections : %d\n", sfinfo.sections) ;
printf ("Seekable : %s\n", (sfinfo.seekable ? "TRUE" : "FALSE")) ;
printf ("Duration : %s\n", generate_duration_str (&sfinfo)) ;
/* Do not use sf_signal_max because it doesn't work for non-seekable files . */
signal_max = get_signal_max (file) ;
decibels = calc_decibels (&sfinfo, signal_max) ;
printf ("Signal Max : %g (%4.2f dB)\n\n", signal_max, decibels) ;
2007-05-14 09:55:24 +00:00
} ;
sf_close (file) ;
2007-05-14 09:55:24 +00:00
} /* info_dump */
/*==============================================================================
** Dumping of SF_INSTRUMENT data.
*/
static const char *
str_of_type (int mode)
{ switch (mode)
{ case SF_LOOP_NONE : return "none" ;
case SF_LOOP_FORWARD : return "fwd " ;
case SF_LOOP_BACKWARD : return "back" ;
case SF_LOOP_ALTERNATING : return "alt " ;
default : break ;
} ;
return "????" ;
} /* str_of_mode */
static void
instrument_dump (const char *filename)
{ SNDFILE *file ;
SF_INFO sfinfo ;
SF_INSTRUMENT inst ;
int got_inst, k ;
memset (&sfinfo, 0, sizeof (sfinfo)) ;
if ((file = sf_open (filename, SFM_READ, &sfinfo)) == NULL)
{ printf ("Error : Not able to open input file %s.\n", filename) ;
fflush (stdout) ;
memset (data, 0, sizeof (data)) ;
puts (sf_strerror (NULL)) ;
return ;
} ;
2007-05-14 09:55:24 +00:00
got_inst = sf_command (file, SFC_GET_INSTRUMENT, &inst, sizeof (inst)) ;
sf_close (file) ;
2007-05-14 09:55:24 +00:00
if (got_inst == SF_FALSE)
{ printf ("Error : File '%s' does not contain instrument data.\n\n", filename) ;
return ;
} ;
2007-05-14 09:55:24 +00:00
printf ("Instrument : %s\n\n", filename) ;
printf (" Gain : %d\n", inst.gain) ;
printf (" Base note : %d\n", inst.basenote) ;
printf (" Velocity : %d - %d\n", (int) inst.velocity_lo, (int) inst.velocity_hi) ;
printf (" Key : %d - %d\n", (int) inst.key_lo, (int) inst.key_hi) ;
printf (" Loop points : %d\n", inst.loop_count) ;
for (k = 0 ; k < inst.loop_count ; k++)
printf (" %-2d Mode : %s Start : %6d End : %6d Count : %6d\n", k, str_of_type (inst.loops [k].mode), inst.loops [k].start, inst.loops [k].end, inst.loops [k].count) ;
putchar ('\n') ;
} /* instrument_dump */
2007-05-14 09:55:24 +00:00
Merge in changes from broadcast WAV branch. Patches applied: * erikd@miles--2004/libsndfile--bext--0--base-0 tag of erikd@miles--2004/libsndfile--mdev--1.0--patch-625 * erikd@miles--2004/libsndfile--bext--0--patch-1 Add BEXT patch from Paul Davis. * erikd@miles--2004/libsndfile--bext--0--patch-2 Make it actually compile. * erikd@miles--2004/libsndfile--bext--0--patch-3 Fix formatting of new code. * erikd@miles--2004/libsndfile--bext--0--patch-4 Fix minor bugs after cleanup. * erikd@miles--2004/libsndfile--bext--0--patch-5 Merge from --mdev branch. * erikd@miles--2004/libsndfile--bext--0--patch-6 sndfile.h.in : Clean up formatting of SF_BROADCAST_INFO struct. * erikd@miles--2004/libsndfile--bext--0--patch-7 wav.c : Cleanup of broadcast WAV stuff. * erikd@miles--2004/libsndfile--bext--0--patch-8 wav.c : Fix minor bug in broadcast WAV stuff. * erikd@miles--2004/libsndfile--bext--0--patch-9 sndfile-info.c : Minor cleanup. * erikd@miles--2004/libsndfile--bext--0--patch-10 sndfile.c : More cleanups. * erikd@miles--2004/libsndfile--bext--0--patch-11 sndfile.h.in : Fix whitespace. * erikd@miles--2004/libsndfile--bext--0--patch-12 Merge from --mdev branch. * erikd@miles--2004/libsndfile--bext--0--patch-13 Change coding_history field from char pointer to char array. * erikd@miles--2004/libsndfile--bext--0--patch-14 Remove function broadcast_info_free. * erikd@miles--2004/libsndfile--bext--0--patch-15 sndfile-info.c : Clean up output of broadcast_dump function. * erikd@miles--2004/libsndfile--bext--0--patch-16 command_test.c : Start work on broadcast chunk tests. * erikd@miles--2004/libsndfile--bext--0--patch-17 wav.c : Jump and ignore the 'levl' chunk. * erikd@miles--2004/libsndfile--bext--0--patch-18 sndfile.h.in : Add block of reserved characters to SF_BROADCAST_INFO. * erikd@miles--2004/libsndfile--bext--0--patch-19 Cleanup of broadcast WAV stuff. * erikd@miles--2004/libsndfile--bext--0--patch-20 sndfile-info.c : Fix print message. * erikd@miles--2004/libsndfile--bext--0--patch-21 Complete bext tests, hook test in test suite.
2006-03-30 22:43:51 +00:00
static void
broadcast_dump (const char *filename)
{ SNDFILE *file ;
SF_INFO sfinfo ;
SF_BROADCAST_INFO bext ;
double time_ref_sec ;
Merge in changes from broadcast WAV branch. Patches applied: * erikd@miles--2004/libsndfile--bext--0--base-0 tag of erikd@miles--2004/libsndfile--mdev--1.0--patch-625 * erikd@miles--2004/libsndfile--bext--0--patch-1 Add BEXT patch from Paul Davis. * erikd@miles--2004/libsndfile--bext--0--patch-2 Make it actually compile. * erikd@miles--2004/libsndfile--bext--0--patch-3 Fix formatting of new code. * erikd@miles--2004/libsndfile--bext--0--patch-4 Fix minor bugs after cleanup. * erikd@miles--2004/libsndfile--bext--0--patch-5 Merge from --mdev branch. * erikd@miles--2004/libsndfile--bext--0--patch-6 sndfile.h.in : Clean up formatting of SF_BROADCAST_INFO struct. * erikd@miles--2004/libsndfile--bext--0--patch-7 wav.c : Cleanup of broadcast WAV stuff. * erikd@miles--2004/libsndfile--bext--0--patch-8 wav.c : Fix minor bug in broadcast WAV stuff. * erikd@miles--2004/libsndfile--bext--0--patch-9 sndfile-info.c : Minor cleanup. * erikd@miles--2004/libsndfile--bext--0--patch-10 sndfile.c : More cleanups. * erikd@miles--2004/libsndfile--bext--0--patch-11 sndfile.h.in : Fix whitespace. * erikd@miles--2004/libsndfile--bext--0--patch-12 Merge from --mdev branch. * erikd@miles--2004/libsndfile--bext--0--patch-13 Change coding_history field from char pointer to char array. * erikd@miles--2004/libsndfile--bext--0--patch-14 Remove function broadcast_info_free. * erikd@miles--2004/libsndfile--bext--0--patch-15 sndfile-info.c : Clean up output of broadcast_dump function. * erikd@miles--2004/libsndfile--bext--0--patch-16 command_test.c : Start work on broadcast chunk tests. * erikd@miles--2004/libsndfile--bext--0--patch-17 wav.c : Jump and ignore the 'levl' chunk. * erikd@miles--2004/libsndfile--bext--0--patch-18 sndfile.h.in : Add block of reserved characters to SF_BROADCAST_INFO. * erikd@miles--2004/libsndfile--bext--0--patch-19 Cleanup of broadcast WAV stuff. * erikd@miles--2004/libsndfile--bext--0--patch-20 sndfile-info.c : Fix print message. * erikd@miles--2004/libsndfile--bext--0--patch-21 Complete bext tests, hook test in test suite.
2006-03-30 22:43:51 +00:00
int got_bext ;
memset (&sfinfo, 0, sizeof (sfinfo)) ;
Merge in changes from broadcast WAV branch. Patches applied: * erikd@miles--2004/libsndfile--bext--0--base-0 tag of erikd@miles--2004/libsndfile--mdev--1.0--patch-625 * erikd@miles--2004/libsndfile--bext--0--patch-1 Add BEXT patch from Paul Davis. * erikd@miles--2004/libsndfile--bext--0--patch-2 Make it actually compile. * erikd@miles--2004/libsndfile--bext--0--patch-3 Fix formatting of new code. * erikd@miles--2004/libsndfile--bext--0--patch-4 Fix minor bugs after cleanup. * erikd@miles--2004/libsndfile--bext--0--patch-5 Merge from --mdev branch. * erikd@miles--2004/libsndfile--bext--0--patch-6 sndfile.h.in : Clean up formatting of SF_BROADCAST_INFO struct. * erikd@miles--2004/libsndfile--bext--0--patch-7 wav.c : Cleanup of broadcast WAV stuff. * erikd@miles--2004/libsndfile--bext--0--patch-8 wav.c : Fix minor bug in broadcast WAV stuff. * erikd@miles--2004/libsndfile--bext--0--patch-9 sndfile-info.c : Minor cleanup. * erikd@miles--2004/libsndfile--bext--0--patch-10 sndfile.c : More cleanups. * erikd@miles--2004/libsndfile--bext--0--patch-11 sndfile.h.in : Fix whitespace. * erikd@miles--2004/libsndfile--bext--0--patch-12 Merge from --mdev branch. * erikd@miles--2004/libsndfile--bext--0--patch-13 Change coding_history field from char pointer to char array. * erikd@miles--2004/libsndfile--bext--0--patch-14 Remove function broadcast_info_free. * erikd@miles--2004/libsndfile--bext--0--patch-15 sndfile-info.c : Clean up output of broadcast_dump function. * erikd@miles--2004/libsndfile--bext--0--patch-16 command_test.c : Start work on broadcast chunk tests. * erikd@miles--2004/libsndfile--bext--0--patch-17 wav.c : Jump and ignore the 'levl' chunk. * erikd@miles--2004/libsndfile--bext--0--patch-18 sndfile.h.in : Add block of reserved characters to SF_BROADCAST_INFO. * erikd@miles--2004/libsndfile--bext--0--patch-19 Cleanup of broadcast WAV stuff. * erikd@miles--2004/libsndfile--bext--0--patch-20 sndfile-info.c : Fix print message. * erikd@miles--2004/libsndfile--bext--0--patch-21 Complete bext tests, hook test in test suite.
2006-03-30 22:43:51 +00:00
if ((file = sf_open (filename, SFM_READ, &sfinfo)) == NULL)
{ printf ("Error : Not able to open input file %s.\n", filename) ;
fflush (stdout) ;
memset (data, 0, sizeof (data)) ;
puts (sf_strerror (NULL)) ;
return ;
} ;
memset (&bext, 0, sizeof (SF_BROADCAST_INFO)) ;
got_bext = sf_command (file, SFC_GET_BROADCAST_INFO, &bext, sizeof (bext)) ;
sf_close (file) ;
if (got_bext == SF_FALSE)
{ printf ("Error : File '%s' does not contain broadcast information.\n\n", filename) ;
return ;
} ;
/*
** From : http://www.ebu.ch/en/technical/publications/userguides/bwf_user_guide.php
**
** Time Reference:
** This field is a count from midnight in samples to the first sample
** of the audio sequence.
*/
time_ref_sec = ((pow (2.0, 32) * bext.time_reference_high) + (1.0 * bext.time_reference_low)) / sfinfo.samplerate ;
printf ("Description : %.*s\n", (int) sizeof (bext.description), bext.description) ;
printf ("Originator : %.*s\n", (int) sizeof (bext.originator), bext.originator) ;
printf ("Origination ref : %.*s\n", (int) sizeof (bext.originator_reference), bext.originator_reference) ;
printf ("Origination date : %.*s\n", (int) sizeof (bext.origination_date), bext.origination_date) ;
printf ("Origination time : %.*s\n", (int) sizeof (bext.origination_time), bext.origination_time) ;
if (bext.time_reference_high == 0 && bext.time_reference_low == 0)
printf ("Time ref : 0\n") ;
else
printf ("Time ref : 0x%x%08x (%.6f seconds)\n", bext.time_reference_high, bext.time_reference_low, time_ref_sec) ;
Merge in changes from broadcast WAV branch. Patches applied: * erikd@miles--2004/libsndfile--bext--0--base-0 tag of erikd@miles--2004/libsndfile--mdev--1.0--patch-625 * erikd@miles--2004/libsndfile--bext--0--patch-1 Add BEXT patch from Paul Davis. * erikd@miles--2004/libsndfile--bext--0--patch-2 Make it actually compile. * erikd@miles--2004/libsndfile--bext--0--patch-3 Fix formatting of new code. * erikd@miles--2004/libsndfile--bext--0--patch-4 Fix minor bugs after cleanup. * erikd@miles--2004/libsndfile--bext--0--patch-5 Merge from --mdev branch. * erikd@miles--2004/libsndfile--bext--0--patch-6 sndfile.h.in : Clean up formatting of SF_BROADCAST_INFO struct. * erikd@miles--2004/libsndfile--bext--0--patch-7 wav.c : Cleanup of broadcast WAV stuff. * erikd@miles--2004/libsndfile--bext--0--patch-8 wav.c : Fix minor bug in broadcast WAV stuff. * erikd@miles--2004/libsndfile--bext--0--patch-9 sndfile-info.c : Minor cleanup. * erikd@miles--2004/libsndfile--bext--0--patch-10 sndfile.c : More cleanups. * erikd@miles--2004/libsndfile--bext--0--patch-11 sndfile.h.in : Fix whitespace. * erikd@miles--2004/libsndfile--bext--0--patch-12 Merge from --mdev branch. * erikd@miles--2004/libsndfile--bext--0--patch-13 Change coding_history field from char pointer to char array. * erikd@miles--2004/libsndfile--bext--0--patch-14 Remove function broadcast_info_free. * erikd@miles--2004/libsndfile--bext--0--patch-15 sndfile-info.c : Clean up output of broadcast_dump function. * erikd@miles--2004/libsndfile--bext--0--patch-16 command_test.c : Start work on broadcast chunk tests. * erikd@miles--2004/libsndfile--bext--0--patch-17 wav.c : Jump and ignore the 'levl' chunk. * erikd@miles--2004/libsndfile--bext--0--patch-18 sndfile.h.in : Add block of reserved characters to SF_BROADCAST_INFO. * erikd@miles--2004/libsndfile--bext--0--patch-19 Cleanup of broadcast WAV stuff. * erikd@miles--2004/libsndfile--bext--0--patch-20 sndfile-info.c : Fix print message. * erikd@miles--2004/libsndfile--bext--0--patch-21 Complete bext tests, hook test in test suite.
2006-03-30 22:43:51 +00:00
printf ("BWF version : %d\n", bext.version) ;
printf ("UMID : %.*s\n", (int) sizeof (bext.umid), bext.umid) ;
Merge in changes from broadcast WAV branch. Patches applied: * erikd@miles--2004/libsndfile--bext--0--base-0 tag of erikd@miles--2004/libsndfile--mdev--1.0--patch-625 * erikd@miles--2004/libsndfile--bext--0--patch-1 Add BEXT patch from Paul Davis. * erikd@miles--2004/libsndfile--bext--0--patch-2 Make it actually compile. * erikd@miles--2004/libsndfile--bext--0--patch-3 Fix formatting of new code. * erikd@miles--2004/libsndfile--bext--0--patch-4 Fix minor bugs after cleanup. * erikd@miles--2004/libsndfile--bext--0--patch-5 Merge from --mdev branch. * erikd@miles--2004/libsndfile--bext--0--patch-6 sndfile.h.in : Clean up formatting of SF_BROADCAST_INFO struct. * erikd@miles--2004/libsndfile--bext--0--patch-7 wav.c : Cleanup of broadcast WAV stuff. * erikd@miles--2004/libsndfile--bext--0--patch-8 wav.c : Fix minor bug in broadcast WAV stuff. * erikd@miles--2004/libsndfile--bext--0--patch-9 sndfile-info.c : Minor cleanup. * erikd@miles--2004/libsndfile--bext--0--patch-10 sndfile.c : More cleanups. * erikd@miles--2004/libsndfile--bext--0--patch-11 sndfile.h.in : Fix whitespace. * erikd@miles--2004/libsndfile--bext--0--patch-12 Merge from --mdev branch. * erikd@miles--2004/libsndfile--bext--0--patch-13 Change coding_history field from char pointer to char array. * erikd@miles--2004/libsndfile--bext--0--patch-14 Remove function broadcast_info_free. * erikd@miles--2004/libsndfile--bext--0--patch-15 sndfile-info.c : Clean up output of broadcast_dump function. * erikd@miles--2004/libsndfile--bext--0--patch-16 command_test.c : Start work on broadcast chunk tests. * erikd@miles--2004/libsndfile--bext--0--patch-17 wav.c : Jump and ignore the 'levl' chunk. * erikd@miles--2004/libsndfile--bext--0--patch-18 sndfile.h.in : Add block of reserved characters to SF_BROADCAST_INFO. * erikd@miles--2004/libsndfile--bext--0--patch-19 Cleanup of broadcast WAV stuff. * erikd@miles--2004/libsndfile--bext--0--patch-20 sndfile-info.c : Fix print message. * erikd@miles--2004/libsndfile--bext--0--patch-21 Complete bext tests, hook test in test suite.
2006-03-30 22:43:51 +00:00
printf ("Coding history : %.*s\n", bext.coding_history_size, bext.coding_history) ;
} /* broadcast_dump */