diff options
author | IOhannes m zmölnig <zmoelnig@umlautQ.umlaeute.mur.at> | 2016-01-25 11:25:59 +0100 |
---|---|---|
committer | IOhannes m zmölnig <zmoelnig@umlautQ.umlaeute.mur.at> | 2016-01-25 11:25:59 +0100 |
commit | 110d59c341b8c50c04f30d90e85e9b8f6f329a0e (patch) | |
tree | 174afbe2ded41ae03923b93a0c4e6975e3163ad5 /headers.c | |
parent | e5328e59987b90c4e98959510b810510e384650d (diff) |
Imported Upstream version 16.1
Diffstat (limited to 'headers.c')
-rw-r--r-- | headers.c | 1571 |
1 files changed, 805 insertions, 766 deletions
@@ -1,6 +1,6 @@ /* readers/writers for various sound file headers * - * Currently supported read/write (in standard data formats): + * Currently supported read/write (in standard sample types): * NeXT/Sun/DEC/AFsp * AIFF/AIFC * RIFF (microsoft wave) @@ -10,10 +10,10 @@ * CAFF * no header * - * Currently supported read-only (in selected data formats): + * Currently supported read-only (in selected sample types): * 8SVX (IFF), EBICSF, INRS, ESPS, SPPACK, ADC (OGI), AVR, VOC, CSL, snack "SMP", PVF, * Sound Tools, Turtle Beach SMP, SoundFont 2.0, Sound Designer I, PSION alaw, MAUD, - * Gravis Ultrasound, Comdisco SPW, Goldwave sample, OMF, NVF, quicktime, sox, + * Gravis Ultrasound, Comdisco SPW, Goldwave sample, OMF, quicktime, sox, * Sonic Foundry (w64), SBStudio II, Delusion digital, Digiplayer ST3, Farandole Composer WaveSample, * Ultratracker WaveSample, Sample Dump exchange, Yamaha SY85 and SY99 (buggy), Yamaha TX16W, * Covox v8, AVI, Kurzweil 2000, Paris Ensoniq, Impulse tracker, Korg, Akai type 4, Maui, @@ -34,7 +34,7 @@ * test cases (sample files): ccrma-ftp.stanford.edu:/pub/Lisp/sf.tar.gz */ -#include <mus-config.h> +#include "mus-config.h" #if USE_SND #include "snd.h" @@ -44,50 +44,18 @@ #include <stdio.h> #include <errno.h> #include <stdlib.h> -#if HAVE_STRING_H - #include <string.h> -#endif -#if (defined(HAVE_LIBC_H) && (!defined(HAVE_UNISTD_H))) - #include <libc.h> +#include <string.h> +#ifndef _MSC_VER + #include <unistd.h> #else - #if (!(defined(_MSC_VER))) - #include <unistd.h> - #endif + #include <io.h> + #pragma warning(disable: 4244) #endif #include "_sndlib.h" #include "sndlib-strings.h" -/* ---------------------------------------- */ -/* from io.c but not in _sndlib.h (these are now internal to sndlib, but I don't like the C-oid "_" prefix): */ -void mus_bint_to_char(unsigned char *j, int x); -int mus_char_to_bint(const unsigned char *inp); -void mus_lint_to_char(unsigned char *j, int x); -int mus_char_to_lint(const unsigned char *inp); -mus_long_t mus_char_to_llong(const unsigned char *inp); -mus_long_t mus_char_to_blong(const unsigned char *inp); -int mus_char_to_uninterpreted_int(const unsigned char *inp); -void mus_bfloat_to_char(unsigned char *j, float x); -float mus_char_to_bfloat(const unsigned char *inp); -void mus_lfloat_to_char(unsigned char *j, float x); -float mus_char_to_lfloat(const unsigned char *inp); -void mus_bshort_to_char(unsigned char *j, short x); -short mus_char_to_bshort(const unsigned char *inp); -void mus_lshort_to_char(unsigned char *j, short x); -short mus_char_to_lshort(const unsigned char *inp); -unsigned short mus_char_to_ubshort(const unsigned char *inp); -unsigned short mus_char_to_ulshort(const unsigned char *inp); -double mus_char_to_ldouble(const unsigned char *inp); -double mus_char_to_bdouble(const unsigned char *inp); -void mus_bdouble_to_char(unsigned char *j, double x); -void mus_blong_to_char(unsigned char *j, mus_long_t x); -void mus_llong_to_char(unsigned char *j, mus_long_t x); -unsigned int mus_char_to_ubint(const unsigned char *inp); -unsigned int mus_char_to_ulint(const unsigned char *inp); -/* ---------------------------------------- */ - - /* can't use LONG_MAX here because we want a 4-byte max even on 64-bit machines */ #define BIGGEST_4_BYTE_SIGNED_INT 2147483647L #define BIGGEST_4_BYTE_UNSIGNED_INT 4294967295UL @@ -159,7 +127,9 @@ static const unsigned char I_IMPS[4] = {'I','M','P','S'}; /* Impulse Tracker */ static const unsigned char I_SMP1[4] = {'S','M','P','1'}; /* Korg */ static const unsigned char I_Maui[4] = {'M','a','u','i'}; /* Turtle Beach */ static const unsigned char I_SDIF[4] = {'S','D','I','F'}; /* IRCAM sdif */ +#if G7XX static const unsigned char I_NVF_[4] = {'N','V','F',' '}; /* Nomad II Creative NVF */ +#endif static const unsigned char I_ajkg[4] = {'a','j','k','g'}; /* shorten */ static const unsigned char I_RF64[4] = {'R','F','6','4'}; /* EBU RF64 */ static const unsigned char I_ds64[4] = {'d','s','6','4'}; /* EBU RF64 */ @@ -218,7 +188,9 @@ int mus_header_initialize(void) #define I_IRCAM_NEXT 0x0004a364 static mus_long_t data_location = 0; -static int srate = 0, chans = 0, header_type = MUS_UNSUPPORTED, data_format = MUS_UNKNOWN, original_data_format = 0; +static int srate = 0, chans = 0, original_sample_type = 0; +static mus_sample_t sample_type = MUS_UNKNOWN_SAMPLE; +static mus_header_t header_type = MUS_UNKNOWN_HEADER; static int type_specifier = 0, bits_per_sample = 0, block_align = 0, fact_samples = 0; static mus_long_t comment_start = 0, comment_end = 0; static mus_long_t true_file_length = 0, data_size = 0; @@ -229,8 +201,8 @@ mus_long_t mus_header_samples(void) {return(data_size);} mus_long_t mus_header_data_location(void) {return(data_location);} int mus_header_chans(void) {return(chans);} int mus_header_srate(void) {return(srate);} -int mus_header_type(void) {return(header_type);} -int mus_header_format(void) {return(data_format);} +mus_header_t mus_header_type(void) {return(header_type);} +mus_sample_t mus_header_sample_type(void) {return(sample_type);} mus_long_t mus_header_comment_start(void) {return(comment_start);} mus_long_t mus_header_comment_end(void) {return(comment_end);} mus_long_t mus_header_aux_comment_start(int n) {if (aux_comment_start) return(aux_comment_start[n]); else return(-1);} @@ -240,7 +212,7 @@ int mus_header_bits_per_sample(void) {return(bits_per_sample);} int mus_header_fact_samples(void) {return(fact_samples);} int mus_header_block_align(void) {return(block_align);} mus_long_t mus_header_true_length(void) {return(true_file_length);} -int mus_header_original_format(void) {return(original_data_format);} +int mus_header_original_sample_type(void) {return(original_sample_type);} int mus_header_loop_mode(int which) {if (loop_modes) return(loop_modes[which]); else return(-1);} int mus_header_loop_start(int which) {if (loop_starts) return(loop_starts[which]); else return(-1);} int mus_header_loop_end(int which) {if (loop_ends) return(loop_ends[which]); else return(-1);} @@ -256,9 +228,9 @@ int mus_header_mark_info(int **m_ids, int **m_positions) } -int mus_bytes_per_sample(int format) +int mus_bytes_per_sample(mus_sample_t samp_type) { - switch (format) + switch (samp_type) { case MUS_BYTE: return(1); break; case MUS_BSHORT: return(2); break; @@ -287,15 +259,15 @@ int mus_bytes_per_sample(int format) } -mus_long_t mus_samples_to_bytes (int format, mus_long_t size) +mus_long_t mus_samples_to_bytes (mus_sample_t samp_type, mus_long_t size) { - return(size * (mus_bytes_per_sample(format))); + return(size * (mus_bytes_per_sample(samp_type))); } -mus_long_t mus_bytes_to_samples (int format, mus_long_t size) +mus_long_t mus_bytes_to_samples (mus_sample_t samp_type, mus_long_t size) { - return((mus_long_t)(size / (mus_bytes_per_sample(format)))); + return((mus_long_t)(size / (mus_bytes_per_sample(samp_type)))); } @@ -351,7 +323,7 @@ static void write_four_chars(unsigned char *head, const unsigned char *match) } -const char *mus_header_type_name(int type) +const char *mus_header_type_name(mus_header_t type) { switch (type) { @@ -415,7 +387,9 @@ const char *mus_header_type_name(int type) case MUS_SOUNDFORGE: return("SoundForge"); break; case MUS_TWINVQ: return("TwinVQ"); break; case MUS_SDIF: return("IRCAM sdif"); break; +#if G7XX case MUS_NVF: return("Creative NVF"); break; +#endif case MUS_OGG: return("Ogg Vorbis"); break; case MUS_FLAC: return("Flac"); break; case MUS_SPEEX: return("Speex"); break; @@ -425,14 +399,14 @@ const char *mus_header_type_name(int type) case MUS_WAVPACK: return("wavpack"); break; case MUS_RF64: return("rf64"); break; case MUS_CAFF: return("caff"); break; - default: return("unsupported"); break; + default: return("unknown"); break; } } -const char *mus_data_format_name(int format) +const char *mus_sample_type_name(mus_sample_t samp_type) { - switch (format) + switch (samp_type) { case MUS_BSHORT: return("big endian short (16 bits)"); break; case MUS_MULAW: return("mulaw (8 bits)"); break; @@ -461,9 +435,9 @@ const char *mus_data_format_name(int format) } -const char *mus_data_format_short_name(int format) +const char *mus_sample_type_short_name(mus_sample_t samp_type) { - switch (format) + switch (samp_type) { case MUS_BSHORT: return("short int"); break; case MUS_MULAW: return("mulaw"); break; @@ -499,7 +473,7 @@ const char *mus_data_format_short_name(int format) #endif -const char *mus_header_type_to_string(int type) +const char *mus_header_type_to_string(mus_header_t type) { switch (type) { @@ -516,14 +490,15 @@ const char *mus_header_type_to_string(int type) case MUS_SOUNDFONT: return(TO_LANG(S_mus_soundfont)); case MUS_RF64: return(TO_LANG(S_mus_rf64)); case MUS_CAFF: return(TO_LANG(S_mus_caff)); + default: break; } return(NULL); } -const char *mus_data_format_to_string(int format) +const char *mus_sample_type_to_string(mus_sample_t samp_type) { - switch (format) + switch (samp_type) { case MUS_BSHORT: return(TO_LANG(S_mus_bshort)); case MUS_LSHORT: return(TO_LANG(S_mus_lshort)); @@ -547,17 +522,17 @@ const char *mus_data_format_to_string(int format) case MUS_LDOUBLE_UNSCALED: return(TO_LANG(S_mus_ldouble_unscaled)); case MUS_BFLOAT_UNSCALED: return(TO_LANG(S_mus_bfloat_unscaled)); case MUS_LFLOAT_UNSCALED: return(TO_LANG(S_mus_lfloat_unscaled)); + default: break; } return(NULL); } -static const char *any_data_format_name(int sndlib_format) +static const char *any_sample_type_name(mus_sample_t sndlib_samp_type) { - if (mus_data_format_p(sndlib_format)) - return(mus_data_format_name(sndlib_format)); - else return(mus_header_original_format_name(mus_header_original_format(), - mus_header_type())); + if (mus_is_sample_type(sndlib_samp_type)) + return(mus_sample_type_name(sndlib_samp_type)); + else return(mus_header_original_sample_type_name(mus_header_original_sample_type(), mus_header_type())); } @@ -571,7 +546,7 @@ static int read_bicsf_header(const char *filename, int fd); * 0: ".snd" * 4: data_location (bytes) (not necessarily word aligned on Sun) * 8: data_size (bytes) -- sometimes incorrect ("advisory") - * 12: data format indicator -- see below + * 12: sample type indicator -- see below * 16: srate (int) * 20: chans * 24: comment start @@ -602,7 +577,7 @@ static int read_next_header(const char *filename, int fd) type_specifier = mus_char_to_uninterpreted_int((unsigned char *)hdrbuf); data_location = mus_char_to_ubint((unsigned char *)(hdrbuf + 4)); - if (data_location < 24) return(mus_error(MUS_HEADER_READ_FAILED, "%s: data location: " MUS_LD "?", filename, data_location)); + if (data_location < 24) return(mus_error(MUS_HEADER_READ_FAILED, "%s: data location: %lld?", filename, data_location)); data_size = mus_char_to_ubint((unsigned char *)(hdrbuf + 8)); /* changed to unsigned 11-Nov-06 */ /* can be bogus -- fixup if possible */ @@ -611,37 +586,37 @@ static int read_next_header(const char *filename, int fd) data_size = (true_file_length - data_location); else { - if (true_file_length > (mus_long_t)(1 << 31)) + if (true_file_length > (mus_long_t)0x80000000) /* (1 << 31)) */ data_size = true_file_length - data_location; /* assume size field overflowed 32 bits */ } - original_data_format = mus_char_to_bint((unsigned char *)(hdrbuf + 12)); - switch (original_data_format) - { - case 1: data_format = MUS_MULAW; break; - case 2: data_format = MUS_BYTE; break; /* some sound files assume MUS_UBYTE here! (NAS from 1994 X11R6 contrib) */ - case 3: data_format = MUS_BSHORT; break; - case 4: data_format = MUS_B24INT; break; - case 5: data_format = MUS_BINT; break; - case 6: data_format = MUS_BFLOAT; break; - case 7: data_format = MUS_BDOUBLE; break; - case 18: data_format = MUS_BSHORT; break; /* "emphasized": Xavier Serra's de-emphasis filter: y(n) = x(n) + .9 y(n-1) */ - case 27: data_format = MUS_ALAW; break; - case 30: data_format = MUS_LINT; break; /* from here on, for Snd's internal benefit -- these are probably not used elsewhere */ - case 31: data_format = MUS_LFLOAT; break; - case 32: data_format = MUS_BINTN; break; - case 33: data_format = MUS_LINTN; break; - case 34: data_format = MUS_LDOUBLE; break; - case 35: data_format = MUS_ULSHORT; break; - case 36: data_format = MUS_UBSHORT; break; - case 37: data_format = MUS_LFLOAT_UNSCALED; break; - case 38: data_format = MUS_BFLOAT_UNSCALED; break; - case 39: data_format = MUS_LDOUBLE_UNSCALED; break; - case 40: data_format = MUS_BDOUBLE_UNSCALED; break; - case 41: data_format = MUS_LSHORT; break; - case 42: data_format = MUS_L24INT; break; - case 43: data_format = MUS_UBYTE; break; - default: data_format = MUS_UNKNOWN; break; + original_sample_type = mus_char_to_bint((unsigned char *)(hdrbuf + 12)); + switch (original_sample_type) + { + case 1: sample_type = MUS_MULAW; break; + case 2: sample_type = MUS_BYTE; break; /* some sound files assume MUS_UBYTE here! (NAS from 1994 X11R6 contrib) */ + case 3: sample_type = MUS_BSHORT; break; + case 4: sample_type = MUS_B24INT; break; + case 5: sample_type = MUS_BINT; break; + case 6: sample_type = MUS_BFLOAT; break; + case 7: sample_type = MUS_BDOUBLE; break; + case 18: sample_type = MUS_BSHORT; break; /* "emphasized": Xavier Serra's de-emphasis filter: y(n) = x(n) + .9 y(n-1) */ + case 27: sample_type = MUS_ALAW; break; + case 30: sample_type = MUS_LINT; break; /* from here on, for Snd's internal benefit -- these are probably not used elsewhere */ + case 31: sample_type = MUS_LFLOAT; break; + case 32: sample_type = MUS_BINTN; break; + case 33: sample_type = MUS_LINTN; break; + case 34: sample_type = MUS_LDOUBLE; break; + case 35: sample_type = MUS_ULSHORT; break; + case 36: sample_type = MUS_UBSHORT; break; + case 37: sample_type = MUS_LFLOAT_UNSCALED; break; + case 38: sample_type = MUS_BFLOAT_UNSCALED; break; + case 39: sample_type = MUS_LDOUBLE_UNSCALED; break; + case 40: sample_type = MUS_BDOUBLE_UNSCALED; break; + case 41: sample_type = MUS_LSHORT; break; + case 42: sample_type = MUS_L24INT; break; + case 43: sample_type = MUS_UBYTE; break; + default: sample_type = MUS_UNKNOWN_SAMPLE; break; } srate = mus_char_to_bint((unsigned char *)(hdrbuf + 16)); @@ -666,14 +641,14 @@ static int read_next_header(const char *filename, int fd) maybe_bicsf = mus_char_to_bint((unsigned char *)(hdrbuf + 28)); if (maybe_bicsf == 107364) err = read_bicsf_header(filename, fd); - data_size = mus_bytes_to_samples(data_format, data_size); + data_size = mus_bytes_to_samples(sample_type, data_size); return(err); } -static int sndlib_format_to_next(int format) +static int sndlib_format_to_next(mus_sample_t samp_type) { - switch (format) + switch (samp_type) { case MUS_MULAW: return(1); break; case MUS_BYTE: return(2); break; @@ -698,9 +673,9 @@ static int sndlib_format_to_next(int format) case MUS_L24INT: return(42); break; case MUS_UBYTE: return(43); break; default: - return(mus_error(MUS_UNSUPPORTED_DATA_FORMAT, "Next header: can't write data format: %d (%s)", - format, - any_data_format_name(format))); + return(mus_error(MUS_UNSUPPORTED_SAMPLE_TYPE, "Next header: can't write sample type: %d (%s)", + samp_type, + any_sample_type_name(samp_type))); break; } } @@ -710,13 +685,13 @@ static int header_write(int fd, unsigned char *buf, int chars) { if (chars > 0) { - ssize_t bytes; - bytes = write(fd, buf, chars); + long long int bytes; + bytes = (long long int)write(fd, buf, chars); if (bytes != chars) { char *errstr = NULL; errstr = STRERROR(errno); - return(mus_error(MUS_WRITE_ERROR, "header_write: wrote " SSIZE_TD " of %d bytes, %s", + return(mus_error(MUS_WRITE_ERROR, "header_write: wrote %lld of %d bytes, %s", bytes, chars, (errstr) ? errstr : "unknown error?")); } } @@ -728,13 +703,13 @@ static int header_read(int fd, unsigned char *buf, int chars) { if (chars > 0) { - ssize_t bytes; - bytes = read(fd, buf, chars); + long long int bytes; + bytes = (long long int)read(fd, buf, chars); if (bytes != chars) { char *errstr = NULL; errstr = STRERROR(errno); - return(mus_error(MUS_READ_ERROR, "header_read: read " SSIZE_TD " of %d bytes, %s", + return(mus_error(MUS_READ_ERROR, "header_read: read %lld of %d bytes, %s", bytes, chars, (errstr) ? errstr : "unknown error?")); } } @@ -750,13 +725,13 @@ static void write_next_comment(int fd, const char *comment, int len, int loc) if (len > 0) { unsigned char *combuf; - combuf = (unsigned char *)calloc(len, sizeof(char)); + combuf = (unsigned char *)calloc(len, sizeof(unsigned char)); header_write(fd, combuf, len); free(combuf); } } -static int mus_header_write_next_header(int fd, int wsrate, int wchans, int loc, int siz, int format, const char *comment, int len) +static int mus_header_write_next_header(int fd, int wsrate, int wchans, int loc, int siz, mus_sample_t samp_type, const char *comment, int len) { int i, j; write_four_chars((unsigned char *)hdrbuf, I_DSND); /* ".snd" */ @@ -765,7 +740,7 @@ static int mus_header_write_next_header(int fd, int wsrate, int wchans, int loc, if (loc < j) loc = j; mus_bint_to_char((unsigned char *)(hdrbuf + 4), loc); mus_bint_to_char((unsigned char *)(hdrbuf + 8), siz); - mus_bint_to_char((unsigned char *)(hdrbuf + 12), sndlib_format_to_next(format)); + mus_bint_to_char((unsigned char *)(hdrbuf + 12), sndlib_format_to_next(samp_type)); mus_bint_to_char((unsigned char *)(hdrbuf + 16), wsrate); mus_bint_to_char((unsigned char *)(hdrbuf + 20), wchans); header_write(fd, hdrbuf, 24); @@ -790,7 +765,7 @@ static int mus_header_write_next_header(int fd, int wsrate, int wchans, int loc, * The chunks we want are "COMM", "SSND", and "APPL". * * COMM: 0: chans - * 2: frames + * 2: framples * 6: bits per sample * 8: srate as 80-bit IEEE float * then if AIFC (not AIFF), 4 bytes giving compression id ("NONE"=not compressed) @@ -901,9 +876,9 @@ static void double_to_ieee_80(double val, unsigned char *p) } -static mus_long_t update_form_size, update_frames_location, update_ssnd_location, update_rf64_location; +static mus_long_t update_form_size, update_framples_location, update_ssnd_location, update_rf64_location; -static ssize_t seek_and_read(int fd, unsigned char *buf, mus_long_t offset, int nbytes) +static long long int seek_and_read(int fd, unsigned char *buf, mus_long_t offset, int nbytes) { if (offset < 0) return(-1); lseek(fd, offset, SEEK_SET); @@ -987,8 +962,8 @@ static void read_aif_aux_comment(unsigned char *buf, mus_long_t offset, int chun static void read_aif_appl_chunk(unsigned char *buf, mus_long_t offset, int chunksize) { - const unsigned char I_SU7M[4] = {'S','U','7','M'}; - const unsigned char I_SU7R[4] = {'S','U','7','R'}; + static const unsigned char I_SU7M[4] = {'S','U','7','M'}; + static const unsigned char I_SU7R[4] = {'S','U','7','R'}; if (match_four_chars((unsigned char *)(buf + 8), I_MUS_)) { @@ -1017,7 +992,7 @@ static int read_aiff_header(const char *filename, int fd, int overall_offset) { /* we know we have checked for FORM xxxx AIFF|AIFC when we arrive here */ /* as far as I can tell, the COMM block has the header data we seek, and the SSND block has the sound data */ - int chunksize, chunkloc, i, ssnd_bytes = 0; + int chunkloc, i, ssnd_bytes = 0; bool happy = true, got_comm = false; mus_long_t offset = 0; @@ -1025,7 +1000,7 @@ static int read_aiff_header(const char *filename, int fd, int overall_offset) update_ssnd_location = 0; chunkloc = 12 + overall_offset; for (i = 0; i < AUX_COMMENTS; i++) aux_comment_start[i] = 0; - data_format = MUS_BSHORT; + sample_type = MUS_BSHORT; srate = 0; chans = 0; markers = 0; @@ -1039,15 +1014,16 @@ static int read_aiff_header(const char *filename, int fd, int overall_offset) while (happy) { + int chunksize; offset += chunkloc; if (seek_and_read(fd, (unsigned char *)hdrbuf, offset, 32) <= 0) { if ((got_comm) && (data_location > 0)) { - mus_print("%s, aiff header: chunks confused at " MUS_LD "; will try to continue", filename, offset); + mus_print("%s, aiff header: chunks confused at %lld; will try to continue", filename, offset); break; } - return(mus_error(MUS_HEADER_READ_FAILED, "%s, aiff header: chunks confused at " MUS_LD , filename, offset)); + return(mus_error(MUS_HEADER_READ_FAILED, "%s, aiff header: chunks confused at %lld" , filename, offset)); } chunksize = mus_char_to_bint((unsigned char *)(hdrbuf + 4)); @@ -1061,97 +1037,97 @@ static int read_aiff_header(const char *filename, int fd, int overall_offset) if (match_four_chars((unsigned char *)hdrbuf, I_COMM)) { - int frames; + int framples; got_comm = true; chans = mus_char_to_bshort((unsigned char *)(hdrbuf + 8)); - frames = mus_char_to_ubint((unsigned char *)(hdrbuf + 10)); /* was bint 27-Jul-01 */ - update_frames_location = 10 + offset; + framples = mus_char_to_ubint((unsigned char *)(hdrbuf + 10)); /* was bint 27-Jul-01 */ + update_framples_location = 10 + offset; - original_data_format = mus_char_to_bshort((unsigned char *)(hdrbuf + 14)); - if ((original_data_format % 8) != 0) + original_sample_type = mus_char_to_bshort((unsigned char *)(hdrbuf + 14)); + if ((original_sample_type % 8) != 0) { /* weird sizes are legal -- * these samples are left-justified (and zero padded on the right), so * we can handle any bit size by rounding up to the nearest byte. */ - original_data_format = 8 * (1 + (original_data_format >> 3)); + original_sample_type = 8 * (1 + (original_sample_type >> 3)); } - if (original_data_format == 8) data_format = MUS_BYTE; - else if (original_data_format == 16) data_format = MUS_BSHORT; - else if (original_data_format == 24) data_format = MUS_B24INT; - else if (original_data_format == 32) data_format = MUS_BINT; - else if (original_data_format == 64) data_format = MUS_BDOUBLE; + if (original_sample_type == 8) sample_type = MUS_BYTE; + else if (original_sample_type == 16) sample_type = MUS_BSHORT; + else if (original_sample_type == 24) sample_type = MUS_B24INT; + else if (original_sample_type == 32) sample_type = MUS_BINT; + else if (original_sample_type == 64) sample_type = MUS_BDOUBLE; else return(mus_error(MUS_HEADER_READ_FAILED, "%s: bits per sample: %d?", filename, mus_char_to_bshort((unsigned char *)(hdrbuf + 14)))); srate = (int)ieee_80_to_double((unsigned char *)(hdrbuf + 16)); - /* if AIFC, compression type over-rides (possibly bogus) original_data_format */ + /* if AIFC, compression type over-rides (possibly bogus) original_sample_type */ if (type_specifier == mus_char_to_uninterpreted_int((unsigned const char *)I_AIFC)) { - const unsigned char I_twos[4] = {'t','w','o','s'}; /* AIFC big endian? */ + static const unsigned char I_twos[4] = {'t','w','o','s'}; /* AIFC big endian? */ /* some aifc files assume the compression field is a new and very weird chunk!! -- surely a bug? */ /* AIFF spec says COMM size is always 18, but this is amended in the newer AIFC spec */ if (chunksize == 18) chunksize += (5 + ((int)hdrbuf[30])); /* 5 = chunk header length in this case */ if ((!(match_four_chars((unsigned char *)(hdrbuf + 26), I_NONE))) && (!(match_four_chars((unsigned char *)(hdrbuf + 26), I_twos)))) { - const unsigned char I_ALAW[4] = {'A','L','A','W'}; - original_data_format = mus_char_to_uninterpreted_int((unsigned char *)(hdrbuf + 26)); + static const unsigned char I_ALAW[4] = {'A','L','A','W'}; + original_sample_type = mus_char_to_uninterpreted_int((unsigned char *)(hdrbuf + 26)); if ((match_four_chars((unsigned char *)(hdrbuf + 26), I_ALAW)) || (match_four_chars((unsigned char *)(hdrbuf + 26), I_alaw))) - data_format = MUS_ALAW; + sample_type = MUS_ALAW; else { if ((match_four_chars((unsigned char *)(hdrbuf + 26), I_ULAW)) || (match_four_chars((unsigned char *)(hdrbuf + 26), I_ulaw))) - data_format = MUS_MULAW; + sample_type = MUS_MULAW; else { - const unsigned char I_ni23[4] = {'n','i','2','3'}; + static const unsigned char I_ni23[4] = {'n','i','2','3'}; if ((match_four_chars((unsigned char *)(hdrbuf + 26), I_sowt)) || (match_four_chars((unsigned char *)(hdrbuf + 26), I_ni23))) { /* Sound.h sez sowt is just 16-bit format */ - if (data_format == MUS_BSHORT) data_format = MUS_LSHORT; - else if (data_format == MUS_B24INT) data_format = MUS_L24INT; - else if (data_format == MUS_BINT) data_format = MUS_LINT; + if (sample_type == MUS_BSHORT) sample_type = MUS_LSHORT; + else if (sample_type == MUS_B24INT) sample_type = MUS_L24INT; + else if (sample_type == MUS_BINT) sample_type = MUS_LINT; } else { if (match_four_chars((unsigned char *)(hdrbuf + 26), I_raw_)) { - if (data_format == MUS_BYTE) data_format = MUS_UBYTE; - else if (data_format == MUS_BSHORT) data_format = MUS_UBSHORT; + if (sample_type == MUS_BYTE) sample_type = MUS_UBYTE; + else if (sample_type == MUS_BSHORT) sample_type = MUS_UBSHORT; } else { unsigned char I_FL32[4] = {'F','L','3','2'}; /* 32-bit float (apparently used by CSound and SoundHack) */ if ((match_four_chars((unsigned char *)(hdrbuf + 26), I_fl32)) || (match_four_chars((unsigned char *)(hdrbuf + 26), I_FL32))) - data_format = MUS_BFLOAT; + sample_type = MUS_BFLOAT; else { if (match_four_chars((unsigned char *)(hdrbuf + 26), I_fl64)) - data_format = MUS_BDOUBLE; + sample_type = MUS_BDOUBLE; else { - const unsigned char I_ima4[4] = {'i','m','a','4'}; /* AIFC IMA adpcm apparently */ + static const unsigned char I_ima4[4] = {'i','m','a','4'}; /* AIFC IMA adpcm apparently */ if (match_four_chars((unsigned char *)(hdrbuf + 26), I_ima4)) { block_align = 34; - original_data_format = MUS_AIFF_IMA_ADPCM; + original_sample_type = MUS_AIFF_IMA_ADPCM; } else { - const unsigned char I_in32[4] = {'i','n','3','2'}; + static const unsigned char I_in32[4] = {'i','n','3','2'}; if (match_four_chars((unsigned char *)(hdrbuf + 26), I_in32)) - data_format = MUS_BINT; + sample_type = MUS_BINT; else { - const unsigned char I_in24[4] = {'i','n','2','4'}; + static const unsigned char I_in24[4] = {'i','n','2','4'}; if (match_four_chars((unsigned char *)(hdrbuf + 26), I_in24)) - data_format = MUS_B24INT; + sample_type = MUS_B24INT; else { /* others from Sound.h: @@ -1171,7 +1147,7 @@ static int read_aiff_header(const char *filename, int fd, int overall_offset) openquicktime and ffmpeg have decoders for some of these; all too complex for my taste on a Mac, we could apparently pick up decoders from coreaudio */ - data_format = MUS_UNKNOWN; + sample_type = MUS_UNKNOWN_SAMPLE; } } } @@ -1183,7 +1159,7 @@ static int read_aiff_header(const char *filename, int fd, int overall_offset) } } } - data_size = (frames * mus_bytes_per_sample(data_format) * chans); + data_size = (framples * mus_bytes_per_sample(sample_type) * chans); } else { @@ -1203,7 +1179,7 @@ static int read_aiff_header(const char *filename, int fd, int overall_offset) } else { - const unsigned char I_AUTH[4] = {'A','U','T','H'}; + static const unsigned char I_AUTH[4] = {'A','U','T','H'}; if ((match_four_chars((unsigned char *)hdrbuf, I_ANNO)) || (match_four_chars((unsigned char *)hdrbuf, I_COMT)) || (match_four_chars((unsigned char *)hdrbuf, I_NAME)) || @@ -1239,20 +1215,20 @@ static int read_aiff_header(const char *filename, int fd, int overall_offset) if (data_size > true_file_length) { data_size = true_file_length - data_location; - if (data_size < 0) return(mus_error(MUS_HEADER_READ_FAILED, "%s: data_size = " MUS_LD "?", filename, data_size)); + if (data_size < 0) return(mus_error(MUS_HEADER_READ_FAILED, "%s: data_size = %lld?", filename, data_size)); } - if ((data_size > ssnd_bytes) && (data_format != MUS_UNKNOWN)) + if ((data_size > ssnd_bytes) && (sample_type != MUS_UNKNOWN_SAMPLE)) data_size = ssnd_bytes; - data_size = mus_bytes_to_samples(data_format, data_size); + data_size = mus_bytes_to_samples(sample_type, data_size); return(MUS_NO_ERROR); } -static int sndlib_format_to_aiff_bits(int format) +static int sndlib_format_to_aiff_bits(mus_sample_t samp_type) { - switch (format) + switch (samp_type) { case MUS_BSHORT: case MUS_LSHORT: case MUS_UBSHORT: case MUS_ULSHORT: return(16); break; case MUS_B24INT: case MUS_L24INT: return(24); break; @@ -1260,17 +1236,17 @@ static int sndlib_format_to_aiff_bits(int format) case MUS_BDOUBLE: case MUS_LDOUBLE: return(64); break; case MUS_BYTE: case MUS_UBYTE: case MUS_MULAW: case MUS_ALAW: return(8); break; default: - return(mus_error(MUS_UNSUPPORTED_DATA_FORMAT, "aiff header: can't write data format: %d (%s)", - format, - any_data_format_name(format))); + return(mus_error(MUS_UNSUPPORTED_SAMPLE_TYPE, "aiff header: can't write sample type: %d (%s)", + samp_type, + any_sample_type_name(samp_type))); break; } } -static const char *sndlib_format_to_aifc_name(int format) +static const char *sndlib_format_to_aifc_name(mus_sample_t samp_type) { - switch (format) + switch (samp_type) { case MUS_BSHORT: case MUS_B24INT: case MUS_BINT: case MUS_BYTE: return((const char *)I_NONE); break; /* use in24 and in32? */ case MUS_LSHORT: case MUS_L24INT: case MUS_LINT: return((const char *)I_sowt); break; /* should this use ni23? */ @@ -1284,14 +1260,13 @@ static const char *sndlib_format_to_aifc_name(int format) } -static int write_aif_header(int fd, int wsrate, int wchans, int siz, int format, const char *comment, int len, bool aifc_header) +static int write_aif_header(int fd, int wsrate, int wchans, int siz, mus_sample_t samp_type, const char *comment, int len, bool aifc_header) { /* we write the simplest possible AIFC header: AIFC | COMM | APPL-MUS_ if needed | SSND eof. */ /* the assumption being that we're going to be appending sound data once the header is out */ /* INST and MARK chunks added Jul-95 for various programs that expect them (MixView). */ /* set aifc_header to false to get old-style AIFF header */ int i, j, lenhdr = 0, lenloop, curend = 0, extra = 0; - char *str; lenloop = 38; if ((loop_modes[0] != 0) || (loop_modes[1] != 0)) lenloop = 42 + 28; @@ -1331,14 +1306,15 @@ static int write_aif_header(int fd, int wsrate, int wchans, int siz, int format, mus_bshort_to_char((unsigned char *)(hdrbuf + 20), (short)wchans); if (wchans > 0) - mus_bint_to_char((unsigned char *)(hdrbuf + 22), siz / (wchans * mus_bytes_per_sample(format))); + mus_bint_to_char((unsigned char *)(hdrbuf + 22), siz / (wchans * mus_bytes_per_sample(samp_type))); - mus_bshort_to_char((unsigned char *)(hdrbuf + 26), sndlib_format_to_aiff_bits(format)); + mus_bshort_to_char((unsigned char *)(hdrbuf + 26), sndlib_format_to_aiff_bits(samp_type)); double_to_ieee_80((double)wsrate, (unsigned char *)(hdrbuf + 28)); if (aifc_header) { - str = (char *)sndlib_format_to_aifc_name(format); + char *str; + str = (char *)sndlib_format_to_aifc_name(samp_type); write_four_chars((unsigned char *)(hdrbuf + 38), (const unsigned char *)str); (*(unsigned char *)(hdrbuf + 42)) = 4; /* final pad null not accounted-for */ write_four_chars((unsigned char *)(hdrbuf + 43), (const unsigned char *)str); @@ -1474,12 +1450,13 @@ char *mus_header_aiff_aux_comment(const char *name, mus_long_t *starts, mus_long sc_len = 0; for (i = 0; i < AUX_COMMENTS; i++) { - mus_long_t start, end, len; + mus_long_t start, end; start = starts[i]; end = ends[i]; if ((start > 0) && (start < end)) { int j; + mus_long_t len; len = end - start + 1; lseek(fd, start, SEEK_SET); header_read(fd, (unsigned char *)(sc + sc_len), len); @@ -1514,8 +1491,8 @@ char *mus_header_aiff_aux_comment(const char *name, mus_long_t *starts, mus_long * 28: format (int32) * 32: format flags * 36: bytes per "packet" - * 40: frames per packet - * 44: channels per frame + * 40: framples per packet + * 44: channels per frample * 48: bits per channel * audio data is in 'data' chunk */ @@ -1531,7 +1508,7 @@ static int read_caff_header(int fd) #define data_is_big_endian (1L << 1) /* misleading name -- flag is 1 if data is little endian */ - data_format = MUS_UNKNOWN; + sample_type = MUS_UNKNOWN_SAMPLE; srate = 0; chans = 0; data_size = 0; @@ -1549,21 +1526,17 @@ static int read_caff_header(int fd) /* 'desc' is always the first chunk, but easier to handle in the loop */ if (match_four_chars((unsigned char *)hdrbuf, I_desc)) { - int format_flags, bytes_per_packet, frames_per_packet, channels_per_frame, bits_per_channel; + int format_flags, channels_per_frample, bits_per_channel; srate = (int)mus_char_to_bdouble((unsigned char *)(hdrbuf + 12)); format_flags = mus_char_to_ubint((unsigned char *)(hdrbuf + 24)); - bytes_per_packet = mus_char_to_ubint((unsigned char *)(hdrbuf + 28)); - frames_per_packet = mus_char_to_ubint((unsigned char *)(hdrbuf + 32)); - channels_per_frame = mus_char_to_ubint((unsigned char *)(hdrbuf + 36)); + /* bytes_per_packet = mus_char_to_ubint((unsigned char *)(hdrbuf + 28)); */ + /* framples_per_packet = mus_char_to_ubint((unsigned char *)(hdrbuf + 32)); */ + channels_per_frample = mus_char_to_ubint((unsigned char *)(hdrbuf + 36)); bits_per_channel = mus_char_to_ubint((unsigned char *)(hdrbuf + 40)); - chans = channels_per_frame; -#if 0 - fprintf(stderr, "srate: %d, format: %c%c%c%c, %d, bytes: %d, frames: %d, chans: %d, bits: %d\n", - srate, hdrbuf[20], hdrbuf[21], hdrbuf[22], hdrbuf[23], - format_flags, bytes_per_packet, frames_per_packet, channels_per_frame, bits_per_channel); -#endif + chans = channels_per_frample; + /* format id can be 'lpcm' 'alaw' 'ulaw' and a bunch of others we ignore */ - original_data_format = mus_char_to_bint((unsigned char *)(hdrbuf + 20)); + original_sample_type = mus_char_to_bint((unsigned char *)(hdrbuf + 20)); if (match_four_chars((unsigned char *)(hdrbuf + 20), I_lpcm)) { if (format_flags & data_is_float) @@ -1571,23 +1544,23 @@ static int read_caff_header(int fd) if (!(format_flags & data_is_big_endian)) { if (bits_per_channel == 32) - data_format = MUS_BFLOAT; + sample_type = MUS_BFLOAT; else { if (bits_per_channel == 64) - data_format = MUS_BDOUBLE; - else err = MUS_UNSUPPORTED_DATA_FORMAT; + sample_type = MUS_BDOUBLE; + else err = MUS_UNSUPPORTED_SAMPLE_TYPE; } } else { if (bits_per_channel == 32) - data_format = MUS_LFLOAT; + sample_type = MUS_LFLOAT; else { if (bits_per_channel == 64) - data_format = MUS_LDOUBLE; - else err = MUS_UNSUPPORTED_DATA_FORMAT; + sample_type = MUS_LDOUBLE; + else err = MUS_UNSUPPORTED_SAMPLE_TYPE; } } } @@ -1596,20 +1569,20 @@ static int read_caff_header(int fd) if (!(format_flags & data_is_big_endian)) { if (bits_per_channel == 32) - data_format = MUS_BINTN; + sample_type = MUS_BINTN; else { if (bits_per_channel == 24) - data_format = MUS_B24INT; + sample_type = MUS_B24INT; else { if (bits_per_channel == 16) - data_format = MUS_BSHORT; + sample_type = MUS_BSHORT; else { if (bits_per_channel == 8) - data_format = MUS_BYTE; - else err = MUS_UNSUPPORTED_DATA_FORMAT; + sample_type = MUS_BYTE; + else err = MUS_UNSUPPORTED_SAMPLE_TYPE; } } } @@ -1617,20 +1590,20 @@ static int read_caff_header(int fd) else { if (bits_per_channel == 32) - data_format = MUS_LINTN; + sample_type = MUS_LINTN; else { if (bits_per_channel == 24) - data_format = MUS_L24INT; + sample_type = MUS_L24INT; else { if (bits_per_channel == 16) - data_format = MUS_LSHORT; + sample_type = MUS_LSHORT; else { if (bits_per_channel == 8) - data_format = MUS_BYTE; - else err = MUS_UNSUPPORTED_DATA_FORMAT; + sample_type = MUS_BYTE; + else err = MUS_UNSUPPORTED_SAMPLE_TYPE; } } } @@ -1641,15 +1614,15 @@ static int read_caff_header(int fd) { if (match_four_chars((unsigned char *)(hdrbuf + 20), I_alaw)) { - data_format = MUS_ALAW; + sample_type = MUS_ALAW; } else { if (match_four_chars((unsigned char *)(hdrbuf + 20), I_ulaw)) { - data_format = MUS_MULAW; + sample_type = MUS_MULAW; } - else err = MUS_UNSUPPORTED_DATA_FORMAT; + else err = MUS_UNSUPPORTED_SAMPLE_TYPE; } } } @@ -1659,7 +1632,7 @@ static int read_caff_header(int fd) { happy = true; data_location = offset + 16; /* skip the 4 bytes for "edit count" */ - update_frames_location = offset + 4; + update_framples_location = offset + 4; /* here chunksize can be -1! */ if (chunksize > 0) @@ -1673,17 +1646,17 @@ static int read_caff_header(int fd) } if (err == MUS_NO_ERROR) - data_size = mus_bytes_to_samples(data_format, data_size); + data_size = mus_bytes_to_samples(sample_type, data_size); return(err); } -static int write_caff_header(int fd, int wsrate, int wchans, mus_long_t wsize, int format) +static int write_caff_header(int fd, int wsrate, int wchans, mus_long_t wsize, mus_sample_t samp_type) { - int format_flags = 0, bytes_per_packet = 0, frames_per_packet = 1, bits_per_channel = 0; + int format_flags = 0, bytes_per_packet = 0, framples_per_packet = 1, bits_per_channel = 0; - switch (format) + switch (samp_type) { case MUS_ALAW: bytes_per_packet = 1; @@ -1696,11 +1669,11 @@ static int write_caff_header(int fd, int wsrate, int wchans, mus_long_t wsize, i break; default: - if ((format == MUS_LFLOAT) || (format == MUS_LDOUBLE) || (format == MUS_BFLOAT) || (format == MUS_BDOUBLE)) + if ((samp_type == MUS_LFLOAT) || (samp_type == MUS_LDOUBLE) || (samp_type == MUS_BFLOAT) || (samp_type == MUS_BDOUBLE)) format_flags = 1; - if ((format == MUS_LFLOAT) || (format == MUS_LDOUBLE) || (format == MUS_LINTN) || (format == MUS_L24INT) || (format == MUS_LSHORT)) + if ((samp_type == MUS_LFLOAT) || (samp_type == MUS_LDOUBLE) || (samp_type == MUS_LINTN) || (samp_type == MUS_L24INT) || (samp_type == MUS_LSHORT)) format_flags |= 2; - switch (format) + switch (samp_type) { case MUS_BYTE: bytes_per_packet = 1; @@ -1726,6 +1699,8 @@ static int write_caff_header(int fd, int wsrate, int wchans, mus_long_t wsize, i bytes_per_packet = 8; bits_per_channel = 64; break; + + default: break; } break; } @@ -1737,7 +1712,7 @@ static int write_caff_header(int fd, int wsrate, int wchans, mus_long_t wsize, i write_four_chars((unsigned char *)(hdrbuf + 8), I_desc); mus_blong_to_char((unsigned char *)(hdrbuf + 12), 32); mus_bdouble_to_char((unsigned char *)(hdrbuf + 20), (double)wsrate); - switch (format) + switch (samp_type) { case MUS_ALAW: write_four_chars((unsigned char *)(hdrbuf + 28), I_alaw); @@ -1753,12 +1728,12 @@ static int write_caff_header(int fd, int wsrate, int wchans, mus_long_t wsize, i } mus_bint_to_char((unsigned char *)(hdrbuf + 32), format_flags); mus_bint_to_char((unsigned char *)(hdrbuf + 36), bytes_per_packet); - mus_bint_to_char((unsigned char *)(hdrbuf + 40), frames_per_packet); + mus_bint_to_char((unsigned char *)(hdrbuf + 40), framples_per_packet); mus_bint_to_char((unsigned char *)(hdrbuf + 44), wchans); mus_bint_to_char((unsigned char *)(hdrbuf + 48), bits_per_channel); write_four_chars((unsigned char *)(hdrbuf + 52), I_data); mus_blong_to_char((unsigned char *)(hdrbuf + 56), wsize); - update_frames_location = 56; + update_framples_location = 56; mus_bint_to_char((unsigned char *)(hdrbuf + 64), 0); data_location = 68; header_write(fd, hdrbuf, 68); @@ -1836,7 +1811,7 @@ static int write_caff_header(int fd, int wsrate, int wchans, mus_long_t wsize, i * bext chunk has comments -- perhaps add these to the info/list list? I need an example! -- is the chunk id "bext"? */ -static int wave_to_sndlib_format(int osf, int bps, bool little) +static mus_sample_t wave_to_sndlib_format(int osf, int bps, bool little) { switch (osf) { @@ -1870,11 +1845,11 @@ static int wave_to_sndlib_format(int osf, int bps, bool little) case 0x101: return(MUS_MULAW); break; case 0x102: return(MUS_ALAW); break; } - return(MUS_UNKNOWN); + return(MUS_UNKNOWN_SAMPLE); } -static void read_riff_fmt_chunk(unsigned char *hdrbuf, bool little) +static void read_riff_fmt_chunk(unsigned char *hbuf, bool little) { /* fmt chunk (also used in RF64 below) * @@ -1895,75 +1870,75 @@ static void read_riff_fmt_chunk(unsigned char *hdrbuf, bool little) * #x000551f8 = 348664 = size in bytes - 8 * #x00000fe4 = 4068 [fmt_ chunk size?] */ - original_data_format = big_or_little_endian_short((unsigned char *)(hdrbuf + 8), little); - chans = big_or_little_endian_short((unsigned char *)(hdrbuf + 10), little); - srate = big_or_little_endian_int((unsigned char *)(hdrbuf + 12), little); - block_align = big_or_little_endian_short((unsigned char *)(hdrbuf + 20), little); - bits_per_sample = big_or_little_endian_short((unsigned char *)(hdrbuf + 22), little); - if (original_data_format == -2) /* 0xFFFE = "extensible" : short size=22, short bits, long chanmap, short format */ - original_data_format = big_or_little_endian_short((unsigned char *)(hdrbuf + 24 + 8), little); - data_format = wave_to_sndlib_format(original_data_format, bits_per_sample, little); + original_sample_type = big_or_little_endian_short((unsigned char *)(hbuf + 8), little); + chans = big_or_little_endian_short((unsigned char *)(hbuf + 10), little); + srate = big_or_little_endian_int((unsigned char *)(hbuf + 12), little); + block_align = big_or_little_endian_short((unsigned char *)(hbuf + 20), little); + bits_per_sample = big_or_little_endian_short((unsigned char *)(hbuf + 22), little); + if (original_sample_type == -2) /* 0xFFFE = "extensible" : short size=22, short bits, long chanmap, short format */ + original_sample_type = big_or_little_endian_short((unsigned char *)(hbuf + 24 + 8), little); + sample_type = wave_to_sndlib_format(original_sample_type, bits_per_sample, little); } -static int write_riff_fmt_chunk(int fd, unsigned char *hdrbuf, int format, int wsrate, int wchans) +static int write_riff_fmt_chunk(int fd, unsigned char *hbuf, mus_sample_t samp_type, int wsrate, int wchans) { int err = MUS_NO_ERROR; - write_four_chars((unsigned char *)hdrbuf, I_fmt_); - mus_lint_to_char((unsigned char *)(hdrbuf + 4), 16); - switch (format) + write_four_chars((unsigned char *)hbuf, I_fmt_); + mus_lint_to_char((unsigned char *)(hbuf + 4), 16); + switch (samp_type) { case MUS_MULAW: - mus_lshort_to_char((unsigned char *)(hdrbuf + 8), 7); - mus_lshort_to_char((unsigned char *)(hdrbuf + 22), 8); + mus_lshort_to_char((unsigned char *)(hbuf + 8), 7); + mus_lshort_to_char((unsigned char *)(hbuf + 22), 8); break; case MUS_ALAW: - mus_lshort_to_char((unsigned char *)(hdrbuf + 8), 6); - mus_lshort_to_char((unsigned char *)(hdrbuf + 22), 8); + mus_lshort_to_char((unsigned char *)(hbuf + 8), 6); + mus_lshort_to_char((unsigned char *)(hbuf + 22), 8); break; case MUS_UBYTE: - mus_lshort_to_char((unsigned char *)(hdrbuf + 8), 1); - mus_lshort_to_char((unsigned char *)(hdrbuf + 22), 8); + mus_lshort_to_char((unsigned char *)(hbuf + 8), 1); + mus_lshort_to_char((unsigned char *)(hbuf + 22), 8); break; case MUS_LSHORT: - mus_lshort_to_char((unsigned char *)(hdrbuf + 8), 1); - mus_lshort_to_char((unsigned char *)(hdrbuf + 22), 16); + mus_lshort_to_char((unsigned char *)(hbuf + 8), 1); + mus_lshort_to_char((unsigned char *)(hbuf + 22), 16); break; case MUS_L24INT: - mus_lshort_to_char((unsigned char *)(hdrbuf + 8), 1); - mus_lshort_to_char((unsigned char *)(hdrbuf + 22), 24); + mus_lshort_to_char((unsigned char *)(hbuf + 8), 1); + mus_lshort_to_char((unsigned char *)(hbuf + 22), 24); break; case MUS_LINT: - mus_lshort_to_char((unsigned char *)(hdrbuf + 8), 1); - mus_lshort_to_char((unsigned char *)(hdrbuf + 22), 32); + mus_lshort_to_char((unsigned char *)(hbuf + 8), 1); + mus_lshort_to_char((unsigned char *)(hbuf + 22), 32); break; case MUS_LFLOAT: - mus_lshort_to_char((unsigned char *)(hdrbuf + 8), 3); - mus_lshort_to_char((unsigned char *)(hdrbuf + 22), 32); + mus_lshort_to_char((unsigned char *)(hbuf + 8), 3); + mus_lshort_to_char((unsigned char *)(hbuf + 22), 32); break; case MUS_LDOUBLE: - mus_lshort_to_char((unsigned char *)(hdrbuf + 8), 3); - mus_lshort_to_char((unsigned char *)(hdrbuf + 22), 64); + mus_lshort_to_char((unsigned char *)(hbuf + 8), 3); + mus_lshort_to_char((unsigned char *)(hbuf + 22), 64); break; default: /* don't call mus_error directly -- we need to close the file first in mus_header_write */ - err = MUS_UNSUPPORTED_DATA_FORMAT; + err = MUS_UNSUPPORTED_SAMPLE_TYPE; break; } - mus_lshort_to_char((unsigned char *)(hdrbuf + 10), (short)wchans); - mus_lint_to_char((unsigned char *)(hdrbuf + 12), wsrate); - mus_lint_to_char((unsigned char *)(hdrbuf + 16), wsrate * wchans * mus_bytes_per_sample(format)); /* added chans 10-Mar-99 */ - mus_lshort_to_char((unsigned char *)(hdrbuf + 20), (short)(wchans * mus_bytes_per_sample(format))); + mus_lshort_to_char((unsigned char *)(hbuf + 10), (short)wchans); + mus_lint_to_char((unsigned char *)(hbuf + 12), wsrate); + mus_lint_to_char((unsigned char *)(hbuf + 16), wsrate * wchans * mus_bytes_per_sample(samp_type)); /* added chans 10-Mar-99 */ + mus_lshort_to_char((unsigned char *)(hbuf + 20), (short)(wchans * mus_bytes_per_sample(samp_type))); /* 22 short written above = bits/sample */ - header_write(fd, hdrbuf, 24); + header_write(fd, hbuf, 24); return(err); } @@ -1973,14 +1948,14 @@ static const unsigned char I_JUNK[4] = {'J','U','N','K'}; static int read_riff_header(const char *filename, int fd) { /* we know we have checked for RIFF xxxx WAVE when we arrive here */ - int chunksize, chunkloc = 12, i; + int chunkloc = 12, i; bool little = true, got_fmt = false; mus_long_t offset = 0; if (match_four_chars((unsigned char *)hdrbuf, I_RIFX)) little = false; /* big-endian data in this case, but I've never seen one */ little_endian = little; type_specifier = mus_char_to_uninterpreted_int((unsigned char *)(hdrbuf + 8)); - data_format = MUS_UNKNOWN; + sample_type = MUS_UNKNOWN_SAMPLE; srate = 0; chans = 0; fact_samples = 0; @@ -1991,6 +1966,7 @@ static int read_riff_header(const char *filename, int fd) while (true) { + int chunksize; offset += chunkloc; if (offset >= true_file_length) break; if (seek_and_read(fd, (unsigned char *)hdrbuf, offset, 64) <= 0) break; @@ -2003,7 +1979,7 @@ static int read_riff_header(const char *filename, int fd) if (match_four_chars((unsigned char *)hdrbuf, I_fmt_)) { got_fmt = true; - update_frames_location = 12 + offset; + update_framples_location = 12 + offset; read_riff_fmt_chunk(hdrbuf, little); } else @@ -2023,7 +1999,7 @@ static int read_riff_header(const char *filename, int fd) } else { - const unsigned char I_inst[4] = {'i','n','s','t'}; /* RIFF wants lower case, just to be different */ + static const unsigned char I_inst[4] = {'i','n','s','t'}; /* RIFF wants lower case, just to be different */ if (match_four_chars((unsigned char *)hdrbuf, I_inst)) { base_note = hdrbuf[8]; @@ -2065,9 +2041,9 @@ static int read_riff_header(const char *filename, int fd) if (data_size > true_file_length) { data_size = true_file_length - data_location; - if (data_size < 0) return(mus_error(MUS_HEADER_READ_FAILED, "%s: data_size = " MUS_LD "?", filename, data_size)); + if (data_size < 0) return(mus_error(MUS_HEADER_READ_FAILED, "%s: data_size = %lld?", filename, data_size)); } - data_size = mus_bytes_to_samples(data_format, data_size); + data_size = mus_bytes_to_samples(sample_type, data_size); return(MUS_NO_ERROR); } @@ -2104,7 +2080,7 @@ static void write_riff_clm_comment(int fd, const char *comment, int len, int ext } -static int write_riff_header(int fd, int wsrate, int wchans, int siz, int format, const char *comment, int len) +static int write_riff_header(int fd, int wsrate, int wchans, int siz, mus_sample_t samp_type, const char *comment, int len) { int j, extra = 0, err = MUS_NO_ERROR; @@ -2116,7 +2092,7 @@ static int write_riff_header(int fd, int wsrate, int wchans, int siz, int format data_location += (8 + len + extra); } /* 36 = "RIFF" + size(4) + "WAVE" + "fmt " + size(4) + 16 for data */ - /* 2nd 36 is for "JUNK" chunk, 8 is data chunk header */ + /* second 36 is for "JUNK" chunk, 8 is data chunk header */ write_four_chars((unsigned char *)hdrbuf, I_RIFF); mus_lint_to_char((unsigned char *)(hdrbuf + 4), data_location + siz - 8); /* added -8 25-June-07 */ @@ -2130,7 +2106,7 @@ static int write_riff_header(int fd, int wsrate, int wchans, int siz, int format header_write(fd, hdrbuf, 36); /* fmt chunk */ - err = write_riff_fmt_chunk(fd, hdrbuf, format, wsrate, wchans); + err = write_riff_fmt_chunk(fd, hdrbuf, samp_type, wsrate, wchans); /* include possible clm (comment) chunk */ if (len > 0) @@ -2149,7 +2125,7 @@ char *mus_header_riff_aux_comment(const char *name, mus_long_t *starts, mus_long char *sc = NULL, *auxcom; if ((starts) && (starts[0] != 0)) { - int len, j, fd, k, m; + int j, fd, k, m; mus_long_t i, end; /* found a LIST+INFO chunk (and no other comment) */ fd = mus_file_open_read(name); @@ -2166,6 +2142,7 @@ char *mus_header_riff_aux_comment(const char *name, mus_long_t *starts, mus_long i += 4; while (i < end) { + int len; for (m = 0; m < 4; m++) sc[j++] = auxcom[k++]; len = mus_char_to_lint((unsigned char *)(auxcom + k)); if ((len <= 0) || (len > end)) break; @@ -2200,10 +2177,10 @@ static int read_soundforge_header(const char *filename, int fd) { /* like RIFF but lowercase and 64-bit vals */ int i, off; - mus_long_t offset, chunksize, chunkloc; + mus_long_t offset, chunkloc; chunkloc = 12 * 2 + 16; offset = 0; - data_format = MUS_UNKNOWN; + sample_type = MUS_UNKNOWN_SAMPLE; srate = 0; chans = 0; fact_samples = 0; @@ -2213,6 +2190,7 @@ static int read_soundforge_header(const char *filename, int fd) update_form_size = mus_char_to_llong((unsigned char *)(hdrbuf + 4 * 2)); while (true) { + int chunksize; offset += chunkloc; if (offset >= true_file_length) break; if (seek_and_read(fd, (unsigned char *)hdrbuf, offset, 64) <= 0) break; @@ -2226,12 +2204,12 @@ static int read_soundforge_header(const char *filename, int fd) if (match_four_chars((unsigned char *)hdrbuf, I_fmt_)) { off = 16; - original_data_format = mus_char_to_lshort((unsigned char *)(hdrbuf + 8 + off)); + original_sample_type = mus_char_to_lshort((unsigned char *)(hdrbuf + 8 + off)); chans = mus_char_to_lshort((unsigned char *)(hdrbuf + 10 + off)); srate = mus_char_to_lint((unsigned char *)(hdrbuf + 12 + off)); block_align = mus_char_to_lshort((unsigned char *)(hdrbuf + 20 + off)); bits_per_sample = mus_char_to_lshort((unsigned char *)(hdrbuf + 22 + off)); - data_format = wave_to_sndlib_format(original_data_format, bits_per_sample, true); + sample_type = wave_to_sndlib_format(original_sample_type, bits_per_sample, true); } else { @@ -2262,9 +2240,9 @@ static int read_soundforge_header(const char *filename, int fd) if (data_size > true_file_length) { data_size = true_file_length - data_location; - if (data_size < 0) return(mus_error(MUS_HEADER_READ_FAILED, "%s: data_size = " MUS_LD "?", filename, data_size)); + if (data_size < 0) return(mus_error(MUS_HEADER_READ_FAILED, "%s: data_size = %lld?", filename, data_size)); } - data_size = mus_bytes_to_samples(data_format, data_size); + data_size = mus_bytes_to_samples(sample_type, data_size); return(MUS_NO_ERROR); } @@ -2294,14 +2272,14 @@ static int read_rf64_header(const char *filename, int fd) /* we've checked RF64 xxxx WAVE before getting here */ /* this is very similar (identical) to RIFF for the most part, but I decided it was cleanest to copy the code */ - mus_long_t chunksize, chunkloc; + mus_long_t chunkloc; bool got_fmt = false, got_ds64 = false; mus_long_t offset; little_endian = true; type_specifier = mus_char_to_uninterpreted_int((unsigned char *)(hdrbuf + 8)); chunkloc = 12; offset = 0; - data_format = MUS_UNKNOWN; + sample_type = MUS_UNKNOWN_SAMPLE; srate = 0; chans = 0; fact_samples = 0; @@ -2315,6 +2293,7 @@ static int read_rf64_header(const char *filename, int fd) while (true) { + mus_long_t chunksize; offset += chunkloc; if (offset >= true_file_length) break; if (seek_and_read(fd, (unsigned char *)hdrbuf, offset, 64) <= 0) break; @@ -2340,7 +2319,7 @@ static int read_rf64_header(const char *filename, int fd) if (match_four_chars((unsigned char *)hdrbuf, I_fmt_)) { got_fmt = true; - update_frames_location = 12 + offset; + update_framples_location = 12 + offset; read_riff_fmt_chunk(hdrbuf, true); } else @@ -2388,15 +2367,15 @@ static int read_rf64_header(const char *filename, int fd) if (data_size > true_file_length) { data_size = true_file_length - data_location; - if (data_size < 0) return(mus_error(MUS_HEADER_READ_FAILED, "%s: data_size = " MUS_LD "?", filename, data_size)); + if (data_size < 0) return(mus_error(MUS_HEADER_READ_FAILED, "%s: data_size = %lld?", filename, data_size)); } - data_size = mus_bytes_to_samples(data_format, data_size); + data_size = mus_bytes_to_samples(sample_type, data_size); return(MUS_NO_ERROR); } -static int write_rf64_header(int fd, int wsrate, int wchans, mus_long_t size, int format, const char *comment, int len) +static int write_rf64_header(int fd, int wsrate, int wchans, mus_long_t size, mus_sample_t samp_type, const char *comment, int len) { int extra = 0, err = MUS_NO_ERROR; data_location = 36 + 36 + 8; @@ -2421,7 +2400,7 @@ static int write_rf64_header(int fd, int wsrate, int wchans, mus_long_t size, in mus_lint_to_char((unsigned char *)(hdrbuf + 32), 0); /* "table size" */ header_write(fd, hdrbuf, 36); - err = write_riff_fmt_chunk(fd, hdrbuf, format, wsrate, wchans); + err = write_riff_fmt_chunk(fd, hdrbuf, samp_type, wsrate, wchans); if (len > 0) write_riff_clm_comment(fd, comment, len, extra); @@ -2490,25 +2469,26 @@ static int mus_header_convert_riff_to_rf64(const char *filename, mus_long_t size static int read_avi_header(const char *filename, int fd) { - const unsigned char I_strf[4] = {'s','t','r','f'}; - const unsigned char I_movi[4] = {'m','o','v','i'}; + static const unsigned char I_strf[4] = {'s','t','r','f'}; + static const unsigned char I_movi[4] = {'m','o','v','i'}; /* we know we have checked for RIFF xxxx AVI when we arrive here */ - int chunksize, chunkloc, cksize, bits; + int chunkloc, cksize, bits; bool happy = true; mus_long_t ckoff, cktotal, offset; type_specifier = mus_char_to_uninterpreted_int((unsigned char *)(hdrbuf + 8)); chunkloc = 12; offset = 0; - data_format = MUS_UNKNOWN; + sample_type = MUS_UNKNOWN_SAMPLE; srate = 0; chans = 1; true_file_length = SEEK_FILE_LENGTH(fd); while (happy) { + int chunksize; offset += chunkloc; if (seek_and_read(fd, (unsigned char *)hdrbuf, offset, 32) <= 0) - return(mus_error(MUS_HEADER_READ_FAILED, "%s avi header: chunks confused at " MUS_LD, filename, offset)); + return(mus_error(MUS_HEADER_READ_FAILED, "%s avi header: chunks confused at %lld", filename, offset)); chunksize = mus_char_to_lint((unsigned char *)(hdrbuf + 4)); if ((chunksize == 0) && /* can be empty data chunk? */ (hdrbuf[0] == 0) && (hdrbuf[1] == 0) && (hdrbuf[2] == 0) && (hdrbuf[3] == 0)) @@ -2547,11 +2527,12 @@ static int read_avi_header(const char *filename, int fd) cktotal += (8 + cksize); if (match_four_chars((unsigned char *)hdrbuf, I_LIST)) { - mus_long_t cksizer, ckoffr, cktotalr, rdsize; + mus_long_t ckoffr, cktotalr, rdsize; ckoffr = ckoff + 12; cktotalr = 12; while (cktotalr < cksize) { + mus_long_t cksizer; lseek(fd, ckoffr, SEEK_SET); header_read(fd, hdrbuf, 8); cksizer = mus_char_to_lint((unsigned char *)(hdrbuf + 4)); @@ -2563,14 +2544,14 @@ static int read_avi_header(const char *filename, int fd) rdsize = cksizer; else rdsize = HDRBUFSIZ; header_read(fd, hdrbuf, rdsize); - original_data_format = mus_char_to_lshort((unsigned char *)hdrbuf); + original_sample_type = mus_char_to_lshort((unsigned char *)hdrbuf); chans = mus_char_to_lshort((unsigned char *)(hdrbuf + 2)); srate = mus_char_to_lint((unsigned char *)(hdrbuf + 4)); /* block_align = mus_char_to_lshort((unsigned char *)(hdrbuf + 12)); */ bits = mus_char_to_lshort((unsigned char *)(hdrbuf + 14)); /* only 16 bit linear little endian for now */ - if ((bits == 16) && (original_data_format == 1)) - data_format = MUS_LSHORT; + if ((bits == 16) && (original_sample_type == 1)) + sample_type = MUS_LSHORT; if (data_location != 0) happy = false; break; } @@ -2585,8 +2566,8 @@ static int read_avi_header(const char *filename, int fd) if (data_location == 0) return(mus_error(MUS_HEADER_READ_FAILED, "%s: no movi chunk?", filename)); if (data_location > true_file_length) - return(mus_error(MUS_HEADER_READ_FAILED, "%s: data_location " MUS_LD " > file length: " MUS_LD, filename, data_location, true_file_length)); - data_size = mus_bytes_to_samples(data_format, true_file_length - data_location); + return(mus_error(MUS_HEADER_READ_FAILED, "%s: data_location %lld > file length: %lld", filename, data_location, true_file_length)); + data_size = mus_bytes_to_samples(sample_type, true_file_length - data_location); return(MUS_NO_ERROR); } @@ -2628,7 +2609,11 @@ static void soundfont_entry(const char *name, int start, int end, int loop_start } else { - soundfont_size += 8; + if (soundfont_size < 123123123) + soundfont_size += 8; + /* believe it or not, without the 123123123 shuffle, gcc complains at mus_header_read_1 [line 5519!] + * that we are making a naughty assumption about overflows. + */ soundfont_starts = (int *)realloc(soundfont_starts, soundfont_size * sizeof(int)); soundfont_ends = (int *)realloc(soundfont_ends, soundfont_size * sizeof(int)); soundfont_loop_starts = (int *)realloc(soundfont_loop_starts, soundfont_size * sizeof(int)); @@ -2657,28 +2642,31 @@ int mus_header_sf2_loop_end(int n) {return(soundfont_loop_ends[n]);} static int read_soundfont_header(const char *filename, int fd) { - const unsigned char I_sdta[4] = {'s','d','t','a'}; - const unsigned char I_shdr[4] = {'s','h','d','r'}; - const unsigned char I_pdta[4] = {'p','d','t','a'}; + static const unsigned char I_sdta[4] = {'s','d','t','a'}; + static const unsigned char I_shdr[4] = {'s','h','d','r'}; + static const unsigned char I_pdta[4] = {'p','d','t','a'}; /* we know we have checked for RIFF xxxx sfbk when we arrive here */ - int chunksize, chunkloc, type, cksize, i, this_end, last_end; + int chunkloc, type, cksize, i, this_end, last_end; mus_long_t ckoff, offset; bool happy = true; + type_specifier = mus_char_to_uninterpreted_int((unsigned char *)(hdrbuf + 8)); chunkloc = 12; offset = 0; soundfont_entries = 0; - data_format = MUS_LSHORT; + sample_type = MUS_LSHORT; srate = 0; chans = 1; last_end = 0; true_file_length = SEEK_FILE_LENGTH(fd); + while (happy) { + int chunksize; offset += chunkloc; if (seek_and_read(fd, (unsigned char *)hdrbuf, offset, 32) <= 0) - return(mus_error(MUS_HEADER_READ_FAILED, "%s soundfont header: chunks confused at " MUS_LD, filename, offset)); + return(mus_error(MUS_HEADER_READ_FAILED, "%s soundfont header: chunks confused at %lld", filename, offset)); chunksize = mus_char_to_lint((unsigned char *)(hdrbuf + 4)); if ((chunksize == 0) && /* can be empty data chunk? */ (hdrbuf[0] == 0) && (hdrbuf[1] == 0) && (hdrbuf[2] == 0) && (hdrbuf[3] == 0)) @@ -2695,8 +2683,8 @@ static int read_soundfont_header(const char *filename, int fd) lseek(fd, ckoff, SEEK_SET); while (srate == 0) { - ssize_t bytes; - bytes = read(fd, hdrbuf, 8); + long long int bytes; + bytes = (long long int)read(fd, hdrbuf, 8); if (bytes == 0) { happy = false; @@ -2831,7 +2819,7 @@ static int decode_nist_value(char *str, int base, int end) value[j] = str[i]; value[j] = 0; if (value[0] =='s') return(MUS_NIST_SHORTPACK); - sscanf(value, "%d", &i); + sscanf(value, "%12d", &i); /* what is the correct way to use mus_long_ts here for the sample count? */ return(i); } @@ -2851,7 +2839,7 @@ static int read_nist_header(const char *filename, int fd) for (k = 8; k < 16; k++) str[k - 8] = hdrbuf[k]; - sscanf(str, "%d", &idata_location); /* always "1024" */ + sscanf(str, "%12d", &idata_location); /* always "1024" */ if (idata_location != 1024) return(mus_error(MUS_HEADER_READ_FAILED, "%s NIST data location: %d?", filename, idata_location)); @@ -2888,7 +2876,7 @@ static int read_nist_header(const char *filename, int fd) if (nm >= MAX_FIELD_LENGTH) { header_type = MUS_RAW; - data_format = MUS_UNKNOWN; + sample_type = MUS_UNKNOWN_SAMPLE; return(mus_error(MUS_UNSUPPORTED_HEADER_TYPE, "%s nist header: unreadable field (length = %d)?", filename, nm)); } name[nm] = 0; @@ -2908,10 +2896,10 @@ static int read_nist_header(const char *filename, int fd) n++; if (n >= hend) { - ssize_t read_bytes; + long long int read_bytes; curbase += hend; n = 0; - read_bytes = read(fd, hdrbuf, HDRBUFSIZ); + read_bytes = (long long int)read(fd, hdrbuf, HDRBUFSIZ); if (read_bytes < HDRBUFSIZ) return(mus_error(MUS_HEADER_READ_FAILED, "%s NIST header truncated?", filename)); hend = HDRBUFSIZ; @@ -2921,62 +2909,62 @@ static int read_nist_header(const char *filename, int fd) data_size = samples * bytes; if (byte_format == MUS_NIST_SHORTPACK) { - data_format = MUS_UNKNOWN; - original_data_format = MUS_NIST_SHORTPACK; + sample_type = MUS_UNKNOWN_SAMPLE; + original_sample_type = MUS_NIST_SHORTPACK; } else { switch (bytes) { case 1: - data_format = MUS_MULAW; + sample_type = MUS_MULAW; break; case 2: if (byte_format == 10) - data_format = MUS_BSHORT; - else data_format = MUS_LSHORT; + sample_type = MUS_BSHORT; + else sample_type = MUS_LSHORT; break; case 3: if (byte_format == 10) - data_format = MUS_B24INT; - else data_format = MUS_L24INT; + sample_type = MUS_B24INT; + else sample_type = MUS_L24INT; break; case 4: if (byte_format == 10) - data_format = MUS_BINT; - else data_format = MUS_LINT; + sample_type = MUS_BINT; + else sample_type = MUS_LINT; break; default: - data_format = MUS_BYTE; + sample_type = MUS_BYTE; break; } } true_file_length = SEEK_FILE_LENGTH(fd); - if ((data_size > true_file_length) && (original_data_format != MUS_NIST_SHORTPACK)) + if ((data_size > true_file_length) && (original_sample_type != MUS_NIST_SHORTPACK)) { data_size = true_file_length - data_location; - if (data_size < 0) return(mus_error(MUS_HEADER_READ_FAILED, "%s: data_size = " MUS_LD "?", filename, data_size)); + if (data_size < 0) return(mus_error(MUS_HEADER_READ_FAILED, "%s: data_size = %lld?", filename, data_size)); } - data_size = mus_bytes_to_samples(data_format, data_size); + data_size = mus_bytes_to_samples(sample_type, data_size); return(MUS_NO_ERROR); } -static int write_nist_header(int fd, int wsrate, int wchans, mus_long_t size, int format) +static int write_nist_header(int fd, int wsrate, int wchans, mus_long_t size, mus_sample_t samp_type) { char *header; int datum; - datum = mus_bytes_per_sample(format); + datum = mus_bytes_per_sample(samp_type); header = (char *)calloc(1024, sizeof(char)); - sprintf(header, "NIST_1A\n 1024\nchannel_count -i %d\nsample_rate -i %d\nsample_n_bytes -i %d\nsample_byte_format -s2 %s\nsample_sig_bits -i %d\nsample_count -i " MUS_LD "\nend_head\n", + snprintf(header, 1024, "NIST_1A\n 1024\nchannel_count -i %d\nsample_rate -i %d\nsample_n_bytes -i %d\nsample_byte_format -s2 %s\nsample_sig_bits -i %d\nsample_count -i %lld\nend_head\n", wchans, wsrate, datum, - ((format == MUS_BSHORT) || (format == MUS_B24INT) || (format == MUS_BINT)) ? "10" : "01", + ((samp_type == MUS_BSHORT) || (samp_type == MUS_B24INT) || (samp_type == MUS_BINT)) ? "10" : "01", datum * 8, size / datum); header_write(fd, (unsigned char *)header, 1024); @@ -2994,13 +2982,13 @@ static int write_nist_header(int fd, int wsrate, int wchans, mus_long_t size, in * 28: bicsf magic number (107364 or trouble) * 32: srate as a 32-bit float * 36: chans - * 40: data format indicator (2 = 16-bit linear, 4 = 32-bit float) + * 40: sample type indicator (2 = 16-bit linear, 4 = 32-bit float) * 44: begin chunks, if any * * followed by AIFF-style chunked header info with chunks like: * * COMM size comment - * MAXA size {max amps (up to 4)} (frame offsets) time-tag unix msec counter + * MAXA size {max amps (up to 4)} (frample offsets) time-tag unix msec counter * CUE, PRNT, ENV etc * * except in Paul Lansky's "hybrid" headers, according to MixViews. @@ -3018,12 +3006,12 @@ static int read_bicsf_header(const char *filename, int fd) lseek(fd, 40, SEEK_SET); header_read(fd, hdrbuf, HDRBUFSIZ); - original_data_format = mus_char_to_bint((unsigned char *)hdrbuf); - switch (original_data_format) + original_sample_type = mus_char_to_bint((unsigned char *)hdrbuf); + switch (original_sample_type) { - case 2: data_format = MUS_BSHORT; break; - case 4: data_format = MUS_BFLOAT; break; - case 8: data_format = MUS_BDOUBLE; break; + case 2: sample_type = MUS_BSHORT; break; + case 4: sample_type = MUS_BFLOAT; break; + case 8: sample_type = MUS_BDOUBLE; break; default: break; } @@ -3075,7 +3063,7 @@ static int read_bicsf_header(const char *filename, int fd) * ^ digit gives machine info, according to AFsp sources -- see IRCAM ints above * 4: srate as a 32-bit float * 8: chans - * 12: data format indicator (2 = 16-bit linear, 4 = 32-bit float) + * 12: sample type indicator (2 = 16-bit linear, 4 = 32-bit float) * according to new Sox (version 11), these packing modes are now bytes/sample in low short, code in high * so 1 = char, 0x10001 = alaw, 0x20001 = mulaw, 2 = short, 3 = 24bit?, 0x40004 = long, 4 = float (AFsp sez 4 can also be double) * 16: comment start -- how to tell if it's a real comment? @@ -3091,7 +3079,7 @@ static int read_bicsf_header(const char *filename, int fd) static int read_ircam_header(const char *filename, int fd) { - short bcode, bloc, bsize; + short bloc; int offset; bool little, happy = true; @@ -3104,42 +3092,42 @@ static int read_ircam_header(const char *filename, int fd) data_location = 1024; true_file_length = SEEK_FILE_LENGTH(fd); data_size = (true_file_length - 1024); - original_data_format = big_or_little_endian_int((unsigned char *)(hdrbuf + 12), little); - data_format = MUS_UNKNOWN; + original_sample_type = big_or_little_endian_int((unsigned char *)(hdrbuf + 12), little); + sample_type = MUS_UNKNOWN_SAMPLE; - if (original_data_format == 2) + if (original_sample_type == 2) { if (little) - data_format = MUS_LSHORT; - else data_format = MUS_BSHORT; + sample_type = MUS_LSHORT; + else sample_type = MUS_BSHORT; } - else if (original_data_format == 4) + else if (original_sample_type == 4) { if (little) { if (mus_char_to_lint((unsigned char *)hdrbuf) == I_IRCAM_VAX) - data_format = MUS_LFLOAT_UNSCALED; /* Csound and MixViews */ - else data_format = MUS_LFLOAT; + sample_type = MUS_LFLOAT_UNSCALED; /* Csound and MixViews */ + else sample_type = MUS_LFLOAT; } - else data_format = MUS_BFLOAT; + else sample_type = MUS_BFLOAT; } - else if (original_data_format == 0x40004) + else if (original_sample_type == 0x40004) { - if (little) data_format = MUS_LINT; - else data_format = MUS_BINT; + if (little) sample_type = MUS_LINT; + else sample_type = MUS_BINT; } - else if (original_data_format == 0x10001) data_format = MUS_ALAW; - else if (original_data_format == 0x20001) data_format = MUS_MULAW; - else if (original_data_format == 1) data_format = MUS_BYTE; - else if (original_data_format == 3) + else if (original_sample_type == 0x10001) sample_type = MUS_ALAW; + else if (original_sample_type == 0x20001) sample_type = MUS_MULAW; + else if (original_sample_type == 1) sample_type = MUS_BYTE; + else if (original_sample_type == 3) { - if (little) data_format = MUS_L24INT; - else data_format = MUS_B24INT; + if (little) sample_type = MUS_L24INT; + else sample_type = MUS_B24INT; } - else if (original_data_format == 8) + else if (original_sample_type == 8) { - if (little) data_format = MUS_LDOUBLE; - else data_format = MUS_BDOUBLE; + if (little) sample_type = MUS_LDOUBLE; + else sample_type = MUS_BDOUBLE; } srate = (int)big_or_little_endian_float((unsigned char *)(hdrbuf + 4), little); @@ -3149,6 +3137,7 @@ static int read_ircam_header(const char *filename, int fd) while (happy) { + short bcode, bsize; offset += bloc; if (seek_and_read(fd, (unsigned char *)hdrbuf, offset, 32) <= 0) return(mus_error(MUS_HEADER_READ_FAILED, "%s ircam header: chunks confused at %d", filename, offset)); @@ -3166,14 +3155,14 @@ static int read_ircam_header(const char *filename, int fd) if ((bsize <= 0) || (bcode <= 0) || ((offset + bloc) > 1023)) happy = false; } - data_size = mus_bytes_to_samples(data_format, data_size); + data_size = mus_bytes_to_samples(sample_type, data_size); return(MUS_NO_ERROR); } -static int sndlib_format_to_ircam(int format) +static int sndlib_format_to_ircam(mus_sample_t samp_type) { - switch (format) + switch (samp_type) { case MUS_MULAW: return(0x20001); break; case MUS_ALAW: return(0x10001); break; @@ -3181,7 +3170,7 @@ static int sndlib_format_to_ircam(int format) case MUS_BINT: return(0x40004); break; case MUS_BFLOAT: return(4); break; default: - return(mus_error(MUS_UNSUPPORTED_DATA_FORMAT, "IRCAM header unsupported data format: %d (%s)", format, any_data_format_name(format))); + return(mus_error(MUS_UNSUPPORTED_SAMPLE_TYPE, "IRCAM header unsupported sample type: %d (%s)", samp_type, any_sample_type_name(samp_type))); break; } } @@ -3205,19 +3194,19 @@ static void write_ircam_comment(int fd, const char *comment, int len) if (len > 0) { unsigned char *combuf; - combuf = (unsigned char *)calloc(len, sizeof(char)); + combuf = (unsigned char *)calloc(len, sizeof(unsigned char)); header_write(fd, combuf, len); free(combuf); } } -static int write_ircam_header(int fd, int wsrate, int wchans, int format, const char *comment, int len) +static int write_ircam_header(int fd, int wsrate, int wchans, mus_sample_t samp_type, const char *comment, int len) { mus_bint_to_char((unsigned char *)hdrbuf, 0x2a364); /* SUN id */ mus_bfloat_to_char((unsigned char *)(hdrbuf + 4), (float)wsrate); mus_bint_to_char((unsigned char *)(hdrbuf + 8), wchans); - mus_bint_to_char((unsigned char *)(hdrbuf + 12), sndlib_format_to_ircam(format)); + mus_bint_to_char((unsigned char *)(hdrbuf + 12), sndlib_format_to_ircam(samp_type)); header_write(fd, hdrbuf, 16); data_location = 1024; write_ircam_comment(fd, comment, len); @@ -3240,16 +3229,16 @@ static int write_ircam_header(int fd, int wsrate, int wchans, int format, const static int read_8svx_header(const char *filename, int fd, bool bytewise) { - const unsigned char I_BODY[4] = {'B','O','D','Y'}; - const unsigned char I_CHAN[4] = {'C','H','A','N'}; - const unsigned char I_VHDR[4] = {'V','H','D','R'}; - int chunksize, offset, chunkloc; + static const unsigned char I_BODY[4] = {'B','O','D','Y'}; + static const unsigned char I_CHAN[4] = {'C','H','A','N'}; + static const unsigned char I_VHDR[4] = {'V','H','D','R'}; + int offset, chunkloc; bool happy = true; type_specifier = mus_char_to_uninterpreted_int((unsigned char *)hdrbuf); chunkloc = 12; offset = 0; - if (bytewise) data_format = MUS_BYTE; else data_format = MUS_BSHORT; + if (bytewise) sample_type = MUS_BYTE; else sample_type = MUS_BSHORT; srate = 0; chans = 1; true_file_length = SEEK_FILE_LENGTH(fd); @@ -3257,6 +3246,7 @@ static int read_8svx_header(const char *filename, int fd, bool bytewise) while (happy) { + int chunksize; offset += chunkloc; if (seek_and_read(fd, (unsigned char *)hdrbuf, offset, 32) <= 0) return(mus_error(MUS_HEADER_READ_FAILED, "%s 8svx header: chunks confused at %d", filename, offset)); @@ -3283,9 +3273,9 @@ static int read_8svx_header(const char *filename, int fd, bool bytewise) { /* num_samples (int) at hdrbuf + 8 */ srate = mus_char_to_ubshort((unsigned char *)(hdrbuf + 20)); - original_data_format = hdrbuf[23]; - if (original_data_format != 0) - data_format = MUS_UNKNOWN; + original_sample_type = hdrbuf[23]; + if (original_sample_type != 0) + sample_type = MUS_UNKNOWN_SAMPLE; } else { @@ -3316,9 +3306,9 @@ static int read_8svx_header(const char *filename, int fd, bool bytewise) if (data_size > true_file_length) { data_size = true_file_length - data_location; - if (data_size < 0) return(mus_error(MUS_HEADER_READ_FAILED, "%s: data_size = " MUS_LD "?", filename, data_size)); + if (data_size < 0) return(mus_error(MUS_HEADER_READ_FAILED, "%s: data_size = %lld?", filename, data_size)); } - data_size = mus_bytes_to_samples(data_format, data_size); + data_size = mus_bytes_to_samples(sample_type, data_size); return(MUS_NO_ERROR); } @@ -3343,22 +3333,23 @@ static int read_8svx_header(const char *filename, int fd, bool bytewise) static int read_voc_header(const char *filename, int fd) { mus_long_t curbase; - int type, len, voc_extended, bits, code; + int voc_extended, bits, code; bool happy = true; - data_format = MUS_UBYTE; + sample_type = MUS_UBYTE; chans = 1; voc_extended = 0; true_file_length = SEEK_FILE_LENGTH(fd); curbase = mus_char_to_lshort((unsigned char *)(hdrbuf + 20)); if (true_file_length < curbase) - return(mus_error(MUS_HEADER_READ_FAILED, "%s: block location " MUS_LD " > file length: " MUS_LD, filename, curbase, true_file_length)); + return(mus_error(MUS_HEADER_READ_FAILED, "%s: block location %lld > file length: %lld", filename, curbase, true_file_length)); lseek(fd, curbase, SEEK_SET); header_read(fd, hdrbuf, HDRBUFSIZ); while (happy) { + int type, len; type = (int)(hdrbuf[0]); len = (((int)hdrbuf[3]) << 16) + (((int)hdrbuf[2]) << 8) + (((int)hdrbuf[1])); if (type == 1) /* voc_data */ @@ -3368,10 +3359,10 @@ static int read_voc_header(const char *filename, int fd) if (voc_extended == 0) { srate = (int)(1000000.0 / (256 - ((int)(hdrbuf[4] & 0xff)))); - original_data_format = hdrbuf[5]; + original_sample_type = hdrbuf[5]; if (hdrbuf[5] == 0) - data_format = MUS_UBYTE; - else data_format = MUS_UNKNOWN; + sample_type = MUS_UBYTE; + else sample_type = MUS_UNKNOWN_SAMPLE; } happy = false; } @@ -3387,16 +3378,16 @@ static int read_voc_header(const char *filename, int fd) { code = mus_char_to_lshort((unsigned char *)(hdrbuf + 10)); if (code == 6) - data_format = MUS_ALAW; + sample_type = MUS_ALAW; else if (code == 7) - data_format = MUS_MULAW; - else data_format = MUS_UBYTE; + sample_type = MUS_MULAW; + else sample_type = MUS_UBYTE; } else if (bits == 16) - data_format = MUS_LSHORT; - else data_format = MUS_UNKNOWN; + sample_type = MUS_LSHORT; + else sample_type = MUS_UNKNOWN_SAMPLE; chans = (int)hdrbuf[9]; if (chans == 0) chans = 1; happy = false; @@ -3414,9 +3405,10 @@ static int read_voc_header(const char *filename, int fd) { if (type == 8) /* voc_extended */ { + /* should voc_extended be set to 1 here? */ srate = (256000000 / (65536 - mus_char_to_lshort((unsigned char *)(hdrbuf + 4)))); if ((int)(hdrbuf[7]) == 0) chans = 1; else chans = 2; - if ((int)(hdrbuf[6]) != 0) data_format = MUS_UNKNOWN; + if ((int)(hdrbuf[6]) != 0) sample_type = MUS_UNKNOWN_SAMPLE; } /* I'd add loop support here if I had any example sound files to test with */ } @@ -3435,9 +3427,9 @@ static int read_voc_header(const char *filename, int fd) if ((data_size > true_file_length) || (data_size < (mus_long_t)(true_file_length / 10))) /* some VOC files seem to have completely bogus lengths */ { data_size = true_file_length - data_location; - if (data_size < 0) return(mus_error(MUS_HEADER_READ_FAILED, "%s: data_size = " MUS_LD "?", filename, data_size)); + if (data_size < 0) return(mus_error(MUS_HEADER_READ_FAILED, "%s: data_size = %lld?", filename, data_size)); } - data_size = mus_bytes_to_samples(data_format, data_size); + data_size = mus_bytes_to_samples(sample_type, data_size); return(MUS_NO_ERROR); } @@ -3465,17 +3457,17 @@ static int read_voc_header(const char *filename, int fd) static int read_twinvq_header(const char *filename, int fd) { - data_format = MUS_UNKNOWN; + sample_type = MUS_UNKNOWN_SAMPLE; data_location = mus_char_to_bint((unsigned char *)(hdrbuf + 12)) + 16 + 8; chans = 1 + mus_char_to_bint((unsigned char *)(hdrbuf + 24)); srate = mus_char_to_bint((unsigned char *)(hdrbuf + 32)); if (srate == 11) srate = 11025; else if (srate == 22) srate = 22050; else if (srate == 44) srate = 44100; else - srate *= 1000; + srate = 48000; true_file_length = SEEK_FILE_LENGTH(fd); data_size = (true_file_length - data_location); - if (data_size < 0) return(mus_error(MUS_HEADER_READ_FAILED, "%s: data_size = " MUS_LD "?", filename, data_size)); + if (data_size < 0) return(mus_error(MUS_HEADER_READ_FAILED, "%s: data_size = %lld?", filename, data_size)); return(MUS_NO_ERROR); } @@ -3489,20 +3481,21 @@ static int read_twinvq_header(const char *filename, int fd) static int read_sdif_header(const char *filename, int fd) { - const unsigned char I_1FQ0[4] = {'1','F','Q','0'}; - const unsigned char I_1STF[4] = {'1','S','T','F'}; - const unsigned char I_1PIC[4] = {'1','P','I','C'}; - const unsigned char I_1TRC[4] = {'1','T','R','C'}; - const unsigned char I_1HRM[4] = {'1','H','R','M'}; - const unsigned char I_1RES[4] = {'1','R','E','S'}; - const unsigned char I_1TDS[4] = {'1','T','D','S'}; /* samples -- all others are useless */ - const char *sdif_names[7] = {"fundamental frequency", "FFT", "spectral peak", "sinusoidal track", "harmonic track", "resonance", "unknown"}; + static const unsigned char I_1FQ0[4] = {'1','F','Q','0'}; + static const unsigned char I_1STF[4] = {'1','S','T','F'}; + static const unsigned char I_1PIC[4] = {'1','P','I','C'}; + static const unsigned char I_1TRC[4] = {'1','T','R','C'}; + static const unsigned char I_1HRM[4] = {'1','H','R','M'}; + static const unsigned char I_1RES[4] = {'1','R','E','S'}; + static const unsigned char I_1TDS[4] = {'1','T','D','S'}; /* samples -- all others are useless */ + static const char *sdif_names[7] = {"fundamental frequency", "FFT", "spectral peak", "sinusoidal track", "harmonic track", "resonance", "unknown"}; - int offset, size; + int offset; bool happy = false; offset = 16; while (!happy) { + int size; if (seek_and_read(fd, (unsigned char *)hdrbuf, offset, 32) <= 0) return(mus_error(MUS_HEADER_READ_FAILED, "%s, sdif header: chunks confused at %d", filename, offset)); size = mus_char_to_bint((unsigned char *)(hdrbuf + 4)) + 8; @@ -3530,16 +3523,17 @@ static int read_sdif_header(const char *filename, int fd) offset += size; } - return(MUS_UNSUPPORTED); + return(MUS_HEADER_READ_FAILED); } +#if G7XX /* ------------------------------------ NVF ------------------------------------ */ static int read_nvf_header(const char *filename, int fd) { - const unsigned char I_VFMT[4] = {'V','F','M','T'}; /* Nomad II Creative NVF */ + static const unsigned char I_VFMT[4] = {'V','F','M','T'}; /* Nomad II Creative NVF */ /* info from nvftools by Tom Mander: */ /* @@ -3561,25 +3555,26 @@ static int read_nvf_header(const char *filename, int fd) The rest of the data is G.721 data nibble packing big-endian, 4bits per sample (nibble) single channel at 32kbit. When the Nomad records an NVF - file it does it in 92 sample (46 byte) frames or 0.0115sec. + file it does it in 92 sample (46 byte) framples or 0.0115sec. */ if (mus_char_to_lint((unsigned char *)(hdrbuf + 4)) != 1) return(mus_error(MUS_HEADER_READ_FAILED, "%s: NVF[4] != 1", filename)); if (!(match_four_chars((unsigned char *)(hdrbuf + 12), I_VFMT))) return(mus_error(MUS_HEADER_READ_FAILED, "%s: no VFMT chunk", filename)); - data_format = MUS_UNKNOWN; /* g721 --translate elsewhere */ + sample_type = MUS_UNKNOWN_SAMPLE; /* g721 --translate elsewhere */ chans = 1; srate = 8000; data_location = 44; true_file_length = SEEK_FILE_LENGTH(fd); data_size = (true_file_length - data_location) * 2; /* 4 bit samps? */ - if (data_size < 0) return(mus_error(MUS_HEADER_READ_FAILED, "%s: data_size = " MUS_LD "?", filename, data_size)); + if (data_size < 0) return(mus_error(MUS_HEADER_READ_FAILED, "%s: data_size = %lld?", filename, data_size)); return(MUS_NO_ERROR); } +#endif /* ------------------------------------ ADC ------------------------------------ * also known as OGI format - * TIMIT format is identical except it omits the data format field (header size claims to be bytes) + * TIMIT format is identical except it omits the sample type 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 @@ -3589,7 +3584,7 @@ static int read_nvf_header(const char *filename, int fd) * 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) + * 12: sample type (0 = big-endian) * 16: data start */ @@ -3598,7 +3593,7 @@ static int read_adc_header(const char *filename, int fd) bool little; little = (mus_char_to_uninterpreted_int((unsigned char *)(hdrbuf + 12)) != 0); /* 0 = big endian */ data_location = 16; - if (little) data_format = MUS_LSHORT; else data_format = MUS_BSHORT; + if (little) sample_type = MUS_LSHORT; else sample_type = MUS_BSHORT; 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); @@ -3608,9 +3603,9 @@ static int read_adc_header(const char *filename, int fd) if (data_size > true_file_length) { data_size = true_file_length - data_location; - if (data_size < 0) return(mus_error(MUS_HEADER_READ_FAILED, "%s: data_size = " MUS_LD "?", filename, data_size)); + if (data_size < 0) return(mus_error(MUS_HEADER_READ_FAILED, "%s: data_size = %lld?", filename, data_size)); } - data_size = mus_bytes_to_samples(data_format, data_size); + data_size = mus_bytes_to_samples(sample_type, data_size); return(MUS_NO_ERROR); } @@ -3622,7 +3617,7 @@ static int read_adc_header(const char *filename, int fd) * 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) + * 16: sample type (signed or unsigned) (short) (0 = unsigned, -1 = signed) * 18: loop (on/off), 20: midi (-1 = no MIDI) * 22: srate * avr.txt has: @@ -3654,18 +3649,18 @@ static int read_avr_header(const char *filename, int fd) if (dsize == 16) { if (dsigned == 0) - data_format = MUS_UBSHORT; - else data_format = MUS_BSHORT; + sample_type = MUS_UBSHORT; + else sample_type = MUS_BSHORT; } else { if (dsize == 8) { if (dsigned == 0) - data_format = MUS_UBYTE; - else data_format = MUS_BYTE; + sample_type = MUS_UBYTE; + else sample_type = MUS_BYTE; } - else return(mus_error(MUS_HEADER_READ_FAILED, "%s: unknown data format", filename)); + else return(mus_error(MUS_HEADER_READ_FAILED, "%s: unknown sample type", filename)); } if (seek_and_read(fd, (unsigned char *)hdrbuf, 64, 64) <= 0) return(mus_error(MUS_HEADER_READ_FAILED, "%s avr header: ran off end of file", filename)); @@ -3677,9 +3672,9 @@ static int read_avr_header(const char *filename, int fd) if (data_size > true_file_length) { data_size = true_file_length - data_location; - if (data_size < 0) return(mus_error(MUS_HEADER_READ_FAILED, "%s: data_size = " MUS_LD "?", filename, data_size)); + if (data_size < 0) return(mus_error(MUS_HEADER_READ_FAILED, "%s: data_size = %lld?", filename, data_size)); } - data_size = mus_bytes_to_samples(data_format, data_size); + data_size = mus_bytes_to_samples(sample_type, data_size); return(MUS_NO_ERROR); } @@ -3714,7 +3709,7 @@ static int read_avr_header(const char *filename, int fd) static int read_sndt_header(const char *filename, int fd) { if (hdrbuf[4] != 'D') return(mus_error(MUS_HEADER_READ_FAILED, "%s: SNDT[4] != 'D'", filename)); - data_format = MUS_UBYTE; + sample_type = MUS_UBYTE; chans = 1; srate = mus_char_to_ulshort((unsigned char *)(hdrbuf + 20)); data_location = 126; @@ -3725,7 +3720,7 @@ static int read_sndt_header(const char *filename, int fd) if (data_size > true_file_length) { data_size = true_file_length - data_location; - if (data_size < 0) return(mus_error(MUS_HEADER_READ_FAILED, "%s: data_size = " MUS_LD "?", filename, data_size)); + if (data_size < 0) return(mus_error(MUS_HEADER_READ_FAILED, "%s: data_size = %lld?", filename, data_size)); } return(MUS_NO_ERROR); } @@ -3740,13 +3735,13 @@ static int read_sndt_header(const char *filename, int fd) static int read_covox_header(const char *filename, int fd) { - data_format = MUS_UBYTE; + sample_type = MUS_UBYTE; chans = 1; data_location = 16; srate = 8000; true_file_length = SEEK_FILE_LENGTH(fd); data_size = true_file_length - data_location; - if (data_size < 0) return(mus_error(MUS_HEADER_READ_FAILED, "%s: data_size = " MUS_LD "?", filename, data_size)); + if (data_size < 0) return(mus_error(MUS_HEADER_READ_FAILED, "%s: data_size = %lld?", filename, data_size)); return(MUS_NO_ERROR); } @@ -3767,7 +3762,7 @@ static int read_covox_header(const char *filename, int fd) static int read_smp_header(const char *filename, int fd) { - data_format = MUS_LSHORT; + sample_type = MUS_LSHORT; chans = 1; comment_start = 22; comment_end = 81; @@ -3775,13 +3770,13 @@ static int read_smp_header(const char *filename, int fd) lseek(fd, 112, SEEK_SET); if (read(fd, hdrbuf, 4) != 4) return(mus_error(MUS_HEADER_READ_FAILED, "%s: SMP header truncated?", filename)); data_size = (mus_char_to_lint((unsigned char *)hdrbuf)); - data_format = MUS_LSHORT; /* just a guess */ + sample_type = MUS_LSHORT; /* just a guess */ srate = 8000; /* docs mention an srate floating around at the end of the file, but I can't find it in any example */ true_file_length = SEEK_FILE_LENGTH(fd); if ((data_size * 2) > true_file_length) { data_size = (true_file_length - data_location) / 2; - if (data_size < 0) return(mus_error(MUS_HEADER_READ_FAILED, "%s: data_size = " MUS_LD "?", filename, data_size)); + if (data_size < 0) return(mus_error(MUS_HEADER_READ_FAILED, "%s: data_size = %lld?", filename, data_size)); } return(MUS_NO_ERROR); } @@ -3795,7 +3790,7 @@ static int read_smp_header(const char *filename, int fd) * 0 160 char Text strings (2 * 80) * 160 80 char Command line * 240 2 int Domain (1-time, 2-freq, 3-qfreq) - * 242 2 int Frame size + * 242 2 int Frample size * 244 4 float Sampling frequency * 252 2 int File identifier (i.e. #o100 #o303) * 254 2 int Data type (0xfc0e = sampled data file) @@ -3809,17 +3804,18 @@ static int read_smp_header(const char *filename, int fd) static int read_sppack_header(const char *filename, int fd) { - int typ, bits; + int typ; data_location = 512; chans = 1; lseek(fd, 240, SEEK_SET); if (read(fd, hdrbuf, 22) != 22) return(mus_error(MUS_HEADER_READ_FAILED, "%s SPPACK header truncated?", filename)); typ = mus_char_to_bshort((unsigned char *)hdrbuf); - data_format = MUS_UNKNOWN; + sample_type = MUS_UNKNOWN_SAMPLE; if (typ == 1) { if (((hdrbuf[254]) == 252) && ((hdrbuf[255]) == 14)) /* #xfc and #x0e */ { + int bits; float sr; typ = mus_char_to_bshort((unsigned char *)(hdrbuf + 18)); bits = mus_char_to_bshort((unsigned char *)(hdrbuf + 16)); @@ -3827,22 +3823,22 @@ static int read_sppack_header(const char *filename, int fd) srate = (int)sr; switch (typ) { - case 1: if (bits == 16) data_format = MUS_BSHORT; else data_format = MUS_BYTE; break; - case 2: data_format = MUS_ALAW; break; - case 3: data_format = MUS_MULAW; break; - default: data_format = MUS_UNKNOWN; break; + case 1: if (bits == 16) sample_type = MUS_BSHORT; else sample_type = MUS_BYTE; break; + case 2: sample_type = MUS_ALAW; break; + case 3: sample_type = MUS_MULAW; break; + default: sample_type = MUS_UNKNOWN_SAMPLE; break; } data_size = SEEK_FILE_LENGTH(fd); - data_size = mus_bytes_to_samples(data_format, data_size - 512); + data_size = mus_bytes_to_samples(sample_type, data_size - 512); comment_start = 0; comment_end = 0; } } true_file_length = SEEK_FILE_LENGTH(fd); if (true_file_length < data_location) - return(mus_error(MUS_HEADER_READ_FAILED, "%s: data_location " MUS_LD " > file length: " MUS_LD, filename, data_location, true_file_length)); - if (data_size > mus_bytes_to_samples(data_format, true_file_length)) - data_size = mus_bytes_to_samples(data_format, true_file_length - data_location); + return(mus_error(MUS_HEADER_READ_FAILED, "%s: data_location %lld > file length: %lld", filename, data_location, true_file_length)); + if (data_size > mus_bytes_to_samples(sample_type, true_file_length)) + data_size = mus_bytes_to_samples(sample_type, true_file_length - data_location); return(MUS_NO_ERROR); } @@ -3875,7 +3871,7 @@ static int read_esps_header(const char *filename, int fd) bool happy = true; mus_long_t curbase, hend; int k, j, n, chars, floats, shorts, doubles; - ssize_t bytes; + long long int bytes; bool little; little = (hdrbuf[18] == 0); if (little) @@ -3883,7 +3879,7 @@ static int read_esps_header(const char *filename, int fd) else data_location = mus_char_to_bint((unsigned char *)(hdrbuf + 8)); true_file_length = SEEK_FILE_LENGTH(fd); data_size = true_file_length - data_location; - if (data_size < 0) return(mus_error(MUS_HEADER_READ_FAILED, "%s: data_size = " MUS_LD "?", filename, data_size)); + if (data_size < 0) return(mus_error(MUS_HEADER_READ_FAILED, "%s: data_size = %lld?", filename, data_size)); srate = 8000; chans = 1; lseek(fd, 132, SEEK_SET); @@ -3904,28 +3900,28 @@ static int read_esps_header(const char *filename, int fd) } if (shorts != 0) { - data_format = ((little) ? MUS_LSHORT : MUS_BSHORT); + sample_type = ((little) ? MUS_LSHORT : MUS_BSHORT); chans = shorts; } else { if (doubles != 0) { - data_format = ((little) ? MUS_LDOUBLE_UNSCALED : MUS_BDOUBLE_UNSCALED); + sample_type = ((little) ? MUS_LDOUBLE_UNSCALED : MUS_BDOUBLE_UNSCALED); chans = doubles; } else { if (floats != 0) { - data_format = ((little) ? MUS_LFLOAT_UNSCALED : MUS_BFLOAT_UNSCALED); + sample_type = ((little) ? MUS_LFLOAT_UNSCALED : MUS_BFLOAT_UNSCALED); chans = floats; } else { if (chars != 0) { - data_format = MUS_BYTE; /* ?? */ + sample_type = MUS_BYTE; /* ?? */ chans = chars; } } @@ -3971,7 +3967,7 @@ static int read_esps_header(const char *filename, int fd) } } if (srate == 0) srate = 8000; - data_size = mus_bytes_to_samples(data_format, data_size); + data_size = mus_bytes_to_samples(sample_type, data_size); return(MUS_NO_ERROR); } @@ -3996,14 +3992,14 @@ static int read_inrs_header(const char *filename, int fd, int loc) true_file_length = SEEK_FILE_LENGTH(fd); comment_start = 6; comment_end = 25; - data_format = MUS_LSHORT; + sample_type = MUS_LSHORT; srate = loc; chans = 1; data_location = 512; true_file_length = SEEK_FILE_LENGTH(fd); if (true_file_length < data_location) - return(mus_error(MUS_HEADER_READ_FAILED, "%s: data_location " MUS_LD " > file length: " MUS_LD, filename, data_location, true_file_length)); - data_size = mus_bytes_to_samples(data_format, true_file_length - data_location); + return(mus_error(MUS_HEADER_READ_FAILED, "%s: data_location %lld > file length: %lld", filename, data_location, true_file_length)); + data_size = mus_bytes_to_samples(sample_type, true_file_length - data_location); return(MUS_NO_ERROR); } @@ -4030,20 +4026,21 @@ static int read_inrs_header(const char *filename, int fd, int loc) static int read_maud_header(const char *filename, int fd) { - const unsigned char I_MHDR[4] = {'M','H','D','R'}; - const unsigned char I_MDAT[4] = {'M','D','A','T'}; + static const unsigned char I_MHDR[4] = {'M','H','D','R'}; + static const unsigned char I_MDAT[4] = {'M','D','A','T'}; - int chunksize, offset, chunkloc; + int offset, chunkloc; bool happy = true; type_specifier = mus_char_to_uninterpreted_int((unsigned char *)hdrbuf); chunkloc = 12; offset = 0; - data_format = MUS_BYTE; + sample_type = MUS_BYTE; srate = 0; chans = 1; update_form_size = mus_char_to_bint((unsigned char *)(hdrbuf + 4)); while (happy) { + int chunksize; offset += chunkloc; if (seek_and_read(fd, (unsigned char *)hdrbuf, offset, 32) <= 0) return(mus_error(MUS_HEADER_READ_FAILED, "%s maud header: chunks confused at %d", filename, offset)); @@ -4067,13 +4064,13 @@ static int read_maud_header(const char *filename, int fd) { switch (den) { - case 0: data_format = MUS_UBYTE; break; - case 2: data_format = MUS_ALAW; break; - case 3: data_format = MUS_MULAW; break; - default: data_format = MUS_UNKNOWN; break; + case 0: sample_type = MUS_UBYTE; break; + case 2: sample_type = MUS_ALAW; break; + case 3: sample_type = MUS_MULAW; break; + default: sample_type = MUS_UNKNOWN_SAMPLE; break; } } - else data_format = MUS_BSHORT; + else sample_type = MUS_BSHORT; num = mus_char_to_bshort((unsigned char *)(hdrbuf + 22)); if (num == 0) chans = 1; else chans = 2; } @@ -4102,9 +4099,9 @@ static int read_maud_header(const char *filename, int fd) if (data_size > true_file_length) { data_size = true_file_length - data_location; - if (data_size < 0) return(mus_error(MUS_HEADER_READ_FAILED, "%s: data_size = " MUS_LD "?", filename, data_size)); + if (data_size < 0) return(mus_error(MUS_HEADER_READ_FAILED, "%s: data_size = %lld?", filename, data_size)); } - data_size = mus_bytes_to_samples(data_format, data_size); + data_size = mus_bytes_to_samples(sample_type, data_size); return(MUS_NO_ERROR); } @@ -4128,24 +4125,25 @@ static int read_maud_header(const char *filename, int fd) static int read_csl_header(const char *filename, int fd) { - const unsigned char I_HEDR[4] = {'H','E','D','R'}; - const unsigned char I_HDR8[4] = {'H','D','R','8'}; - const unsigned char I_SDA_[4] = {'S','D','A','_'}; - const unsigned char I_SDAB[4] = {'S','D','A','B'}; - const unsigned char I_SD_B[4] = {'S','D','_','B'}; - const unsigned char I_NOTE[4] = {'N','O','T','E'}; + static const unsigned char I_HEDR[4] = {'H','E','D','R'}; + static const unsigned char I_HDR8[4] = {'H','D','R','8'}; + static const unsigned char I_SDA_[4] = {'S','D','A','_'}; + static const unsigned char I_SDAB[4] = {'S','D','A','B'}; + static const unsigned char I_SD_B[4] = {'S','D','_','B'}; + static const unsigned char I_NOTE[4] = {'N','O','T','E'}; - int chunksize, offset, chunkloc; + int offset, chunkloc; bool happy = true; type_specifier = mus_char_to_uninterpreted_int((unsigned char *)hdrbuf); chunkloc = 12; offset = 0; - data_format = MUS_LSHORT; + sample_type = MUS_LSHORT; srate = 0; chans = 1; update_form_size = mus_char_to_lint((unsigned char *)(hdrbuf + 8)); while (happy) { + int chunksize; offset += chunkloc; if (seek_and_read(fd, (unsigned char *)hdrbuf, offset, 64) <= 0) return(mus_error(MUS_HEADER_READ_FAILED, "%s csl header: chunks confused at %d", filename, offset)); @@ -4193,9 +4191,9 @@ static int read_csl_header(const char *filename, int fd) if (data_size > true_file_length) { data_size = true_file_length - data_location; - if (data_size < 0) return(mus_error(MUS_HEADER_READ_FAILED, "%s: data_size = " MUS_LD "?", filename, data_size)); + if (data_size < 0) return(mus_error(MUS_HEADER_READ_FAILED, "%s: data_size = %lld?", filename, data_size)); } - data_size = mus_bytes_to_samples(data_format, data_size); + data_size = mus_bytes_to_samples(sample_type, data_size); return(MUS_NO_ERROR); } @@ -4221,27 +4219,27 @@ static int read_file_samp_header(const char *filename, int fd) data_location = 1024; chans = 1; srate = 8000; - data_format = MUS_LSHORT; + sample_type = MUS_LSHORT; lseek(fd, 10, SEEK_SET); locbuf = (unsigned char *)calloc(1024, sizeof(unsigned char)); header_read(fd, locbuf, 1024); while (i < 1024) { if (strncmp((char *)(locbuf + i), "sftot", 5) == 0) - sscanf((const char *)(&locbuf[i + 6]), "%d", &srate); + sscanf((const char *)(&locbuf[i + 6]), "%12d", &srate); if (strncmp((char *)(locbuf + i), "nchans", 6) == 0) - sscanf((const char *)(&locbuf[i + 7]), "%d", &chans); + sscanf((const char *)(&locbuf[i + 7]), "%12d", &chans); if (strncmp((char *)(locbuf + i), "msb", 3) == 0) if (strncmp((char *)(locbuf + i + 4), "first", 5) == 0) - data_format = MUS_BSHORT; + sample_type = MUS_BSHORT; while ((i < 1024) && (locbuf[i] != 10) && (locbuf[i] != 0)) i++; i++; } free(locbuf); true_file_length = SEEK_FILE_LENGTH(fd); if (true_file_length < data_location) - return(mus_error(MUS_HEADER_READ_FAILED, "%s: data_location " MUS_LD " > file length: " MUS_LD, filename, data_location, true_file_length)); - data_size = mus_bytes_to_samples(data_format, true_file_length - data_location); + return(mus_error(MUS_HEADER_READ_FAILED, "%s: data_location %lld > file length: %lld", filename, data_location, true_file_length)); + data_size = mus_bytes_to_samples(sample_type, true_file_length - data_location); return(MUS_NO_ERROR); } @@ -4273,12 +4271,12 @@ static int read_sd1_header(const char *filename, int fd) srate = mus_char_to_bint((unsigned char *)hdrbuf); n = mus_char_to_bshort((unsigned char *)(hdrbuf + 8)); if (n == 16) - data_format = MUS_BSHORT; - else data_format = MUS_BYTE; + sample_type = MUS_BSHORT; + else sample_type = MUS_BYTE; true_file_length = SEEK_FILE_LENGTH(fd); if (true_file_length < data_location) - return(mus_error(MUS_HEADER_READ_FAILED, "%s: data_location " MUS_LD " > file length: " MUS_LD, filename, data_location, true_file_length)); - data_size = mus_bytes_to_samples(data_format, true_file_length - data_location); + return(mus_error(MUS_HEADER_READ_FAILED, "%s: data_location %lld > file length: %lld", filename, data_location, true_file_length)); + data_size = mus_bytes_to_samples(sample_type, true_file_length - data_location); n = ((unsigned char)hdrbuf[44]); if (n != 0) { @@ -4309,15 +4307,15 @@ static int read_psion_header(const char *filename, int fd) chans = 1; data_location = 32; srate = 8000; - data_format = MUS_ALAW; + sample_type = MUS_ALAW; data_size = mus_char_to_lint((unsigned char *)(hdrbuf + 18)); /* always little-endian? */ true_file_length = SEEK_FILE_LENGTH(fd); if (data_size > true_file_length) { data_size = true_file_length - data_location; - if (data_size < 0) return(mus_error(MUS_HEADER_READ_FAILED, "%s: data_size = " MUS_LD "?", filename, data_size)); + if (data_size < 0) return(mus_error(MUS_HEADER_READ_FAILED, "%s: data_size = %lld?", filename, data_size)); } - data_size = mus_bytes_to_samples(data_format, data_size); + data_size = mus_bytes_to_samples(sample_type, data_size); return(MUS_NO_ERROR); } @@ -4392,23 +4390,23 @@ static int read_gravis_header(const char *filename, int fd) if (mode & 1) { if (mode & 2) - data_format = MUS_ULSHORT; - else data_format = MUS_LSHORT; + sample_type = MUS_ULSHORT; + else sample_type = MUS_LSHORT; } else { if (mode & 2) - data_format = MUS_UBYTE; - else data_format = MUS_BYTE; + sample_type = MUS_UBYTE; + else sample_type = MUS_BYTE; } data_location = 337; true_file_length = SEEK_FILE_LENGTH(fd); if (data_size > true_file_length) { data_size = true_file_length - data_location; - if (data_size < 0) return(mus_error(MUS_HEADER_READ_FAILED, "%s: data_size = " MUS_LD "?", filename, data_size)); + if (data_size < 0) return(mus_error(MUS_HEADER_READ_FAILED, "%s: data_size = %lld?", filename, data_size)); } - data_size = mus_bytes_to_samples(data_format, data_size); + data_size = mus_bytes_to_samples(sample_type, data_size); return(MUS_NO_ERROR); } @@ -4423,11 +4421,11 @@ static int read_goldwave_header(const char *filename, int fd) { chans = 1; data_location = 28; - data_format = MUS_LSHORT; + sample_type = MUS_LSHORT; data_size = mus_char_to_lint((unsigned char *)(hdrbuf + 22)); true_file_length = SEEK_FILE_LENGTH(fd); if (true_file_length < data_location) - return(mus_error(MUS_HEADER_READ_FAILED, "%s: data_location " MUS_LD " > file length: " MUS_LD, filename, data_location, true_file_length)); + return(mus_error(MUS_HEADER_READ_FAILED, "%s: data_location %lld > file length: %lld", filename, data_location, true_file_length)); if ((data_size <= 24) || (data_size > true_file_length)) data_size = (true_file_length - data_location) / 2; else data_size /= 2; @@ -4448,10 +4446,10 @@ static int read_srfs_header(const char *filename, int fd) data_location = 32; true_file_length = SEEK_FILE_LENGTH(fd); if (true_file_length < data_location) - return(mus_error(MUS_HEADER_READ_FAILED, "%s: data_location " MUS_LD " > file length: " MUS_LD, filename, data_location, true_file_length)); + return(mus_error(MUS_HEADER_READ_FAILED, "%s: data_location %lld > file length: %lld", filename, data_location, true_file_length)); data_size = (true_file_length - data_location) / 2; srate = mus_char_to_lint((unsigned char *)(hdrbuf + 6)); - data_format = MUS_LSHORT; + sample_type = MUS_LSHORT; return(MUS_NO_ERROR); } @@ -4469,9 +4467,9 @@ static int read_qt_header(const char *filename, int fd) data_location = 12; true_file_length = SEEK_FILE_LENGTH(fd); data_size = (true_file_length - data_location); - if (data_size < 0) return(mus_error(MUS_HEADER_READ_FAILED, "%s: data_size = " MUS_LD "?", filename, data_size)); + if (data_size < 0) return(mus_error(MUS_HEADER_READ_FAILED, "%s: data_size = %lld?", filename, data_size)); srate = 11025; /* ?? */ - data_format = MUS_UBYTE; + sample_type = MUS_UBYTE; return(MUS_NO_ERROR); } @@ -4495,16 +4493,16 @@ static int read_qt_header(const char *filename, int fd) static int read_sbstudio_header(const char *filename, int fd) { - const unsigned char I_SNIN[4] = {'S','N','I','N'}; - const unsigned char I_SNNA[4] = {'S','N','N','A'}; - const unsigned char I_SNDT[4] = {'S','N','D','T'}; + static const unsigned char I_SNIN[4] = {'S','N','I','N'}; + static const unsigned char I_SNNA[4] = {'S','N','N','A'}; + static const unsigned char I_SNDT[4] = {'S','N','D','T'}; int i, tmp; bool happy = true; unsigned char *bp; chans = 1; srate = 8000; /* no sampling rate field in this header */ - data_format = MUS_UNKNOWN; + sample_type = MUS_UNKNOWN_SAMPLE; true_file_length = SEEK_FILE_LENGTH(fd); i = 8; bp = (unsigned char *)(hdrbuf + 8); @@ -4522,12 +4520,12 @@ static int read_sbstudio_header(const char *filename, int fd) { tmp = mus_char_to_lshort((unsigned char *)(bp + 15)); if ((tmp & 1) == 0) - data_format = MUS_UNKNOWN; + sample_type = MUS_UNKNOWN_SAMPLE; else { if ((tmp & 2) == 0) - data_format = MUS_BYTE; - else data_format = MUS_LSHORT; + sample_type = MUS_BYTE; + else sample_type = MUS_LSHORT; } i += 26; bp += 26; @@ -4549,20 +4547,20 @@ static int read_sbstudio_header(const char *filename, int fd) } if (i >= HDRBUFSIZ) { - data_format = MUS_UNKNOWN; + sample_type = MUS_UNKNOWN_SAMPLE; happy = false; } } if (data_location == 0) return(mus_error(MUS_HEADER_READ_FAILED, "%s: no SNDT chunk?", filename)); - if ((data_size == 0) || (data_format == MUS_UNKNOWN)) - return(mus_error(MUS_HEADER_READ_FAILED, "%s: data size or format bogus", filename)); + if ((data_size == 0) || (sample_type == MUS_UNKNOWN_SAMPLE)) + return(mus_error(MUS_HEADER_READ_FAILED, "%s: data size or sample type bogus", filename)); if (data_size > true_file_length) { data_size = true_file_length - data_location; - if (data_size < 0) return(mus_error(MUS_HEADER_READ_FAILED, "%s: data_size = " MUS_LD "?", filename, data_size)); + if (data_size < 0) return(mus_error(MUS_HEADER_READ_FAILED, "%s: data_size = %lld?", filename, data_size)); } - data_size = mus_bytes_to_samples(data_format, data_size); + data_size = mus_bytes_to_samples(sample_type, data_size); return(MUS_NO_ERROR); } @@ -4586,10 +4584,10 @@ static int read_delusion_header(const char *filename, int fd) data_location = 55; true_file_length = SEEK_FILE_LENGTH(fd); data_size = (true_file_length - data_location); - if (data_size < 0) return(mus_error(MUS_HEADER_READ_FAILED, "%s: data_size = " MUS_LD "?", filename, data_size)); + if (data_size < 0) return(mus_error(MUS_HEADER_READ_FAILED, "%s: data_size = %lld?", filename, data_size)); srate = 8000; - data_format = MUS_LSHORT; - data_size = mus_bytes_to_samples(data_format, data_size); + sample_type = MUS_LSHORT; + data_size = mus_bytes_to_samples(sample_type, data_size); return(MUS_NO_ERROR); } @@ -4616,12 +4614,12 @@ static int read_farandole_header(const char *filename, int fd) data_location = 51; true_file_length = SEEK_FILE_LENGTH(fd); data_size = (true_file_length - data_location); - if (data_size < 0) return(mus_error(MUS_HEADER_READ_FAILED, "%s: data_size = " MUS_LD "?", filename, data_size)); + if (data_size < 0) return(mus_error(MUS_HEADER_READ_FAILED, "%s: data_size = %lld?", filename, data_size)); srate = 8000; if (hdrbuf[49] == 0) - data_format = MUS_BYTE; - else data_format = MUS_LSHORT; - data_size = mus_bytes_to_samples(data_format, data_size); + sample_type = MUS_BYTE; + else sample_type = MUS_LSHORT; + data_size = mus_bytes_to_samples(sample_type, data_size); return(MUS_NO_ERROR); } @@ -4651,7 +4649,7 @@ static int read_tx16w_header(const char *filename, int fd) data_location = 32; true_file_length = SEEK_FILE_LENGTH(fd); data_size = (true_file_length - data_location); - if (data_size < 0) return(mus_error(MUS_HEADER_READ_FAILED, "%s: data_size = " MUS_LD "?", filename, data_size)); + if (data_size < 0) return(mus_error(MUS_HEADER_READ_FAILED, "%s: data_size = %lld?", filename, data_size)); srate = 16000; if (hdrbuf[23] == 1) srate = 33000; else if (hdrbuf[23] == 2) srate = 50000; @@ -4662,8 +4660,8 @@ static int read_tx16w_header(const char *filename, int fd) else if ((hdrbuf[26] & 0xFE) == 0x10) srate = 50000; else if ((hdrbuf[26] & 0xFE) == 0xf6) srate = 16000; } - original_data_format = MUS_UNKNOWN; - data_format = MUS_UNKNOWN; + original_sample_type = MUS_UNKNOWN_SAMPLE; + sample_type = MUS_UNKNOWN_SAMPLE; data_size = (mus_long_t)((double)data_size / 1.5); if (hdrbuf[22] == 0x49) { @@ -4693,10 +4691,10 @@ static int read_sy85_header(const char *filename, int fd) data_location = 1024; true_file_length = SEEK_FILE_LENGTH(fd); data_size = (true_file_length - data_location); - if (data_size < 0) return(mus_error(MUS_HEADER_READ_FAILED, "%s: data_size = " MUS_LD "?", filename, data_size)); + if (data_size < 0) return(mus_error(MUS_HEADER_READ_FAILED, "%s: data_size = %lld?", filename, data_size)); srate = 8000; /* unknown */ - data_format = MUS_BSHORT; /* not right */ - data_size = mus_bytes_to_samples(data_format, data_size); + sample_type = MUS_BSHORT; /* not right */ + data_size = mus_bytes_to_samples(sample_type, data_size); return(MUS_NO_ERROR); } @@ -4713,10 +4711,10 @@ static int read_kurzweil_2000_header(const char *filename, int fd) data_location = mus_char_to_bint((unsigned char *)(hdrbuf + 4)); true_file_length = SEEK_FILE_LENGTH(fd); data_size = (true_file_length - data_location); - if (data_size < 0) return(mus_error(MUS_HEADER_READ_FAILED, "%s: data_size = " MUS_LD "?", filename, data_size)); + if (data_size < 0) return(mus_error(MUS_HEADER_READ_FAILED, "%s: data_size = %lld?", filename, data_size)); srate = 44100; /* unknown */ - data_format = MUS_BSHORT; - data_size = mus_bytes_to_samples(data_format, data_size); + sample_type = MUS_BSHORT; + data_size = mus_bytes_to_samples(sample_type, data_size); return(MUS_NO_ERROR); } @@ -4732,10 +4730,10 @@ static int read_korg_header(const char *filename, int fd) data_location = 70; true_file_length = SEEK_FILE_LENGTH(fd); data_size = (true_file_length - data_location); - if (data_size < 0) return(mus_error(MUS_HEADER_READ_FAILED, "%s: data_size = " MUS_LD "?", filename, data_size)); + if (data_size < 0) return(mus_error(MUS_HEADER_READ_FAILED, "%s: data_size = %lld?", filename, data_size)); srate = mus_char_to_bint((unsigned char *)(hdrbuf + 48)); - data_format = MUS_BSHORT; - data_size = mus_bytes_to_samples(data_format, data_size); + sample_type = MUS_BSHORT; + data_size = mus_bytes_to_samples(sample_type, data_size); return(MUS_NO_ERROR); } @@ -4753,12 +4751,12 @@ static int read_maui_header(const char *filename, int fd) data_location = 776; true_file_length = SEEK_FILE_LENGTH(fd); if (true_file_length < data_location) - return(mus_error(MUS_HEADER_READ_FAILED, "%s: data_location " MUS_LD " > file length: " MUS_LD, filename, data_location, true_file_length)); + return(mus_error(MUS_HEADER_READ_FAILED, "%s: data_location %lld > file length: %lld", filename, data_location, true_file_length)); data_size = mus_char_to_lint((unsigned char *)(hdrbuf + 8)); if ((data_size * 2) > true_file_length) data_size = (true_file_length - data_location) / 2; srate = mus_char_to_lint((unsigned char *)(hdrbuf)); - data_format = MUS_LSHORT; + sample_type = MUS_LSHORT; return(MUS_NO_ERROR); } @@ -4790,14 +4788,14 @@ static int read_maui_header(const char *filename, int fd) static int read_impulsetracker_header(const char *filename, int fd) { if (hdrbuf[18] & 4) chans = 2; else chans = 1; - if (hdrbuf[18] & 2) data_format = MUS_LSHORT; else data_format = MUS_BYTE; + if (hdrbuf[18] & 2) sample_type = MUS_LSHORT; else sample_type = MUS_BYTE; data_location = mus_char_to_lint((unsigned char *)(hdrbuf + 72)); true_file_length = SEEK_FILE_LENGTH(fd); if (true_file_length < data_location) - return(mus_error(MUS_HEADER_READ_FAILED, "%s: data_location " MUS_LD " > file length: " MUS_LD, filename, data_location, true_file_length)); + return(mus_error(MUS_HEADER_READ_FAILED, "%s: data_location %lld > file length: %lld", filename, data_location, true_file_length)); data_size = (true_file_length - data_location); srate = mus_char_to_lint((unsigned char *)(hdrbuf + 60)); - data_size = mus_bytes_to_samples(data_format, data_size); + data_size = mus_bytes_to_samples(sample_type, data_size); return(MUS_NO_ERROR); } @@ -4810,10 +4808,10 @@ static int read_akai3_header(const char *filename, int fd) data_location = 192; true_file_length = SEEK_FILE_LENGTH(fd); data_size = (true_file_length - data_location); - if (data_size < 0) return(mus_error(MUS_HEADER_READ_FAILED, "%s: data_size = " MUS_LD "?", filename, data_size)); + if (data_size < 0) return(mus_error(MUS_HEADER_READ_FAILED, "%s: data_size = %lld?", filename, data_size)); if (hdrbuf[1] == 0) srate = 22050; else srate = 44100; - data_format = MUS_LSHORT; - data_size = mus_bytes_to_samples(data_format, data_size); + sample_type = MUS_LSHORT; + data_size = mus_bytes_to_samples(sample_type, data_size); return(MUS_NO_ERROR); } #endif @@ -4830,10 +4828,10 @@ static int read_akai4_header(const char *filename, int fd) data_location = 42; true_file_length = SEEK_FILE_LENGTH(fd); data_size = (true_file_length - data_location); - if (data_size < 0) return(mus_error(MUS_HEADER_READ_FAILED, "%s: data_size = " MUS_LD "?", filename, data_size)); + if (data_size < 0) return(mus_error(MUS_HEADER_READ_FAILED, "%s: data_size = %lld?", filename, data_size)); srate = mus_char_to_ulshort((unsigned char *)(hdrbuf + 40)); - data_format = MUS_LSHORT; - data_size = mus_bytes_to_samples(data_format, data_size); + sample_type = MUS_LSHORT; + data_size = mus_bytes_to_samples(sample_type, data_size); return(MUS_NO_ERROR); } @@ -4858,7 +4856,7 @@ static int read_pvf_header(const char *filename, int fd) if (hdrbuf[4] != '\n') return(mus_error(MUS_HEADER_READ_FAILED, "PVF header messed up")); type_specifier = mus_char_to_uninterpreted_int((unsigned char *)hdrbuf); buf = (char *)(hdrbuf + 5); - sscanf(buf, "%d %d %d", &chans, &srate, &bits); + sscanf(buf, "%12d %12d %12d", &chans, &srate, &bits); if (chans < 1) chans = 1; if (srate < 0) srate = 8000; if (bits < 8) bits = 8; @@ -4872,18 +4870,18 @@ static int read_pvf_header(const char *filename, int fd) return(mus_error(MUS_HEADER_READ_FAILED, "%s PVF header bad data location", filename)); if (match_four_chars((unsigned char *)hdrbuf, I_PVF2)) { - data_format = MUS_UNKNOWN; /* ascii text */ - return(mus_error(MUS_HEADER_READ_FAILED, "%s PVF header unknown data format", filename)); + sample_type = MUS_UNKNOWN_SAMPLE; /* ascii text */ + return(mus_error(MUS_HEADER_READ_FAILED, "%s PVF header unknown sample type", filename)); } /* big endian data -- they're using htonl etc */ if (bits == 8) - data_format = MUS_BYTE; + sample_type = MUS_BYTE; else if (bits == 16) - data_format = MUS_BSHORT; - else data_format = MUS_BINT; + sample_type = MUS_BSHORT; + else sample_type = MUS_BINT; true_file_length = SEEK_FILE_LENGTH(fd); - data_size = mus_bytes_to_samples(data_format, true_file_length - data_location); + data_size = mus_bytes_to_samples(sample_type, true_file_length - data_location); return(MUS_NO_ERROR); } @@ -4907,11 +4905,11 @@ static int read_ultratracker_header(const char *filename, int fd) data_location = 64; true_file_length = SEEK_FILE_LENGTH(fd); if (true_file_length < data_location) - return(mus_error(MUS_HEADER_READ_FAILED, "%s: data_location " MUS_LD " > file length: " MUS_LD, filename, data_location, true_file_length)); + return(mus_error(MUS_HEADER_READ_FAILED, "%s: data_location %lld > file length: %lld", filename, data_location, true_file_length)); data_size = (true_file_length - data_location); srate = 8000; - data_format = MUS_LSHORT; - data_size = mus_bytes_to_samples(data_format, data_size); + sample_type = MUS_LSHORT; + data_size = mus_bytes_to_samples(sample_type, data_size); return(MUS_NO_ERROR); } @@ -4927,7 +4925,7 @@ static int read_ultratracker_header(const char *filename, int fd) * 0: packing (0 = pcm) * 1: midi channel * 2 + 256*[3]: sample number - * 4: sample format (15: 16 bit unsigned(?), 8: 8bit unsigned(?) + * 4: sample type (15: 16 bit unsigned(?), 8: 8bit unsigned(?) * 5: sample rate (big int?) * 9: sample length * 13: loop start @@ -4961,11 +4959,11 @@ static int read_sample_dump_header(const char *filename, int fd) data_location = i + 3 + len + 23; true_file_length = SEEK_FILE_LENGTH(fd); data_size = (true_file_length - data_location); - if (data_size < 0) return(mus_error(MUS_HEADER_READ_FAILED, "%s: data_size = " MUS_LD "?", filename, data_size)); + if (data_size < 0) return(mus_error(MUS_HEADER_READ_FAILED, "%s: data_size = %lld?", filename, data_size)); if (hdrbuf[0] == 0) - data_format = MUS_ULSHORT; - else data_format = MUS_UNKNOWN; - data_size = mus_bytes_to_samples(data_format, data_size); + sample_type = MUS_ULSHORT; + else sample_type = MUS_UNKNOWN_SAMPLE; + data_size = mus_bytes_to_samples(sample_type, data_size); return(MUS_NO_ERROR); } @@ -5002,17 +5000,17 @@ static int read_digiplayer_header(const char *filename, int fd) data_location = 80; true_file_length = SEEK_FILE_LENGTH(fd); data_size = (true_file_length - data_location); - if (data_size < 0) return(mus_error(MUS_HEADER_READ_FAILED, "%s: data_size = " MUS_LD "?", filename, data_size)); + if (data_size < 0) return(mus_error(MUS_HEADER_READ_FAILED, "%s: data_size = %lld?", filename, data_size)); srate = 8000; - data_format = MUS_ULSHORT; + sample_type = MUS_ULSHORT; if (hdrbuf[30] & 2) chans = 2; if (hdrbuf[30] & 1) - data_format = MUS_UNKNOWN; + sample_type = MUS_UNKNOWN_SAMPLE; else { - if (hdrbuf[30] & 4) data_format = MUS_UBYTE; /* may be backwards -- using Convert 1.4 output here */ + if (hdrbuf[30] & 4) sample_type = MUS_UBYTE; /* may be backwards -- using Convert 1.4 output here */ } - data_size = mus_bytes_to_samples(data_format, data_size); + data_size = mus_bytes_to_samples(sample_type, data_size); return(MUS_NO_ERROR); } @@ -5048,18 +5046,18 @@ static int read_adf_header(const char *filename, int fd) if ((bits == 16) || (bits == 12)) { if (numsys == 0) - data_format = MUS_LSHORT; - else data_format = MUS_ULSHORT; + sample_type = MUS_LSHORT; + else sample_type = MUS_ULSHORT; } - else data_format = MUS_UNKNOWN; + else sample_type = MUS_UNKNOWN_SAMPLE; srate = (int)(1000 * mus_char_to_lfloat((unsigned char *)(hdrbuf + 22))); data_size = mus_char_to_lint((unsigned char *)(hdrbuf + 8)); data_location = 512; true_file_length = SEEK_FILE_LENGTH(fd); if (true_file_length < data_location) - return(mus_error(MUS_HEADER_READ_FAILED, "%s: data_location " MUS_LD " > file length: " MUS_LD, filename, data_location, true_file_length)); - if (data_size > mus_bytes_to_samples(data_format, true_file_length - data_location)) - data_size = mus_bytes_to_samples(data_format, true_file_length - data_location); + return(mus_error(MUS_HEADER_READ_FAILED, "%s: data_location %lld > file length: %lld", filename, data_location, true_file_length)); + if (data_size > mus_bytes_to_samples(sample_type, true_file_length - data_location)) + data_size = mus_bytes_to_samples(sample_type, true_file_length - data_location); return(MUS_NO_ERROR); } @@ -5096,23 +5094,23 @@ static int read_diamondware_header(const char *filename, int fd) chans = hdrbuf[34]; if (hdrbuf[31] == 0) { - if (hdrbuf[35] == 8) data_format = MUS_BYTE; - else data_format = MUS_LSHORT; + if (hdrbuf[35] == 8) sample_type = MUS_BYTE; + else sample_type = MUS_LSHORT; } else { - data_format = MUS_UNKNOWN; - return(mus_error(MUS_HEADER_READ_FAILED, "%s unknown data format", filename)); + sample_type = MUS_UNKNOWN_SAMPLE; + return(mus_error(MUS_HEADER_READ_FAILED, "%s unknown sample type", filename)); } srate = mus_char_to_ulshort((unsigned char *)(hdrbuf + 32)); data_size = mus_char_to_lint((unsigned char *)(hdrbuf + 38)); data_location = mus_char_to_lint((unsigned char *)(hdrbuf + 46)); true_file_length = SEEK_FILE_LENGTH(fd); if (true_file_length < data_location) - return(mus_error(MUS_HEADER_READ_FAILED, "%s: data_location " MUS_LD " > file length: " MUS_LD, filename, data_location, true_file_length)); + return(mus_error(MUS_HEADER_READ_FAILED, "%s: data_location %lld > file length: %lld", filename, data_location, true_file_length)); if (data_size > true_file_length - data_location) data_size = true_file_length - data_location; - data_size = mus_bytes_to_samples(data_format, data_size); + data_size = mus_bytes_to_samples(sample_type, data_size); return(MUS_NO_ERROR); } @@ -5134,30 +5132,30 @@ static int read_paf_header(const char *filename, int fd) { int form; bool little = false; - data_format = MUS_UNKNOWN; + sample_type = MUS_UNKNOWN_SAMPLE; if (mus_char_to_bint((unsigned char *)(hdrbuf + 8))) little = true; if (little) { srate = mus_char_to_ulint((unsigned char *)(hdrbuf + 12)); form = mus_char_to_ulint((unsigned char *)(hdrbuf + 16)); - if (form == 0) data_format = MUS_LSHORT; - if (form == 2) data_format = MUS_BYTE; + if (form == 0) sample_type = MUS_LSHORT; + if (form == 2) sample_type = MUS_BYTE; chans = mus_char_to_ulint((unsigned char *)(hdrbuf + 20)); } else { srate = mus_char_to_ubint((unsigned char *)(hdrbuf + 12)); form = mus_char_to_ubint((unsigned char *)(hdrbuf + 16)); - if (form == 0) data_format = MUS_BSHORT; - if (form == 2) data_format = MUS_BYTE; + if (form == 0) sample_type = MUS_BSHORT; + if (form == 2) sample_type = MUS_BYTE; chans = mus_char_to_ubint((unsigned char *)(hdrbuf + 20)); } data_location = 2048; true_file_length = SEEK_FILE_LENGTH(fd); if (true_file_length < data_location) - return(mus_error(MUS_HEADER_READ_FAILED, "%s: data_location " MUS_LD " > file length: " MUS_LD, filename, data_location, true_file_length)); - if (data_format != MUS_UNKNOWN) - data_size = mus_bytes_to_samples(data_format, true_file_length - 2048); + return(mus_error(MUS_HEADER_READ_FAILED, "%s: data_location %lld > file length: %lld", filename, data_location, true_file_length)); + if (sample_type != MUS_UNKNOWN_SAMPLE) + data_size = mus_bytes_to_samples(sample_type, true_file_length - 2048); return(MUS_NO_ERROR); } @@ -5194,6 +5192,7 @@ static int read_comdisco_header(const char *filename, int fd) char *line = NULL; int i, j, k, m, n, curend, offset, len, type, d_size = 0; bool happy = true, little, commenting; + k = 15; line = (char *)calloc(256, sizeof(char)); little = false; @@ -5261,29 +5260,28 @@ static int read_comdisco_header(const char *filename, int fd) for (n = 0, m = j + 2; m < len; m++, n++) value[n] = line[m]; value[n] ='\0'; - if (strcmp(portion, "Sampling") == 0) sscanf(value, "%d", &srate); else - if (strcmp(portion, "Number o") == 0) sscanf(value, "%d", &d_size); else + if (strcmp(portion, "Sampling") == 0) sscanf(value, "%12d", &srate); else + if (strcmp(portion, "Number o") == 0) sscanf(value, "%12d", &d_size); else if (strcmp(portion, "Signal T") == 0) {if (value[1] == 'o') type = 2; else if (value[1] == 'l') type = 1;} else if (strcmp(portion, "Fixed Po") == 0) {if (value[1] == '8') type = 3;} } } /* now clean up this mess */ - if (data_location == 0) - return(mus_error(MUS_HEADER_READ_FAILED, "%s: no $DATA BINARY field?", filename)); - if (srate == 0) return(mus_error(MUS_HEADER_READ_FAILED, "%s: srate == 0", filename)); + if (data_location == 0) {free(line); return(mus_error(MUS_HEADER_READ_FAILED, "%s: no $DATA BINARY field?", filename));} + if (srate == 0) {free(line); return(mus_error(MUS_HEADER_READ_FAILED, "%s: srate == 0", filename));} chans = 1; if (d_size != 0) data_size = (mus_long_t)d_size; switch (type) { - case 0: if (little) data_format = MUS_LSHORT; else data_format = MUS_BSHORT; break; - case 1: if (little) data_format = MUS_LFLOAT; else data_format = MUS_BFLOAT; break; - case 2: if (little) data_format = MUS_LDOUBLE; else data_format = MUS_BDOUBLE; break; - case 3: data_format = MUS_BYTE; break; + case 0: if (little) sample_type = MUS_LSHORT; else sample_type = MUS_BSHORT; break; + case 1: if (little) sample_type = MUS_LFLOAT; else sample_type = MUS_BFLOAT; break; + case 2: if (little) sample_type = MUS_LDOUBLE; else sample_type = MUS_BDOUBLE; break; + case 3: sample_type = MUS_BYTE; break; } true_file_length = SEEK_FILE_LENGTH(fd); - if (data_size > mus_bytes_to_samples(data_format, true_file_length - data_location)) - data_size = mus_bytes_to_samples(data_format, true_file_length - data_location); + if (data_size > mus_bytes_to_samples(sample_type, true_file_length - data_location)) + data_size = mus_bytes_to_samples(sample_type, true_file_length - data_location); free(line); return(MUS_NO_ERROR); } @@ -5300,7 +5298,7 @@ static int read_comdisco_header(const char *filename, int fd) static int read_asf_header(const char *filename, int fd) { - /* a chunked data format, so not really acceptable here or elsewhere -- needs to be unchunked */ + /* a chunked sample type, so not really acceptable here or elsewhere -- needs to be unchunked */ int len, ilen = 0, i, j, bits = 0; bool asf_huge = false, present; /* apparently "huge" has some meaning in Windoze C */ @@ -5328,7 +5326,7 @@ static int read_asf_header(const char *filename, int fd) srate = mus_char_to_lint((unsigned char *)(hdrbuf + j+11+36)); bits = mus_char_to_lint((unsigned char *)(hdrbuf + j+11+32)); chans = mus_char_to_ulshort((unsigned char *)(hdrbuf + j+65)); - original_data_format = mus_char_to_lint((unsigned char *)(hdrbuf + j+11)); + original_sample_type = mus_char_to_lint((unsigned char *)(hdrbuf + j+11)); break; default: @@ -5341,7 +5339,7 @@ static int read_asf_header(const char *filename, int fd) } i = len; seek_and_read(fd, (unsigned char *)hdrbuf, i, HDRBUFSIZ); - data_format = MUS_UNKNOWN; + sample_type = MUS_UNKNOWN_SAMPLE; if (((unsigned int)(hdrbuf[1]) == 0x29) && ((unsigned int)(hdrbuf[0]) == 0xd2)) { int a_huge = 2; @@ -5349,17 +5347,17 @@ static int read_asf_header(const char *filename, int fd) if (asf_huge) a_huge = 4; data_location = i + 20 + a_huge + 2+4+3+1; if (bits == 0) bits = 8; - data_format = wave_to_sndlib_format(original_data_format, bits, true); + sample_type = wave_to_sndlib_format(original_sample_type, bits, true); } - else return(mus_error(MUS_HEADER_READ_FAILED, "%s: unknown data format", filename)); + else return(mus_error(MUS_HEADER_READ_FAILED, "%s: unknown sample type", filename)); data_size = ilen - data_location; true_file_length = SEEK_FILE_LENGTH(fd); if (data_size > true_file_length) { data_size = true_file_length - data_location; - if (data_size < 0) return(mus_error(MUS_HEADER_READ_FAILED, "%s: data_size = " MUS_LD "?", filename, data_size)); + if (data_size < 0) return(mus_error(MUS_HEADER_READ_FAILED, "%s: data_size = %lld?", filename, data_size)); } - data_size = mus_bytes_to_samples(data_format, data_size); + data_size = mus_bytes_to_samples(sample_type, data_size); return(MUS_NO_ERROR); } @@ -5383,14 +5381,14 @@ static int read_sox_header(const char *filename, int fd) if (match_four_chars((unsigned char *)(hdrbuf + 0), I_dSoX)) { - data_format = MUS_LINTN; + sample_type = MUS_LINTN; samps = mus_char_to_llong((unsigned char *)(hdrbuf + 8)); srate = (int)mus_char_to_ldouble((unsigned char *)(hdrbuf + 16)); little_endian = true; } else { /* untested */ - data_format = MUS_BINTN; + sample_type = MUS_BINTN; samps = mus_char_to_blong((unsigned char *)(hdrbuf + 8)); srate = (int)mus_char_to_bdouble((unsigned char *)(hdrbuf + 16)); little_endian = false; @@ -5406,8 +5404,8 @@ static int read_sox_header(const char *filename, int fd) } true_file_length = SEEK_FILE_LENGTH(fd); data_size = (true_file_length - data_location); - if (data_size < 0) return(mus_error(MUS_HEADER_READ_FAILED, "%s: data_size = " MUS_LD "?", filename, data_size)); - data_size = mus_bytes_to_samples(data_format, data_size); + if (data_size < 0) return(mus_error(MUS_HEADER_READ_FAILED, "%s: data_size = %lld?", filename, data_size)); + data_size = mus_bytes_to_samples(sample_type, data_size); if (samps < data_size) data_size = samps; return(MUS_NO_ERROR); } @@ -5434,8 +5432,8 @@ static int read_sox_header(const char *filename, int fd) static int read_matlab_5_header(const char *filename, int fd) { - int i, type, chunksize, loc, size; - bool swapped = false; + int i, type, loc, size; + /* bool swapped = false; */ comment_start = 0; comment_end = 124; @@ -5445,16 +5443,15 @@ static int read_matlab_5_header(const char *filename, int fd) comment_end = i; break; } - - if (mus_char_to_lshort((unsigned char *)(hdrbuf + 126)) == 0x494d) - swapped = true; + + /* if (mus_char_to_lshort((unsigned char *)(hdrbuf + 126)) == 0x494d) swapped = true; */ /* byte swapping not handled yet */ type = mus_char_to_lint((unsigned char *)(hdrbuf + 128)); if (type != 14) - return(mus_error(MUS_HEADER_READ_FAILED, "%s: unknown Matlab data format (%d)", filename, type)); + return(mus_error(MUS_HEADER_READ_FAILED, "%s: unknown Matlab sample type (%d)", filename, type)); - chunksize = mus_char_to_lint((unsigned char *)(hdrbuf + 132)); + /* chunksize = mus_char_to_lint((unsigned char *)(hdrbuf + 132)); */ /* now grovel through the array header */ /* assume the "flags" are not interesting */ @@ -5472,8 +5469,8 @@ static int read_matlab_5_header(const char *filename, int fd) type = mus_char_to_lint((unsigned char *)(hdrbuf + loc)); if (type == 9) - data_format = MUS_LDOUBLE; - else data_format = MUS_LFLOAT; + sample_type = MUS_LDOUBLE; + else sample_type = MUS_LFLOAT; data_size = mus_char_to_lint((unsigned char *)(hdrbuf + loc + 4)); chans = 1; @@ -5488,36 +5485,36 @@ static int read_matlab_5_header(const char *filename, int fd) /* ------------------------------------ no header ------------------------------------- */ -static int header_raw_srate = 44100; -static int header_raw_chans = 2; -static int header_raw_format = MUS_BSHORT; +static int raw_header_srate = 44100; +static int raw_header_chans = 2; +static mus_sample_t raw_header_sample_type = MUS_BSHORT; static int read_no_header(int fd) { - srate = header_raw_srate; - chans = header_raw_chans; - data_format = header_raw_format; + srate = raw_header_srate; + chans = raw_header_chans; + sample_type = raw_header_sample_type; data_location = 0; data_size = SEEK_FILE_LENGTH(fd); true_file_length = data_size; - data_size = mus_bytes_to_samples(data_format, data_size); + data_size = mus_bytes_to_samples(sample_type, data_size); return(MUS_NO_ERROR); } -void mus_header_set_raw_defaults(int sr, int chn, int frm) +void mus_header_set_raw_defaults(int sr, int chn, mus_sample_t samp_type) { - if (sr > 0) header_raw_srate = sr; - if (chn > 0) header_raw_chans = chn; - if (mus_data_format_p(frm)) header_raw_format = frm; + if (sr > 0) raw_header_srate = sr; + if (chn > 0) raw_header_chans = chn; + if (mus_is_sample_type(samp_type)) raw_header_sample_type = samp_type; } -void mus_header_raw_defaults(int *sr, int *chn, int *frm) +void mus_header_raw_defaults(int *sr, int *chn, mus_sample_t *samp_type) { - (*sr) = header_raw_srate; - (*chn) = header_raw_chans; - (*frm) = header_raw_format; + (*sr) = raw_header_srate; + (*chn) = raw_header_chans; + (*samp_type) = raw_header_sample_type; } @@ -5526,46 +5523,46 @@ void mus_header_raw_defaults(int *sr, int *chn, int *frm) static int mus_header_read_1(const char *filename, int fd) { - const unsigned char I_HCOM[4] = {'H','C','O','M'}; - const unsigned char I_FSSD[4] = {'F','S','S','D'}; - const unsigned char I_8SVX[4] = {'8','S','V','X'}; - const unsigned char I_16SV[4] = {'1','6','S','V'}; - const unsigned char I_VOC1[4] = {'t','i','v','e'}; - const unsigned char I_Soun[4] = {'S','o','u','n'}; - const unsigned char I_MAUD[4] = {'M','A','U','D'}; - const unsigned char I_mdat[4] = {'m','d','a','t'}; /* quicktime */ - const unsigned char I_sfbk[4] = {'s','f','b','k'}; /* SoundFont 2.0 */ - const unsigned char I_ATCH[4] = {'A','T','C','H'}; - const unsigned char I_NAL_[4] = {'N','A','L','_'}; - const unsigned char I__WAV[4] = {' ','S','A','M'}; - const unsigned char I_ondW[4] = {'o','n','d','W'}; - const unsigned char I_SDXc[4] = {'S','D','X',':'}; /* Sample dump exchange format */ - const unsigned char I_AVI_[4] = {'A','V','I',' '}; /* RIFF AVI */ - const unsigned char I_ones[4] = {(unsigned char)'\377',(unsigned char)'\377',(unsigned char)'\377',(unsigned char)'\377'}; - const unsigned char I_zeros[4] = {'\0','\0','\0','\0'}; - const unsigned char I_asf0[4] = {(unsigned char)'\321','\051',(unsigned char)'\342',(unsigned char)'\326'}; - const unsigned char I_asf1[4] = {(unsigned char)'\332','\065',(unsigned char)'\321','\021'}; - const unsigned char I_asf2[4] = {(unsigned char)'\220','\064','\000',(unsigned char)'\240'}; - const unsigned char I_asf3[4] = {(unsigned char)'\311','\003','\111',(unsigned char)'\276'}; - const unsigned char I_DS16[4] = {'D','S','1','6'}; /* CSL */ - const unsigned char I__sam[4] = {'=','s','a','m'}; - const unsigned char I_OggS[4] = {'O','g','g','S'}; /* Ogg-related files, apparently -- ogg123 has "vorbis" instead of "Speex" */ - const unsigned char I_fLaC[4] = {'f','L','a','C'}; /* FLAC */ - const unsigned char I_TTA1[4] = {'T','T','A','1'}; /* ttaenc */ - const unsigned char I_wvpk[4] = {'w','v','p','k'}; /* wavpack */ - const unsigned char I_MATL[4] = {'M','A','T','L'}; /* matlab 5.0 */ - const unsigned char I_AB_5[4] = {'A','B',' ','5'}; + static const unsigned char I_HCOM[4] = {'H','C','O','M'}; + static const unsigned char I_FSSD[4] = {'F','S','S','D'}; + static const unsigned char I_8SVX[4] = {'8','S','V','X'}; + static const unsigned char I_16SV[4] = {'1','6','S','V'}; + static const unsigned char I_VOC1[4] = {'t','i','v','e'}; + static const unsigned char I_Soun[4] = {'S','o','u','n'}; + static const unsigned char I_MAUD[4] = {'M','A','U','D'}; + static const unsigned char I_mdat[4] = {'m','d','a','t'}; /* quicktime */ + static const unsigned char I_sfbk[4] = {'s','f','b','k'}; /* SoundFont 2.0 */ + static const unsigned char I_ATCH[4] = {'A','T','C','H'}; + static const unsigned char I_NAL_[4] = {'N','A','L','_'}; + static const unsigned char I__WAV[4] = {' ','S','A','M'}; + static const unsigned char I_ondW[4] = {'o','n','d','W'}; + static const unsigned char I_SDXc[4] = {'S','D','X',':'}; /* Sample dump exchange format */ + static const unsigned char I_AVI_[4] = {'A','V','I',' '}; /* RIFF AVI */ + static const unsigned char I_ones[4] = {(unsigned char)'\377',(unsigned char)'\377',(unsigned char)'\377',(unsigned char)'\377'}; + static const unsigned char I_zeros[4] = {'\0','\0','\0','\0'}; + static const unsigned char I_asf0[4] = {(unsigned char)'\321','\051',(unsigned char)'\342',(unsigned char)'\326'}; + static const unsigned char I_asf1[4] = {(unsigned char)'\332','\065',(unsigned char)'\321','\021'}; + static const unsigned char I_asf2[4] = {(unsigned char)'\220','\064','\000',(unsigned char)'\240'}; + static const unsigned char I_asf3[4] = {(unsigned char)'\311','\003','\111',(unsigned char)'\276'}; + static const unsigned char I_DS16[4] = {'D','S','1','6'}; /* CSL */ + static const unsigned char I__sam[4] = {'=','s','a','m'}; + static const unsigned char I_OggS[4] = {'O','g','g','S'}; /* Ogg-related files, apparently -- ogg123 has "vorbis" instead of "Speex" */ + static const unsigned char I_fLaC[4] = {'f','L','a','C'}; /* FLAC */ + static const unsigned char I_TTA1[4] = {'T','T','A','1'}; /* ttaenc */ + static const unsigned char I_wvpk[4] = {'w','v','p','k'}; /* wavpack */ + static const unsigned char I_MATL[4] = {'M','A','T','L'}; /* matlab 5.0 */ + static const unsigned char I_AB_5[4] = {'A','B',' ','5'}; #define NINRS 7 - const unsigned int I_INRS[NINRS] = {0xcb460020, 0xd0465555, 0xfa460000, 0x1c470040, 0x3b470080, 0x7a470000, 0x9c470040}; - int inrs_srates[NINRS] = {6500, 6667, 8000, 10000, 12000, 16000, 20000}; + static const unsigned int I_INRS[NINRS] = {0xcb460020, 0xd0465555, 0xfa460000, 0x1c470040, 0x3b470080, 0x7a470000, 0x9c470040}; + static int inrs_srates[NINRS] = {6500, 6667, 8000, 10000, 12000, 16000, 20000}; /* returns 0 on success (at least to the extent that we can report the header type), -1 for error */ int i, loc = 0; - ssize_t bytes; + long long int bytes; - header_type = MUS_UNSUPPORTED; - data_format = MUS_UNKNOWN; + header_type = MUS_UNKNOWN_HEADER; + sample_type = MUS_UNKNOWN_SAMPLE; comment_start = 0; comment_end = 0; data_size = 0; @@ -5577,7 +5574,7 @@ static int mus_header_read_1(const char *filename, int fd) loop_modes[1] = 0; } - bytes = read(fd, hdrbuf, INITIAL_READ_SIZE); + bytes = (long long int)read(fd, hdrbuf, INITIAL_READ_SIZE); /* if it's a 0 length file we need to get out */ if (bytes < 0) return(mus_error(MUS_HEADER_READ_FAILED, "%s: %s", filename, (errno) ? STRERROR(errno) : "bytes read < 0?")); @@ -5585,9 +5582,9 @@ static int mus_header_read_1(const char *filename, int fd) if (bytes == 0) { header_type = MUS_RAW; - srate = header_raw_srate; - chans = header_raw_chans; - data_format = header_raw_format; + srate = raw_header_srate; + chans = raw_header_chans; + sample_type = raw_header_sample_type; data_location = 0; true_file_length = 0; return(MUS_NO_ERROR); @@ -5603,7 +5600,7 @@ static int mus_header_read_1(const char *filename, int fd) (match_four_chars((unsigned char *)hdrbuf, I_DECN))) { if (bytes < 24) - return(mus_error(MUS_HEADER_READ_FAILED, "%s NeXT header truncated? found only " SSIZE_TD " bytes", filename, bytes)); + return(mus_error(MUS_HEADER_READ_FAILED, "%s NeXT header truncated? found only %lld bytes", filename, bytes)); header_type = MUS_NEXT; return(read_next_header(filename, fd)); } @@ -5612,7 +5609,7 @@ static int mus_header_read_1(const char *filename, int fd) { /* next 4 bytes are apparently the file size or something equally useless */ if (bytes < 12) - return(mus_error(MUS_HEADER_READ_FAILED, "%s AIFF header truncated? found only " SSIZE_TD " bytes", filename, bytes)); + return(mus_error(MUS_HEADER_READ_FAILED, "%s AIFF header truncated? found only %lld bytes", filename, bytes)); if (match_four_chars((unsigned char *)(hdrbuf + 8), I_AIFF)) { @@ -5658,7 +5655,7 @@ static int mus_header_read_1(const char *filename, int fd) (match_four_chars((unsigned char *)hdrbuf, I_RIFX))) { if (bytes < 12) - return(mus_error(MUS_HEADER_READ_FAILED, "%s RIFF header truncated? found only " SSIZE_TD " bytes", filename, bytes)); + return(mus_error(MUS_HEADER_READ_FAILED, "%s RIFF header truncated? found only %lld bytes", filename, bytes)); if (match_four_chars((unsigned char *)(hdrbuf + 8), I_WAVE)) { @@ -5685,7 +5682,7 @@ static int mus_header_read_1(const char *filename, int fd) { header_type = MUS_RF64; if (bytes < 28) - return(mus_error(MUS_HEADER_READ_FAILED, "%s RF64 header truncated? found only " SSIZE_TD " bytes", filename, bytes)); + return(mus_error(MUS_HEADER_READ_FAILED, "%s RF64 header truncated? found only %lld bytes", filename, bytes)); if ((mus_char_to_lint((unsigned char *)(hdrbuf + 4)) != -1) || (!(match_four_chars((unsigned char *)(hdrbuf + 8), I_WAVE)))) return(mus_error(MUS_HEADER_READ_FAILED, "%s: messed up RF64 header", filename)); @@ -5698,7 +5695,7 @@ static int mus_header_read_1(const char *filename, int fd) (equal_big_or_little_endian((unsigned char *)hdrbuf, I_IRCAM_NEXT))) { if (bytes < 24) - return(mus_error(MUS_HEADER_READ_FAILED, "%s IRCAM header truncated? found only " SSIZE_TD " bytes", filename, bytes)); + return(mus_error(MUS_HEADER_READ_FAILED, "%s IRCAM header truncated? found only %lld bytes", filename, bytes)); header_type = MUS_IRCAM; return(read_ircam_header(filename, fd)); } @@ -5712,7 +5709,7 @@ static int mus_header_read_1(const char *filename, int fd) if (match_four_chars((unsigned char *)hdrbuf, I_caff)) { if (bytes < 32) /* INITIAL_READ_SIZE */ - return(mus_error(MUS_HEADER_READ_FAILED, "%s CAFF header truncated? found only " SSIZE_TD " bytes", filename, bytes)); + return(mus_error(MUS_HEADER_READ_FAILED, "%s CAFF header truncated? found only %lld bytes", filename, bytes)); header_type = MUS_CAFF; return(read_caff_header(fd)); } @@ -5721,15 +5718,15 @@ static int mus_header_read_1(const char *filename, int fd) (match_four_chars((unsigned char *)(hdrbuf + 4), I_AB_5))) { if (bytes < 128) /* INITIAL_READ_SIZE=256 */ - return(mus_error(MUS_HEADER_READ_FAILED, "%s Matlab header truncated? found only " SSIZE_TD " bytes", filename, bytes)); + return(mus_error(MUS_HEADER_READ_FAILED, "%s Matlab header truncated? found only %lld bytes", filename, bytes)); header_type = MUS_MATLAB; return(read_matlab_5_header(filename, fd)); } if (match_four_chars((unsigned char *)hdrbuf, I_SOUN)) { - const unsigned char I_D_SA[4] = {'D',' ','S','A'}; - const unsigned char I_MPLE[4] = {'M','P','L','E'}; + static const unsigned char I_D_SA[4] = {'D',' ','S','A'}; + static const unsigned char I_MPLE[4] = {'M','P','L','E'}; if ((match_four_chars((unsigned char *)(hdrbuf + 4), I_D_SA)) && (match_four_chars((unsigned char *)(hdrbuf + 8), I_MPLE))) { @@ -5754,7 +5751,7 @@ static int mus_header_read_1(const char *filename, int fd) (match_four_chars((unsigned char *)(hdrbuf + 4), I_VOC1))) { if (bytes < 24) - return(mus_error(MUS_HEADER_READ_FAILED, "%s VOC header truncated? found only " SSIZE_TD " bytes", filename, bytes)); + return(mus_error(MUS_HEADER_READ_FAILED, "%s VOC header truncated? found only %lld bytes", filename, bytes)); header_type = MUS_VOC; return(read_voc_header(filename, fd)); } @@ -6000,11 +5997,13 @@ static int mus_header_read_1(const char *filename, int fd) return(read_sdif_header(filename, fd)); } +#if G7XX if (match_four_chars((unsigned char *)hdrbuf, I_NVF_)) { header_type = MUS_NVF; return(read_nvf_header(filename, fd)); } +#endif if (match_four_chars((unsigned char *)hdrbuf, I_TWIN)) { @@ -6093,6 +6092,20 @@ static int mus_header_read_1(const char *filename, int fd) } /* SMS files start with 767 (4-byte int, apparently in native order) */ + + /* try to catch mpeg... */ + { + int len; + len = strlen(filename); + if (len > 4) + { + if (strcmp((const char *)(filename + len - 4), ".mp3") == 0) + { + header_type = MUS_MPEG; + return(MUS_NO_ERROR); + } + } + } header_type = MUS_RAW; return(read_no_header(fd)); @@ -6141,7 +6154,8 @@ mus_header_write_hook_t *mus_header_write_set_hook(mus_header_write_hook_t *new_ } -int mus_header_write(const char *name, int type, int in_srate, int in_chans, mus_long_t loc, mus_long_t size_in_samples, int format, const char *comment, int len) +int mus_header_write(const char *name, mus_header_t type, int in_srate, int in_chans, mus_long_t loc, + mus_long_t size_in_samples, mus_sample_t samp_type, const char *comment, int len) { /* the "loc" arg is a mistake -- just always set it to 0 */ @@ -6155,7 +6169,7 @@ int mus_header_write(const char *name, int type, int in_srate, int in_chans, mus if (mus_header_write_hook) (*mus_header_write_hook)(name); - siz = mus_samples_to_bytes(format, size_in_samples); + siz = mus_samples_to_bytes(samp_type, size_in_samples); switch (type) { case MUS_RAW: case MUS_IRCAM: case MUS_NEXT: case MUS_RIFF: case MUS_RF64: case MUS_CAFF: @@ -6172,34 +6186,34 @@ int mus_header_write(const char *name, int type, int in_srate, int in_chans, mus switch (type) { - case MUS_NEXT: err = mus_header_write_next_header(fd, in_srate, in_chans, loc, siz, format, comment, len); break; - case MUS_AIFC: err = write_aif_header(fd, in_srate, in_chans, siz, format, comment, len, true); break; - case MUS_AIFF: err = write_aif_header(fd, in_srate, in_chans, siz, format, comment, len, false); break; - case MUS_RF64: err = write_rf64_header(fd, in_srate, in_chans, siz, format, comment, len); break; - case MUS_CAFF: err = write_caff_header(fd, in_srate, in_chans, siz, format); break; - case MUS_IRCAM: err = write_ircam_header(fd, in_srate, in_chans, format, comment, len); break; - case MUS_NIST: err = write_nist_header(fd, in_srate, in_chans, siz, format); break; + case MUS_NEXT: err = mus_header_write_next_header(fd, in_srate, in_chans, loc, siz, samp_type, comment, len); break; + case MUS_AIFC: err = write_aif_header(fd, in_srate, in_chans, siz, samp_type, comment, len, true); break; + case MUS_AIFF: err = write_aif_header(fd, in_srate, in_chans, siz, samp_type, comment, len, false); break; + case MUS_RF64: err = write_rf64_header(fd, in_srate, in_chans, siz, samp_type, comment, len); break; + case MUS_CAFF: err = write_caff_header(fd, in_srate, in_chans, siz, samp_type); break; + case MUS_IRCAM: err = write_ircam_header(fd, in_srate, in_chans, samp_type, comment, len); break; + case MUS_NIST: err = write_nist_header(fd, in_srate, in_chans, siz, samp_type); break; case MUS_RIFF: - err = write_riff_header(fd, in_srate, in_chans, siz, format, comment, len); + err = write_riff_header(fd, in_srate, in_chans, siz, samp_type, comment, len); if (err != MUS_NO_ERROR) { CLOSE(fd, name); - return(mus_error(err, "can't write %s header for %s (fd: %d, format: %s, srate: %d, chans: %d)", + return(mus_error(err, "can't write %s header for %s (fd: %d, sample type: %s, srate: %d, chans: %d)", mus_header_type_name(type), name, fd, - mus_data_format_short_name(format), + mus_sample_type_short_name(samp_type), in_srate, in_chans)); } break; case MUS_RAW: data_location = 0; - data_size = mus_bytes_to_samples(format, siz); + data_size = mus_bytes_to_samples(samp_type, siz); srate = in_srate; chans = in_chans; header_type = MUS_RAW; - data_format = format; + sample_type = samp_type; break; default: @@ -6213,16 +6227,16 @@ int mus_header_write(const char *name, int type, int in_srate, int in_chans, mus } -int mus_write_header(const char *name, int type, int in_srate, int in_chans, mus_long_t size_in_samples, int format, const char *comment) +int mus_write_header(const char *name, mus_header_t type, int in_srate, int in_chans, mus_long_t size_in_samples, mus_sample_t samp_type, const char *comment) { int len = 0; if (comment) len = strlen(comment); - return(mus_header_write(name, type, in_srate, in_chans, 0, size_in_samples, format, comment, len)); + return(mus_header_write(name, type, in_srate, in_chans, 0, size_in_samples, samp_type, comment, len)); } -int mus_header_change_data_size(const char *filename, int type, mus_long_t size) /* in bytes */ +int mus_header_change_data_size(const char *filename, mus_header_t type, mus_long_t size) /* in bytes */ { /* the read header at sample update (sound-close) time could be avoided if the * ssnd_location (etc) were saved and passed in -- perhaps an added optimized @@ -6251,7 +6265,7 @@ int mus_header_change_data_size(const char *filename, int type, mus_long_t size) if (size < 0) { CLOSE(fd, filename); - return(mus_error(MUS_BAD_SIZE, "%s: change size to " MUS_LD "?", filename, size)); + return(mus_error(MUS_BAD_SIZE, "%s: change size to %lld?", filename, size)); } switch (type) @@ -6271,24 +6285,24 @@ int mus_header_change_data_size(const char *filename, int type, mus_long_t size) case MUS_AIFF: /* we apparently have to make sure the form size and the data size are correct * assumed here that we'll only be updating our own AIFF files - * There are 3 such locations -- the 2nd word of the file which is the overall form size, - * the frames variable in the COMM chunk, and the chunk-size variable in the SSND chunk + * There are 3 such locations -- the second word of the file which is the overall form size, + * the framples variable in the COMM chunk, and the chunk-size variable in the SSND chunk * an unexpected hassle for CLM is that we can open/close the output file many times if running mix, * so we have to update the various size fields taking into account the old size */ - /* read sets current update_form_size, data_size, data_format, update_frames_location, update_ssnd_location */ + /* read sets current update_form_size, data_size, sample_type, update_framples_location, update_ssnd_location */ if (size > BIGGEST_4_BYTE_SIGNED_INT) { err = MUS_BAD_SIZE; - mus_print("%s size: " MUS_LD " is too large for %s headers", filename, size, mus_header_type_name(type)); + mus_print("%s size: %lld is too large for %s headers", filename, size, mus_header_type_name(type)); size = BIGGEST_4_BYTE_SIGNED_INT; } lseek(fd, 4L, SEEK_SET); - mus_bint_to_char((unsigned char *)hdrbuf, (int)size + update_form_size - mus_samples_to_bytes(data_format, data_size)); + mus_bint_to_char((unsigned char *)hdrbuf, (int)size + update_form_size - mus_samples_to_bytes(sample_type, data_size)); /* cancel old data_size from previous possible write */ header_write(fd, hdrbuf, 4); - lseek(fd, update_frames_location, SEEK_SET); - mus_bint_to_char((unsigned char *)hdrbuf, (int)size / (chans * mus_bytes_per_sample(data_format))); + lseek(fd, update_framples_location, SEEK_SET); + mus_bint_to_char((unsigned char *)hdrbuf, (int)size / (chans * mus_bytes_per_sample(sample_type))); header_write(fd, hdrbuf, 4); lseek(fd, update_ssnd_location, SEEK_SET); mus_bint_to_char((unsigned char *)hdrbuf, (int)size + 8); @@ -6296,14 +6310,14 @@ int mus_header_change_data_size(const char *filename, int type, mus_long_t size) break; case MUS_RIFF: - /* read sets current update_form_size, data_format, data_size, update_ssnd_location */ + /* read sets current update_form_size, sample_type, data_size, update_ssnd_location */ if (size > BIGGEST_4_BYTE_SIGNED_INT) { CLOSE(fd, filename); return(mus_header_convert_riff_to_rf64(filename, size)); } lseek(fd, 4L, SEEK_SET); - mus_lint_to_char((unsigned char *)hdrbuf, (int)size + update_form_size - mus_samples_to_bytes(data_format, data_size)); + mus_lint_to_char((unsigned char *)hdrbuf, (int)size + update_form_size - mus_samples_to_bytes(sample_type, data_size)); header_write(fd, hdrbuf, 4); lseek(fd, update_ssnd_location, SEEK_SET); mus_lint_to_char((unsigned char *)hdrbuf, (int)size); @@ -6311,7 +6325,7 @@ int mus_header_change_data_size(const char *filename, int type, mus_long_t size) break; case MUS_RF64: - /* read sets current update_form_size, data_format, data_size, update_ssnd_location, update_rf64_location */ + /* read sets current update_form_size, sample_type, data_size, update_ssnd_location, update_rf64_location */ /* assume here that this really is an rf64 file (i.e. -1 for form size and data chunk size */ lseek(fd, update_rf64_location, SEEK_SET); mus_llong_to_char((unsigned char *)hdrbuf, data_location + size - 8); /* 25-June-07 */ @@ -6326,20 +6340,20 @@ int mus_header_change_data_size(const char *filename, int type, mus_long_t size) break; case MUS_NIST: - /* read sets current srate, chans, data_format */ + /* read sets current srate, chans, sample_type */ if (size > BIGGEST_4_BYTE_SIGNED_INT) { err = MUS_BAD_SIZE; - mus_print("%s size: " MUS_LD " is too large for %s headers", filename, size, mus_header_type_name(type)); + mus_print("%s size: %lld is too large for %s headers", filename, size, mus_header_type_name(type)); size = BIGGEST_4_BYTE_SIGNED_INT; } lseek(fd, 0L, SEEK_SET); - write_nist_header(fd, mus_header_srate(), mus_header_chans(), size, mus_header_format()); + write_nist_header(fd, mus_header_srate(), mus_header_chans(), size, mus_header_sample_type()); break; case MUS_CAFF: - if (update_frames_location < 56) update_frames_location = 56; - lseek(fd, update_frames_location, SEEK_SET); + if (update_framples_location < 56) update_framples_location = 56; + lseek(fd, update_framples_location, SEEK_SET); mus_blong_to_char((unsigned char *)(hdrbuf + 0), size); header_write(fd, hdrbuf, 8); break; @@ -6355,10 +6369,10 @@ int mus_header_change_data_size(const char *filename, int type, mus_long_t size) } -int mus_header_change_chans(const char *filename, int type, int new_chans) +int mus_header_change_chans(const char *filename, mus_header_t type, int new_chans) { int err = MUS_NO_ERROR, fd; - mus_long_t new_frames; + mus_long_t new_framples; switch (type) { case MUS_AIFF: @@ -6393,21 +6407,21 @@ int mus_header_change_chans(const char *filename, int type, int new_chans) case MUS_NIST: lseek(fd, 0L, SEEK_SET); - write_nist_header(fd, srate, new_chans, mus_bytes_per_sample(data_format) * data_size, data_format); + write_nist_header(fd, srate, new_chans, mus_bytes_per_sample(sample_type) * data_size, sample_type); /* header size is always 1024, so this is safe */ break; case MUS_AIFF: case MUS_AIFC: - lseek(fd, update_frames_location - 2, SEEK_SET); - new_frames = data_size / new_chans; + lseek(fd, update_framples_location - 2, SEEK_SET); + new_framples = data_size / new_chans; mus_bshort_to_char((unsigned char *)hdrbuf, new_chans); - mus_bint_to_char((unsigned char *)(hdrbuf + 2), new_frames); + mus_bint_to_char((unsigned char *)(hdrbuf + 2), new_framples); header_write(fd, hdrbuf, 6); break; case MUS_RIFF: case MUS_RF64: - lseek(fd, update_frames_location - 2, SEEK_SET); + lseek(fd, update_framples_location - 2, SEEK_SET); if (little_endian) mus_lshort_to_char((unsigned char *)hdrbuf, new_chans); else mus_bshort_to_char((unsigned char *)hdrbuf, new_chans); @@ -6420,13 +6434,15 @@ int mus_header_change_chans(const char *filename, int type, int new_chans) header_write(fd, hdrbuf, 4); /* we should probably also change bytes_per_packet at 36, but... */ break; + + default: break; } CLOSE(fd, filename); return(err); } -int mus_header_change_srate(const char *filename, int type, int new_srate) +int mus_header_change_srate(const char *filename, mus_header_t type, int new_srate) { int err = MUS_NO_ERROR, fd; switch (type) @@ -6463,19 +6479,19 @@ int mus_header_change_srate(const char *filename, int type, int new_srate) case MUS_NIST: lseek(fd, 0L, SEEK_SET); - write_nist_header(fd, new_srate, chans, mus_bytes_per_sample(data_format) * data_size, data_format); + write_nist_header(fd, new_srate, chans, mus_bytes_per_sample(sample_type) * data_size, sample_type); break; case MUS_AIFF: case MUS_AIFC: - lseek(fd, update_frames_location + 6, SEEK_SET); + lseek(fd, update_framples_location + 6, SEEK_SET); double_to_ieee_80((double)new_srate, (unsigned char *)hdrbuf); header_write(fd, hdrbuf, 10); break; case MUS_RIFF: case MUS_RF64: - lseek(fd, update_frames_location, SEEK_SET); + lseek(fd, update_framples_location, SEEK_SET); if (little_endian) mus_lint_to_char((unsigned char *)hdrbuf, new_srate); else mus_bint_to_char((unsigned char *)hdrbuf, new_srate); @@ -6487,13 +6503,15 @@ int mus_header_change_srate(const char *filename, int type, int new_srate) mus_bdouble_to_char((unsigned char *)hdrbuf, (double)new_srate); header_write(fd, hdrbuf, 8); break; + + default: break; } CLOSE(fd, filename); return(err); } -int mus_header_change_type(const char *filename, int new_type, int new_format) +int mus_header_change_type(const char *filename, mus_header_t new_type, mus_sample_t new_format) { int err = MUS_NO_ERROR; /* open temp, write header, copy data, replace original with temp */ @@ -6502,9 +6520,9 @@ int mus_header_change_type(const char *filename, int new_type, int new_format) { if (header_type != new_type) { - int ofd, ifd; - ssize_t nbytes; - mus_long_t loc, len = 0; + int ofd, ifd, len; + long long int nbytes; + mus_long_t loc; unsigned char *buf = NULL; char *new_file, *comment = NULL; @@ -6512,21 +6530,23 @@ int mus_header_change_type(const char *filename, int new_type, int new_format) (new_type == MUS_RF64)) return(mus_header_convert_riff_to_rf64(filename, data_size)); - new_file = (char *)calloc(strlen(filename) + 5, sizeof(char)); - sprintf(new_file, "%s.tmp", filename); + len = strlen(filename) + 5; + new_file = (char *)malloc(len * sizeof(char)); + snprintf(new_file, len, "%s.tmp", filename); loc = mus_header_data_location(); if (new_type != MUS_RAW) { if (comment_end > comment_start) { - len = comment_end - comment_start + 1; - comment = (char *)calloc(len + 1, sizeof(char)); + mus_long_t clen; + clen = comment_end - comment_start + 1; + comment = (char *)calloc(clen + 1, sizeof(char)); ifd = mus_file_open_read(filename); lseek(ifd, comment_start, SEEK_SET); - header_read(ifd, (unsigned char *)comment, len); + header_read(ifd, (unsigned char *)comment, clen); CLOSE(ifd, filename); } - data_size = data_size * mus_bytes_per_sample(data_format) / mus_bytes_per_sample(new_format); + data_size = data_size * mus_bytes_per_sample(sample_type) / mus_bytes_per_sample(new_format); mus_write_header(new_file, new_type, srate, chans, data_size, new_format, comment); } else mus_file_create(new_file); @@ -6548,9 +6568,9 @@ int mus_header_change_type(const char *filename, int new_type, int new_format) } -int mus_header_change_format(const char *filename, int type, int new_format) +int mus_header_change_sample_type(const char *filename, mus_header_t type, mus_sample_t new_format) { - int err = MUS_NO_ERROR, fd; + int err = MUS_NO_ERROR, fd, fr; mus_long_t old_bytes; switch (type) { @@ -6564,10 +6584,12 @@ int mus_header_change_format(const char *filename, int type, int new_format) default: break; } + if (err == MUS_ERROR) return(err); fd = mus_file_reopen_write(filename); if (fd == -1) - return(mus_error(MUS_CANT_OPEN_FILE, "mus_header_change_format for %s failed: %s", filename, STRERROR(errno))); + return(mus_error(MUS_CANT_OPEN_FILE, "mus_header_change_sample_type for %s failed: %s", filename, STRERROR(errno))); + switch (type) { case MUS_NEXT: @@ -6584,13 +6606,13 @@ int mus_header_change_format(const char *filename, int type, int new_format) case MUS_NIST: lseek(fd, 0L, SEEK_SET); - write_nist_header(fd, srate, chans, mus_bytes_per_sample(data_format) * data_size, new_format); + write_nist_header(fd, srate, chans, mus_bytes_per_sample(sample_type) * data_size, new_format); break; case MUS_AIFF: case MUS_AIFC: - old_bytes = data_size * mus_bytes_per_sample(data_format); - lseek(fd, update_frames_location, SEEK_SET); + old_bytes = data_size * mus_bytes_per_sample(sample_type); + lseek(fd, update_framples_location, SEEK_SET); mus_bint_to_char((unsigned char *)hdrbuf, old_bytes / (chans * mus_bytes_per_sample(new_format))); mus_bshort_to_char((unsigned char *)(hdrbuf + 4), sndlib_format_to_aiff_bits(new_format)); header_write(fd, hdrbuf, 6); @@ -6598,7 +6620,7 @@ int mus_header_change_format(const char *filename, int type, int new_format) { const char *str; str = sndlib_format_to_aifc_name(new_format); - lseek(fd, update_frames_location + 16, SEEK_SET); + lseek(fd, update_framples_location + 16, SEEK_SET); write_four_chars((unsigned char *)(hdrbuf + 0), (const unsigned char *)str); (*(unsigned char *)(hdrbuf + 4)) = 4; /* final pad null not accounted-for */ write_four_chars((unsigned char *)(hdrbuf + 5), (const unsigned char *)str); @@ -6609,45 +6631,49 @@ int mus_header_change_format(const char *filename, int type, int new_format) case MUS_RIFF: case MUS_RF64: - lseek(fd, update_frames_location + 24, SEEK_SET); + lseek(fd, update_framples_location + 24, SEEK_SET); if (little_endian) mus_lshort_to_char((unsigned char *)hdrbuf, sndlib_format_to_aiff_bits(new_format)); else mus_bshort_to_char((unsigned char *)hdrbuf, sndlib_format_to_aiff_bits(new_format)); header_write(fd, hdrbuf, 2); - lseek(fd, update_frames_location + 10, SEEK_SET); + lseek(fd, update_framples_location + 10, SEEK_SET); switch (new_format) { case MUS_MULAW: - new_format = 7; + fr = 7; break; case MUS_ALAW: - new_format = 6; + fr = 6; break; case MUS_UBYTE: case MUS_LSHORT: case MUS_L24INT: case MUS_LINT: case MUS_BSHORT: case MUS_B24INT: case MUS_BINT: - new_format = 1; + fr = 1; break; case MUS_LFLOAT: case MUS_LDOUBLE: case MUS_BFLOAT: case MUS_BDOUBLE: - new_format = 3; + fr = 3; break; + + default: fr = 0; break; } if (little_endian) - mus_lshort_to_char((unsigned char *)hdrbuf, new_format); - else mus_bshort_to_char((unsigned char *)hdrbuf, new_format); + mus_lshort_to_char((unsigned char *)hdrbuf, fr); + else mus_bshort_to_char((unsigned char *)hdrbuf, fr); header_write(fd, hdrbuf, 2); break; + + default: break; } CLOSE(fd, filename); return(err); } -int mus_header_change_location(const char *filename, int type, mus_long_t new_location) +int mus_header_change_location(const char *filename, mus_header_t type, mus_long_t new_location) { /* only Next/Sun changeable in this regard */ int err = MUS_NO_ERROR, fd; @@ -6665,21 +6691,25 @@ int mus_header_change_location(const char *filename, int type, mus_long_t new_lo } -int mus_header_change_comment(const char *filename, int type, const char *new_comment) +int mus_header_change_comment(const char *filename, mus_header_t type, const char *new_comment) { - int err = MUS_NO_ERROR, fd, len = 0; - bool need_ripple = false; + int err = MUS_NO_ERROR; err = mus_header_read(filename); if (err == MUS_NO_ERROR) { + int fd; + bool need_ripple = false; switch (type) { case MUS_IRCAM: - fd = mus_file_reopen_write(filename); - lseek(fd, 16L, SEEK_SET); - if (new_comment) len = strlen(new_comment); - write_ircam_comment(fd, new_comment, len); - CLOSE(fd, filename); + { + int len = 0; + fd = mus_file_reopen_write(filename); + lseek(fd, 16L, SEEK_SET); + if (new_comment) len = strlen(new_comment); + write_ircam_comment(fd, new_comment, len); + CLOSE(fd, filename); + } break; case MUS_NEXT: @@ -6705,14 +6735,15 @@ int mus_header_change_comment(const char *filename, int type, const char *new_co { /* open temp, write header, copy data, replace original with temp */ char *new_file; - int ofd, ifd; + int ofd, ifd, len; mus_long_t loc; - ssize_t nbytes; + long long int nbytes; unsigned char *buf = NULL; - new_file = (char *)calloc(strlen(filename) + 5, sizeof(char)); - sprintf(new_file, "%s.tmp", filename); + len = strlen(filename) + 5; + new_file = (char *)malloc(len * sizeof(char)); + snprintf(new_file, len, "%s.tmp", filename); loc = mus_header_data_location(); - mus_write_header(new_file, header_type, srate, chans, data_size, data_format, new_comment); + mus_write_header(new_file, header_type, srate, chans, data_size, sample_type, new_comment); ifd = mus_file_open_read(filename); lseek(ifd, loc, SEEK_SET); ofd = mus_file_reopen_write(new_file); @@ -6730,18 +6761,18 @@ int mus_header_change_comment(const char *filename, int type, const char *new_co } -bool mus_header_writable(int type, int format) /* -2 to ignore format for this call */ +bool mus_header_writable(mus_header_t type, mus_sample_t samp_type) /* MUS_IGNORE_SAMPLE to ignore sample type for this call */ { switch (type) { case MUS_NEXT: - if (format == MUS_UNKNOWN) return(false); + if (samp_type == MUS_UNKNOWN_SAMPLE) return(false); return(true); break; case MUS_NIST: - if (format == -2) return(true); - switch (format) + if (samp_type == MUS_IGNORE_SAMPLE) return(true); + switch (samp_type) { case MUS_BYTE: case MUS_BSHORT: case MUS_B24INT: case MUS_BINT: case MUS_LSHORT: case MUS_L24INT: case MUS_LINT: @@ -6752,8 +6783,8 @@ bool mus_header_writable(int type, int format) /* -2 to ignore format for this c break; case MUS_AIFC: - if (format == -2) return(true); - switch (format) + if (samp_type == MUS_IGNORE_SAMPLE) return(true); + switch (samp_type) { case MUS_BSHORT: case MUS_B24INT: case MUS_BINT: case MUS_BYTE: case MUS_MULAW: case MUS_ALAW: @@ -6768,8 +6799,8 @@ bool mus_header_writable(int type, int format) /* -2 to ignore format for this c break; case MUS_AIFF: - if (format == -2) return(true); - switch (format) + if (samp_type == MUS_IGNORE_SAMPLE) return(true); + switch (samp_type) { case MUS_BSHORT: case MUS_B24INT: case MUS_BINT: case MUS_BYTE: return(true); @@ -6782,8 +6813,8 @@ bool mus_header_writable(int type, int format) /* -2 to ignore format for this c case MUS_RIFF: case MUS_RF64: - if (format == -2) return(true); - switch (format) + if (samp_type == MUS_IGNORE_SAMPLE) return(true); + switch (samp_type) { case MUS_MULAW: case MUS_ALAW: case MUS_UBYTE: case MUS_LFLOAT: case MUS_LSHORT: case MUS_L24INT: case MUS_LINT: case MUS_LDOUBLE: @@ -6796,8 +6827,8 @@ bool mus_header_writable(int type, int format) /* -2 to ignore format for this c break; case MUS_IRCAM: - if (format == -2) return(true); - switch (format) + if (samp_type == MUS_IGNORE_SAMPLE) return(true); + switch (samp_type) { case MUS_MULAW: case MUS_ALAW: case MUS_BSHORT: case MUS_BINT: case MUS_BFLOAT: return(true); @@ -6809,8 +6840,8 @@ bool mus_header_writable(int type, int format) /* -2 to ignore format for this c break; case MUS_CAFF: - if (format == -2) return(true); - switch (format) + if (samp_type == MUS_IGNORE_SAMPLE) return(true); + switch (samp_type) { case MUS_MULAW: case MUS_ALAW: case MUS_BYTE: case MUS_LFLOAT: case MUS_LSHORT: case MUS_L24INT: case MUS_LINTN: case MUS_LDOUBLE: @@ -6837,13 +6868,13 @@ bool mus_header_writable(int type, int format) /* -2 to ignore format for this c static char aifc_format[5]; -/* try to give some info on data formats that aren't supported by sndlib */ -const char *mus_header_original_format_name(int format, int type) +/* try to give some info on sample types that aren't supported by sndlib */ +const char *mus_header_original_sample_type_name(int samp_type, mus_header_t type) { switch (type) { case MUS_NEXT: - switch (format) + switch (samp_type) { case 0: return("unspecified"); break; case 8: return("indirect"); break; case 9: return("nested"); break; case 10: return("dsp_core"); break; case 11: return("dsp_data_8"); break; case 12: return("dsp_data_16"); break; @@ -6859,9 +6890,9 @@ const char *mus_header_original_format_name(int format, int type) case MUS_CAFF: aifc_format[4] = 0; #if MUS_LITTLE_ENDIAN - sprintf(aifc_format, "%c%c%c%c", format & 0xff, (format >> 8) & 0xff, (format >> 16) & 0xff, (format >> 24) & 0xff); + snprintf(aifc_format, 5, "%c%c%c%c", samp_type & 0xff, (samp_type >> 8) & 0xff, (samp_type >> 16) & 0xff, (samp_type >> 24) & 0xff); #else - sprintf(aifc_format, "%c%c%c%c", (format >> 24) & 0xff, (format >> 16) & 0xff, (format >> 8) & 0xff, format & 0xff); + snprintf(aifc_format, 5, "%c%c%c%c", (samp_type >> 24) & 0xff, (samp_type >> 16) & 0xff, (samp_type >> 8) & 0xff, samp_type & 0xff); #endif return(aifc_format); break; @@ -6873,7 +6904,7 @@ const char *mus_header_original_format_name(int format, int type) case MUS_RIFF: case MUS_RF64: - switch (format) + switch (samp_type) { case 2: return("ADPCM"); break; case 4: return("VSELP"); break; case 5: return("IBM_CVSD"); break; case 0x10: return("OKI_ADPCM"); break; case 0x11: return("DVI_ADPCM"); break; case 0x12: return("MediaSpace_ADPCM"); break; @@ -6912,6 +6943,8 @@ const char *mus_header_original_format_name(int format, int type) case 0x1500: return("Soundspace musicompression"); break; case 0x2000: return("DVM"); break; } break; + + default: break; } return("unknown"); /* NULL here isn't safe -- Sun segfaults */ } @@ -6920,12 +6953,12 @@ const char *mus_header_original_format_name(int format, int type) bool mus_header_no_header(const char *filename) { int fd; - ssize_t bytes; + long long int bytes; bool ok = false; fd = mus_file_open_read(filename); if (fd == -1) return(mus_error(MUS_CANT_OPEN_FILE, "mus_header: can't open %s: %s", filename, STRERROR(errno))); - bytes = read(fd, hdrbuf, INITIAL_READ_SIZE); + bytes = (long long int)read(fd, hdrbuf, INITIAL_READ_SIZE); CLOSE(fd, filename); if (bytes > 4) ok = ((match_four_chars((unsigned char *)hdrbuf, I_DSND)) || @@ -6977,8 +7010,11 @@ bool mus_header_no_header(const char *filename) (match_four_chars((unsigned char *)hdrbuf, I_SMP1)) || (match_four_chars((unsigned char *)hdrbuf, I_Maui)) || (match_four_chars((unsigned char *)hdrbuf, I_SDIF)) || - (match_four_chars((unsigned char *)hdrbuf, I_ajkg)) || - (match_four_chars((unsigned char *)hdrbuf, I_NVF_))); + (match_four_chars((unsigned char *)hdrbuf, I_ajkg)) +#if G7XX + || (match_four_chars((unsigned char *)hdrbuf, I_NVF_)) +#endif + ); return(!ok); } @@ -7005,7 +7041,7 @@ void mus_header_set_aiff_loop_info(int *data) } -bool mus_header_type_p(int n) +bool mus_is_header_type(int n) { switch (n) { @@ -7019,9 +7055,12 @@ bool mus_header_type_p(int n) case MUS_YAMAHA_SY85: case MUS_YAMAHA_TX16W: case MUS_DIGIPLAYER: case MUS_COVOX: case MUS_AVI: case MUS_OMF: case MUS_QUICKTIME: case MUS_ASF: case MUS_YAMAHA_SY99: case MUS_KURZWEIL_2000: case MUS_AIFF: case MUS_PAF: case MUS_CSL: case MUS_FILE_SAMP: case MUS_PVF: case MUS_SOUNDFORGE: - case MUS_TWINVQ: case MUS_AKAI4: case MUS_IMPULSETRACKER: case MUS_KORG: case MUS_NVF: case MUS_CAFF: + case MUS_TWINVQ: case MUS_AKAI4: case MUS_IMPULSETRACKER: case MUS_KORG: case MUS_CAFF: case MUS_MAUI: case MUS_SDIF: case MUS_OGG: case MUS_FLAC: case MUS_SPEEX: case MUS_MPEG: case MUS_SHORTEN: case MUS_TTA: case MUS_WAVPACK: +#if G7XX + case MUS_NVF: +#endif return(true); break; } @@ -7029,7 +7068,7 @@ bool mus_header_type_p(int n) } -bool mus_data_format_p(int n) +bool mus_is_sample_type(int n) { switch (n) { |