Skip to content
This repository has been archived by the owner on Feb 12, 2023. It is now read-only.

Commit

Permalink
fix(audio): specify format for sounds and make sounds follow it
Browse files Browse the repository at this point in the history
This should reduce the problem that some sounds are very silent and some are loud.
  • Loading branch information
sudden6 committed Sep 20, 2018
1 parent 064dccf commit 5d65ab3
Show file tree
Hide file tree
Showing 16 changed files with 31 additions and 13 deletions.
Binary file removed audio/ToxEndCall.pcm
Binary file not shown.
Binary file added audio/ToxEndCall.s16le.pcm
Binary file not shown.
Binary file removed audio/ToxIncomingCall.pcm
Binary file not shown.
Binary file added audio/ToxIncomingCall.s16le.pcm
Binary file not shown.
Binary file removed audio/ToxOutgoingCall.pcm
Binary file not shown.
Binary file added audio/ToxOutgoingCall.s16le.pcm
Binary file not shown.
17 changes: 17 additions & 0 deletions audio/format.md
Original file line number Diff line number Diff line change
@@ -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 removed audio/notification.pcm
Binary file not shown.
Binary file added audio/notification.s16le.pcm
Binary file not shown.
Binary file added audio/original/ToxEndCall.wav
Binary file not shown.
Binary file added audio/original/ToxIncomingCall.wav
Binary file not shown.
Binary file added audio/original/ToxOutgoingCall.wav
Binary file not shown.
Binary file added audio/original/notification.wav
Binary file not shown.
8 changes: 4 additions & 4 deletions res.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
11 changes: 6 additions & 5 deletions src/audio/audio.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ class Audio : public QObject
{
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();
Expand Down Expand Up @@ -109,6 +109,7 @@ class Audio : public QObject

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 =
Expand Down
8 changes: 4 additions & 4 deletions src/audio/backend/openal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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)
{
Expand All @@ -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));
}

Expand Down

0 comments on commit 5d65ab3

Please sign in to comment.