17#include <rapidjson/document.h>
24#include "FLAC++/encoder.h"
50const std::initializer_list<PlainExportOptionsEditor::OptionDesc>
FlacOptions {
56 { std::string(
"16"), std::string(
"24") },
57 {
XO(
"16 bit") ,
XO(
"24 bit") }
58 },
wxT(
"/FileFormats/FLACBitDepth")
87 },
wxT(
"/FileFormats/FLACLevel")
94 wxT(
"/FileFormats/FLACBitDepth"),
97 {
XO(
"16 bit") ,
XO(
"24 bit") , },
98 {
wxT(
"16") ,
wxT(
"24") , }
104 wxT(
"/FileFormats/FLACLevel"),
133#define SAMPLES_PER_RUN 8192u
136#if !defined FLACPP_API_VERSION_CURRENT || FLACPP_API_VERSION_CURRENT < 6
154 {
false,
false,
false,
false, 0, 2, 2, 0, 0 },
155 {
false,
false,
true,
true, 0, 2, 2, 0, 0 },
156 {
false,
false,
true,
false, 0, 0, 3, 0, 0 },
157 {
false,
false,
false,
false, 0, 3, 3, 0, 6 },
158 {
false,
false,
true,
true, 0, 3, 3, 0, 8 },
159 {
false,
false,
true,
false, 0, 3, 3, 0, 8 },
160 {
false,
false,
true,
false, 0, 0, 4, 0, 8 },
161 {
true,
false,
true,
false, 0, 0, 6, 0, 8 },
162 {
true,
false,
true,
false, 0, 0, 6, 0, 12 },
169 {
if (p) ::FLAC__metadata_object_delete(p); }
195 double t0,
double t1,
bool selectedOnly,
198 const Tags* tags)
override;
218 std::vector<std::string>
GetMimeTypes(
int)
const override;
222 std::unique_ptr<ExportOptionsEditor>
240 wxT(
"FLAC"),
XO(
"FLAC Files"), {
wxT(
"flac") }, FLAC__MAX_CHANNELS,
true
246 if(!config.IsObject() ||
247 !config.HasMember(
"level") || !config[
"level"].IsNumber() ||
248 !config.HasMember(
"bit_depth") || !config[
"bit_depth"].IsNumber())
251 const auto level =
ExportValue(std::to_string(config[
"level"].GetInt()));
252 const auto bitDepth =
ExportValue(std::to_string(config[
"bit_depth"].GetInt()));
256 const auto& option =
desc.option;
258 std::find(option.values.begin(),
260 level) == option.values.end())
263 std::find(option.values.begin(),
265 bitDepth) == option.values.end()))
278 return {
"audio/x-flac" };
281std::unique_ptr<ExportOptionsEditor>
284 return std::make_unique<PlainExportOptionsEditor>(
FlacOptions, listener);
289 return std::make_unique<FLACExportProcessor>();
296 double t0,
double t1,
bool selectionOnly,
308 long levelPref = std::stol(ExportPluginHelpers::GetParameterValue<std::string>(parameters,
FlacOptionIDLevel));
309 auto bitDepthPref = ExportPluginHelpers::GetParameterValue<std::string>(parameters,
FlacOptionIDBitDepth);
327 if (success && !metadata) {
332 if (success && metadata) {
335 FLAC__StreamMetadata *p = metadata.get();
336 success =
encoder.set_metadata(&p, 1);
340 if (bitDepthPref ==
"24") {
342 success = success &&
encoder.set_bits_per_sample(24);
345 success = success &&
encoder.set_bits_per_sample(16);
350 if (levelPref < 0 || levelPref > 8) {
359 encoder.set_do_mid_side_stereo(
false) &&
360 encoder.set_loose_mid_side_stereo(
false);
383 const auto path =
fName.GetFullPath();
394 if (
status != FLAC__STREAM_ENCODER_INIT_STATUS_OK) {
408 ?
XO(
"Exporting the selected audio as FLAC")
409 :
XO(
"Exporting the audio as FLAC");
420 auto cleanup2 =
finally( [&] {
432 auto samplesThisRun =
context.mixer->Process();
433 if (samplesThisRun == 0)
436 for (
size_t i = 0; i <
context.numChannels; i++) {
437 auto mixed =
context.mixer->GetBuffer(i);
439 for (
decltype(samplesThisRun) j = 0; j < samplesThisRun; j++) {
440 tmpsmplbuf[i][j] = ((
const int *)mixed)[j];
444 for (
decltype(samplesThisRun) j = 0; j < samplesThisRun; j++) {
445 tmpsmplbuf[i][j] = ((
const short *)mixed)[j];
450 reinterpret_cast<FLAC__int32**
>( tmpsmplbuf.get() ),
490 ::FLAC__metadata_object_new(FLAC__METADATA_TYPE_VORBIS_COMMENT)
494 for (
const auto &pair : tags->
GetRange()) {
496 const auto &v = pair.second;
504 FLAC::Metadata::VorbisComment::Entry
entry(n.mb_str(wxConvUTF8),
505 v.mb_str(wxConvUTF8));
506 if (! ::FLAC__metadata_object_vorbiscomment_append_comment(metadata.get(),
511 n =
wxT(
"DESCRIPTION");
513 FLAC::Metadata::VorbisComment::Entry
entry(n.mb_str(wxConvUTF8),
514 v.mb_str(wxConvUTF8));
515 if (! ::FLAC__metadata_object_vorbiscomment_append_comment(metadata.get(),
526 []{
return std::make_unique< ExportFLAC >(); }
unsigned min_residual_partition_order
unsigned rice_parameter_search_dist
static struct @169 flacLevels[]
bool do_exhaustive_model_search
unsigned max_residual_partition_order
static ExportPluginRegistry::RegisteredPlugin sRegisteredPlugin
bool loose_mid_side_stereo
std::unique_ptr< FLAC__StreamMetadata, FLAC__StreamMetadataDeleter > FLAC__StreamMetadataHandle
unsigned qlp_coeff_precision
ChoiceSetting FLACBitDepth
std::variant< bool, int, double, std::string > ExportValue
A type of option values (parameters) used by exporting plugins.
static ProjectFileIORegistry::AttributeWriterEntry entry
declares abstract base class Track, TrackList, and iterators over TrackList
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
std::unique_ptr< ExportOptionsEditor > CreateOptionsEditor(int, ExportOptionsEditor::Listener *listener) const override
Creates format-dependent options editor, that is used to create a valid set of parameters to be used ...
bool ParseConfig(int, const rapidjson::Value &config, ExportProcessor::Parameters ¶meters) const override
Attempt to parse configuration JSON object and produce a suitable set of parameters....
std::unique_ptr< ExportProcessor > CreateProcessor(int format) const override
int GetFormatCount() const override
FormatInfo GetFormatInfo(int) const override
Returns FormatInfo structure for given index if it's valid, or a default one. FormatInfo::format isn'...
std::vector< std::string > GetMimeTypes(int) const override
Listener object that is used to report on option changes.
static ExportResult UpdateProgress(ExportProcessorDelegate &delegate, Mixer &mixer, double t0, double t1)
Sends progress update to delegate and retrieves state update from it. Typically used inside each expo...
static std::unique_ptr< Mixer > CreateMixer(const AudacityProject &project, bool selectionOnly, double startTime, double stopTime, unsigned numOutChannels, size_t outBufferSize, bool outInterleaved, double outRate, sampleFormat outFormat, MixerOptions::Downmix *mixerSpec)
virtual void SetStatusString(const TranslatableString &str)=0
std::vector< std::tuple< ExportOptionID, ExportValue > > Parameters
bool Initialize(AudacityProject &project, const Parameters ¶meters, const wxFileNameWrapper &filename, double t0, double t1, bool selectedOnly, double sampleFormat, unsigned channels, MixerOptions::Downmix *mixerSpec, const Tags *tags) override
Called before start processing.
std::unique_ptr< Mixer > mixer
ExportResult Process(ExportProcessorDelegate &delegate) override
TranslatableString status
FLAC__StreamMetadataHandle MakeMetadata(AudacityProject *project, const Tags *tags) const
FLAC::Encoder::File encoder
struct FLACExportProcessor::@171 context
A matrix of booleans, one row per input channel, column per output.
Holds a msgid for the translation catalog; may also bind format arguments.
constexpr auto sampleRate
const std::initializer_list< PlainExportOptionsEditor::OptionDesc > FlacOptions
const TranslatableString desc
void swap(std::unique_ptr< Alg_seq > &a, std::unique_ptr< Alg_seq > &b)
@ TypeEnum
List/enum option. values holds items, and names text to be displayed.