Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement #2000 ("Add mp3 encoding and/or decoding support") #3615

Merged
merged 8 commits into from
Jun 12, 2017
2 changes: 1 addition & 1 deletion .travis/linux..install.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

PACKAGES="cmake libsndfile-dev fftw3-dev libvorbis-dev libogg-dev
PACKAGES="cmake libsndfile-dev fftw3-dev libvorbis-dev libogg-dev libmp3lame-dev
libasound2-dev libjack-dev libsdl-dev libsamplerate0-dev libstk0-dev
libfluidsynth-dev portaudio19-dev wine-dev g++-multilib libfltk1.3-dev
libgig-dev libsoundio-dev"
Expand Down
2 changes: 1 addition & 1 deletion .travis/linux.win32.install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ MINGW_PACKAGES="mingw32-x-sdl mingw32-x-libvorbis mingw32-x-fluidsynth mingw32-x
mingw32-x-glib2 mingw32-x-portaudio mingw32-x-libsndfile mingw32-x-fftw
mingw32-x-flac mingw32-x-fltk mingw32-x-libsamplerate
mingw32-x-pkgconfig mingw32-x-binutils mingw32-x-gcc mingw32-x-runtime
mingw32-x-libgig mingw32-x-libsoundio $MINGW_PACKAGES"
mingw32-x-libgig mingw32-x-libsoundio mingw32-x-lame $MINGW_PACKAGES"

export MINGW_PACKAGES

Expand Down
2 changes: 1 addition & 1 deletion .travis/linux.win64.install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ MINGW_PACKAGES="mingw64-x-sdl mingw64-x-libvorbis mingw64-x-fluidsynth mingw64-x
mingw64-x-glib2 mingw64-x-portaudio mingw64-x-libsndfile
mingw64-x-fftw mingw64-x-flac mingw64-x-fltk mingw64-x-libsamplerate
mingw64-x-pkgconfig mingw64-x-binutils mingw64-x-gcc mingw64-x-runtime
mingw64-x-libgig mingw64-x-libsoundio $MINGW_PACKAGES"
mingw64-x-libgig mingw64-x-libsoundio mingw64-x-lame $MINGW_PACKAGES"

export MINGW_PACKAGES

Expand Down
2 changes: 1 addition & 1 deletion .travis/osx..install.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

PACKAGES="cmake pkgconfig fftw libogg libvorbis libsndfile libsamplerate jack sdl libgig libsoundio stk portaudio node fltk"
PACKAGES="cmake pkgconfig fftw libogg libvorbis lame libsndfile libsamplerate jack sdl libgig libsoundio stk portaudio node fltk"

if [ $QT5 ]; then
PACKAGES="$PACKAGES homebrew/versions/qt55"
Expand Down
17 changes: 17 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ OPTION(WANT_CAPS "Include C* Audio Plugin Suite (LADSPA plugins)" ON)
OPTION(WANT_CARLA "Include Carla plugin" ON)
OPTION(WANT_CMT "Include Computer Music Toolkit LADSPA plugins" ON)
OPTION(WANT_JACK "Include JACK (Jack Audio Connection Kit) support" ON)
OPTION(WANT_MP3LAME "Include MP3/Lame support" ON)
OPTION(WANT_OGGVORBIS "Include OGG/Vorbis support" ON)
OPTION(WANT_PULSEAUDIO "Include PulseAudio support" ON)
OPTION(WANT_PORTAUDIO "Include PortAudio support" ON)
Expand Down Expand Up @@ -306,6 +307,21 @@ IF(NOT LMMS_HAVE_PULSEAUDIO)
ENDIF(NOT LMMS_HAVE_PULSEAUDIO)


# check for MP3/Lame-libraries
IF(WANT_MP3LAME)
FIND_PACKAGE(Lame)
IF(LAME_FOUND)
SET(LMMS_HAVE_MP3LAME TRUE)
SET(STATUS_MP3LAME "OK")
ELSE(LAME_FOUND)
SET(STATUS_MP3LAME "not found, please install libmp3lame-dev (or similar)")
SET(LAME_LIBRARIES "")
SET(LAME_INCLUDE_DIRS "")
ENDIF(LAME_FOUND)
ELSE(WANT_MP3LAME)
SET(STATUS_MP3LAME "Disabled for build")
ENDIF(WANT_MP3LAME)

# check for OGG/Vorbis-libraries
IF(WANT_OGGVORBIS)
FIND_PACKAGE(OggVorbis)
Expand Down Expand Up @@ -593,6 +609,7 @@ MESSAGE(
"-----------------------------------------\n"
"* WAVE : OK\n"
"* OGG/VORBIS : ${STATUS_OGGVORBIS}\n"
"* MP3/Lame : ${STATUS_MP3LAME}\n"
)

MESSAGE(
Expand Down
16 changes: 16 additions & 0 deletions cmake/modules/FindLame.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# - Try to find LAME
# Once done this will define
#
# LAME_FOUND - system has liblame
# LAME_INCLUDE_DIRS - the liblame include directory
# LAME_LIBRARIES - The liblame libraries

find_path(LAME_INCLUDE_DIRS lame/lame.h)
find_library(LAME_LIBRARIES mp3lame)

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Lame DEFAULT_MSG LAME_INCLUDE_DIRS LAME_LIBRARIES)

list(APPEND LAME_DEFINITIONS -DHAVE_LIBMP3LAME=1)

mark_as_advanced(LAME_INCLUDE_DIRS LAME_LIBRARIES LAME_DEFINITIONS)
74 changes: 74 additions & 0 deletions include/AudioFileMP3.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* AudioFileMP3.h - Audio-device which encodes a wave stream into
* an MP3 file. This is used for song export.
*
* Copyright (c) 2017 to present Michael Gregorius <michael.gregorius.git/at/arcor[dot]de>
*
* This file is part of LMMS - https://lmms.io
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program (see COPYING); if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
*/

#ifndef AUDIO_FILE_MP3_H
#define AUDIO_FILE_MP3_H

#include "lmmsconfig.h"

#ifdef LMMS_HAVE_MP3LAME

#include "AudioFileDevice.h"

#include "lame/lame.h"


class AudioFileMP3 : public AudioFileDevice
{
public:
AudioFileMP3( OutputSettings const & outputSettings,
const ch_cnt_t _channels,
bool & successful,
const QString & _file,
Mixer* mixer );
virtual ~AudioFileMP3();

static AudioFileDevice * getInst( const QString & outputFilename,
OutputSettings const & outputSettings,
const ch_cnt_t channels,
Mixer* mixer,
bool & successful )
{
return new AudioFileMP3( outputSettings, channels, successful,
outputFilename, mixer );
}

protected:
virtual void writeBuffer( const surroundSampleFrame * /* _buf*/,
const fpp_t /*_frames*/,
const float /*_master_gain*/ );

private:
void flushRemainingBuffers();
bool initEncoder();
void tearDownEncoder();

private:
lame_t m_lame;
};

#endif

#endif
24 changes: 22 additions & 2 deletions include/OutputSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ class OutputSettings
NumDepths
};

enum StereoMode
{
StereoMode_Stereo,
StereoMode_JointStereo,
StereoMode_Mono
};

class BitRateSettings
{
public:
Expand All @@ -60,10 +67,19 @@ class OutputSettings
public:
OutputSettings( sample_rate_t sampleRate,
BitRateSettings const & bitRateSettings,
BitDepth bitDepth ) :
BitDepth bitDepth,
StereoMode stereoMode ) :
m_sampleRate(sampleRate),
m_bitRateSettings(bitRateSettings),
m_bitDepth(bitDepth)
m_bitDepth(bitDepth),
m_stereoMode(stereoMode)
{
}

OutputSettings( sample_rate_t sampleRate,
BitRateSettings const & bitRateSettings,
BitDepth bitDepth ) :
OutputSettings(sampleRate, bitRateSettings, bitDepth, StereoMode_Stereo )
{
}

Expand All @@ -76,10 +92,14 @@ class OutputSettings
BitDepth getBitDepth() const { return m_bitDepth; }
void setBitDepth(BitDepth bitDepth) { m_bitDepth = bitDepth; }

StereoMode getStereoMode() const { return m_stereoMode; }
void setStereoMode(StereoMode stereoMode) { m_stereoMode = stereoMode; }

private:
sample_rate_t m_sampleRate;
BitRateSettings m_bitRateSettings;
BitDepth m_bitDepth;
StereoMode m_stereoMode;
};

#endif
3 changes: 3 additions & 0 deletions include/ProjectRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,14 @@ class ProjectRenderer : public QThread
{
WaveFile,
OggFile,
MP3File,
NumFileFormats
} ;

struct FileEncodeDevice
{
bool isAvailable() const { return m_getDevInst != nullptr; }

ExportFileFormats m_fileFormat;
const char * m_description;
const char * m_extension;
Expand Down
6 changes: 6 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ IF(NOT ("${OGGVORBIS_INCLUDE_DIR}" STREQUAL ""))
INCLUDE_DIRECTORIES("${OGGVORBIS_INCLUDE_DIR}")
ENDIF()

IF(NOT ("${LAME_INCLUDE_DIRS}" STREQUAL ""))
INCLUDE_DIRECTORIES("${LAME_INCLUDE_DIRS}")
ENDIF()

# Use libraries in non-standard directories (e.g., another version of Qt)
IF(LMMS_BUILD_LINUX)
LINK_LIBRARIES(-Wl,--enable-new-dtags)
Expand Down Expand Up @@ -139,6 +143,7 @@ SET(LMMS_REQUIRED_LIBS
${PULSEAUDIO_LIBRARIES}
${JACK_LIBRARIES}
${OGGVORBIS_LIBRARIES}
${LAME_LIBRARIES}
Copy link
Member

@tresf tresf Jun 7, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the way CMake works on all of these libraries, if can't find lame, the LAME_LIBRARIES variable will be a value of LAME_LIBRARIES-NOTFOUND which will abort the build. This is a problem with our build scripts and not necessarily a problem with this PR, but once merged, people without the proper lame libraries will get build errors, hence this comment about the "trick" mentioned here. #3615 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So something like this, @tresf?

IF(WANT_MP3LAME)
	FIND_PACKAGE(Lame)
	IF(LAME_FOUND)
		SET(LMMS_HAVE_MP3LAME TRUE)
		SET(STATUS_MP3LAME "OK")
	ELSE(LAME_FOUND)
		SET(STATUS_MP3LAME "not found, please install libmp3lame-dev (or similar)")
		SET(LAME_LIBRARIES "")
		SET(LAME_INCLUDE_DIRS "")
	ENDIF(LAME_FOUND)
ELSE(WANT_MP3LAME)
	SET(STATUS_MP3LAME "Disabled for build")
ENDIF(WANT_MP3LAME)

On the other hand wouldn't it be cleaner to have a structure like the following in src/CMakeLists.txt?

IF(LMMS_HAVE_MP3LAME) # alternatively use LAME_FOUND
# Add include directory for lame here
# Add library for lame here
ENDIF()

${SAMPLERATE_LIBRARIES}
${SNDFILE_LIBRARIES}
${EXTRA_LIBRARIES}
Expand Down Expand Up @@ -194,6 +199,7 @@ IF(LMMS_BUILD_WIN32)
"${MINGW_PREFIX}/bin/libvorbisfile-3.dll"
"${MINGW_PREFIX}/bin/libjpeg-9.dll"
"${MINGW_PREFIX}/bin/libogg-0.dll"
"${MINGW_PREFIX}/bin/libmp3lame-0.dll"
"${MINGW_PREFIX}/bin/libfftw3f-3.dll"
"${MINGW_PREFIX}/bin/libFLAC-8.dll"
"${MINGW_PREFIX}/bin/libpng16-16.dll"
Expand Down
1 change: 1 addition & 0 deletions src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ set(LMMS_SRCS
core/audio/AudioAlsa.cpp
core/audio/AudioDevice.cpp
core/audio/AudioFileDevice.cpp
core/audio/AudioFileMP3.cpp
core/audio/AudioFileOgg.cpp
core/audio/AudioFileWave.cpp
core/audio/AudioJack.cpp
Expand Down
10 changes: 10 additions & 0 deletions src/core/ProjectRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

#include "AudioFileWave.h"
#include "AudioFileOgg.h"
#include "AudioFileMP3.h"

#ifdef LMMS_HAVE_SCHED_H
#include "sched.h"
Expand All @@ -48,6 +49,15 @@ const ProjectRenderer::FileEncodeDevice ProjectRenderer::fileEncodeDevices[] =
&AudioFileOgg::getInst
#else
NULL
#endif
},
{ ProjectRenderer::MP3File,
QT_TRANSLATE_NOOP( "ProjectRenderer", "Compressed MP3-File (*.mp3)" ),
".mp3",
#ifdef LMMS_HAVE_MP3LAME
&AudioFileMP3::getInst
#else
NULL
#endif
},
// ... insert your own file-encoder-infos here... may be one day the
Expand Down
3 changes: 2 additions & 1 deletion src/core/Song.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1316,7 +1316,8 @@ void Song::exportProject( bool multiExport )
efd.setFileMode( FileDialog::AnyFile );
int idx = 0;
QStringList types;
while( ProjectRenderer::fileEncodeDevices[idx].m_fileFormat != ProjectRenderer::NumFileFormats )
while( ProjectRenderer::fileEncodeDevices[idx].m_fileFormat != ProjectRenderer::NumFileFormats &&
ProjectRenderer::fileEncodeDevices[idx].isAvailable())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@michaelgregorius This logic malfunctions if LMMS is built with WAV + MP3 support (no OGG). I found it while testing #3714.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PhysSong Good catch! For now I have asked @irrenhaus3 whether (s)he can fix it as part of #3713.

{
types << tr( ProjectRenderer::fileEncodeDevices[idx].m_description );
++idx;
Expand Down
Loading