Skip to content
Browse files

Fix "Inverted samples in WAV recording when clipping" #971

When libsndfile is handed float data but asked to write it in a
non-float format by default wrapping behavior occurs. This lead to
very audible artifacts in recordings for those file types.

This fix enables hard-clipping behavior in libsndfile for non-float
file formats by setting the SFC_SET_CLIPPING property to true.
  • Loading branch information...
hacst committed Nov 8, 2013
1 parent ed424af commit 8e22f9a2110907df0cf49dc1a838da3e6043bbb5
Showing with 10 additions and 0 deletions.
  1. +10 −0 src/mumble/VoiceRecorder.cpp
@@ -201,6 +201,9 @@ int VoiceRecorder::indexForUser(const ClientUser *clientUser) const {
SF_INFO VoiceRecorder::createSoundFileInfo() const {
Q_ASSERT(m_config.sampleRate != 0);

// When adding new formats make sure to properly configure needed additional
// behavior after opening the file handle (e.g. to enable clipping).

// Convert |fmFormat| to a SF_INFO structure for libsndfile.
SF_INFO sfinfo;
switch (m_config.recordingFormat) {
@@ -301,6 +304,13 @@ bool VoiceRecorder::ensureFileIsOpenedFor(SF_INFO& soundFileInfo, boost::shared_

// Store the username in the title attribute of the file (if supported by the format).
sf_set_string(ri->soundFile, SF_STR_TITLE, qPrintable(ri->userName));

// Enable hard-clipping for non-float formats to prevent wrapping
if (!(soundFileInfo.format & SF_FORMAT_FLOAT) &&
!(soundFileInfo.format & SF_FORMAT_VORBIS)) {

sf_command(ri->soundFile, SFC_SET_CLIPPING, NULL, SF_TRUE);

return true;

0 comments on commit 8e22f9a

Please sign in to comment.
You can’t perform that action at this time.