1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

Fix bad audio quality

This commit is contained in:
Tux3 / Mlkj / !Lev.uXFMLA 2014-08-28 23:06:53 +02:00
parent 3fc37d2d4c
commit 5fba31927f
2 changed files with 11 additions and 8 deletions

2
core.h
View File

@ -271,7 +271,7 @@ private:
static void cleanupCall(int callId); static void cleanupCall(int callId);
static void playCallAudio(ToxAv *toxav, int32_t callId, int16_t *data, int samples, void *user_data); // Callback static void playCallAudio(ToxAv *toxav, int32_t callId, int16_t *data, int samples, void *user_data); // Callback
static void sendCallAudio(int callId, ToxAv* toxav); static void sendCallAudio(int callId, ToxAv* toxav);
static void playAudioBuffer(int callId, int16_t *data, int samples); static void playAudioBuffer(int callId, int16_t *data, int samples, unsigned channels, int sampleRate);
static void playCallVideo(ToxAv* toxav, int32_t callId, vpx_image_t* img, void *user_data); static void playCallVideo(ToxAv* toxav, int32_t callId, vpx_image_t* img, void *user_data);
void sendCallVideo(int callId); void sendCallVideo(int callId);

View File

@ -153,14 +153,17 @@ void Core::cleanupCall(int callId)
alcCaptureCloseDevice(calls[callId].alInDev); alcCaptureCloseDevice(calls[callId].alInDev);
} }
void Core::playCallAudio(ToxAv*, int32_t callId, int16_t *data, int samples, void *user_data) void Core::playCallAudio(ToxAv* toxav, int32_t callId, int16_t *data, int samples, void *user_data)
{ {
Q_UNUSED(user_data); Q_UNUSED(user_data);
if (!calls[callId].active) if (!calls[callId].active)
return; return;
playAudioBuffer(callId, data, samples); ToxAvCSettings dest;
if(toxav_get_peer_csettings(toxav, callId, 0, &dest) == 0)
playAudioBuffer(callId, data, samples, dest.audio_channels, dest.audio_sample_rate);
//playAudioBuffer(callId, data, samples, 1, av_DefaultSettings.audio_sample_rate);
} }
void Core::sendCallAudio(int callId, ToxAv* toxav) void Core::sendCallAudio(int callId, ToxAv* toxav)
@ -479,10 +482,10 @@ void Core::onAvStart(void* _toxav, int32_t call_index, void* core)
} }
// This function's logic was shamelessly stolen from uTox // This function's logic was shamelessly stolen from uTox
void Core::playAudioBuffer(int callId, int16_t *data, int samples) void Core::playAudioBuffer(int callId, int16_t *data, int samples, unsigned channels, int sampleRate)
{ {
unsigned channels = calls[callId].codecSettings.audio_channels; if(!channels || channels > 2)
if(!channels || channels > 2) { {
qWarning() << "Core::playAudioBuffer: trying to play on "<<channels<<" channels! Giving up."; qWarning() << "Core::playAudioBuffer: trying to play on "<<channels<<" channels! Giving up.";
return; return;
} }
@ -506,12 +509,12 @@ void Core::playAudioBuffer(int callId, int16_t *data, int samples)
} }
else else
{ {
qDebug() << "Core: Dropped audio frame"; qDebug() << "Core: Dropped audio frame" << sampleRate << ", " << channels<<", "<<samples;
return; return;
} }
alBufferData(bufid, (channels == 1) ? AL_FORMAT_MONO16 : AL_FORMAT_STEREO16, data, alBufferData(bufid, (channels == 1) ? AL_FORMAT_MONO16 : AL_FORMAT_STEREO16, data,
samples * 2 * channels, calls[callId].codecSettings.audio_sample_rate); samples * 2 * channels, sampleRate);
alSourceQueueBuffers(calls[callId].alSource, 1, &bufid); alSourceQueueBuffers(calls[callId].alSource, 1, &bufid);
ALint state; ALint state;