-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add FLAC export and related options #3731
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
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
5f1c9dc
Add FLAC export, based on WAV renderer
b41bbab
Indent with TAB character
irrenhaus3 ed7a4b6
Depend on sndfile>=1.0.18 (previously >=1.0.11)
irrenhaus3 d7bb49a
Introduces new CPP definition LMMS_SF_HAVE_CMPLEVEL
irrenhaus3 36354a8
Add compression option to FLAC export, if available.
irrenhaus3 8fe7994
Save into the correct file extension upon export.
irrenhaus3 5ba265f
Use unique_ptr in FLAC renderer and be more expressive about involved…
irrenhaus3 caba25e
Enable compression setting unconditionally, only use the SF_COMPLEVEL…
irrenhaus3 f89475d
Use unique_ptr and remove manual memory management in ExportProjectDi…
irrenhaus3 dfe6a69
Populate compLevelCB unconditionally and make its strings translatable.
irrenhaus3 9d24ebc
Remove unused #include statement.
irrenhaus3 14b6ce3
Fixed a silly typo.
irrenhaus3 20cbfbf
Remove use of deprecated symbol QApplication::UnicodeUTF8
irrenhaus3 65443db
Added copyright information
irrenhaus3 d7ee49c
Adapt file extension only in single-export mode.
irrenhaus3 18cda1d
Add 'flac' format info to --help and manpage
irrenhaus3 597d947
Code style
irrenhaus3 597bc8f
More code style
irrenhaus3 2c3cb02
CMakeLists says: FLAC's pretty OK.
irrenhaus3 521c08c
Yet more code style.
irrenhaus3 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| /* | ||
| * AudioFileFlac.h - Audio device which encodes a wave stream into a FLAC file. | ||
| * | ||
| * Copyright (c) 2017 to present Levin Oehlmann <irrenhaus3/at/gmail[dot]com> et al. | ||
| * | ||
| * 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_FLAC_H | ||
| #define AUDIO_FILE_FLAC_H | ||
|
|
||
| #include "lmmsconfig.h" | ||
|
|
||
| #include "AudioFileDevice.h" | ||
| #include <sndfile.h> | ||
|
|
||
| class AudioFileFlac: public AudioFileDevice | ||
| { | ||
| public: | ||
| AudioFileFlac(OutputSettings const& outputSettings, | ||
| ch_cnt_t const channels, | ||
| bool& successful, | ||
| QString const& file, | ||
| Mixer* mixer | ||
| ); | ||
|
|
||
| virtual ~AudioFileFlac(); | ||
|
|
||
| static AudioFileDevice* getInst(QString const& outputFilename, | ||
| OutputSettings const& outputSettings, | ||
| ch_cnt_t const channels, | ||
| Mixer* mixer, | ||
| bool& successful) | ||
| { | ||
| return new AudioFileFlac( | ||
| outputSettings, | ||
| channels, | ||
| successful, | ||
| outputFilename, | ||
| mixer | ||
| ); | ||
| } | ||
|
|
||
| private: | ||
|
|
||
| SF_INFO m_sfinfo; | ||
| SNDFILE* m_sf; | ||
|
|
||
| virtual void writeBuffer(surroundSampleFrame const* _ab, | ||
| fpp_t const frames, | ||
| float master_gain) override; | ||
|
|
||
| bool startEncoding(); | ||
| void finishEncoding(); | ||
|
|
||
| }; | ||
|
|
||
| #endif //AUDIO_FILE_FLAC_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| /* | ||
| * AudioFileFlac.cpp - Audio device which encodes a wave stream into a FLAC file (Implementation). | ||
| * | ||
| * Copyright (c) 2017 to present Levin Oehlmann <irrenhaus3/at/gmail[dot]com> et al. | ||
| * | ||
| * 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. | ||
| * | ||
| */ | ||
|
|
||
| #include <memory> | ||
|
|
||
| #include "AudioFileFlac.h" | ||
| #include "endian_handling.h" | ||
| #include "Mixer.h" | ||
|
|
||
| AudioFileFlac::AudioFileFlac(OutputSettings const& outputSettings, ch_cnt_t const channels, bool& successful, QString const& file, Mixer* mixer): | ||
| AudioFileDevice(outputSettings,channels,file,mixer), | ||
| m_sf(nullptr) | ||
| { | ||
| successful = outputFileOpened() && startEncoding(); | ||
| } | ||
|
|
||
| AudioFileFlac::~AudioFileFlac() | ||
| { | ||
| finishEncoding(); | ||
| } | ||
|
|
||
| bool AudioFileFlac::startEncoding() | ||
| { | ||
| m_sfinfo.samplerate=sampleRate(); | ||
| m_sfinfo.channels=channels(); | ||
| m_sfinfo.frames = mixer()->framesPerPeriod(); | ||
| m_sfinfo.sections=1; | ||
| m_sfinfo.seekable=0; | ||
|
|
||
| m_sfinfo.format = SF_FORMAT_FLAC; | ||
|
|
||
| switch (getOutputSettings().getBitDepth()) | ||
| { | ||
| case OutputSettings::Depth_24Bit: | ||
| case OutputSettings::Depth_32Bit: | ||
| // FLAC does not support 32bit sampling, so take it as 24. | ||
| m_sfinfo.format |= SF_FORMAT_PCM_24; | ||
| break; | ||
| default: | ||
| m_sfinfo.format |= SF_FORMAT_PCM_16; | ||
| } | ||
|
|
||
| #ifdef LMMS_HAVE_SF_COMPLEVEL | ||
| double compression = getOutputSettings().getCompressionLevel(); | ||
| sf_command(m_sf, SFC_SET_COMPRESSION_LEVEL, &compression, sizeof(double)); | ||
| #endif | ||
|
|
||
| m_sf = sf_open( | ||
| #ifdef LMMS_BUILD_WIN32 | ||
| outputFile().toLocal8Bit().constData(), | ||
| #else | ||
| outputFile().toUtf8().constData(), | ||
| #endif | ||
| SFM_WRITE, | ||
| &m_sfinfo | ||
| ); | ||
|
|
||
| sf_command(m_sf, SFC_SET_CLIPPING, nullptr, SF_TRUE); | ||
|
|
||
| sf_set_string(m_sf, SF_STR_SOFTWARE, "LMMS"); | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| void AudioFileFlac::writeBuffer(surroundSampleFrame const* _ab, fpp_t const frames, float master_gain) | ||
| { | ||
| OutputSettings::BitDepth depth = getOutputSettings().getBitDepth(); | ||
|
|
||
| if (depth == OutputSettings::Depth_24Bit || depth == OutputSettings::Depth_32Bit) // Float encoding | ||
| { | ||
| std::unique_ptr<sample_t[]> buf{ new sample_t[frames*channels()] }; | ||
| for(fpp_t frame = 0; frame < frames; ++frame) | ||
| { | ||
| for(ch_cnt_t channel=0; channel<channels(); ++channel) | ||
| { | ||
| buf[frame*channels() + channel] = _ab[frame][channel] * master_gain; | ||
| } | ||
| } | ||
| sf_writef_float(m_sf,static_cast<float*>(buf.get()),frames); | ||
| } | ||
| else // integer PCM encoding | ||
| { | ||
| std::unique_ptr<int_sample_t[]> buf{ new int_sample_t[frames*channels()] }; | ||
| convertToS16(_ab, frames, master_gain, buf.get(), !isLittleEndian()); | ||
| sf_writef_short(m_sf, static_cast<short*>(buf.get()), frames); | ||
| } | ||
|
|
||
| } | ||
|
|
||
|
|
||
| void AudioFileFlac::finishEncoding() | ||
| { | ||
| if (m_sf) | ||
| { | ||
| sf_write_sync(m_sf); | ||
| sf_close(m_sf); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here, too.