From 2d08b3877ffdeb0fd6399211fe295b86adf57467 Mon Sep 17 00:00:00 2001 From: Erik de Castro Lopo Date: Mon, 15 Aug 2005 13:31:34 +0000 Subject: [PATCH] Improve log output for WAVE_FORMAT_EXTENSIBLE files. --- ChangeLog | 4 +++ src/wav.c | 43 ++++--------------------------- src/wav_w64.c | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/wav_w64.h | 3 ++- 4 files changed, 81 insertions(+), 39 deletions(-) diff --git a/ChangeLog b/ChangeLog index a3536496..b8e977de 100644 --- a/ChangeLog +++ b/ChangeLog @@ -6,6 +6,10 @@ * src/file_io.c Fix psf_fsync() for win32. + * src/wav.c src/wav_w64.(c|h) + Move some code from wav.c to wav_w64.c to improve the log output of files of + type WAVE_FORMAT_EXTENSIBLE. + 2005-08-10 Erik de Castro Lopo * src/create_symbols_file.py diff --git a/src/wav.c b/src/wav.c index e7cc70bc..34ef8a86 100644 --- a/src/wav.c +++ b/src/wav.c @@ -1,6 +1,6 @@ /* ** Copyright (C) 1999-2005 Erik de Castro Lopo -** Copyright (C) 2004 David Viens +** Copyright (C) 2004-2005 David Viens ** ** This program is free software; you can redistribute it and/or modify ** it under the terms of the GNU Lesser General Public License as published by @@ -129,7 +129,6 @@ static const EXT_SUBFORMAT MSGUID_SUBTYPE_PVOCEX = static int wav_read_header (SF_PRIVATE *psf, int *blockalign, int *framesperblock) ; static int wav_write_header (SF_PRIVATE *psf, int calc_length) ; -static void wavex_write_guid (SF_PRIVATE *psf, const EXT_SUBFORMAT * subformat) ; static int wavex_write_header (SF_PRIVATE *psf, int calc_length) ; static int wav_write_tailer (SF_PRIVATE *psf) ; @@ -141,8 +140,6 @@ static int wav_subchunk_parse (SF_PRIVATE *psf, int chunk) ; static int wav_read_smpl_chunk (SF_PRIVATE *psf, unsigned int chunklen) ; static int wav_read_acid_chunk (SF_PRIVATE *psf, unsigned int chunklen) ; -static int wavex_write_guid_equal (const EXT_SUBFORMAT * first, const EXT_SUBFORMAT * second) ; - /*------------------------------------------------------------------------------ ** Public function. */ @@ -559,26 +556,11 @@ wav_read_header (SF_PRIVATE *psf, int *blockalign, int *framesperblock) } ; switch (format) - { - - case WAVE_FORMAT_EXTENSIBLE : - /* compare GUIDs for known ones */ - if (wavex_write_guid_equal (&wav_fmt.ext.esf, &MSGUID_SUBTYPE_PCM)) - psf->sf.format = SF_FORMAT_WAVEX | u_bitwidth_to_subformat (psf->bytewidth * 8) ; - else - if (wavex_write_guid_equal (&wav_fmt.ext.esf, &MSGUID_SUBTYPE_MS_ADPCM)) - { psf->sf.format = (SF_FORMAT_WAVEX | SF_FORMAT_MS_ADPCM) ; - *blockalign = wav_fmt.msadpcm.blockalign ; + { case WAVE_FORMAT_EXTENSIBLE : + if (psf->sf.format == (SF_FORMAT_WAVEX | SF_FORMAT_MS_ADPCM)) + { *blockalign = wav_fmt.msadpcm.blockalign ; *framesperblock = wav_fmt.msadpcm.samplesperblock ; - } - else if (wavex_write_guid_equal (&wav_fmt.ext.esf, &MSGUID_SUBTYPE_IEEE_FLOAT)) - psf->sf.format = SF_FORMAT_WAVEX | ((psf->bytewidth == 8) ? SF_FORMAT_DOUBLE : SF_FORMAT_FLOAT) ; - else if (wavex_write_guid_equal (&wav_fmt.ext.esf, &MSGUID_SUBTYPE_ALAW)) - psf->sf.format = (SF_FORMAT_WAVEX | SF_FORMAT_ALAW) ; - else if (wavex_write_guid_equal (&wav_fmt.ext.esf, &MSGUID_SUBTYPE_MULAW)) - psf->sf.format = (SF_FORMAT_WAVEX | SF_FORMAT_ULAW) ; - else - return SFE_UNIMPLEMENTED ; + } ; break ; case WAVE_FORMAT_PCM : @@ -817,21 +799,6 @@ wav_write_header (SF_PRIVATE *psf, int calc_length) -static int -wavex_write_guid_equal (const EXT_SUBFORMAT * first, const EXT_SUBFORMAT * second) -{ return !memcmp (first, second, sizeof (EXT_SUBFORMAT)) ; -} /* wavex_write_guid_equal */ - - -static void -wavex_write_guid (SF_PRIVATE *psf, const EXT_SUBFORMAT * subformat) -{ - psf_binheader_writef (psf, "e422b", subformat->esf_field1, - subformat->esf_field2, subformat->esf_field3, - subformat->esf_field4, 8) ; -} /* wavex_write_guid */ - - static int wavex_write_header (SF_PRIVATE *psf, int calc_length) { sf_count_t current ; diff --git a/src/wav_w64.c b/src/wav_w64.c index d012afc8..5e8d6fdb 100644 --- a/src/wav_w64.c +++ b/src/wav_w64.c @@ -1,5 +1,6 @@ /* ** Copyright (C) 1999-2005 Erik de Castro Lopo +** Copyright (C) 2004-2005 David Viens ** ** This program is free software; you can redistribute it and/or modify ** it under the terms of the GNU Lesser General Public License as published by @@ -27,10 +28,46 @@ #include "common.h" #include "wav_w64.h" +/* Known WAVEFORMATEXTENSIBLE GUIDS. */ +static const EXT_SUBFORMAT MSGUID_SUBTYPE_PCM = +{ 0x00000001, 0x0000, 0x0010, { 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 } +} ; + +static const EXT_SUBFORMAT MSGUID_SUBTYPE_MS_ADPCM = +{ 0x00000002, 0x0000, 0x0010, { 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 } +} ; + +static const EXT_SUBFORMAT MSGUID_SUBTYPE_IEEE_FLOAT = +{ 0x00000003, 0x0000, 0x0010, { 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 } +} ; + +static const EXT_SUBFORMAT MSGUID_SUBTYPE_ALAW = +{ 0x00000006, 0x0000, 0x0010, { 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 } +} ; + +static const EXT_SUBFORMAT MSGUID_SUBTYPE_MULAW = +{ 0x00000007, 0x0000, 0x0010, { 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 } +} ; + +#if 0 +/* maybe interesting one day to read the following through sf_read_raw */ +/* http://www.bath.ac.uk/~masrwd/pvocex/pvocex.html */ +static const EXT_SUBFORMAT MSGUID_SUBTYPE_PVOCEX = +{ 0x8312B9C2, 0x2E6E, 0x11d4, { 0xA8, 0x24, 0xDE, 0x5B, 0x96, 0xC3, 0xAB, 0x21 } +} ; +#endif + /*------------------------------------------------------------------------------ * Private static functions. */ +static int +wavex_write_guid_equal (const EXT_SUBFORMAT * first, const EXT_SUBFORMAT * second) +{ return !memcmp (first, second, sizeof (EXT_SUBFORMAT)) ; +} /* wavex_write_guid_equal */ + + + int wav_w64_read_fmt_chunk (SF_PRIVATE *psf, WAV_FMT *wav_fmt, int structsize) { int bytesread, k, bytespersec = 0 ; @@ -204,6 +241,30 @@ wav_w64_read_fmt_chunk (SF_PRIVATE *psf, WAV_FMT *wav_fmt, int structsize) } ; psf_log_printf (psf, "\n") ; psf->bytewidth = BITWIDTH2BYTES (wav_fmt->ext.bitwidth) ; + + /* Compare GUIDs for known ones. */ + if (wavex_write_guid_equal (&wav_fmt->ext.esf, &MSGUID_SUBTYPE_PCM)) + { psf->sf.format = SF_FORMAT_WAVEX | u_bitwidth_to_subformat (psf->bytewidth * 8) ; + psf_log_printf (psf, " format : pcm\n") ; + } + else if (wavex_write_guid_equal (&wav_fmt->ext.esf, &MSGUID_SUBTYPE_MS_ADPCM)) + { psf->sf.format = (SF_FORMAT_WAVEX | SF_FORMAT_MS_ADPCM) ; + psf_log_printf (psf, " format : ms adpcm\n") ; + } + else if (wavex_write_guid_equal (&wav_fmt->ext.esf, &MSGUID_SUBTYPE_IEEE_FLOAT)) + { psf->sf.format = SF_FORMAT_WAVEX | ((psf->bytewidth == 8) ? SF_FORMAT_DOUBLE : SF_FORMAT_FLOAT) ; + psf_log_printf (psf, " format : IEEE float\n") ; + } + else if (wavex_write_guid_equal (&wav_fmt->ext.esf, &MSGUID_SUBTYPE_ALAW)) + { psf->sf.format = (SF_FORMAT_WAVEX | SF_FORMAT_ALAW) ; + psf_log_printf (psf, " format : A-law\n") ; + } + else if (wavex_write_guid_equal (&wav_fmt->ext.esf, &MSGUID_SUBTYPE_MULAW)) + { psf->sf.format = (SF_FORMAT_WAVEX | SF_FORMAT_ULAW) ; + psf_log_printf (psf, " format : u-law\n") ; + } + else + return SFE_UNIMPLEMENTED ; break ; default : break ; @@ -221,6 +282,15 @@ wav_w64_read_fmt_chunk (SF_PRIVATE *psf, WAV_FMT *wav_fmt, int structsize) return 0 ; } /* wav_w64_read_fmt_chunk */ +void +wavex_write_guid (SF_PRIVATE *psf, const EXT_SUBFORMAT * subformat) +{ + psf_binheader_writef (psf, "e422b", subformat->esf_field1, + subformat->esf_field2, subformat->esf_field3, + subformat->esf_field4, 8) ; +} /* wavex_write_guid */ + + /*============================================================================== */ diff --git a/src/wav_w64.h b/src/wav_w64.h index 0ca29869..3f33f1b8 100644 --- a/src/wav_w64.h +++ b/src/wav_w64.h @@ -265,12 +265,13 @@ typedef struct void msadpcm_write_adapt_coeffs (SF_PRIVATE *psf) ; /*------------------------------------------------------------------------------------ -** Functions defined in wav_gsm610.c +** Functions defined in wav_w64.c */ int wav_w64_srate2blocksize (int srate_chan_product) ; char const* wav_w64_format_str (int k) ; int wav_w64_read_fmt_chunk (SF_PRIVATE *psf, WAV_FMT *wav_fmt, int structsize) ; +void wavex_write_guid (SF_PRIVATE *psf, const EXT_SUBFORMAT * subformat) ; #endif /*