diff --git a/Open_Theremin_V3/application.cpp b/Open_Theremin_V3/application.cpp index a547b16..9689d19 100644 --- a/Open_Theremin_V3/application.cpp +++ b/Open_Theremin_V3/application.cpp @@ -82,7 +82,7 @@ unsigned long Application::GetQMeasurement() { int qn=0; - TCCR1B = (1< 681) + if (registerPotValue > 681) { - registerValue = 1; + registerValue = 1; } else if(registerPotValue < 342) { - registerValue = 3; + registerValue = 3; } else { - registerValue = 2; + registerValue = 2; } if (_state == PLAYING && HW_BUTTON_PRESSED) { @@ -288,9 +287,12 @@ void Application::loop() { // vol_v = vol_v - (1 + MAX_VOLUME - (volumePotValue << 2)); vol_v = vol_v ; vol_v = max(vol_v, 0); - vScaledVolume = vol_v >> 4; + tmpVolume = vol_v >> 4; + + // Give vScaledVolume a pseudo-exponential characteristic: + vScaledVolume = tmpVolume * (tmpVolume + 2); - volumeValueAvailable = false; + volumeValueAvailable = false; } goto mloop; // End of main loop @@ -494,7 +496,7 @@ void Application::hzToAddVal(float hz) { } void Application::playNote(float hz, uint16_t milliseconds = 500, uint8_t volume = 255) { - vScaledVolume = volume; + vScaledVolume = volume * (volume + 2); hzToAddVal(hz); millitimer(milliseconds); vScaledVolume = 0; diff --git a/Open_Theremin_V3/ihandlers.cpp b/Open_Theremin_V3/ihandlers.cpp index 2b9c51f..9b29087 100644 --- a/Open_Theremin_V3/ihandlers.cpp +++ b/Open_Theremin_V3/ihandlers.cpp @@ -25,7 +25,7 @@ const int16_t* const wavetables[] = { //Fixed following a suggestion by Michael sine_table8 }; -static const uint32_t MCP_DAC_BASE = 2047; +static const uint32_t MCP_DAC_BASE = 2048; #define INT0_STATE (PIND & (1<> 6) & 0x3ff; #if CV_ENABLED // Generator for CV output @@ -146,25 +130,14 @@ ISR (INT1_vect) { #else //Play sound - // Read next wave table value - waveSample = (int16_t)pgm_read_word_near(wavetables[vWavetableSelector] + offset); + // Read next wave table value + waveSample = (int16_t)pgm_read_word_near(wavetables[vWavetableSelector] + offset); - // multiply 16 bit wave number by 8 bit volume value (11.2us / 5.4us) - scaledSample = MCP_DAC_BASE + (mulsu_16_8(waveSample, vScaledVolume) >> 8); + scaledSample = ((int32_t)waveSample * (uint32_t)vScaledVolume) >> 16; -// Added by ThF 20200419 -#ifdef TH_DEBUG - HW_LED2_ON; -#endif + SPImcpDACsend(scaledSample + MCP_DAC_BASE); //Send result to Digital to Analogue Converter (audio out) (6 us) - SPImcpDACsend(scaledSample); //Send result to Digital to Analogue Converter (audio out) (6 us) - -// Added by ThF 20200419 -#ifdef TH_DEBUG - HW_LED2_OFF; -#endif - - pointer = pointer + vPointerIncrement; // increment table pointer (ca. 2us) + pointer += vPointerIncrement; // increment table pointer (ca. 2us) #endif //CV play sound incrementTimer(); // update 32us timer @@ -195,6 +168,10 @@ ISR (INT1_vect) { noInterrupts(); enableInt1(); +// Added by ThF 20200419 +#ifdef TH_DEBUG + HW_LED2_OFF; +#endif } /* VOLUME read - interrupt service routine for capturing volume counter value */ @@ -221,5 +198,3 @@ ISR(TIMER1_OVF_vect) { timer_overflow_counter++; } - - diff --git a/Open_Theremin_V3/ihandlers.h b/Open_Theremin_V3/ihandlers.h index d6de5d0..9e65988 100644 --- a/Open_Theremin_V3/ihandlers.h +++ b/Open_Theremin_V3/ihandlers.h @@ -3,7 +3,7 @@ extern volatile uint16_t pitch; // Pitch value extern volatile uint16_t vol; // Volume value -extern volatile uint8_t vScaledVolume; // Volume byte +extern volatile uint16_t vScaledVolume; // Volume byte extern volatile uint16_t pitch_counter; // Pitch counter extern volatile uint16_t pitch_counter_l; // Last value of pitch counter @@ -19,7 +19,7 @@ extern volatile bool pitchValueAvailable; // Pitch read flag extern volatile bool reenableInt1; // Pitch read flag extern volatile uint8_t vWavetableSelector; -extern volatile uint16_t vPointerIncrement; // Table pointer increment +extern volatile uint16_t vPointerIncrement; // Table pointer increment inline void resetPitchFlag() { pitchValueAvailable = false; } inline void resetVolFlag() { volumeValueAvailable = false; }