2008-08-16 06:16:39 +00:00
|
|
|
/*
|
2019-04-01 08:38:34 +00:00
|
|
|
** Copyright (C) 1999-2019 Erik de Castro Lopo <erikd@mega-nerd.com>
|
2008-09-25 10:28:40 +00:00
|
|
|
** Copyright (C) 2008 George Blood Audio
|
2008-08-16 06:16:39 +00:00
|
|
|
**
|
|
|
|
** All rights reserved.
|
|
|
|
**
|
|
|
|
** Redistribution and use in source and binary forms, with or without
|
|
|
|
** modification, are permitted provided that the following conditions are
|
|
|
|
** met:
|
|
|
|
**
|
|
|
|
** * 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <ctype.h>
|
2010-02-22 07:31:20 +00:00
|
|
|
#include <stdint.h>
|
2019-08-21 16:43:24 +00:00
|
|
|
#include <math.h>
|
2008-08-16 06:16:39 +00:00
|
|
|
|
|
|
|
#include <sndfile.h>
|
|
|
|
|
2008-09-25 10:19:03 +00:00
|
|
|
#include "common.h"
|
2008-08-16 06:16:39 +00:00
|
|
|
|
2012-01-21 03:24:38 +00:00
|
|
|
#define BUFFER_LEN 4096
|
2008-08-16 06:16:39 +00:00
|
|
|
|
2012-01-21 03:24:38 +00:00
|
|
|
#define MIN(x, y) ((x) < (y) ? (x) : (y))
|
2008-10-08 10:32:15 +00:00
|
|
|
|
2017-09-27 12:46:18 +00:00
|
|
|
int
|
2013-07-02 07:47:58 +00:00
|
|
|
sfe_copy_data_fp (SNDFILE *outfile, SNDFILE *infile, int channels, int normalize)
|
2008-08-16 06:16:39 +00:00
|
|
|
{ static double data [BUFFER_LEN], max ;
|
2017-07-28 23:13:11 +00:00
|
|
|
sf_count_t frames, readcount, k ;
|
2008-08-16 06:16:39 +00:00
|
|
|
|
|
|
|
frames = BUFFER_LEN / channels ;
|
|
|
|
readcount = frames ;
|
|
|
|
|
|
|
|
sf_command (infile, SFC_CALC_SIGNAL_MAX, &max, sizeof (max)) ;
|
2017-09-27 12:46:18 +00:00
|
|
|
if (!isnormal (max)) /* neither zero, subnormal, infinite, nor NaN */
|
|
|
|
return 1 ;
|
2008-08-16 06:16:39 +00:00
|
|
|
|
2013-07-02 07:47:58 +00:00
|
|
|
if (!normalize && max < 1.0)
|
2008-08-16 06:16:39 +00:00
|
|
|
{ while (readcount > 0)
|
|
|
|
{ readcount = sf_readf_double (infile, data, frames) ;
|
|
|
|
sf_writef_double (outfile, data, readcount) ;
|
|
|
|
} ;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{ sf_command (infile, SFC_SET_NORM_DOUBLE, NULL, SF_FALSE) ;
|
|
|
|
|
|
|
|
while (readcount > 0)
|
|
|
|
{ readcount = sf_readf_double (infile, data, frames) ;
|
|
|
|
for (k = 0 ; k < readcount * channels ; k++)
|
2017-09-27 12:46:18 +00:00
|
|
|
{ data [k] /= max ;
|
|
|
|
|
|
|
|
if (!isfinite (data [k])) /* infinite or NaN */
|
|
|
|
return 1;
|
|
|
|
}
|
2008-08-16 06:16:39 +00:00
|
|
|
sf_writef_double (outfile, data, readcount) ;
|
|
|
|
} ;
|
|
|
|
} ;
|
|
|
|
|
2017-09-27 12:46:18 +00:00
|
|
|
return 0 ;
|
2008-08-16 06:16:39 +00:00
|
|
|
} /* sfe_copy_data_fp */
|
|
|
|
|
|
|
|
void
|
|
|
|
sfe_copy_data_int (SNDFILE *outfile, SNDFILE *infile, int channels)
|
|
|
|
{ static int data [BUFFER_LEN] ;
|
|
|
|
int frames, readcount ;
|
|
|
|
|
|
|
|
frames = BUFFER_LEN / channels ;
|
|
|
|
readcount = frames ;
|
|
|
|
|
|
|
|
while (readcount > 0)
|
|
|
|
{ readcount = sf_readf_int (infile, data, frames) ;
|
|
|
|
sf_writef_int (outfile, data, readcount) ;
|
|
|
|
} ;
|
|
|
|
|
|
|
|
return ;
|
|
|
|
} /* sfe_copy_data_int */
|
|
|
|
|
2008-09-25 10:28:40 +00:00
|
|
|
/*==============================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int
|
|
|
|
merge_broadcast_info (SNDFILE * infile, SNDFILE * outfile, int format, const METADATA_INFO * info)
|
2008-10-26 19:28:14 +00:00
|
|
|
{ SF_BROADCAST_INFO_2K binfo ;
|
2008-09-25 10:28:40 +00:00
|
|
|
int infileminor ;
|
|
|
|
|
|
|
|
memset (&binfo, 0, sizeof (binfo)) ;
|
|
|
|
|
|
|
|
if ((SF_FORMAT_TYPEMASK & format) != SF_FORMAT_WAV)
|
|
|
|
{ printf ("Error : This is not a WAV file and hence broadcast info cannot be added to it.\n\n") ;
|
|
|
|
return 1 ;
|
|
|
|
} ;
|
|
|
|
|
|
|
|
infileminor = SF_FORMAT_SUBMASK & format ;
|
|
|
|
|
|
|
|
switch (infileminor)
|
|
|
|
{ case SF_FORMAT_PCM_16 :
|
|
|
|
case SF_FORMAT_PCM_24 :
|
|
|
|
case SF_FORMAT_PCM_32 :
|
|
|
|
break ;
|
|
|
|
|
|
|
|
default :
|
|
|
|
printf (
|
|
|
|
"Warning : The EBU Technical Recommendation R68-2000 states that the only\n"
|
|
|
|
" allowed encodings are Linear PCM and MPEG3. This file is not in\n"
|
|
|
|
" the right format.\n\n"
|
|
|
|
) ;
|
|
|
|
break ;
|
|
|
|
} ;
|
|
|
|
|
|
|
|
if (sf_command (infile, SFC_GET_BROADCAST_INFO, &binfo, sizeof (binfo)) == 0)
|
|
|
|
{ if (infile == outfile)
|
|
|
|
{ printf (
|
|
|
|
"Error : Attempting in-place broadcast info update, but file does not\n"
|
|
|
|
" have a 'bext' chunk to modify. The solution is to specify both\n"
|
|
|
|
" input and output files on the command line.\n\n"
|
|
|
|
) ;
|
|
|
|
return 1 ;
|
|
|
|
} ;
|
|
|
|
} ;
|
|
|
|
|
|
|
|
#define REPLACE_IF_NEW(x) \
|
|
|
|
if (info->x != NULL) \
|
2008-11-05 23:07:59 +00:00
|
|
|
{ memset (binfo.x, 0, sizeof (binfo.x)) ; \
|
|
|
|
memcpy (binfo.x, info->x, MIN (strlen (info->x), sizeof (binfo.x))) ; \
|
|
|
|
} ;
|
2008-09-25 10:28:40 +00:00
|
|
|
|
|
|
|
REPLACE_IF_NEW (description) ;
|
|
|
|
REPLACE_IF_NEW (originator) ;
|
|
|
|
REPLACE_IF_NEW (originator_reference) ;
|
|
|
|
REPLACE_IF_NEW (origination_date) ;
|
|
|
|
REPLACE_IF_NEW (origination_time) ;
|
|
|
|
REPLACE_IF_NEW (umid) ;
|
|
|
|
|
2019-08-21 16:43:24 +00:00
|
|
|
/* Special case loudness values */
|
|
|
|
#define REPLACE_IF_NEW_INT(x) \
|
|
|
|
if (info->x != NULL) \
|
|
|
|
{ binfo.x = round (atof (info->x) * 100.0) ; \
|
|
|
|
} ;
|
|
|
|
|
|
|
|
REPLACE_IF_NEW_INT (loudness_value) ;
|
|
|
|
REPLACE_IF_NEW_INT (loudness_range) ;
|
|
|
|
REPLACE_IF_NEW_INT (max_true_peak_level) ;
|
|
|
|
REPLACE_IF_NEW_INT (max_momentary_loudness) ;
|
|
|
|
REPLACE_IF_NEW_INT (max_shortterm_loudness) ;
|
|
|
|
|
2010-02-22 07:31:20 +00:00
|
|
|
/* Special case for Time Ref. */
|
|
|
|
if (info->time_ref != NULL)
|
|
|
|
{ uint64_t ts = atoll (info->time_ref) ;
|
|
|
|
|
|
|
|
binfo.time_reference_high = (ts >> 32) ;
|
|
|
|
binfo.time_reference_low = (ts & 0xffffffff) ;
|
|
|
|
} ;
|
|
|
|
|
2008-09-25 10:28:40 +00:00
|
|
|
/* Special case for coding_history because we may want to append. */
|
|
|
|
if (info->coding_history != NULL)
|
|
|
|
{ if (info->coding_hist_append)
|
|
|
|
{ int slen = strlen (binfo.coding_history) ;
|
|
|
|
|
|
|
|
while (slen > 1 && isspace (binfo.coding_history [slen - 1]))
|
|
|
|
slen -- ;
|
|
|
|
|
|
|
|
memcpy (binfo.coding_history + slen, info->coding_history, sizeof (binfo.coding_history) - slen) ;
|
|
|
|
}
|
|
|
|
else
|
2008-10-17 07:43:53 +00:00
|
|
|
{ size_t slen = MIN (strlen (info->coding_history), sizeof (binfo.coding_history)) ;
|
|
|
|
|
|
|
|
memset (binfo.coding_history, 0, sizeof (binfo.coding_history)) ;
|
|
|
|
memcpy (binfo.coding_history, info->coding_history, slen) ;
|
|
|
|
binfo.coding_history_size = slen ;
|
2008-09-25 10:28:40 +00:00
|
|
|
} ;
|
|
|
|
} ;
|
|
|
|
|
|
|
|
if (sf_command (outfile, SFC_SET_BROADCAST_INFO, &binfo, sizeof (binfo)) == 0)
|
2008-10-26 07:02:04 +00:00
|
|
|
{ printf ("Error : Setting of broadcast info chunks failed.\n\n") ;
|
|
|
|
return 1 ;
|
|
|
|
} ;
|
2008-09-25 10:28:40 +00:00
|
|
|
|
|
|
|
return 0 ;
|
|
|
|
} /* merge_broadcast_info*/
|
|
|
|
|
|
|
|
static void
|
|
|
|
update_strings (SNDFILE * outfile, const METADATA_INFO * info)
|
|
|
|
{
|
|
|
|
if (info->title != NULL)
|
|
|
|
sf_set_string (outfile, SF_STR_TITLE, info->title) ;
|
|
|
|
|
|
|
|
if (info->copyright != NULL)
|
2010-01-07 09:41:47 +00:00
|
|
|
sf_set_string (outfile, SF_STR_COPYRIGHT, info->copyright) ;
|
2008-09-25 10:28:40 +00:00
|
|
|
|
|
|
|
if (info->artist != NULL)
|
|
|
|
sf_set_string (outfile, SF_STR_ARTIST, info->artist) ;
|
|
|
|
|
|
|
|
if (info->comment != NULL)
|
2010-01-07 09:41:47 +00:00
|
|
|
sf_set_string (outfile, SF_STR_COMMENT, info->comment) ;
|
2008-09-25 10:28:40 +00:00
|
|
|
|
|
|
|
if (info->date != NULL)
|
|
|
|
sf_set_string (outfile, SF_STR_DATE, info->date) ;
|
|
|
|
|
|
|
|
if (info->album != NULL)
|
2010-01-07 09:41:47 +00:00
|
|
|
sf_set_string (outfile, SF_STR_ALBUM, info->album) ;
|
2008-09-25 10:28:40 +00:00
|
|
|
|
|
|
|
if (info->license != NULL)
|
2010-01-07 09:41:47 +00:00
|
|
|
sf_set_string (outfile, SF_STR_LICENSE, info->license) ;
|
2008-09-25 10:28:40 +00:00
|
|
|
|
|
|
|
} /* update_strings */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
sfe_apply_metadata_changes (const char * filenames [2], const METADATA_INFO * info)
|
|
|
|
{ SNDFILE *infile = NULL, *outfile = NULL ;
|
|
|
|
SF_INFO sfinfo ;
|
|
|
|
METADATA_INFO tmpinfo ;
|
|
|
|
int error_code = 0 ;
|
|
|
|
|
|
|
|
memset (&sfinfo, 0, sizeof (sfinfo)) ;
|
|
|
|
memset (&tmpinfo, 0, sizeof (tmpinfo)) ;
|
|
|
|
|
|
|
|
if (filenames [1] == NULL)
|
|
|
|
infile = outfile = sf_open (filenames [0], SFM_RDWR, &sfinfo) ;
|
|
|
|
else
|
|
|
|
{ infile = sf_open (filenames [0], SFM_READ, &sfinfo) ;
|
|
|
|
|
|
|
|
/* Output must be WAV. */
|
|
|
|
sfinfo.format = SF_FORMAT_WAV | (SF_FORMAT_SUBMASK & sfinfo.format) ;
|
|
|
|
outfile = sf_open (filenames [1], SFM_WRITE, &sfinfo) ;
|
|
|
|
} ;
|
|
|
|
|
|
|
|
if (infile == NULL)
|
|
|
|
{ printf ("Error : Not able to open input file '%s' : %s\n", filenames [0], sf_strerror (infile)) ;
|
|
|
|
error_code = 1 ;
|
|
|
|
goto cleanup_exit ;
|
|
|
|
} ;
|
|
|
|
|
|
|
|
if (outfile == NULL)
|
|
|
|
{ printf ("Error : Not able to open output file '%s' : %s\n", filenames [1], sf_strerror (outfile)) ;
|
|
|
|
error_code = 1 ;
|
|
|
|
goto cleanup_exit ;
|
|
|
|
} ;
|
|
|
|
|
|
|
|
if (info->has_bext_fields && merge_broadcast_info (infile, outfile, sfinfo.format, info))
|
|
|
|
{ error_code = 1 ;
|
|
|
|
goto cleanup_exit ;
|
|
|
|
} ;
|
|
|
|
|
|
|
|
if (infile != outfile)
|
|
|
|
{ int infileminor = SF_FORMAT_SUBMASK & sfinfo.format ;
|
|
|
|
|
|
|
|
/* If the input file is not the same as the output file, copy the data. */
|
|
|
|
if ((infileminor == SF_FORMAT_DOUBLE) || (infileminor == SF_FORMAT_FLOAT))
|
2017-09-27 12:46:18 +00:00
|
|
|
{ if (sfe_copy_data_fp (outfile, infile, sfinfo.channels, SF_FALSE) != 0)
|
|
|
|
{ printf ("Error : Not able to decode input file '%s'\n", filenames [0]) ;
|
|
|
|
error_code = 1 ;
|
|
|
|
goto cleanup_exit ;
|
|
|
|
} ;
|
|
|
|
}
|
2008-09-25 10:28:40 +00:00
|
|
|
else
|
|
|
|
sfe_copy_data_int (outfile, infile, sfinfo.channels) ;
|
|
|
|
} ;
|
|
|
|
|
2010-05-07 12:10:58 +00:00
|
|
|
update_strings (outfile, info) ;
|
|
|
|
|
2008-09-25 10:28:40 +00:00
|
|
|
cleanup_exit :
|
|
|
|
|
|
|
|
if (outfile != NULL && outfile != infile)
|
|
|
|
sf_close (outfile) ;
|
|
|
|
|
|
|
|
if (infile != NULL)
|
|
|
|
sf_close (infile) ;
|
|
|
|
|
|
|
|
if (error_code)
|
|
|
|
exit (error_code) ;
|
|
|
|
|
|
|
|
return ;
|
|
|
|
} /* sfe_apply_metadata_changes */
|
|
|
|
|
2009-12-02 09:26:06 +00:00
|
|
|
/*==============================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{ const char *ext ;
|
|
|
|
int len ;
|
|
|
|
int format ;
|
|
|
|
} OUTPUT_FORMAT_MAP ;
|
|
|
|
|
2019-04-01 08:38:34 +00:00
|
|
|
/* Map a file name extension to a container format. */
|
2009-12-02 09:26:06 +00:00
|
|
|
static OUTPUT_FORMAT_MAP format_map [] =
|
|
|
|
{
|
|
|
|
{ "wav", 0, SF_FORMAT_WAV },
|
2014-07-01 06:51:13 +00:00
|
|
|
{ "aif", 3, SF_FORMAT_AIFF },
|
2009-12-02 09:26:06 +00:00
|
|
|
{ "au", 0, SF_FORMAT_AU },
|
|
|
|
{ "snd", 0, SF_FORMAT_AU },
|
2014-07-01 06:51:13 +00:00
|
|
|
{ "raw", 0, SF_FORMAT_RAW },
|
2019-04-02 09:08:09 +00:00
|
|
|
{ "gsm", 0, SF_FORMAT_RAW | SF_FORMAT_GSM610 },
|
|
|
|
{ "vox", 0, SF_FORMAT_RAW | SF_FORMAT_VOX_ADPCM },
|
2014-07-01 06:51:13 +00:00
|
|
|
{ "paf", 0, SF_FORMAT_PAF | SF_ENDIAN_BIG },
|
|
|
|
{ "fap", 0, SF_FORMAT_PAF | SF_ENDIAN_LITTLE },
|
|
|
|
{ "svx", 0, SF_FORMAT_SVX },
|
2009-12-02 09:26:06 +00:00
|
|
|
{ "nist", 0, SF_FORMAT_NIST },
|
2014-07-01 06:51:13 +00:00
|
|
|
{ "sph", 0, SF_FORMAT_NIST },
|
|
|
|
{ "voc", 0, SF_FORMAT_VOC },
|
2009-12-02 09:26:06 +00:00
|
|
|
{ "ircam", 0, SF_FORMAT_IRCAM },
|
|
|
|
{ "sf", 0, SF_FORMAT_IRCAM },
|
|
|
|
{ "w64", 0, SF_FORMAT_W64 },
|
2014-07-01 06:51:13 +00:00
|
|
|
{ "mat", 0, SF_FORMAT_MAT4 },
|
2009-12-02 09:26:06 +00:00
|
|
|
{ "mat4", 0, SF_FORMAT_MAT4 },
|
|
|
|
{ "mat5", 0, SF_FORMAT_MAT5 },
|
|
|
|
{ "pvf", 0, SF_FORMAT_PVF },
|
2014-07-01 06:51:13 +00:00
|
|
|
{ "xi", 0, SF_FORMAT_XI },
|
|
|
|
{ "htk", 0, SF_FORMAT_HTK },
|
2009-12-02 09:26:06 +00:00
|
|
|
{ "sds", 0, SF_FORMAT_SDS },
|
2014-07-01 06:51:13 +00:00
|
|
|
{ "avr", 0, SF_FORMAT_AVR },
|
|
|
|
{ "wavex", 0, SF_FORMAT_WAVEX },
|
2009-12-02 09:26:06 +00:00
|
|
|
{ "sd2", 0, SF_FORMAT_SD2 },
|
2014-07-01 06:51:13 +00:00
|
|
|
{ "flac", 0, SF_FORMAT_FLAC },
|
|
|
|
{ "caf", 0, SF_FORMAT_CAF },
|
2009-12-02 09:26:06 +00:00
|
|
|
{ "wve", 0, SF_FORMAT_WVE },
|
2014-07-01 06:51:13 +00:00
|
|
|
{ "prc", 0, SF_FORMAT_WVE },
|
2012-07-09 09:41:04 +00:00
|
|
|
{ "ogg", 0, SF_FORMAT_OGG },
|
2014-07-01 06:51:13 +00:00
|
|
|
{ "oga", 0, SF_FORMAT_OGG },
|
2019-04-02 09:08:09 +00:00
|
|
|
{ "opus", 0, SF_FORMAT_OGG | SF_FORMAT_OPUS },
|
2009-12-02 09:26:06 +00:00
|
|
|
{ "mpc", 0, SF_FORMAT_MPC2K },
|
|
|
|
{ "rf64", 0, SF_FORMAT_RF64 },
|
|
|
|
} ; /* format_map */
|
|
|
|
|
|
|
|
int
|
|
|
|
sfe_file_type_of_ext (const char *str, int format)
|
|
|
|
{ char buffer [16], *cptr ;
|
|
|
|
int k ;
|
|
|
|
|
|
|
|
format &= SF_FORMAT_SUBMASK ;
|
|
|
|
|
|
|
|
if ((cptr = strrchr (str, '.')) == NULL)
|
|
|
|
return 0 ;
|
|
|
|
|
|
|
|
strncpy (buffer, cptr + 1, 15) ;
|
|
|
|
buffer [15] = 0 ;
|
|
|
|
|
|
|
|
for (k = 0 ; buffer [k] ; k++)
|
|
|
|
buffer [k] = tolower ((buffer [k])) ;
|
|
|
|
|
|
|
|
for (k = 0 ; k < (int) (sizeof (format_map) / sizeof (format_map [0])) ; k++)
|
2019-04-02 09:08:09 +00:00
|
|
|
{ if ((format_map [k].len > 0 && strncmp (buffer, format_map [k].ext, format_map [k].len) == 0) ||
|
|
|
|
(strcmp (buffer, format_map [k].ext) == 0))
|
|
|
|
{ if (format_map [k].format & SF_FORMAT_SUBMASK)
|
|
|
|
return format_map [k].format ;
|
|
|
|
else
|
|
|
|
return format_map [k].format | format ;
|
|
|
|
} ;
|
2009-12-02 09:26:06 +00:00
|
|
|
} ;
|
|
|
|
|
|
|
|
/* Default if all the above fails. */
|
|
|
|
return (SF_FORMAT_WAV | SF_FORMAT_PCM_24) ;
|
|
|
|
} /* sfe_file_type_of_ext */
|
|
|
|
|
|
|
|
void
|
|
|
|
sfe_dump_format_map (void)
|
|
|
|
{ SF_FORMAT_INFO info ;
|
|
|
|
int k ;
|
|
|
|
|
|
|
|
for (k = 0 ; k < ARRAY_LEN (format_map) ; k++)
|
|
|
|
{ info.format = format_map [k].format ;
|
|
|
|
sf_command (NULL, SFC_GET_FORMAT_INFO, &info, sizeof (info)) ;
|
2019-04-02 09:08:09 +00:00
|
|
|
printf (" %-10s : %s", format_map [k].ext, info.name == NULL ? "????" : info.name) ;
|
|
|
|
if (format_map [k].format & SF_FORMAT_SUBMASK)
|
|
|
|
{ info.format = format_map [k].format & SF_FORMAT_SUBMASK ;
|
|
|
|
sf_command (NULL, SFC_GET_FORMAT_INFO, &info, sizeof (info)) ;
|
|
|
|
printf (" %s", info.name == NULL ? "????" : info.name) ;
|
|
|
|
} ;
|
|
|
|
putchar ('\n') ;
|
|
|
|
|
2009-12-02 09:26:06 +00:00
|
|
|
} ;
|
|
|
|
|
|
|
|
} /* sfe_dump_format_map */
|
2011-03-21 10:16:13 +00:00
|
|
|
|
|
|
|
const char *
|
|
|
|
program_name (const char * argv0)
|
|
|
|
{ const char * tmp ;
|
|
|
|
|
|
|
|
tmp = strrchr (argv0, '/') ;
|
|
|
|
argv0 = tmp ? tmp + 1 : argv0 ;
|
|
|
|
|
|
|
|
/* Remove leading libtool name mangling. */
|
|
|
|
if (strstr (argv0, "lt-") == argv0)
|
|
|
|
return argv0 + 3 ;
|
|
|
|
|
|
|
|
return argv0 ;
|
|
|
|
} /* program_name */
|
2013-06-24 09:12:07 +00:00
|
|
|
|
|
|
|
const char *
|
|
|
|
sfe_endian_name (int format)
|
|
|
|
{
|
|
|
|
switch (format & SF_FORMAT_ENDMASK)
|
|
|
|
{ case SF_ENDIAN_FILE : return "file" ;
|
|
|
|
case SF_ENDIAN_LITTLE : return "little" ;
|
|
|
|
case SF_ENDIAN_BIG : return "big" ;
|
|
|
|
case SF_ENDIAN_CPU : return "cpu" ;
|
|
|
|
default : break ;
|
|
|
|
} ;
|
|
|
|
|
|
|
|
return "unknown" ;
|
|
|
|
} /* sfe_endian_name */
|
|
|
|
|
|
|
|
const char *
|
|
|
|
sfe_container_name (int format)
|
|
|
|
{
|
|
|
|
switch (format & SF_FORMAT_TYPEMASK)
|
|
|
|
{ case SF_FORMAT_WAV : return "WAV" ;
|
|
|
|
case SF_FORMAT_AIFF : return "AIFF" ;
|
|
|
|
case SF_FORMAT_AU : return "AU" ;
|
|
|
|
case SF_FORMAT_RAW : return "RAW" ;
|
|
|
|
case SF_FORMAT_PAF : return "PAF" ;
|
|
|
|
case SF_FORMAT_SVX : return "SVX" ;
|
|
|
|
case SF_FORMAT_NIST : return "NIST" ;
|
|
|
|
case SF_FORMAT_VOC : return "VOC" ;
|
|
|
|
case SF_FORMAT_IRCAM : return "IRCAM" ;
|
|
|
|
case SF_FORMAT_W64 : return "W64" ;
|
|
|
|
case SF_FORMAT_MAT4 : return "MAT4" ;
|
|
|
|
case SF_FORMAT_MAT5 : return "MAT5" ;
|
|
|
|
case SF_FORMAT_PVF : return "PVF" ;
|
|
|
|
case SF_FORMAT_XI : return "XI" ;
|
|
|
|
case SF_FORMAT_HTK : return "HTK" ;
|
|
|
|
case SF_FORMAT_SDS : return "SDS" ;
|
|
|
|
case SF_FORMAT_AVR : return "AVR" ;
|
|
|
|
case SF_FORMAT_WAVEX : return "WAVEX" ;
|
|
|
|
case SF_FORMAT_SD2 : return "SD2" ;
|
|
|
|
case SF_FORMAT_FLAC : return "FLAC" ;
|
|
|
|
case SF_FORMAT_CAF : return "CAF" ;
|
|
|
|
case SF_FORMAT_WVE : return "WVE" ;
|
|
|
|
case SF_FORMAT_OGG : return "OGG" ;
|
|
|
|
case SF_FORMAT_MPC2K : return "MPC2K" ;
|
|
|
|
case SF_FORMAT_RF64 : return "RF64" ;
|
|
|
|
default : break ;
|
|
|
|
} ;
|
|
|
|
|
|
|
|
return "unknown" ;
|
|
|
|
} /* sfe_container_name */
|
|
|
|
|
|
|
|
const char *
|
|
|
|
sfe_codec_name (int format)
|
|
|
|
{
|
|
|
|
switch (format & SF_FORMAT_SUBMASK)
|
|
|
|
{ case SF_FORMAT_PCM_S8 : return "signed 8 bit PCM" ;
|
|
|
|
case SF_FORMAT_PCM_16 : return "16 bit PCM" ;
|
|
|
|
case SF_FORMAT_PCM_24 : return "24 bit PCM" ;
|
|
|
|
case SF_FORMAT_PCM_32 : return "32 bit PCM" ;
|
|
|
|
case SF_FORMAT_PCM_U8 : return "unsigned 8 bit PCM" ;
|
|
|
|
case SF_FORMAT_FLOAT : return "32 bit float" ;
|
|
|
|
case SF_FORMAT_DOUBLE : return "64 bit double" ;
|
|
|
|
case SF_FORMAT_ULAW : return "u-law" ;
|
|
|
|
case SF_FORMAT_ALAW : return "a-law" ;
|
|
|
|
case SF_FORMAT_IMA_ADPCM : return "IMA ADPCM" ;
|
|
|
|
case SF_FORMAT_MS_ADPCM : return "MS ADPCM" ;
|
|
|
|
case SF_FORMAT_GSM610 : return "gsm610" ;
|
|
|
|
case SF_FORMAT_VOX_ADPCM : return "Vox ADPCM" ;
|
|
|
|
case SF_FORMAT_G721_32 : return "g721 32kbps" ;
|
|
|
|
case SF_FORMAT_G723_24 : return "g723 24kbps" ;
|
|
|
|
case SF_FORMAT_G723_40 : return "g723 40kbps" ;
|
|
|
|
case SF_FORMAT_DWVW_12 : return "12 bit DWVW" ;
|
|
|
|
case SF_FORMAT_DWVW_16 : return "16 bit DWVW" ;
|
|
|
|
case SF_FORMAT_DWVW_24 : return "14 bit DWVW" ;
|
|
|
|
case SF_FORMAT_DWVW_N : return "DWVW" ;
|
|
|
|
case SF_FORMAT_DPCM_8 : return "8 bit DPCM" ;
|
|
|
|
case SF_FORMAT_DPCM_16 : return "16 bit DPCM" ;
|
|
|
|
case SF_FORMAT_VORBIS : return "Vorbis" ;
|
|
|
|
case SF_FORMAT_ALAC_16 : return "16 bit ALAC" ;
|
|
|
|
case SF_FORMAT_ALAC_20 : return "20 bit ALAC" ;
|
|
|
|
case SF_FORMAT_ALAC_24 : return "24 bit ALAC" ;
|
|
|
|
case SF_FORMAT_ALAC_32 : return "32 bit ALAC" ;
|
2019-04-01 08:38:34 +00:00
|
|
|
case SF_FORMAT_OPUS : return "Opus" ;
|
2013-06-24 09:12:07 +00:00
|
|
|
default : break ;
|
|
|
|
} ;
|
|
|
|
return "unknown" ;
|
|
|
|
} /* sfe_codec_name */
|