Commit 84523fae authored by Alexandre Savard's avatar Alexandre Savard
Browse files

[#5249] Fix audio samplerate update algorithm for g722

parent b9f8a89d
......@@ -158,7 +158,8 @@ void AudioRtpRecordHandler::updateRtpMedia (AudioCodec *audioCodec)
_audioRtpRecord.audioCodecMutex.leave();
Manager::instance().getMainBuffer()->setInternalSamplingRate (_audioRtpRecord._codecSampleRate);
// Manager::instance().getMainBuffer()->setInternalSamplingRate (_audioRtpRecord._codecSampleRate);
Manager::instance().audioSamplingRateChanged(_audioRtpRecord._codecSampleRate);
if (lastSamplingRate != _audioRtpRecord._codecSampleRate)
updateNoiseSuppress();
......@@ -173,7 +174,8 @@ void AudioRtpRecordHandler::initBuffers()
int codecSampleRate = _audioRtpRecord._codecSampleRate;
// Set sampling rate, main buffer choose the highest one
Manager::instance().getMainBuffer()->setInternalSamplingRate (codecSampleRate);
// Manager::instance().getMainBuffer()->setInternalSamplingRate (codecSampleRate);
Manager::instance().audioSamplingRateChanged(codecSampleRate);
// initialize SampleRate converter using AudioLayer's sampling rate
// (internal buffers initialized with maximal sampling rate and frame size)
......
......@@ -103,10 +103,20 @@ class G722 : public AudioCodec
// Enable 8khz mode, encode using lower subband only
encode_s->eight_k = FALSE;
// Never set packed TRUE when using 64 kbps
encode_s->packed = FALSE;
memset(encode_s->band, 0, sizeof(decode_s->band) * 2);
encode_s->band[0].det = 32;
encode_s->band[1].det = 8;
memset(encode_s->x, 0, sizeof(int) * 24);
decode_s->in_buffer = 0;
decode_s->in_bits = 0;
decode_s->out_buffer = 0;
decode_s->out_bits = 0;
}
void g722_decode_init (void) {
......@@ -121,14 +131,23 @@ class G722 : public AudioCodec
// Never set packed TRUE when using 64 kbps
decode_s->packed = FALSE;
memset(decode_s->band, 0, sizeof(decode_s->band) * 2);
decode_s->band[0].det = 32;
decode_s->band[1].det = 8;
decode_s->in_bits = 0;
memset(decode_s->x, 0, sizeof(int) * 24);
decode_s->in_buffer = 0;
decode_s->in_bits = 0;
decode_s->out_buffer = 0;
decode_s->out_bits = 0;
}
int16_t saturate (int32_t amp) {
int16_t amp16;
int16_t amp16 = 0;
/* Hopefully this is optimised for the common case - not clipping */
amp16 = (int16_t) amp;
......
......@@ -57,11 +57,11 @@ void MainBuffer::setInternalSamplingRate (int sr)
// This call takes the mutex
flushAllBuffers();
ost::MutexLock guard (_mutex);
// ost::MutexLock guard (_mutex);
_internalSamplingRate = sr;
Manager::instance().audioSamplingRateChanged();
// Manager::instance().audioSamplingRateChanged(sr);
}
}
......
......@@ -3038,10 +3038,10 @@ void ManagerImpl::switchAudioManager (void)
// }
}
void ManagerImpl::audioSamplingRateChanged (void)
void ManagerImpl::audioSamplingRateChanged (int samplerate)
{
int type, samplerate, framesize, numCardIn, numCardOut, numCardRing;
int type, currentSamplerate, framesize, numCardIn, numCardOut, numCardRing;
std::string alsaPlugin;
_debug ("Manager: Audio sampling rate changed");
......@@ -3049,9 +3049,14 @@ void ManagerImpl::audioSamplingRateChanged (void)
if (!_audiodriver)
return;
// Only modify internal sampling rate if new sampling rate is higher
currentSamplerate = _mainBuffer.getInternalSamplingRate();
if(currentSamplerate <= samplerate)
return;
type = _audiodriver->getLayerType();
samplerate = _mainBuffer.getInternalSamplingRate();
// samplerate = _mainBuffer.getInternalSamplingRate();
framesize = audioPreference.getFramesize();
_debug ("Manager: new samplerate: %d, new framesize %d", samplerate, framesize);
......@@ -3101,6 +3106,8 @@ void ManagerImpl::audioSamplingRateChanged (void)
_debug ("Manager: Current device: %d ", type);
_mainBuffer.setInternalSamplingRate(samplerate);
if (_audiodriver) {
unsigned int sampleRate = _audiodriver->getSampleRate();
......
......@@ -851,7 +851,11 @@ class ManagerImpl
void switchAudioManager (void);
void audioSamplingRateChanged (void);
/**
* Set the internal audio sampling rate change. Should close the audio layer and
* reopen stream at different rate,
*/
void audioSamplingRateChanged (int);
/**
* Get the desktop mail notification level
......
Supports Markdown
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