ubitx-iop/ubitx_iop/tx_audio_proc.ino
2020-05-25 23:11:36 -05:00

52 lines
1.2 KiB
C++

//======================================================================
// tx_audio_proc.ino
//
// Classes/functions for processing transmit audio.
//======================================================================
#include "tx_audio_proc.h"
SpeechCompressor::SpeechCompressor(AudioEffectCompressor& comp, AudioAmplifier& amp, AudioAnalyzeRMS& rms):
_compress(comp), _amp(amp), _rms(rms)
{
}
//void SpeechCompressor::config(AudioEffectCompressor* comp, AudioAnalyzeRMS* rms)
//{
// _compress = comp;
// _rms = rms;
//}
bool SpeechCompressor::isEnabled() const
{
return _enabled;
}
void SpeechCompressor::enable()
{
_enabled = true;
_compress.begin(1, 0.5, 4); // Need to make configurable
}
void SpeechCompressor::disable()
{
_enabled = false;
_compress.disable();
}
// Speech compressor code based on post by 'hyperdyne': https://forum.pjrc.com/threads/36245-Changing-Pitch-of-Voice
void SpeechCompressor::update()
{
float rms_cur;
if (_enabled && _rms.available()) {
rms_cur = _rms.read();
_env = rms_cur + (_alpha * (_env - rms_cur));
_compress.update_pwr(_env);
}
}
//======================================================================
// EOF
//======================================================================