PDL-Audio
view release on metacpan or search on metacpan
sndlib/headers.c view on Meta::CPAN
* TIMIT format is identical except it omits the data format field (header size claims to be bytes)
*
* from ad.h and other files, ogitools-v1.0.tar.gz
* we'll look for the big/little endian sequence (short) 8 1 1-or-2 given big/little decision
*
* 0: header size in shorts (8 = 16 bytes) (OGI says this is in bytes)
* 2: version (1)
* 4: chans
* 6: rate (srate = 4000000/rate)
* 8: samples (int) -- seems to be off by 2 -- are they counting ints here?
* 12: data format (0=big-endian)
* 16: data start
*/
static int read_adc_header(int chan)
{
int little;
little = mus_uninterpreted_int((unsigned char *)(hdrbuf+12)); /* 0=big endian */
data_location = 16;
if (little) data_format = SNDLIB_16_LINEAR_LITTLE_ENDIAN; else data_format = SNDLIB_16_LINEAR;
chans = big_or_little_endian_short((unsigned char *)(hdrbuf+4),little);
srate = 4000000 / big_or_little_endian_short((unsigned char *)(hdrbuf+6),little);
data_size = 2*big_or_little_endian_int((unsigned char *)(hdrbuf+8),little);
comment_start=0;
comment_end=0;
header_distributed = 0;
true_file_length=lseek(chan,0L,SEEK_END);
data_size = mus_bytes2samples(data_format,data_size);
return(0);
}
/* ------------------------------------ AVR --------------------------------------
*
* 0: "2BIT"
* 4: sample name (null padded ASCII)
* 12: chans (short) (0=mono, -1=stereo)
* 14: sample size (8 or 16 bit) (short) (value is 8, 12, or 16)
* 16: sample format (signed or unsigned) (short) (0=unsigned, -1=signed)
* 18: loop (on/off), 20: midi (-1 = no MIDI)
* 22: srate
* avr.txt has:
* 22: Replay speed 0=5.485 Khz, 1=8.084 Khz, 2=10.971 Khz, 3=16.168 Khz, 4=21.942 Khz, 5=32.336 Khz, 6=43.885 Khz, 7=47.261 Khz
* 23: sample rate in Hertz (as a 3 byte quantity??)
* 26: length in samples
* 30: loop beg, 34: loop end, 38: midi (keyboard split), 40: compression, 42: nada ("reserved"), 44: name
* 64: comment (limited to 64 bytes)
* 128: data start
*
* the Atari .avr files appear to be 8000 Hz, mono, 8-bit linear unsigned data with an unknown header of 128 words
* apparently there was a change in format sometime in the 90's.
*
* The actual avr files I've found on the net are either garbled, or
* something is wrong with this definition (taken from CMJ and www.wotsit.org's avr.txt).
* SGI dmconvert assumes big-endian here -- this is an Atari format, so it's probably safe to assume big-endian.
*/
static int read_avr_header(int chan)
{
int dsize,dsigned,i;
chans = mus_big_endian_short((unsigned char *)(hdrbuf+12));
if (chans == 0) chans=1; else chans=2;
data_location = 128;
data_size = mus_big_endian_int((unsigned char *)(hdrbuf+26));
header_distributed = 0;
srate = mus_big_endian_unsigned_short((unsigned char *)(hdrbuf+24));
dsize = mus_big_endian_short((unsigned char *)(hdrbuf+14));
dsigned = mus_big_endian_short((unsigned char *)(hdrbuf+16));
if (dsize == 16)
{
if (dsigned == 0)
data_format = SNDLIB_16_UNSIGNED;
else data_format = SNDLIB_16_LINEAR;
}
else
{
if (dsigned == 0)
data_format = SNDLIB_8_UNSIGNED;
else data_format = SNDLIB_8_LINEAR;
}
if (seek_and_read(chan,(unsigned char *)hdrbuf,64,64) <= 0)
{
mus_error(MUS_HEADER_READ_FAILED,"AVR header looks wrong");
return(-1);
}
comment_start = 64;
i = 0;
while ((i < 64) && (hdrbuf[i] != 0)) i++;
comment_end = 64+(i-1);
true_file_length=lseek(chan,0L,SEEK_END);
data_size = mus_bytes2samples(data_format,data_size);
return(0);
}
/* ------------------------------------ SNDT -------------------------------------
*
* this taken from sndrtool.c (sox-10): (modified 6-Feb-98)
* 0: "SOUND" (or off by two throughout if not "0x1a"?)
* 5: 0x1a
* 6-7: 0
* 8-11: nsamps (at 12)
* 12-15: 0
* 16-19: nsamps
* 20-21: srate (little endian short) (at 22)
* 22-23: 0
* 24-25: 10
* 26-27: 4
* 28-> : <filename> "- File created by Sound Exchange"
* .->95: 0 ?
*/
/* similar is Sounder format:
* 0: 0
* 2: short srate (little endian)
* 4: 10
* 6: 4
* then data
* but this format can't be distinguished from a raw sound file
*/
static int read_sndt_header(int chan)
{
data_format = SNDLIB_8_UNSIGNED;
chans = 1;
srate = mus_little_endian_unsigned_short((unsigned char *)(hdrbuf+20));
data_location = 126;
data_size = mus_little_endian_int((unsigned char *)(hdrbuf+8));
if (data_size < 0) data_size = mus_little_endian_int((unsigned char *)(hdrbuf+10));
if (srate <= 1) srate = mus_little_endian_unsigned_short((unsigned char *)(hdrbuf+22));
header_distributed = 0;
true_file_length=lseek(chan,0L,SEEK_END);
return(0);
}
( run in 1.280 second using v1.01-cache-2.11-cpan-71847e10f99 )