diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/adlmidi.cpp | 52 | ||||
-rw-r--r-- | src/adlmidi_private.hpp | 10 |
2 files changed, 52 insertions, 10 deletions
diff --git a/src/adlmidi.cpp b/src/adlmidi.cpp index 9a0aaa4..59d7a7e 100644 --- a/src/adlmidi.cpp +++ b/src/adlmidi.cpp @@ -477,17 +477,15 @@ inline static void SendStereoAudio(MIDIplay::Setup &device, ADLMIDI_EXPORT int adl_play(ADL_MIDIPlayer *device, int sampleCount, short *out) { + sampleCount -= sampleCount % 2; //Avoid even sample requests + if(sampleCount < 0) + return 0; if(!device) return 0; MIDIplay *player = reinterpret_cast<MIDIplay *>(device->adl_midiPlayer); MIDIplay::Setup &setup = player->m_setup; - sampleCount -= sampleCount % 2; //Avoid even sample requests - - if(sampleCount < 0) - return 0; - ssize_t gotten_len = 0; ssize_t n_periodCountStereo = 512; //ssize_t n_periodCountPhys = n_periodCountStereo * 2; @@ -576,3 +574,47 @@ ADLMIDI_EXPORT int adl_play(ADL_MIDIPlayer *device, int sampleCount, short *out) return static_cast<int>(gotten_len); } + + +ADLMIDI_EXPORT int adl_generate(ADL_MIDIPlayer *device, int sampleCount, short *out) +{ + sampleCount -= sampleCount % 2; //Avoid even sample requests + if(sampleCount < 0) + return 0; + if(!device) + return 0; + + MIDIplay *player = reinterpret_cast<MIDIplay *>(device->adl_midiPlayer); + sampleCount = (sampleCount > 1024) ? 1024 : sampleCount; + + //! Count of stereo samples + ssize_t in_generatedStereo = sampleCount / 2; + //! Unsigned total sample count + //fill buffer with zeros + std::memset(out, 0, static_cast<size_t>(sampleCount) * sizeof(int16_t)); + + if(player->m_setup.NumCards == 1) + { + #ifdef ADLMIDI_USE_DOSBOX_OPL + player->opl.cards[0].GenerateArr(out, &in_generatedStereo); + in_generatedPhys = in_generatedStereo * 2; + #else + OPL3_GenerateStream(&player->opl.cards[0], out, static_cast<Bit32u>(in_generatedStereo)); + #endif + } + else + { + /* Generate data from every chip and mix result */ + for(unsigned card = 0; card < player->m_setup.NumCards; ++card) + { + #ifdef ADLMIDI_USE_DOSBOX_OPL + player->opl.cards[card].GenerateArrMix(out, &in_generatedStereo); + in_generatedPhys = in_generatedStereo * 2; + #else + OPL3_GenerateStreamMix(&player->opl.cards[card], out, static_cast<Bit32u>(in_generatedStereo)); + #endif + } + } + + return sampleCount; +} diff --git a/src/adlmidi_private.hpp b/src/adlmidi_private.hpp index 0997556..650291a 100644 --- a/src/adlmidi_private.hpp +++ b/src/adlmidi_private.hpp @@ -236,6 +236,7 @@ struct MIDIEventHooks void *onDebugMessage_userData; }; + class MIDIplay { public: @@ -424,7 +425,6 @@ public: // Index to physical adlib data structure, adlins[] char ____padding2[3]; uint32_t insmeta; - char ____padding3[4]; struct Phys { //! ins, inde to adl[] @@ -442,7 +442,8 @@ public: } }; typedef std::map<uint16_t, Phys> PhysMap; - // List of adlib channels it is currently occupying. + char ____padding3[4]; + // List of OPL3 channels it is currently occupying. std::map<uint16_t /*adlchn*/, Phys> phys; }; typedef std::map<uint8_t, NoteInfo> activenotemap_t; @@ -462,7 +463,7 @@ public: activenotes() { } }; - // Additional information about AdLib channels + // Additional information about OPL3 channels struct AdlChannel { // For collisions @@ -483,9 +484,8 @@ public: struct LocationData { bool sustained; - char ____padding[1]; + char ____padding[7]; MIDIchannel::NoteInfo::Phys ins; // a copy of that in phys[] - char ____padding2[4]; int64_t kon_time_until_neglible; int64_t vibdelay; }; |