From c07b146a1a3991edd6c3233dcd1956b989303dd3 Mon Sep 17 00:00:00 2001 From: Wohlstand Date: Tue, 17 Oct 2017 03:57:21 +0300 Subject: EXPERIMENTAL: Support for custom banks! TODO: Fix support for real 4-operator support for dynamical instruments which now are silent. 2-op and pseudo-4-op still work fine. --- src/midiplay/adlmidiplay.cpp | 116 +++++++++++++++++++++++++++++-------------- 1 file changed, 79 insertions(+), 37 deletions(-) (limited to 'src/midiplay/adlmidiplay.cpp') diff --git a/src/midiplay/adlmidiplay.cpp b/src/midiplay/adlmidiplay.cpp index 34bf885..ca22025 100644 --- a/src/midiplay/adlmidiplay.cpp +++ b/src/midiplay/adlmidiplay.cpp @@ -11,29 +11,38 @@ class MutexType { - SDL_mutex* mut; + SDL_mutex *mut; public: MutexType() : mut(SDL_CreateMutex()) { } - ~MutexType() { SDL_DestroyMutex(mut); } - void Lock() { SDL_mutexP(mut); } - void Unlock() { SDL_mutexV(mut); } + ~MutexType() + { + SDL_DestroyMutex(mut); + } + void Lock() + { + SDL_mutexP(mut); + } + void Unlock() + { + SDL_mutexV(mut); + } }; static std::deque AudioBuffer; static MutexType AudioBuffer_lock; -static void SDL_AudioCallbackX(void*, Uint8* stream, int len) +static void SDL_AudioCallbackX(void *, Uint8 *stream, int len) { SDL_LockAudio(); - short* target = (short*) stream; + short *target = (short *) stream; AudioBuffer_lock.Lock(); /*if(len != AudioBuffer.size()) fprintf(stderr, "len=%d stereo samples, AudioBuffer has %u stereo samples", len/4, (unsigned) AudioBuffer.size()/2);*/ - unsigned ate = len/2; // number of shorts + unsigned ate = len / 2; // number of shorts if(ate > AudioBuffer.size()) ate = AudioBuffer.size(); - for(unsigned a=0; a [ ] [ [ [ ] ] ]\n" + "Usage: adlmidi [ ] [ [ [ ] ] ]\n" " -p Enables adlib percussion instrument mode\n" " -t Enables tremolo amplification mode\n" " -v Enables vibrato amplification mode\n" " -s Enables scaling of modulator volumes\n" " -nl Quit without looping\n" " -w Write WAV file rather than playing\n" + "\n" + "Where - number of embeeded bank or filepath to custom WOPL bank file\n" + "\n" + "Note: To create WOPL bank files use OPL Bank Editor you can get here: \n" + "https://github.com/Wohlstand/OPL3BankEditor\n" + "\n" ); -/* - for(unsigned a=0; a= 3) { - int bankno = std::atoi(argv[2]); - if(adl_setBank(myDevice, bankno)!=0) + if(is_number(argv[2])) { - std::fprintf(stderr,"%s", adl_errorString()); - return 0; + int bankno = std::atoi(argv[2]); + if(adl_setBank(myDevice, bankno) != 0) + { + std::fprintf(stderr, "%s\n", adl_errorString()); + std::fflush(stderr); + return 0; + } + } + else + { + std::fprintf(stdout, "Loading custom bank file %s...", argv[2]); + std::fflush(stdout); + if(adl_openBankFile(myDevice, argv[2]) != 0) + { + std::fprintf(stdout, "FAILED!\n"); + std::fflush(stdout); + std::fprintf(stderr, "%s\n", adl_errorString()); + std::fflush(stderr); + return 0; + } + std::fprintf(stdout, "OK!\n"); + std::fflush(stdout); } } @@ -160,14 +202,14 @@ int main(int argc, char** argv) } if(argc >= 5) { - if(adl_setNumFourOpsChn(myDevice, std::atoi(argv[4]))!=0) + if(adl_setNumFourOpsChn(myDevice, std::atoi(argv[4])) != 0) { std::fprintf(stderr, "%s\n", adl_errorString()); return 0; } } - if(adl_openFile(myDevice, argv[1])!=0) + if(adl_openFile(myDevice, argv[1]) != 0) { std::fprintf(stderr, "%s\n", adl_errorString()); return 2; @@ -179,17 +221,17 @@ int main(int argc, char** argv) { short buff[4096]; unsigned long gotten = adl_play(myDevice, 4096, buff); - if(gotten<=0) break; + if(gotten <= 0) break; AudioBuffer_lock.Lock(); - size_t pos = AudioBuffer.size(); - AudioBuffer.resize(pos + gotten); - for(unsigned long p = 0; p < gotten; ++p) - AudioBuffer[pos+p] = buff[p]; + size_t pos = AudioBuffer.size(); + AudioBuffer.resize(pos + gotten); + for(unsigned long p = 0; p < gotten; ++p) + AudioBuffer[pos + p] = buff[p]; AudioBuffer_lock.Unlock(); - const SDL_AudioSpec& spec_ = obtained; - while(AudioBuffer.size() > spec_.samples + (spec_.freq*2) * OurHeadRoomLength) + const SDL_AudioSpec &spec_ = obtained; + while(AudioBuffer.size() > spec_.samples + (spec_.freq * 2) * OurHeadRoomLength) { SDL_Delay(1); } -- cgit v1.2.3