Skip to content

Commit

Permalink
FEAT(client): Add interaural delay
Browse files Browse the repository at this point in the history
There is a small time delay (interaural time delay or ITD) between your
ears depending on the sound source position on the horizontal plane and
the distance between your ears. This commit will add this delay by using
the extra sound data in the audio buffer.

For me at least, implementing this makes it much easier to identify
where a sound is coming from when positional audio is enabled.

Implements mumble-voip#2324
  • Loading branch information
Epicalert committed Jun 2, 2021
1 parent 0af1dfb commit f875f92
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/mumble/Audio.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

#define SAMPLE_RATE 48000

// interaural delay (in samples) for a sound coming directly from the side of the head
#define INTERAURAL_DELAY 0.0006 / (1 / static_cast< float >(SAMPLE_RATE))

typedef QPair< QString, QVariant > audioDevice;

class LoopUser : public ClientUser {
Expand Down
5 changes: 3 additions & 2 deletions src/mumble/AudioOutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,7 @@ bool AudioOutput::mix(void *outbuff, unsigned int frameCount) {
const float old = (aop->pfVolume[s] >= 0.0f) ? aop->pfVolume[s] : str;
const float inc = (str - old) / static_cast< float >(frameCount);
aop->pfVolume[s] = str;
const unsigned int offset = INTERAURAL_DELAY * (1.0 + dot) / 2.0;
/*
qWarning("%d: Pos %f %f %f : Dot %f Len %f Str %f", s, speaker[s*3+0],
speaker[s*3+1], speaker[s*3+2], dot, len, str);
Expand All @@ -607,10 +608,10 @@ bool AudioOutput::mix(void *outbuff, unsigned int frameCount) {
if (speech && speech->bStereo) {
// Mix stereo user's stream into mono
// frame: for a stereo stream, the [LR] pair inside ...[LR]LRLRLR.... is a frame
o[i * nchan] += (pfBuffer[2 * i] / 2.0 + pfBuffer[2 * i + 1] / 2.0)
o[i * nchan] += (pfBuffer[2 * i + offset] / 2.0 + pfBuffer[2 * i + offset + 1] / 2.0)
* (old + inc * static_cast< float >(i));
} else {
o[i * nchan] += pfBuffer[i] * (old + inc * static_cast< float >(i));
o[i * nchan] += pfBuffer[i + offset] * (old + inc * static_cast< float >(i));
}
}
}
Expand Down

0 comments on commit f875f92

Please sign in to comment.