fix(audio): specify format for sounds and make sounds follow it

This should reduce the problem that some sounds are very silent and some are loud.
reviewable/pr5305/r2
sudden6 2018-08-25 18:40:23 +02:00
parent 064dccf8b4
commit 5d65ab3876
No known key found for this signature in database
GPG Key ID: 279509B499E032B9
16 changed files with 31 additions and 13 deletions

Binary file not shown.

BIN
audio/ToxEndCall.s16le.pcm Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

17
audio/format.md Normal file
View File

@ -0,0 +1,17 @@
To keep sounds consistent a sound file should follow the parameters listed
below.
# Format
Internally qTox needs PCM with signed 16Bit integers and a samplerate of
48kHz and one channel (mono).
You can use ffmpeg to create those files as follows:
```
ffmpeg -i notification.wav -f s16le -acodec pcm_s16le -ac 1 -ar 48000 notification.s16le.pcm
```
# Normalization
All sound files should have their maximum at -1.0 dB.
To normalize them correctly you can use Audacity with the "Normalize" plugin.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -6,10 +6,10 @@
<file alias="DejaVuSans.ttf">res/font/DejaVuSans.ttf</file>
</qresource>
<qresource prefix="/">
<file>audio/notification.pcm</file>
<file>audio/ToxIncomingCall.pcm</file>
<file>audio/ToxOutgoingCall.pcm</file>
<file>audio/ToxEndCall.pcm</file>
<file>audio/notification.s16le.pcm</file>
<file>audio/ToxIncomingCall.s16le.pcm</file>
<file>audio/ToxOutgoingCall.s16le.pcm</file>
<file>audio/ToxEndCall.s16le.pcm</file>
<file>img/add.svg</file>
<file>img/avatar_mask.svg</file>
<file>img/contact.svg</file>

View File

@ -48,15 +48,15 @@ public:
{
switch (s) {
case Sound::Test:
return QStringLiteral(":/audio/notification.pcm");
return QStringLiteral(":/audio/notification.s16le.pcm");
case Sound::NewMessage:
return QStringLiteral(":/audio/notification.pcm");
return QStringLiteral(":/audio/notification.s16le.pcm");
case Sound::IncomingCall:
return QStringLiteral(":/audio/ToxIncomingCall.pcm");
return QStringLiteral(":/audio/ToxIncomingCall.s16le.pcm");
case Sound::OutgoingCall:
return QStringLiteral(":/audio/ToxOutgoingCall.pcm");
return QStringLiteral(":/audio/ToxOutgoingCall.s16le.pcm");
case Sound::CallEnd:
return QStringLiteral(":/audio/ToxEndCall.pcm");
return QStringLiteral(":/audio/ToxEndCall.s16le.pcm");
}
assert(false);
return QString();
@ -109,6 +109,7 @@ public:
protected:
// Public default audio settings
// Samplerate for Tox calls and sounds
static constexpr uint32_t AUDIO_SAMPLE_RATE = 48000;
static constexpr uint32_t AUDIO_FRAME_DURATION = 20;
static constexpr uint32_t AUDIO_FRAME_SAMPLE_COUNT_PER_CHANNEL =

View File

@ -377,7 +377,7 @@ bool OpenAL::initOutput(const QString& deviceName)
}
/**
* @brief Play a 44100Hz mono 16bit PCM sound from a file
* @brief Play a 48kHz mono 16bit PCM sound from a file
*
* @param[in] path the path to the sound file
*/
@ -389,7 +389,7 @@ void OpenAL::playMono16Sound(const QString& path)
}
/**
* @brief Play a 44100Hz mono 16bit PCM sound
* @brief Play a 48kHz mono 16bit PCM sound
*/
void OpenAL::playMono16Sound(const QByteArray& data)
{
@ -408,11 +408,11 @@ void OpenAL::playMono16Sound(const QByteArray& data)
alSourcei(alMainSource, AL_BUFFER, AL_NONE);
}
alBufferData(alMainBuffer, AL_FORMAT_MONO16, data.constData(), data.size(), 44100);
alBufferData(alMainBuffer, AL_FORMAT_MONO16, data.constData(), data.size(), AUDIO_SAMPLE_RATE);
alSourcei(alMainSource, AL_BUFFER, static_cast<ALint>(alMainBuffer));
alSourcePlay(alMainSource);
int durationMs = data.size() * 1000 / 2 / 44100;
int durationMs = data.size() * 1000 / 2 / AUDIO_SAMPLE_RATE;
QMetaObject::invokeMethod(&playMono16Timer, "start", Q_ARG(int, durationMs + 50));
}