diff options
-rw-r--r-- | fm_banks/ibk_files/my-gmopldrums.IBK | bin | 3204 -> 3204 bytes | |||
-rw-r--r-- | src/adldata.cpp | 58 | ||||
-rw-r--r-- | src/adlmidi.cpp | 157 | ||||
-rw-r--r-- | src/adlmidi.h | 8 | ||||
-rw-r--r-- | src/dbopl.cpp | 13 | ||||
-rw-r--r-- | src/dbopl.h | 3 | ||||
-rw-r--r-- | src/fraction.h | 2 |
7 files changed, 127 insertions, 114 deletions
diff --git a/fm_banks/ibk_files/my-gmopldrums.IBK b/fm_banks/ibk_files/my-gmopldrums.IBK Binary files differindex 33f065c..c1ade22 100644 --- a/fm_banks/ibk_files/my-gmopldrums.IBK +++ b/fm_banks/ibk_files/my-gmopldrums.IBK diff --git a/src/adldata.cpp b/src/adldata.cpp index eb1ff05..15089dc 100644 --- a/src/adldata.cpp +++ b/src/adldata.cpp @@ -4235,7 +4235,7 @@ const adldata adl[4254] = { 0x0F0F000,0x2C78780, 0x00,0x0A, 0xE,+0 }, // 4219: b65PP54; b66PP54; Tamborin { 0x067FD00,0x086F641, 0x0A,0x0D, 0x6,+0 }, // 4220: b65PP56; b66PP56; CowBell { 0x60070E0,0x6F4A4A0, 0x00,0x1B, 0xC,+0 }, // 4221: b65PP58; b66PP58; VibeSlap - { 0x064DD03,0x205FD02, 0x1D,0x03, 0x8,+0 }, // 4222: b65PP59; b66PP59; Ride1 + { 0x064DD03,0x205ED02, 0x1D,0x03, 0x8,+0 }, // 4222: b65PP59; b66PP59; Ride1 { 0x1F8F830,0x0B6F511, 0x21,0x08, 0x0,+0 }, // 4223: b65PP60; b66PP60; HiBongo { 0x1F8F830,0x0A6F511, 0x1E,0x08, 0x0,+0 }, // 4224: b65PP61; b66PP61; LoBongo { 0x248EB00,0x078F700, 0x95,0x0D, 0x0,+0 }, // 4225: b65PP62; b66PP62; MTHCongo @@ -4246,7 +4246,7 @@ const adldata adl[4254] = { 0x387FD00,0x0F6E622, 0x00,0x08, 0x0,+0 }, // 4230: b65PP67; b66PP67; HiAgogo { 0x387FD00,0x0F6F522, 0x00,0x08, 0x0,+0 }, // 4231: b65PP68; b66PP68; LoAgogo { 0x0FEF025,0x2586C03, 0x00,0x93, 0xE,+0 }, // 4232: b65PP69; b66PP69; Cabasa - { 0x4F77720,0x2F87811, 0x11,0x13, 0x1,+0 }, // 4233: b65PP70; b66PP70; Maracas + { 0x4F77720,0x2F86811, 0x11,0x13, 0x1,+0 }, // 4233: b65PP70; b66PP70; Maracas { 0x3F77723,0x2F68623, 0x04,0x0A, 0xC,+0 }, // 4234: b65PP71; b66PP71; StWhistl { 0x3F76623,0x2F68623, 0x04,0x0A, 0xC,+0 }, // 4235: b65PP72; b66PP72; LgWhistl { 0x1F97869,0x0F9D721, 0xC0,0x00, 0xE,+0 }, // 4236: b65PP73; b66PP73; StGuiro @@ -20950,7 +20950,7 @@ const struct adlinsdata adlins[4203] = // fades to 20% at 0.6s, keyoff fades to 20% in 0.6s. {4221,4221, 35, 0, 593, 593 }, // 4169: b65PP58; b66PP58; VibeSlap - // Amplitude begins at 834.1, peaks 881.3 at 0.0s, + // Amplitude begins at 844.8, peaks 882.9 at 0.0s, // fades to 20% at 0.4s, keyoff fades to 20% in 0.4s. {4222,4222, 35, 0, 386, 386 }, // 4170: b65PP59; b66PP59; Ride1 @@ -20994,9 +20994,9 @@ const struct adlinsdata adlins[4203] = // fades to 20% at 0.1s, keyoff fades to 20% in 0.1s. {4232,4232, 35, 0, 100, 100 }, // 4180: b65PP69; b66PP69; Cabasa - // Amplitude begins at 4.8, peaks 278.5 at 0.0s, + // Amplitude begins at 0.6, peaks 273.6 at 0.0s, // fades to 20% at 0.1s, keyoff fades to 20% in 0.1s. - {4233,4233, 35, 0, 86, 86 }, // 4181: b65PP70; b66PP70; Maracas + {4233,4233, 35, 0, 100, 100 }, // 4181: b65PP70; b66PP70; Maracas // Amplitude begins at 21.7, peaks 489.3 at 0.0s, // fades to 20% at 0.2s, keyoff fades to 20% in 0.2s. @@ -22015,14 +22015,14 @@ const unsigned short banks[67][256] = 2920,2921,2574,2922,2513,2923,2924,2925, 692, 575,2926,2927,2928, 815,2929,2930, 2931,2932,2933,2934,2935,2936,2937,2938,2939,2940,2573,2941,2942,2943,2944,2945, 2946,2947, 715, 832,2948, 833,2655,2949,2950,2951,2534,2952,2953,1976,2954,2955, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +3980,3980,3980,3980,3980,3980,3980,3980,3980,3980,3980,3980,3980,3980,3980,3980, +3980,3980,3980,3980,3980,3980,3980,3980,3980,3980,3980,3981,3981,3981,3981,3981, +3981,3981,3981,3982,3983,3984,3985,3986,3987,3988,3989,3990,3991,3992,3993,3994, +3995,3996,3997,3998,3999,4000,4001,4002,4003,4004,4005,4006,4007,4008,4009,4010, +4011,4012,4013,4014,4015,3991,4016,4017,4018,4019,4020,4021,4022,4023,4024,4025, +4026,4027,4028,3981,3981,3981,3981,3981,3981,3980,4029,4029,4029,4029,4029,4029, +4029,4029,4029,4029,4029,4029,4029,4029,4029,4029,4029,4029,4029,4029,4029,4029, +4029,4029,4029,4029,4029,4029,4029,4029,4029,4029,4029,4029,4029,4029,4029,4029, }, { // bank 48, AIL (Ultimate Soccer Manager :: partially 4op) 2521,2522,2523,2524,2525,2526,2527, 766,2528,2529,2530,2531,2532,2533,2534,2535, @@ -22339,14 +22339,14 @@ const unsigned short banks[67][256] = 4127,4128,4129, 83,4130,4131, 86,4132,4133, 89,4134,4135,4136,4137, 94,4138, 96, 97, 98,4139,4140, 101, 102,4141, 104,4142, 106, 107, 108,4143,4144,4145, 4146, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122,4147,4148,4149, 126,4150, -4151,3204,3204,3204,3204,3204,3204,3204,3204,3204,3204,3204,3204,3204,3204,3204, -3204,3204,3204,3204,3204,3204,3204,3204,3204,3204,3204,3204,3204,3204,3204,3204, -3204,3204,3204,4152,4152,4153,4154,4155,4156,4157,4158,4159,4160,4161,4162,4161, -4163,4164,4161,4165,4164,4166,4167,4164,4168,4164,4169,4170,4171,4172,4173,4174, -4175,4176,4177,4178,4179,4180,4181,4182,4183,4184,4185,4186,4187,4187,4188,4189, -4190,4191,3204,3204,3204,3204,3204,3204,3204,3204,3204,3204,3204,3204,3204,3204, -3204,3204,3204,3204,3204,3204,3204,3204,3204,3204,3204,3204,3204,3204,3204,3204, -3204,3204,3204,3204,3204,3204,3204,3204,3204,3204,3204,3204,3204,3204,3204,3204, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 277, 277, 625, 626, 627, 628, 278, 629, 541, 608, 542, 630, 543, +544, 631, 545, 632, 553, 633,3429, 614, 635, 636,3430, 638, 639, 640, 641, 642, +643, 355, 644, 645, 646, 647, 648, 649, 650, 353,3431, 653, 654, 655, 337, 338, +656, 657, 546, 659, 727, 661, 662, 361, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, { // bank 66, SB (Jammey O'Connel's bank) 3220,3221, 459,3222, 749,3129,3223, 460,3224, 667,3225,3226,3227,3228,4192,3230, @@ -22357,13 +22357,13 @@ const unsigned short banks[67][256] = 3273,3274,4197,3276,3277,3278,4198, 435,3280,3281,3282,3237,3283,1750,3284,3285, 3286,3287,3288,3289,4199, 253,3290,3291,1982,2455,3292,3293, 711,3294,3295,3296, 3297,4200,3299,3300,4201,4202, 715,3302,3303, 455,3304, 448,3305,2456,3306, 458, -4151,3204,3204,3204,3204,3204,3204,3204,3204,3204,3204,3204,3204,3204,3204,3204, -3204,3204,3204,3204,3204,3204,3204,3204,3204,3204,3204,3204,3204,3204,3204,3204, -3204,3204,3204,4152,4152,4153,4154,4155,4156,4157,4158,4159,4160,4161,4162,4161, -4163,4164,4161,4165,4164,4166,4167,4164,4168,4164,4169,4170,4171,4172,4173,4174, -4175,4176,4177,4178,4179,4180,4181,4182,4183,4184,4185,4186,4187,4187,4188,4189, -4190,4191,3204,3204,3204,3204,3204,3204,3204,3204,3204,3204,3204,3204,3204,3204, -3204,3204,3204,3204,3204,3204,3204,3204,3204,3204,3204,3204,3204,3204,3204,3204, -3204,3204,3204,3204,3204,3204,3204,3204,3204,3204,3204,3204,3204,3204,3204,3204, +3980,3980,3980,3980,3980,3980,3980,3980,3980,3980,3980,3980,3980,3980,3980,3980, +3980,3980,3980,3980,3980,3980,3980,3980,3980,3980,3980,3981,3981,3981,3981,3981, +3981,3981,3981,3982,3983,3984,3985,3986,3987,3988,3989,3990,3991,3992,3993,3994, +3995,3996,3997,3998,3999,4000,4001,4002,4003,4004,4005,4006,4007,4008,4009,4010, +4011,4012,4013,4014,4015,3991,4016,4017,4018,4019,4020,4021,4022,4023,4024,4025, +4026,4027,4028,3981,3981,3981,3981,3981,3981,3980,4029,4029,4029,4029,4029,4029, +4029,4029,4029,4029,4029,4029,4029,4029,4029,4029,4029,4029,4029,4029,4029,4029, +4029,4029,4029,4029,4029,4029,4029,4029,4029,4029,4029,4029,4029,4029,4029,4029, }, }; diff --git a/src/adlmidi.cpp b/src/adlmidi.cpp index bdf4eac..a994fa0 100644 --- a/src/adlmidi.cpp +++ b/src/adlmidi.cpp @@ -1846,47 +1846,6 @@ int adlRefreshNumCards(ADL_MIDIPlayer* device) return 0; } -struct Mixx -{ - static int requested_len; //size of target buffer - static int stored_samples; //num of collected samples - static int backup_samples[1024]; //Backup sample storage. - static int backup_samples_size; //Backup sample storage. - //If requested number of samples less than 512 bytes, backup will be stored - - static int *_len; - static int *_out; - static void SendStereoAudio(unsigned long count, int* samples) - { - if(!count) return; - stored_samples=0; - size_t pos=(*_len); - for(unsigned long p = 0; p < count; ++p) - for(unsigned w=0; w<2; ++w) - { - int out=samples[p*2+w]; - int offset=pos+p*2+w; - if(offset<requested_len) - _out[offset] = out; - else - { - backup_samples[backup_samples_size]=out; - backup_samples_size++; stored_samples++; - } - } - } - -}; - -int Mixx::requested_len=0; -int Mixx::stored_samples=0; -int Mixx::backup_samples[1024]; -int Mixx::backup_samples_size=0; -int *Mixx::_len=NULL; -int *Mixx::_out=NULL; - - - /*---------------------------EXPORTS---------------------------*/ ADLMIDI_EXPORT struct ADL_MIDIPlayer* adl_init(long sample_rate) @@ -1908,6 +1867,10 @@ ADLMIDI_EXPORT struct ADL_MIDIPlayer* adl_init(long sample_rate) _device->carry=0.0; _device->mindelay = 1.0 / (double)_device->PCM_RATE; _device->maxdelay = 512.0 / (double)_device->PCM_RATE; + + _device->stored_samples=0; + _device->backup_samples_size=0; + _device->adl_midiPlayer = (void*)new MIDIplay; ((MIDIplay*)_device->adl_midiPlayer)->opl._parent=_device; ((MIDIplay*)_device->adl_midiPlayer)->opl.NumCards=_device->NumCards; @@ -1917,7 +1880,7 @@ ADLMIDI_EXPORT struct ADL_MIDIPlayer* adl_init(long sample_rate) ((MIDIplay*)_device->adl_midiPlayer)->opl.HighVibratoMode=(bool)_device->HighVibratoMode; ((MIDIplay*)_device->adl_midiPlayer)->opl.AdlPercussionMode=(bool)_device->AdlPercussionMode; ((MIDIplay*)_device->adl_midiPlayer)->opl.ScaleModulators=(bool)_device->ScaleModulators; - ((MIDIplay*)(_device->adl_midiPlayer))->ChooseDevice(""); + ((MIDIplay*)(_device->adl_midiPlayer))->ChooseDevice(""); adlRefreshNumCards(_device); return _device; } @@ -2006,9 +1969,10 @@ ADLMIDI_EXPORT void adl_setLoopEnabled(ADL_MIDIPlayer *device, int loopEn) ADLMIDI_EXPORT int adl_openFile(ADL_MIDIPlayer *device, char *filePath) { - Mixx::backup_samples_size=0; if(device && device->adl_midiPlayer) { + device->stored_samples=0; + device->backup_samples_size=0; if(!((MIDIplay *)device->adl_midiPlayer)->LoadMIDI(filePath)) { ADLMIDI_ErrorString="ADL MIDI: Can't load file"; @@ -2021,9 +1985,10 @@ ADLMIDI_EXPORT int adl_openFile(ADL_MIDIPlayer *device, char *filePath) ADLMIDI_EXPORT int adl_openData(ADL_MIDIPlayer* device, void *mem, long size) { - Mixx::backup_samples_size=0; if(device && device->adl_midiPlayer) { + device->stored_samples=0; + device->backup_samples_size=0; if(!((MIDIplay *)device->adl_midiPlayer)->LoadMIDI(mem, size)) { ADLMIDI_ErrorString="ADL MIDI: Can't load data from memory"; @@ -2048,8 +2013,10 @@ ADLMIDI_EXPORT const char *adl_getMusicTitle(ADL_MIDIPlayer *device) ADLMIDI_EXPORT void adl_close(ADL_MIDIPlayer *device) { - Mixx::backup_samples_size=0; - if(device->adl_midiPlayer) delete ((MIDIplay*)(device->adl_midiPlayer)); + if(device->adl_midiPlayer) + { + delete ((MIDIplay*)(device->adl_midiPlayer)); + } device->adl_midiPlayer = NULL; free(device); device=NULL; @@ -2058,42 +2025,73 @@ ADLMIDI_EXPORT void adl_close(ADL_MIDIPlayer *device) ADLMIDI_EXPORT void adl_reset(ADL_MIDIPlayer *device) { if(!device) return; - Mixx::backup_samples_size=0; + device->stored_samples=0; + device->backup_samples_size=0; ((MIDIplay*)device->adl_midiPlayer)->opl.Reset(); } -ADLMIDI_EXPORT int adl_play(ADL_MIDIPlayer*device, int sampleCount, int *out) +inline static void SendStereoAudio(ADL_MIDIPlayer*device, + int& samples_requested, + unsigned long& in_size, + int* _in, + int out_pos, + short* _out) +{ + if(!in_size) return; + device->stored_samples=0; + int out; + int offset; + for(unsigned long p = 0; p < in_size; ++p) + { + for(unsigned w=0; w<2; ++w) + { + out = _in[p*2+w]; + offset = out_pos+p*2+w; + if(offset<samples_requested) + { + _out[offset] = (short)out; + } + else + { + device->backup_samples[device->backup_samples_size]=out; + device->backup_samples_size++; device->stored_samples++; + } + } + } +} + + +ADLMIDI_EXPORT int adl_play(ADL_MIDIPlayer*device, int sampleCount, short *out) { if(!device) return 0; + sampleCount -= sampleCount%2;//Avoid non-odd sample requests if(sampleCount<0) return 0; if(device->QuitFlag) return 0; int gotten_len=0; - Mixx::requested_len=sampleCount; - Mixx::_len=&gotten_len; - Mixx::_out=out; unsigned long n_samples=512; unsigned long n_samples_2=n_samples*2; - while(sampleCount>0) + int left = sampleCount; + while(left>0) { - if(Mixx::backup_samples_size>0) + if(device->backup_samples_size>0) { //Send reserved samples if exist int ate=0; - while((ate<Mixx::backup_samples_size) && (ate<sampleCount)) + while((ate<device->backup_samples_size) && (ate<left)) { - out[ate]=Mixx::backup_samples[ate]; ate++; + out[ate]=(short)device->backup_samples[ate]; ate++; } - sampleCount-=ate; + left-=ate; gotten_len+=ate; - if(ate<Mixx::backup_samples_size) + if(ate<device->backup_samples_size) { for(int j=0; j<ate; j++) - Mixx::backup_samples[(ate-1)-j]=Mixx::backup_samples[(Mixx::backup_samples_size-1)-j]; + device->backup_samples[(ate-1)-j]=device->backup_samples[(device->backup_samples_size-1)-j]; } - Mixx::backup_samples_size-=ate; + device->backup_samples_size-=ate; } else { const double eat_delay = device->delay < device->maxdelay ? device->delay : device->maxdelay; device->delay -= eat_delay; @@ -2106,36 +2104,35 @@ ADLMIDI_EXPORT int adl_play(ADL_MIDIPlayer*device, int sampleCount, int *out) device->SkipForward -= 1; else { - sampleCount-=n_samples_2; + left -= n_samples_2; + int buf[n_samples*2]; + unsigned long in_count=n_samples; + if(device->NumCards == 1) { - ((MIDIplay*)(device->adl_midiPlayer))->opl.cards[0].Generate(0, Mixx::SendStereoAudio, n_samples); + ((MIDIplay*)(device->adl_midiPlayer))->opl.cards[0].GenerateArr(buf, &in_count); + /* Process it */ + SendStereoAudio(device, sampleCount, in_count, buf, gotten_len, out); } else if(n_samples > 0) { - /* Mix together the audio from different cards */ - static std::vector<int> sample_buf; - sample_buf.clear(); - sample_buf.resize(n_samples*2); - struct Mix - { - static void AddStereoAudio(unsigned long count, int* samples) - { - for(unsigned long a=0; a<count*2; ++a) - sample_buf[a] += samples[a]; - } - }; + int in[n_samples*2]; + + //fill buffer with zeros + for(unsigned long a=0; a<(in_count*2); ++a) buf[a] = 0; + + unsigned long in_count = n_samples; for(unsigned card = 0; card < device->NumCards; ++card) { - ((MIDIplay*)(device->adl_midiPlayer))->opl.cards[card].Generate( - 0, - Mix::AddStereoAudio, - n_samples); + ((MIDIplay*)(device->adl_midiPlayer))->opl.cards[card].GenerateArr( in, &in_count ); + for(unsigned long a=0; a<(in_count*2); ++a) + buf[a] += in[a]; } + /* Process it */ - Mixx::SendStereoAudio(n_samples, &sample_buf[0]); + SendStereoAudio(device, sampleCount, in_count, buf, gotten_len, out); } - gotten_len += (n_samples*2)-Mixx::stored_samples; + gotten_len += (n_samples*2)-device->stored_samples; } device->delay = ((MIDIplay*)device->adl_midiPlayer)->Tick(eat_delay, device->mindelay); } @@ -2144,8 +2141,6 @@ ADLMIDI_EXPORT int adl_play(ADL_MIDIPlayer*device, int sampleCount, int *out) } - - #ifdef ADLMIDI_buildAsApp int main(int argc, char** argv) diff --git a/src/adlmidi.h b/src/adlmidi.h index 75ae8a5..7e8bbd6 100644 --- a/src/adlmidi.h +++ b/src/adlmidi.h @@ -47,6 +47,12 @@ struct ADL_MIDIPlayer { double mindelay; double maxdelay; + /*For internal usage*/ + int stored_samples; //num of collected samples + int backup_samples[1024]; //Backup sample storage. + int backup_samples_size; //Backup sample storage. + /*For internal usage*/ + void *adl_midiPlayer; unsigned long PCM_RATE; }; @@ -94,7 +100,7 @@ extern void adl_reset(struct ADL_MIDIPlayer*device); extern void adl_close(struct ADL_MIDIPlayer *device); /*Take a sample buffer*/ -extern int adl_play(struct ADL_MIDIPlayer*device, int sampleCount, int out []); +extern int adl_play(struct ADL_MIDIPlayer*device, int sampleCount, short out[]); #ifdef __cplusplus } diff --git a/src/dbopl.cpp b/src/dbopl.cpp index 54df48c..809d394 100644 --- a/src/dbopl.cpp +++ b/src/dbopl.cpp @@ -1551,10 +1551,21 @@ void Handler::Generate( void(*AddSamples_m32)(Bitu,Bit32s*), AddSamples_m32( samples, buffer ); } else { chip.GenerateBlock3( samples, buffer ); - AddSamples_s32( samples, buffer ); + AddSamples_s32( samples, buffer ); } } +void Handler::GenerateArr(Bit32s* out, Bitu *samples ) +{ + if ( GCC_UNLIKELY(*samples > 512) ) + *samples = 512; + if ( !chip.opl3Active ) { + chip.GenerateBlock2( *samples, out ); + } else { + chip.GenerateBlock3( *samples, out ); + } +} + void Handler::Init( Bitu rate ) { InitTables(); chip.Setup( rate ); diff --git a/src/dbopl.h b/src/dbopl.h index bf10295..794c645 100644 --- a/src/dbopl.h +++ b/src/dbopl.h @@ -265,7 +265,8 @@ struct Handler { void Generate( void(*AddSamples_m32)(Bitu,Bit32s*), void(*AddSamples_s32)(Bitu,Bit32s*), Bitu samples ); - void Init( Bitu rate ); + void GenerateArr(Bit32s* out, Bitu *samples ); + void Init( Bitu rate ); }; diff --git a/src/fraction.h b/src/fraction.h index bdebe2a..f0943dd 100644 --- a/src/fraction.h +++ b/src/fraction.h @@ -84,7 +84,7 @@ void fraction<inttype>::Optim() { /* Euclidean algorithm */ inttype n1, n2; - if(abs(num1) < abs(num2)) + if(labs(num1) < labs(num2)) n1 = num1, n2 = num2; else n1 = num2, n2 = num1; |