Start work on reading/writing the SF_INSTRUMENT data. Add support for Ambisoncs B WAVEX files.

This commit is contained in:
Erik de Castro Lopo 2005-10-22 20:10:42 +00:00
parent 98fa740100
commit 29aee93d17
4 changed files with 97 additions and 18 deletions

View File

@ -1,3 +1,15 @@
2005-10-23 Erik de Castro Lopo <erikd AT mega-nerd DOT com>
* src/sndfile.h.in src/common.h src/common.c
Update definition of SF_INSTRUMENT struct and create a function to allocate
and initialize the struct (input from David Viens).
* src/wav.c src/wav_w64.c
Add support for Ambisoncs B WAVEX files (David Viens).
* src/aiff.c src/wav.c src/wav_w64.c
Start work on reading/writing the SF_INSTRUMENT data.
2005-10-15 Erik de Castro Lopo <erikd AT mega-nerd DOT com>
* src/gsm610.c

View File

@ -124,7 +124,7 @@ typedef struct
typedef struct
{ short playMode ;
unsigned short beginLoop ;
unsigned short beginLoop ;
unsigned short endLoop ;
} INST_LOOP ;
@ -597,6 +597,9 @@ aiff_read_header (SF_PRIVATE *psf, COMM_CHUNK *comm_fmt)
{ unsigned char bytes [6] ;
short gain ;
if (psf->instrument == NULL && (psf->instrument = psf_instrument_alloc ()) == NULL)
return SFE_MALLOC_FAILED ;
psf_binheader_readf (psf, "b", bytes, 6) ;
psf_log_printf (psf, " Base Note : %u\n Detune : %u\n"
" Low Note : %u\n High Note : %u\n"
@ -649,6 +652,12 @@ aiff_read_header (SF_PRIVATE *psf, COMM_CHUNK *comm_fmt)
bytesread += psf_binheader_readf (psf, "b", psf->u.scbuf, pstr_len) ;
psf_log_printf (psf, " Name : %s\n", psf->u.scbuf) ;
/* TODO if psf->u.scbuf is equal to
** either Beg_loop, Beg loop or beg loop and spam
if (psf->instrument == NULL && (psf->instrument = psf_instrument_alloc()) == NULL)
return SFE_MALLOC_FAILED ;
*/
mark_count -- ;
} ;
} ;

View File

@ -114,6 +114,19 @@ static const EXT_SUBFORMAT MSGUID_SUBTYPE_MULAW =
{ 0x00000007, 0x0000, 0x0010, { 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 }
} ;
/*
** the next two are from
** http://dream.cs.bath.ac.uk/researchdev/wave-ex/bformat.html
*/
static const EXT_SUBFORMAT MSGUID_SUBTYPE_AMBISONIC_B_FORMAT_PCM =
{ 0x00000001, 0x0721, 0x11d3, { 0x86, 0x44, 0xC8, 0xC1, 0xCA, 0x00, 0x00, 0x00 }
} ;
static const EXT_SUBFORMAT MSGUID_SUBTYPE_AMBISONIC_B_FORMAT_IEEE_FLOAT =
{ 0x00000003, 0x0721, 0x11d3, { 0x86, 0x44, 0xC8, 0xC1, 0xCA, 0x00, 0x00, 0x00 }
} ;
#if 0
/* maybe interesting one day to read the following through sf_read_raw */
/* http://www.bath.ac.uk/~masrwd/pvocex/pvocex.html */
@ -1208,7 +1221,8 @@ wav_subchunk_parse (SF_PRIVATE *psf, int chunk)
static int
wav_read_smpl_chunk (SF_PRIVATE *psf, unsigned int chunklen)
{ unsigned int bytesread = 0, dword, sampler_data, loop_count ;
int k ;
unsigned int note, start, end, type = -1, count ;
int j, k ;
chunklen += (chunklen & 1) ;
@ -1221,8 +1235,8 @@ wav_read_smpl_chunk (SF_PRIVATE *psf, unsigned int chunklen)
bytesread += psf_binheader_readf (psf, "e4", &dword) ;
psf_log_printf (psf, " Period : %u nsec\n", dword) ;
bytesread += psf_binheader_readf (psf, "e4", &dword) ;
psf_log_printf (psf, " Midi Note : %u\n", dword) ;
bytesread += psf_binheader_readf (psf, "e4", &note) ;
psf_log_printf (psf, " Midi Note : %u\n", note) ;
bytesread += psf_binheader_readf (psf, "e4", &dword) ;
if (dword != 0)
@ -1249,25 +1263,50 @@ wav_read_smpl_chunk (SF_PRIVATE *psf, unsigned int chunklen)
*/
bytesread += psf_binheader_readf (psf, "e4", &sampler_data) ;
while (loop_count > 0 && chunklen - bytesread >= 24)
{
bytesread += psf_binheader_readf (psf, "e4", &dword) ;
if ((psf->instrument = psf_instrument_alloc ()) == NULL)
return SFE_MALLOC_FAILED ;
psf->instrument->num_loops = loop_count ;
for (j = 0 ; loop_count > 0 && chunklen - bytesread >= 24 ; j ++)
{ bytesread += psf_binheader_readf (psf, "e4", &dword) ;
psf_log_printf (psf, " Cue ID : %2u", dword) ;
bytesread += psf_binheader_readf (psf, "e4", &dword) ;
psf_log_printf (psf, " Type : %2u", dword) ;
bytesread += psf_binheader_readf (psf, "e4", &type) ;
psf_log_printf (psf, " Type : %2u", type) ;
bytesread += psf_binheader_readf (psf, "e4", &dword) ;
psf_log_printf (psf, " Start : %5u", dword) ;
bytesread += psf_binheader_readf (psf, "e4", &start) ;
psf_log_printf (psf, " Start : %5u", start) ;
bytesread += psf_binheader_readf (psf, "e4", &dword) ;
psf_log_printf (psf, " End : %5u", dword) ;
bytesread += psf_binheader_readf (psf, "e4", &end) ;
psf_log_printf (psf, " End : %5u", end) ;
bytesread += psf_binheader_readf (psf, "e4", &dword) ;
psf_log_printf (psf, " Fraction : %5u", dword) ;
bytesread += psf_binheader_readf (psf, "e4", &dword) ;
psf_log_printf (psf, " Count : %5u\n", dword) ;
bytesread += psf_binheader_readf (psf, "e4", &count) ;
psf_log_printf (psf, " Count : %5u\n", count) ;
if (j < ARRAY_LEN (psf->instrument->loops))
{ psf->instrument->loops [j].start = start ;
psf->instrument->loops [j].end = end ;
psf->instrument->loops [j].count = count ;
switch (type)
{ case 0 :
psf->instrument->loops [j].mode = SF_LOOP_FORWARD ;
break ;
case 1 :
psf->instrument->loops [j].mode = SF_LOOP_ALTERNATING ;
break ;
case 2 :
psf->instrument->loops [j].mode = SF_LOOP_BACKWARD ;
break ;
default:
psf->instrument->loops [j].mode = SF_LOOP_NONE ;
break ;
} ;
} ;
loop_count -- ;
} ;
@ -1300,6 +1339,9 @@ wav_read_smpl_chunk (SF_PRIVATE *psf, unsigned int chunklen)
psf_log_printf (psf, "\n") ;
} ;
psf->instrument->basenote = note ;
psf->instrument->gain = 1 ;
return 0 ;
} /* wav_read_smpl_chunk */

View File

@ -50,6 +50,20 @@ static const EXT_SUBFORMAT MSGUID_SUBTYPE_MULAW =
{ 0x00000007, 0x0000, 0x0010, { 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 }
} ;
/*
** the next two are from
** http://dream.cs.bath.ac.uk/researchdev/wave-ex/bformat.html
*/
static const EXT_SUBFORMAT MSGUID_SUBTYPE_AMBISONIC_B_FORMAT_PCM =
{ 0x00000001, 0x0721, 0x11d3, { 0x86, 0x44, 0xC8, 0xC1, 0xCA, 0x00, 0x00, 0x00 }
} ;
static const EXT_SUBFORMAT MSGUID_SUBTYPE_AMBISONIC_B_FORMAT_IEEE_FLOAT =
{ 0x00000003, 0x0721, 0x11d3, { 0x86, 0x44, 0xC8, 0xC1, 0xCA, 0x00, 0x00, 0x00 }
} ;
#if 0
/* maybe interesting one day to read the following through sf_read_raw */
/* http://www.bath.ac.uk/~masrwd/pvocex/pvocex.html */
@ -230,7 +244,7 @@ wav_w64_read_fmt_chunk (SF_PRIVATE *psf, WAV_FMT *wav_fmt, int structsize)
psf_binheader_readf (psf, "e422", &(wav_fmt->ext.esf.esf_field1), &(wav_fmt->ext.esf.esf_field2),
&(wav_fmt->ext.esf.esf_field3)) ;
/* compare the esf_fields with each known GUID? and print?*/
/* compare the esf_fields with each known GUID? and print? */
psf_log_printf (psf, " Subformat\n") ;
psf_log_printf (psf, " esf_field1 : 0x%X\n", wav_fmt->ext.esf.esf_field1) ;
psf_log_printf (psf, " esf_field2 : 0x%X\n", wav_fmt->ext.esf.esf_field2) ;
@ -244,7 +258,8 @@ wav_w64_read_fmt_chunk (SF_PRIVATE *psf, WAV_FMT *wav_fmt, int structsize)
psf->bytewidth = BITWIDTH2BYTES (wav_fmt->ext.bitwidth) ;
/* Compare GUIDs for known ones. */
if (wavex_write_guid_equal (&wav_fmt->ext.esf, &MSGUID_SUBTYPE_PCM))
if (wavex_write_guid_equal (&wav_fmt->ext.esf, &MSGUID_SUBTYPE_PCM)
|| wavex_write_guid_equal (&wav_fmt->ext.esf, &MSGUID_SUBTYPE_AMBISONIC_B_FORMAT_PCM))
{ psf->sf.format = SF_FORMAT_WAVEX | u_bitwidth_to_subformat (psf->bytewidth * 8) ;
psf_log_printf (psf, " format : pcm\n") ;
}
@ -252,7 +267,8 @@ wav_w64_read_fmt_chunk (SF_PRIVATE *psf, WAV_FMT *wav_fmt, int structsize)
{ 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))
else if (wavex_write_guid_equal (&wav_fmt->ext.esf, &MSGUID_SUBTYPE_IEEE_FLOAT)
|| wavex_write_guid_equal (&wav_fmt->ext.esf, &MSGUID_SUBTYPE_AMBISONIC_B_FORMAT_PCM))
{ psf->sf.format = SF_FORMAT_WAVEX | ((psf->bytewidth == 8) ? SF_FORMAT_DOUBLE : SF_FORMAT_FLOAT) ;
psf_log_printf (psf, " format : IEEE float\n") ;
}