Skip to content

Commit

Permalink
MBE audio interpolator and filter: use a volume setting for fixed values
Browse files Browse the repository at this point in the history
  • Loading branch information
f4exb committed Jun 24, 2018
1 parent 4b2b594 commit 8a1d78b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 16 deletions.
10 changes: 7 additions & 3 deletions dsd_decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,17 +249,21 @@ void DSDDecoder::setAudioGain(float gain)
else if (m_opts.audio_gain == 0.0f)
{
m_dsdLogger.log("Enabling audio out auto-gain\n");
m_mbeDecoder1.setAudioGain(25);
m_mbeDecoder1.setAutoGain(true);
m_mbeDecoder1.setAudioGain(25);
m_mbeDecoder1.setVolume(1.0f);
m_mbeDecoder1.setAutoGain(true);
m_mbeDecoder2.setAudioGain(25);
m_mbeDecoder2.setVolume(1.0f);
m_mbeDecoder2.setAutoGain(true);
}
else
{
m_dsdLogger.log("Setting audio out gain to %f\n", m_opts.audio_gain);
m_mbeDecoder1.setAudioGain(m_opts.audio_gain);
m_mbeDecoder1.setVolume(m_opts.audio_gain);
m_mbeDecoder1.setAutoGain(false);
m_mbeDecoder2.setAudioGain(m_opts.audio_gain);
m_mbeDecoder2.setVolume(m_opts.audio_gain);
m_mbeDecoder2.setAutoGain(false);
}
}
Expand Down Expand Up @@ -1396,7 +1400,7 @@ void DSDDecoder::formatStatusText(char *statusText)
// 1 2 2 3 3 4 4 5 5 6 6 7 7 8
// 5....0....5....0....5....0....5....0....5....0....5....0....5....0..
// NXD>RC cc mm llllll ssss
sprintf(&statusText[15], "NXD>RC %02d %02X %06X %02X",
sprintf(&statusText[15], "NXD>RC %02d %02X %06X %02X",
getNXDNDecoder().getRAN(),
getNXDNDecoder().getMessageType(),
getNXDNDecoder().getLocationId(),
Expand Down
27 changes: 14 additions & 13 deletions dsd_mbe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ DSDMBEDecoder::DSDMBEDecoder(DSDDecoder *dsdDecoder) :
m_audio_out_idx2 = 0;

m_aout_gain = 25;
m_volume = 1.0f;
m_auto_gain = true;
m_stereo = false;
m_channels = 3; // both channels by default if stereo is set
Expand Down Expand Up @@ -238,24 +239,24 @@ void DSDMBEDecoder::processAudio()
}

gaindelta /= (float) 160;

// adjust output gain
m_audio_out_temp_buf_p = m_audio_out_temp_buf;

for (n = 0; n < 160; n++)
{
*m_audio_out_temp_buf_p = (m_aout_gain
+ ((float) n * gaindelta)) * (*m_audio_out_temp_buf_p);
m_audio_out_temp_buf_p++;
}

m_aout_gain += ((float) 160 * gaindelta);
}
else
{
gaindelta = (float) 0;
}

// adjust output gain
m_audio_out_temp_buf_p = m_audio_out_temp_buf;

for (n = 0; n < 160; n++)
{
*m_audio_out_temp_buf_p = (m_aout_gain
+ ((float) n * gaindelta)) * (*m_audio_out_temp_buf_p);
m_audio_out_temp_buf_p++;
}

m_aout_gain += ((float) 160 * gaindelta);

// copy audio data to output buffer and upsample if necessary
m_audio_out_temp_buf_p = m_audio_out_temp_buf;

Expand Down Expand Up @@ -369,7 +370,7 @@ void DSDMBEDecoder::upsample(int upsampling, float invalue)
// outbuf1--;
// c = *outbuf1;
c = m_upsamplerLastValue;
d = m_upsamplingFilter.usesHP() ? m_upsamplingFilter.runHP(invalue) : invalue;
d = (m_upsamplingFilter.usesHP() ? m_upsamplingFilter.runHP(invalue) : invalue)*m_volume;
// basic triangle interpolation
// outbuf1++;
if (upsampling == 2)
Expand Down
2 changes: 2 additions & 0 deletions dsd_mbe.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class DSDMBEDecoder

void setAudioGain(float aout_gain) { m_aout_gain = aout_gain; }
void setAutoGain(bool auto_gain) { m_auto_gain = auto_gain; }
void setVolume(float volume) { m_volume = volume; }
void setStereo(bool stereo) { m_stereo = stereo; }
void setChannels(unsigned char channels) { m_channels = channels % 4; }
void setUpsamplingFactor(int upsample) { m_upsample = upsample; }
Expand Down Expand Up @@ -87,6 +88,7 @@ class DSDMBEDecoder
int m_audio_out_idx2;

float m_aout_gain;
float m_volume;
bool m_auto_gain;
int m_upsample; //!< upsampling factor
bool m_stereo; //!< double each audio sample to produce L+R channels
Expand Down

0 comments on commit 8a1d78b

Please sign in to comment.