--- np2/sound/vermouth/midinst.c 2003/11/28 08:01:33 1.2 +++ np2/sound/vermouth/midinst.c 2006/12/16 12:11:07 1.8 @@ -3,6 +3,22 @@ #include "midiout.h" +#if defined(SUPPORT_ARC) +#include "arc.h" +#define _FILEH ARCFH +#define _FILEH_INVALID NULL +#define _file_open arcex_fileopen +#define _file_read arc_fileread +#define _file_close arc_fileclose +#else +#define _FILEH FILEH +#define _FILEH_INVALID FILEH_INVALID +#define _file_open file_open +#define _file_read file_read +#define _file_close file_close +#endif + + // GUS format references: http://www.onicos.com/staff/iz/formats/guspat.html typedef struct { @@ -10,55 +26,55 @@ typedef struct { char id[10]; char description[60]; - BYTE instruments; - BYTE voice; - BYTE channels; - BYTE waveforms[2]; - BYTE volume[2]; - BYTE datasize[4]; - BYTE reserved1[36]; - - BYTE instrument[2]; - BYTE instname[16]; - BYTE instsize[4]; - BYTE layers; - BYTE reserved2[40]; - - BYTE layerdupe; - BYTE layer; - BYTE layersize[4]; - BYTE layersamples; - BYTE reserved3[40]; + UINT8 instruments; + UINT8 voice; + UINT8 channels; + UINT8 waveforms[2]; + UINT8 volume[2]; + UINT8 datasize[4]; + UINT8 reserved1[36]; + + UINT8 instrument[2]; + UINT8 instname[16]; + UINT8 instsize[4]; + UINT8 layers; + UINT8 reserved2[40]; + + UINT8 layerdupe; + UINT8 layer; + UINT8 layersize[4]; + UINT8 layersamples; + UINT8 reserved3[40]; } GUSHEAD; typedef struct { - BYTE wavename[7]; - BYTE fractions; - BYTE datasize[4]; - BYTE loopstart[4]; - BYTE loopend[4]; - BYTE samprate[2]; - BYTE freqlow[4]; - BYTE freqhigh[4]; - BYTE freqroot[4]; - BYTE tune[2]; - BYTE balance; - BYTE env[6]; - BYTE envpos[6]; - BYTE tre_sweep; - BYTE tre_rate; - BYTE tre_depth; - BYTE vib_sweep; - BYTE vib_rate; - BYTE vib_depth; - BYTE mode; - BYTE scalefreq[2]; - BYTE scalefactor[2]; - BYTE reserved[36]; + UINT8 wavename[7]; + UINT8 fractions; + UINT8 datasize[4]; + UINT8 loopstart[4]; + UINT8 loopend[4]; + UINT8 samprate[2]; + UINT8 freqlow[4]; + UINT8 freqhigh[4]; + UINT8 freqroot[4]; + UINT8 tune[2]; + UINT8 balance; + UINT8 env[6]; + UINT8 envpos[6]; + UINT8 tre_sweep; + UINT8 tre_rate; + UINT8 tre_depth; + UINT8 vib_sweep; + UINT8 vib_rate; + UINT8 vib_depth; + UINT8 mode; + UINT8 scalefreq[2]; + UINT8 scalefactor[2]; + UINT8 reserved[36]; } GUSWAVE; -static void inst_destroy(INSTRUMENT inst); +static void VERMOUTHCL inst_destroy(INSTRUMENT inst); // ---- resample @@ -66,7 +82,8 @@ static void inst_destroy(INSTRUMENT inst #define BASEBITS 9 #define MIXBASE (1 << BASEBITS) -static SAMPLE downsamp(SAMPLE dst, SAMPLE src, int count, int mrate) { +static SAMPLE VERMOUTHCL downsamp(SAMPLE dst, SAMPLE src, int count, + int mrate) { int rem; SINT32 pcm; @@ -93,7 +110,8 @@ static SAMPLE downsamp(SAMPLE dst, SAMPL return(dst); } -static SAMPLE upsamp(SAMPLE dst, SAMPLE src, int count, int mrate) { +static SAMPLE VERMOUTHCL upsamp(SAMPLE dst, SAMPLE src, int count, + int mrate) { int rem; SINT32 tmp; @@ -124,7 +142,7 @@ static SAMPLE upsamp(SAMPLE dst, SAMPLE return(dst); } -static void resample(MIDIMOD mod, INSTLAYER inst, int freq) { +static void VERMOUTHCL resample(MIDIMOD mod, INSTLAYER inst, int freq) { int mrate; int orgcnt; @@ -166,17 +184,17 @@ static void resample(MIDIMOD mod, INSTLA // ---- load -static const char ext_pat[] = ".pat"; +static const OEMCHAR ext_pat[] = OEMTEXT(".pat"); static const char sig_GF1PATCH100[] = "GF1PATCH100"; static const char sig_GF1PATCH110[] = "GF1PATCH110"; static const char sig_ID000002[] = "ID#000002"; static const char str_question6[] = "??????"; -static INSTRUMENT inst_create(MIDIMOD mod, TONECFG cfg) { +static INSTRUMENT VERMOUTHCL inst_create(MIDIMOD mod, const _TONECFG *cfg) { - char filename[MAX_PATH]; - char path[MAX_PATH]; - FILEH fh; + OEMCHAR filename[MAX_PATH]; + OEMCHAR path[MAX_PATH]; + _FILEH fh; INSTRUMENT ret; GUSHEAD head; int layers; @@ -186,7 +204,7 @@ static INSTRUMENT inst_create(MIDIMOD mo int i; SAMPLE dat; _SAMPLE tmp; -const BYTE *d; +const UINT8 *d; SINT16 *p; SINT16 *q; int cnt; @@ -194,20 +212,20 @@ const BYTE *d; if (cfg->name == NULL) { goto li_err1; } - file_cpyname(filename, cfg->name, sizeof(filename)); + file_cpyname(filename, cfg->name, NELEMENTS(filename)); file_cutext(filename); - file_catname(filename, ext_pat, sizeof(filename)); - if (cfgfile_getfile(mod, filename, path, sizeof(path)) != SUCCESS) { + file_catname(filename, ext_pat, NELEMENTS(filename)); + if (midimod_getfile(mod, filename, path, NELEMENTS(path)) != SUCCESS) { goto li_err1; } - fh = file_open_rb(path); - if (fh == FILEH_INVALID) { + fh = _file_open(path); + if (fh == _FILEH_INVALID) { // TRACEOUT(("not found: %s", path)); goto li_err1; } // head check - if ((file_read(fh, &head, sizeof(head)) != sizeof(head)) && + if ((_file_read(fh, &head, sizeof(head)) != sizeof(head)) && (memcmp(head.sig, sig_GF1PATCH100, 12)) && (memcmp(head.sig, sig_GF1PATCH110, 12)) && (memcmp(head.id, sig_ID000002, 10)) && @@ -233,9 +251,9 @@ const BYTE *d; } do { - BYTE fractions; + UINT8 fractions; - if (file_read(fh, &wave, sizeof(wave)) != sizeof(wave)) { + if (_file_read(fh, &wave, sizeof(wave)) != sizeof(wave)) { goto li_err3; } fractions = wave.fractions; @@ -317,7 +335,7 @@ const BYTE *d; goto li_err3; } layer->data = dat; - if (file_read(fh, dat, layer->datasize) != (UINT)layer->datasize) { + if (_file_read(fh, dat, layer->datasize) != (UINT)layer->datasize) { goto li_err3; } dat[cnt] = 0; @@ -328,8 +346,8 @@ const BYTE *d; #if defined(BYTESEX_LITTLE) if (sizeof(_SAMPLE) != 2) { // Ara!? #endif - d = (BYTE *)dat; - d += layer->datasize; + d = (UINT8 *)dat; + d += layer->datasize * 2; q = dat + layer->datasize; do { d -= 2; @@ -341,7 +359,7 @@ const BYTE *d; #endif } else { - d = (BYTE *)dat; + d = (UINT8 *)dat; d += layer->datasize; q = dat + layer->datasize; do { @@ -409,6 +427,7 @@ const BYTE *d; } if ((ret->freq) && (!(wave.mode & MODE_LOOPING))) { +// TRACEOUT(("resample: %s", cfg->name)); resample(mod, layer, ret->freq); } if (cfg->flag & TONECFG_NOTAIL) { @@ -419,20 +438,20 @@ const BYTE *d; layer++; } while(--layers); - file_close(fh); + _file_close(fh); return(ret); li_err3: inst_destroy(ret); li_err2: - file_close(fh); + _file_close(fh); li_err1: return(NULL); } -static void inst_destroy(INSTRUMENT inst) { +static void VERMOUTHCL inst_destroy(INSTRUMENT inst) { int layers; INSTLAYER layer; @@ -450,11 +469,11 @@ static void inst_destroy(INSTRUMENT inst } } -int inst_singleload(MIDIMOD mod, UINT bank, UINT num) { +int VERMOUTHCL inst_singleload(MIDIMOD mod, UINT bank, UINT num) { INSTRUMENT *inst; INSTRUMENT tone; - TONECFG cfg; +const _TONECFG *cfg; if (bank >= (MIDI_BANKS * 2)) { return(MIDIOUT_FAILURE); @@ -484,11 +503,17 @@ int inst_singleload(MIDIMOD mod, UINT ba return(MIDIOUT_SUCCESS); } -int inst_bankload(MIDIMOD mod, UINT bank) { +int VERMOUTHCL inst_bankload(MIDIMOD mod, UINT bank) { + + return(inst_bankloadex(mod, bank, NULL, NULL)); +} + +int VERMOUTHCL inst_bankloadex(MIDIMOD mod, UINT bank, + FNMIDIOUTLAEXCB cb, MIDIOUTLAEXPARAM *param) { INSTRUMENT *inst; INSTRUMENT tone; - TONECFG cfg; +const _TONECFG *cfg; UINT num; if (bank >= (MIDI_BANKS * 2)) { @@ -501,6 +526,15 @@ int inst_bankload(MIDIMOD mod, UINT bank inst = mod->tone[bank]; for (num = 0; num<0x80; num++) { if ((inst == NULL) || (inst[num] == NULL)) { + if ((cb != NULL) && (cfg[num].name != NULL)) { + if (param) { + param->progress++; + param->num = num; + } + if ((*cb)(param) != SUCCESS) { + return(MIDIOUT_ABORT); + } + } tone = inst_create(mod, cfg + num); if (tone) { // TRACEOUT(("load %d %d", bank, num)); @@ -521,7 +555,7 @@ int inst_bankload(MIDIMOD mod, UINT bank return(MIDIOUT_SUCCESS); } -void inst_bankfree(MIDIMOD mod, UINT bank) { +void VERMOUTHCL inst_bankfree(MIDIMOD mod, UINT bank) { INSTRUMENT *inst; INSTRUMENT *i; @@ -547,3 +581,28 @@ void inst_bankfree(MIDIMOD mod, UINT ban } } +UINT VERMOUTHCL inst_gettones(MIDIMOD mod, UINT bank) { + + INSTRUMENT *inst; +const _TONECFG *cfg; + UINT ret; + UINT num; + + if (bank >= (MIDI_BANKS * 2)) { + return(0); + } + cfg = mod->tonecfg[bank]; + if (cfg == NULL) { + return(0); + } + inst = mod->tone[bank]; + ret = 0; + for (num = 0; num<0x80; num++) { + if ((inst == NULL) || (inst[num] == NULL)) { + if (cfg[num].name != NULL) { + ret++; + } + } + } + return(ret); +}