Commit 85a76811 authored by Tristan Matthews's avatar Tristan Matthews

* #9979: AudioRtpRecord: let AudioRtpRecord handle fadeIn internally

parent 859e5e3a
......@@ -29,6 +29,7 @@
#include "audio_rtp_record_handler.h"
#include <fstream>
#include <algorithm>
#include "logger.h"
#include "sip/sipcall.h"
......@@ -52,7 +53,7 @@ AudioRtpRecord::AudioRtpRecord() :
, codecFrameSize_(0)
, converterSamplingRate_(0)
, dtmfQueue_()
, micAmplFactor_(INIT_FADE_IN_FACTOR)
, fadeFactor_(INIT_FADE_IN_FACTOR)
, noiseSuppress_(0)
, audioProcessMutex_()
, callId_("")
......@@ -138,7 +139,7 @@ int AudioRtpRecordHandler::processDataEncode()
int samples = bytesToGet / sizeof(SFLDataFormat);
fadeIn(micData, samples, &audioRtpRecord_.micAmplFactor_);
audioRtpRecord_.fadeInDecodedData(samples);
if (Manager::instance().getEchoCancelState())
echoCanceller.getData(micData);
......@@ -169,10 +170,6 @@ void AudioRtpRecordHandler::processDataDecode(unsigned char *spkrData, size_t si
if (getCodecPayloadType() != payloadType)
return;
int codecSampleRate = getCodecSampleRate();
int mainBufferSampleRate = Manager::instance().getMainBuffer()->getInternalSamplingRate();
int inSamples = 0;
SFLDataFormat *spkrDataDecoded = audioRtpRecord_.decData_.data();
{
......@@ -181,7 +178,7 @@ void AudioRtpRecordHandler::processDataDecode(unsigned char *spkrData, size_t si
inSamples = audioRtpRecord_.audioCodec_->decode(spkrDataDecoded, spkrData, size);
}
fadeIn(spkrDataDecoded, inSamples, &audioRtpRecord_.micAmplFactor_);
audioRtpRecord_.fadeInDecodedData(inSamples);
// Normalize incomming signal
gainController.process(spkrDataDecoded, inSamples);
......@@ -189,6 +186,9 @@ void AudioRtpRecordHandler::processDataDecode(unsigned char *spkrData, size_t si
SFLDataFormat *out = spkrDataDecoded;
int outSamples = inSamples;
int codecSampleRate = getCodecSampleRate();
int mainBufferSampleRate = Manager::instance().getMainBuffer()->getInternalSamplingRate();
// test if resampling is required
if (codecSampleRate != mainBufferSampleRate) {
out = audioRtpRecord_.resampledData_.data();
......@@ -203,15 +203,17 @@ void AudioRtpRecordHandler::processDataDecode(unsigned char *spkrData, size_t si
Manager::instance().getMainBuffer()->putData(out, outSamples * sizeof(SFLDataFormat), id_);
}
void AudioRtpRecordHandler::fadeIn(SFLDataFormat *audio, size_t size, SFLDataFormat *factor)
void AudioRtpRecord::fadeInDecodedData(size_t size)
{
// if factor reaches 0, this function should have no effect
if (!audio or !factor or *factor <= 0)
if (fadeFactor_ <= 0 or size > decData_.size())
return;
while (size > 0)
audio[--size] /= *factor;
std::transform(decData_.begin(), decData_.begin() + size, decData_.begin(),
std::bind1st(std::divides<double>(), fadeFactor_));
*factor /= FADEIN_STEP_SIZE;
// Factor used to increase volume in fade in
const SFLDataFormat FADEIN_STEP_SIZE = 4;
fadeFactor_ /= FADEIN_STEP_SIZE;
}
}
......@@ -51,9 +51,6 @@ namespace sfl {
// Frequency (in packet number)
#define RTP_TIMESTAMP_RESET_FREQ 100
// Factor use to increase volume in fade in
#define FADEIN_STEP_SIZE 4;
static const int schedulingTimeout = 4000;
static const int expireTimeout = 1000000;
......@@ -92,12 +89,18 @@ class AudioRtpRecord {
int codecFrameSize_;
int converterSamplingRate_;
std::list<int> dtmfQueue_;
SFLDataFormat micAmplFactor_;
SFLDataFormat fadeFactor_;
NoiseSuppress *noiseSuppress_;
ost::Mutex audioProcessMutex_;
std::string callId_;
unsigned int dtmfPayloadType_;
private:
friend class AudioRtpRecordHandler;
/**
* Ramp In audio data to avoid audio click from peer
*/
void fadeInDecodedData(size_t size);
NON_COPYABLE(AudioRtpRecord);
};
......@@ -154,11 +157,6 @@ class AudioRtpRecordHandler {
*/
void processDataDecode(unsigned char * spkrData, size_t size, int payloadType);
/**
* Ramp In audio data to avoid audio click from peer
*/
void fadeIn(SFLDataFormat *audio, size_t size, SFLDataFormat *factor);
void setDtmfPayloadType(unsigned int payloadType) {
audioRtpRecord_.dtmfPayloadType_ = payloadType;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment