Correct sample rate entry and add overall gain control

pull/16/merge
boblark 2 years ago
parent d01dc8ebd4
commit 2aa2bc444c
  1. 12
      RadioIQMixer_F32.cpp
  2. 17
      RadioIQMixer_F32.h

@ -73,6 +73,7 @@ void RadioIQMixer_F32::update(void) {
} }
// doSimple has amplitude (-1, 1) and sin/cos differ by 90.00 degrees. // doSimple has amplitude (-1, 1) and sin/cos differ by 90.00 degrees.
// Also no block gain, gainOut. Rev 2023
if (doSimple) { if (doSimple) {
for (i=0; i < block_size; i++) { for (i=0; i < block_size; i++) {
phaseS += phaseIncrement; phaseS += phaseIncrement;
@ -93,9 +94,9 @@ void RadioIQMixer_F32::update(void) {
b = sinTable512_f32[index+1]; b = sinTable512_f32[index+1];
/* deltaPhase will be the same as used for sin */ /* deltaPhase will be the same as used for sin */
if(twoChannel) if(twoChannel)
blockOut_q->data[i] = blockIn1->data[i]*(a + (b-a)*deltaPhase); blockOut_q->data[i] = gainOut * blockIn1->data[i]*(a + (b-a)*deltaPhase);
else else
blockOut_q->data[i] = blockIn0->data[i]*(a + (b-a)*deltaPhase); blockOut_q->data[i] = gainOut * blockIn0->data[i]*(a + (b-a)*deltaPhase);
} }
} }
else { // Do a more flexible update, i.e., not doSimple else { // Do a more flexible update, i.e., not doSimple
@ -109,7 +110,7 @@ void RadioIQMixer_F32::update(void) {
b = sinTable512_f32[index+1]; b = sinTable512_f32[index+1];
// We now have a sine value, so multiply with the input data and save // We now have a sine value, so multiply with the input data and save
// Linear interpolate sine and multiply with the input and amplitude (about 1.0) // Linear interpolate sine and multiply with the input and amplitude (about 1.0)
blockOut_i->data[i] = amplitude_pk * blockIn0->data[i] * (a + (b-a)*deltaPhase); blockOut_i->data[i] = gainOut * amplitude_pk * blockIn0->data[i] * (a + (b-a)*deltaPhase);
/* Shift forward phaseS_C and get cos. First, the calculation of index of the table */ /* Shift forward phaseS_C and get cos. First, the calculation of index of the table */
phaseC = phaseS + phaseS_C; phaseC = phaseS + phaseS_C;
@ -121,11 +122,12 @@ void RadioIQMixer_F32::update(void) {
b = sinTable512_f32[index+1]; b = sinTable512_f32[index+1];
// Same as sin, but leave amplitude of LO at +/- 1.0 // Same as sin, but leave amplitude of LO at +/- 1.0
if(twoChannel) if(twoChannel)
blockOut_q->data[i] = blockIn1->data[i]*(a + (b-a)*deltaPhase); blockOut_q->data[i] = gainOut * blockIn1->data[i]*(a + (b-a)*deltaPhase);
else else
blockOut_q->data[i] = blockIn0->data[i]*(a + (b-a)*deltaPhase); blockOut_q->data[i] = gainOut * blockIn0->data[i]*(a + (b-a)*deltaPhase);
} }
} }
AudioStream_F32::release(blockIn0); // Done with this AudioStream_F32::release(blockIn0); // Done with this
if(twoChannel) if(twoChannel)
AudioStream_F32::release(blockIn1); AudioStream_F32::release(blockIn1);

@ -21,7 +21,8 @@
* *
* The amplitudeC(a) allows balancing of I and Q channels. * The amplitudeC(a) allows balancing of I and Q channels.
* *
* The output levels are 0.5 times the input level. * The output levels are 0.5 times the input level, unless adjusted by
* gainOut(g).
* *
* Status: Tested in doSimple==1 * Status: Tested in doSimple==1
* Tested in FineFreqShift_OA.ino, T3.6 and T4.0 * Tested in FineFreqShift_OA.ino, T3.6 and T4.0
@ -37,12 +38,15 @@
* void useSimple(bool s) Faster if 1, but no phase/amplitude adjustment * void useSimple(bool s) Faster if 1, but no phase/amplitude adjustment
* void setSampleRate_Hz(float32_t fs_Hz) Allows dynamic sample rate change for this function * void setSampleRate_Hz(float32_t fs_Hz) Allows dynamic sample rate change for this function
* void useTwoChannel(bool 2Ch) Uses 2 input cannels, I & Q, if true. Apr 2021 * void useTwoChannel(bool 2Ch) Uses 2 input cannels, I & Q, if true. Apr 2021
* void setGainOut(float32_t gainO) Sets gain after mixers. Often a value of 2.0 makes the
* block lossless. For both doSimple and not doSimple.
* *
* Time: T3.6 For an update of a 128 sample block, doSimple=1, 46 microseconds * Time: T3.6 For an update of a 128 sample block, doSimple=true, 46 microseconds
* T4.0 For an update of a 128 sample block, doSimple=1, 20 microseconds * T4.0 For an update of a 128 sample block, doSimple=true, 20 microseconds
* *
* Rev Apr2021 Allowed for 2-channel I-Q input. Defaults to 1 Channel. "real." * Rev Apr2021 Allowed for 2-channel I-Q input. Defaults to 1 Channel. "real."
* Rev 30Jan23 Corrected setSampleRate_Hz(sr) to do so! RSL * Rev 30Jan23 Corrected setSampleRate_Hz(sr) to do so! RSL
* Rev 2 Feb 2023 Added gainOut, with or without doSimple. RSL
*/ */
#ifndef _radioIQMixer_f32_h #ifndef _radioIQMixer_f32_h
@ -123,6 +127,10 @@ public:
return; return;
} }
void setGainOut(float32_t _gainO) { // Rev 2023
gainOut = _gainO;
}
void setSampleRate_Hz(float32_t fs_Hz) { void setSampleRate_Hz(float32_t fs_Hz) {
sample_rate_Hz = fs_Hz; // Added 30Jan23 RSL sample_rate_Hz = fs_Hz; // Added 30Jan23 RSL
// Check freq range // Check freq range
@ -145,11 +153,10 @@ private:
float32_t amplitude_pk = 1.0f; float32_t amplitude_pk = 1.0f;
float32_t sample_rate_Hz = AUDIO_SAMPLE_RATE_EXACT; float32_t sample_rate_Hz = AUDIO_SAMPLE_RATE_EXACT;
float32_t phaseIncrement = 512.00f * freq /sample_rate_Hz; float32_t phaseIncrement = 512.00f * freq /sample_rate_Hz;
float32_t gainOut = 1.0f;
uint16_t block_size = AUDIO_BLOCK_SAMPLES; uint16_t block_size = AUDIO_BLOCK_SAMPLES;
uint16_t errorPrintIQM = 0; // Normally off uint16_t errorPrintIQM = 0; // Normally off
bool doSimple = true; bool doSimple = true;
bool twoChannel = false; // Activates 2 channels for I-Q input bool twoChannel = false; // Activates 2 channels for I-Q input
}; };
#endif #endif

Loading…
Cancel
Save