Skip to content

Commit 5d65ab3

Browse files
committed
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.
1 parent 064dccf commit 5d65ab3

16 files changed

+31
-13
lines changed

audio/ToxEndCall.pcm

-97.6 KB
Binary file not shown.

audio/ToxEndCall.s16le.pcm

48.8 KB
Binary file not shown.

audio/ToxIncomingCall.pcm

-293 KB
Binary file not shown.

audio/ToxIncomingCall.s16le.pcm

159 KB
Binary file not shown.

audio/ToxOutgoingCall.pcm

-348 KB
Binary file not shown.

audio/ToxOutgoingCall.s16le.pcm

189 KB
Binary file not shown.

audio/format.md

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

audio/notification.pcm

-33.1 KB
Binary file not shown.

audio/notification.s16le.pcm

36.1 KB
Binary file not shown.

audio/original/ToxEndCall.wav

97.9 KB
Binary file not shown.

audio/original/ToxIncomingCall.wav

293 KB
Binary file not shown.

audio/original/ToxOutgoingCall.wav

348 KB
Binary file not shown.

audio/original/notification.wav

33.2 KB
Binary file not shown.

res.qrc

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
<file alias="DejaVuSans.ttf">res/font/DejaVuSans.ttf</file>
77
</qresource>
88
<qresource prefix="/">
9-
<file>audio/notification.pcm</file>
10-
<file>audio/ToxIncomingCall.pcm</file>
11-
<file>audio/ToxOutgoingCall.pcm</file>
12-
<file>audio/ToxEndCall.pcm</file>
9+
<file>audio/notification.s16le.pcm</file>
10+
<file>audio/ToxIncomingCall.s16le.pcm</file>
11+
<file>audio/ToxOutgoingCall.s16le.pcm</file>
12+
<file>audio/ToxEndCall.s16le.pcm</file>
1313
<file>img/add.svg</file>
1414
<file>img/avatar_mask.svg</file>
1515
<file>img/contact.svg</file>

src/audio/audio.h

+6-5
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,15 @@ class Audio : public QObject
4848
{
4949
switch (s) {
5050
case Sound::Test:
51-
return QStringLiteral(":/audio/notification.pcm");
51+
return QStringLiteral(":/audio/notification.s16le.pcm");
5252
case Sound::NewMessage:
53-
return QStringLiteral(":/audio/notification.pcm");
53+
return QStringLiteral(":/audio/notification.s16le.pcm");
5454
case Sound::IncomingCall:
55-
return QStringLiteral(":/audio/ToxIncomingCall.pcm");
55+
return QStringLiteral(":/audio/ToxIncomingCall.s16le.pcm");
5656
case Sound::OutgoingCall:
57-
return QStringLiteral(":/audio/ToxOutgoingCall.pcm");
57+
return QStringLiteral(":/audio/ToxOutgoingCall.s16le.pcm");
5858
case Sound::CallEnd:
59-
return QStringLiteral(":/audio/ToxEndCall.pcm");
59+
return QStringLiteral(":/audio/ToxEndCall.s16le.pcm");
6060
}
6161
assert(false);
6262
return QString();
@@ -109,6 +109,7 @@ class Audio : public QObject
109109

110110
protected:
111111
// Public default audio settings
112+
// Samplerate for Tox calls and sounds
112113
static constexpr uint32_t AUDIO_SAMPLE_RATE = 48000;
113114
static constexpr uint32_t AUDIO_FRAME_DURATION = 20;
114115
static constexpr uint32_t AUDIO_FRAME_SAMPLE_COUNT_PER_CHANNEL =

src/audio/backend/openal.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ bool OpenAL::initOutput(const QString& deviceName)
377377
}
378378

379379
/**
380-
* @brief Play a 44100Hz mono 16bit PCM sound from a file
380+
* @brief Play a 48kHz mono 16bit PCM sound from a file
381381
*
382382
* @param[in] path the path to the sound file
383383
*/
@@ -389,7 +389,7 @@ void OpenAL::playMono16Sound(const QString& path)
389389
}
390390

391391
/**
392-
* @brief Play a 44100Hz mono 16bit PCM sound
392+
* @brief Play a 48kHz mono 16bit PCM sound
393393
*/
394394
void OpenAL::playMono16Sound(const QByteArray& data)
395395
{
@@ -408,11 +408,11 @@ void OpenAL::playMono16Sound(const QByteArray& data)
408408
alSourcei(alMainSource, AL_BUFFER, AL_NONE);
409409
}
410410

411-
alBufferData(alMainBuffer, AL_FORMAT_MONO16, data.constData(), data.size(), 44100);
411+
alBufferData(alMainBuffer, AL_FORMAT_MONO16, data.constData(), data.size(), AUDIO_SAMPLE_RATE);
412412
alSourcei(alMainSource, AL_BUFFER, static_cast<ALint>(alMainBuffer));
413413
alSourcePlay(alMainSource);
414414

415-
int durationMs = data.size() * 1000 / 2 / 44100;
415+
int durationMs = data.size() * 1000 / 2 / AUDIO_SAMPLE_RATE;
416416
QMetaObject::invokeMethod(&playMono16Timer, "start", Q_ARG(int, durationMs + 50));
417417
}
418418

0 commit comments

Comments
 (0)