From e4340c630d208131af491dd44bcf2f811e07ad05 Mon Sep 17 00:00:00 2001 From: Vesa Date: Sat, 22 Mar 2014 13:33:42 +0200 Subject: [PATCH] Do the opl amplification smarter --- plugins/opl2/opl2instrument.cpp | 38 ++++++++++++++++----------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/plugins/opl2/opl2instrument.cpp b/plugins/opl2/opl2instrument.cpp index a1b58a7e7..4704f0147 100644 --- a/plugins/opl2/opl2instrument.cpp +++ b/plugins/opl2/opl2instrument.cpp @@ -22,7 +22,7 @@ * */ -// TODO: +// TODO: // - Better voice allocation: long releases get cut short :( // - .sbi (or similar) file loading into models // - RT safety = get rid of mutex = make emulator code thread-safe @@ -36,9 +36,9 @@ // - SBI file import? // - Envelope times in ms for UI: t[0] = 0, t[n] = ( 1<write(0x40+adlib_opadd[voice], + theEmulator->write(0x40+adlib_opadd[voice], ( (int)op1_scale_mdl.value() & 0x03 << 6) + ( vel_adjusted & 0x3f ) ); - + vel_adjusted = 63 - ( op2_lvl_mdl.value() * vel/127.0 ); // vel_adjusted = 63 - op2_lvl_mdl.value(); - theEmulator->write(0x43+adlib_opadd[voice], + theEmulator->write(0x43+adlib_opadd[voice], ( (int)op2_scale_mdl.value() & 0x03 << 6) + ( vel_adjusted & 0x3f ) ); } @@ -293,10 +293,10 @@ bool opl2instrument::handleMidiEvent( const MidiEvent& event, const MidiTime& ti // to get us in line with MIDI(?) key = event.key() +12; vel = event.velocity(); - + voice = popVoice(); if( voice != OPL2_NO_VOICE ) { - // Turn voice on, NB! the frequencies are straight by voice number, + // Turn voice on, NB! the frequencies are straight by voice number, // not by the adlib_opadd table! theEmulator->write(0xA0+voice, fnums[key] & 0xff); theEmulator->write(0xB0+voice, 32 + ((fnums[key] & 0x1f00) >> 8) ); @@ -306,7 +306,7 @@ bool opl2instrument::handleMidiEvent( const MidiEvent& event, const MidiTime& ti } break; case MidiNoteOff: - key = event.key() +12; + key = event.key() +12; for(voice=0; voice<9; ++voice) { if( voiceNote[voice] == key ) { theEmulator->write(0xA0+voice, fnums[key] & 0xff); @@ -331,12 +331,12 @@ bool opl2instrument::handleMidiEvent( const MidiEvent& event, const MidiTime& ti break; case MidiPitchBend: // Update fnumber table - // Pitchbend should be in the range 0...16383 but the new range knob gets it wrong. + // Pitchbend should be in the range 0...16383 but the new range knob gets it wrong. // tmp_pb = (2*BEND_CENTS)*((float)event.m_data.m_param[0]/16383)-BEND_CENTS; // Something like 100 cents = 8192, but offset by 8192 so the +/-100 cents range goes from 0...16383? tmp_pb = ( event.pitchBend()-8192 ) * pitchBendRange / 8192; - + if( tmp_pb != pitchbend ) { pitchbend = tmp_pb; tuneEqual(69, 440.0); @@ -349,7 +349,7 @@ bool opl2instrument::handleMidiEvent( const MidiEvent& event, const MidiTime& ti } } break; - case MidiControlChange: + case MidiControlChange: switch (event.controllerNumber()) { case MidiControllerRegisteredParameterNumberLSB: RPNfine = event.controllerValue(); @@ -385,17 +385,17 @@ PluginView * opl2instrument::instantiateView( QWidget * _parent ) } -void opl2instrument::play( sampleFrame * _working_buffer ) +void opl2instrument::play( sampleFrame * _working_buffer ) { emulatorMutex.lock(); theEmulator->update(renderbuffer, frameCount); for( fpp_t frame = 0; frame < frameCount; ++frame ) { - sample_t s = float(renderbuffer[frame])/32768.0; + sample_t s = float(renderbuffer[frame]) / 8192.0; for( ch_cnt_t ch = 0; ch < DEFAULT_CHANNELS; ++ch ) { - _working_buffer[frame][ch] = s * 4.0; + _working_buffer[frame][ch] = s; } } emulatorMutex.unlock(); @@ -406,7 +406,7 @@ void opl2instrument::play( sampleFrame * _working_buffer ) } -void opl2instrument::saveSettings( QDomDocument & _doc, QDomElement & _this ) +void opl2instrument::saveSettings( QDomDocument & _doc, QDomElement & _this ) { op1_a_mdl.saveSettings( _doc, _this, "op1_a" ); op1_d_mdl.saveSettings( _doc, _this, "op1_d" ); @@ -577,11 +577,11 @@ opl2instrumentView::opl2instrumentView( Instrument * _instrument, QWidget * _parent ) : InstrumentView( _instrument, _parent ) { - /* Unnecessary? + /* Unnecessary? m_patch = new LcdSpinBox( 3, this , "PRESET"); m_patch->setLabel( "PRESET" ); m_patch->move( 100, 1 ); - m_patch->setEnabled( true ); + m_patch->setEnabled( true ); */ #define KNOB_GEN(knobname, hinttext, hintunit,xpos,ypos) \ @@ -608,7 +608,7 @@ opl2instrumentView::opl2instrumentView( Instrument * _instrument, toolTip::add( buttname, tr( tooltip ) );\ buttname->move( xpos, ypos );\ buttgroup->addButton(buttname); - + // OP1 knobs & buttons... KNOB_GEN(op1_a_kn, "Attack", "", 6, 48);