Skip to content

Commit

Permalink
FEAT(client): Add MP3 Recording
Browse files Browse the repository at this point in the history
  • Loading branch information
Chinry committed Oct 9, 2023
1 parent 0310159 commit 21ad3cf
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/mumble/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,13 @@ else()
message(WARNING "libsndfile is missing Opus-support -> No Opus-format recording")
endif()

# Check if sndfile version supports mp3
if("${sndfile_VERSION}" VERSION_GREATER_EQUAL "1.1.0")
target_compile_definitions(mumble_client_object_lib PUBLIC USE_SNDFILE_MP3)
else()
message(WARNING "libsndfile is missing Mp3-support -> No Mp3-format recording")
endif()

# Look for various targets as they are named differently on different platforms
if(static AND TARGET sndfile-static)
target_link_libraries(mumble_client_object_lib PUBLIC sndfile-static)
Expand Down
32 changes: 31 additions & 1 deletion src/mumble/VoiceRecorder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ QString VoiceRecorder::sanitizeFilenameOrPathComponent(const QString &str) const
}
#else
// For the rest just make sure the string doesn't contain a \0 or any forward-slashes
res = res.replace(QRegExp(QLatin1String("\\x00|/")), QLatin1String("_"));
res = res.replace(QRegExp(QLatin1String("\\x00|/")), QLatin1String("_"));
#endif
return res;
}
Expand Down Expand Up @@ -223,6 +223,18 @@ SF_INFO VoiceRecorder::createSoundFileInfo() const {
qWarning() << "VoiceRecorder: recording started to" << m_config.fileName << "@" << m_config.sampleRate
<< "hz in OPUS format";
break;
#endif
#ifdef USE_SNDFILE_MP3
case VoiceRecorderFormat::MP3:
sfinfo.frames = 0;
sfinfo.samplerate = m_config.sampleRate;
sfinfo.channels = 1;
sfinfo.format = SF_FORMAT_MPEG | SF_FORMAT_MPEG_LAYER_III;
sfinfo.sections = 0;
sfinfo.seekable = 0;
qWarning() << "VoiceRecorder: recording started to" << m_config.fileName << "@" << m_config.sampleRate
<< "hz in MP3 format";
break;
#endif
}

Expand Down Expand Up @@ -277,6 +289,16 @@ bool VoiceRecorder::ensureFileIsOpenedFor(SF_INFO &soundFileInfo, boost::shared_
return false;
}

#ifdef USE_SNDFILE_MP3
// Enable constant 320kbps for MP3 formats
if (m_config.recordingFormat == VoiceRecorderFormat::MP3) {
int bitrate = SF_BITRATE_MODE_CONSTANT;
double compression = 0.0;
sf_command(ri->soundFile, SFC_SET_BITRATE_MODE, &bitrate, sizeof(int));
sf_command(ri->soundFile, SFC_SET_COMPRESSION_LEVEL, &compression, sizeof(double));
}
#endif

// 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));

Expand Down Expand Up @@ -445,6 +467,10 @@ QString VoiceRecorderFormat::getFormatDescription(VoiceRecorderFormat::Format fm
#ifdef USE_SNDFILE_OPUS
case VoiceRecorderFormat::OPUS:
return VoiceRecorder::tr(".opus - Lossy compressed");
#endif
#ifdef USE_SNDFILE_MP3
case VoiceRecorderFormat::MP3:
return VoiceRecorder::tr(".mp3 - Lossy compressed");
#endif
default:
return QString();
Expand All @@ -466,6 +492,10 @@ QString VoiceRecorderFormat::getFormatDefaultExtension(VoiceRecorderFormat::Form
#ifdef USE_SNDFILE_OPUS
case VoiceRecorderFormat::OPUS:
return QLatin1String("opus");
#endif
#ifdef USE_SNDFILE_MP3
case VoiceRecorderFormat::MP3:
return QLatin1String("mp3");
#endif
default:
return QString();
Expand Down
3 changes: 3 additions & 0 deletions src/mumble/VoiceRecorder.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ enum Format {
#ifdef USE_SNDFILE_OPUS
// OPUS Format
OPUS,
#endif
#ifdef USE_SNDFILE_MP3
MP3,
#endif
kEnd
};
Expand Down

0 comments on commit 21ad3cf

Please sign in to comment.