26#include "FLAC++/encoder.h"
76 wxT(
"/FileFormats/FLACBitDepth"),
79 {
XO(
"16 bit") ,
XO(
"24 bit") , },
80 {
wxT(
"16") ,
wxT(
"24") , }
86 wxT(
"/FileFormats/FLACLevel"),
119 S.StartVerticalLay();
121 S.StartHorizontalLay(wxCENTER);
123 S.StartMultiColumn(2, wxCENTER);
130 S.EndHorizontalLay();
160#define SAMPLES_PER_RUN 8192u
163#if !defined FLACPP_API_VERSION_CURRENT || FLACPP_API_VERSION_CURRENT < 6
181 {
false,
false,
false,
false, 0, 2, 2, 0, 0 },
182 {
false,
false,
true,
true, 0, 2, 2, 0, 0 },
183 {
false,
false,
true,
false, 0, 0, 3, 0, 0 },
184 {
false,
false,
false,
false, 0, 3, 3, 0, 6 },
185 {
false,
false,
true,
true, 0, 3, 3, 0, 8 },
186 {
false,
false,
true,
false, 0, 3, 3, 0, 8 },
187 {
false,
false,
true,
false, 0, 0, 4, 0, 8 },
188 {
true,
false,
true,
false, 0, 0, 6, 0, 8 },
189 {
true,
false,
true,
false, 0, 0, 6, 0, 12 },
196 {
if (p) ::FLAC__metadata_object_delete(p); }
212 std::unique_ptr<BasicUI::ProgressDialog> &pDialog,
219 const Tags *metadata = NULL,
220 int subformat = 0)
override;
244 std::unique_ptr<BasicUI::ProgressDialog> &pDialog,
245 unsigned numChannels,
251 const Tags *metadata,
252 int WXUNUSED(subformat))
265 FLAC::Encoder::File encoder;
270 encoder.set_filename(
OSOUTPUT(fName)) &&
272 encoder.set_channels(numChannels) &&
273 encoder.set_sample_rate(
lrint(rate));
285 FLAC__StreamMetadata *p =
mMetadata.get();
286 success = encoder.set_metadata(&p, 1);
289 auto cleanup1 =
finally( [&] {
294 if (bitDepthPref ==
wxT(
"24")) {
296 success = success && encoder.set_bits_per_sample(24);
299 success = success && encoder.set_bits_per_sample(16);
304 if (levelPref < 0 || levelPref > 8) {
311 if (numChannels != 2) {
313 encoder.set_do_mid_side_stereo(
false) &&
314 encoder.set_loose_mid_side_stereo(
false);
339 const auto path = fName.GetFullPath();
340 if (!f.Open(path,
wxT(
"w+b"))) {
348 int status = encoder.init(f.fp());
349 if (status != FLAC__STREAM_ENCODER_INIT_STATUS_OK) {
351 XO(
"FLAC encoder failed to initialize\nStatus: %d")
359 auto cleanup2 =
finally( [&] {
361 updateResult == ProgressResult::Stopped)) {
378 ?
XO(
"Exporting the selected audio as FLAC")
379 :
XO(
"Exporting the audio as FLAC") );
380 auto &progress = *pDialog;
383 auto samplesThisRun = mixer->Process();
384 if (samplesThisRun == 0)
387 for (
size_t i = 0; i < numChannels; i++) {
388 auto mixed = mixer->GetBuffer(i);
390 for (
decltype(samplesThisRun) j = 0; j < samplesThisRun; j++) {
391 tmpsmplbuf[i][j] = ((
const int *)mixed)[j];
395 for (
decltype(samplesThisRun) j = 0; j < samplesThisRun; j++) {
396 tmpsmplbuf[i][j] = ((
const short *)mixed)[j];
400 if (! encoder.process(
401 reinterpret_cast<FLAC__int32**
>( tmpsmplbuf.get() ),
410 progress.Poll(mixer->MixGetCurrentTime() - t0, t1 - t0);
415 updateResult == ProgressResult::Stopped) {
419 if (!encoder.finish())
421 return ProgressResult::Failed;
423 if (!f.Flush() || !f.Close())
424 return ProgressResult::Failed;
448 mMetadata.reset(::FLAC__metadata_object_new(FLAC__METADATA_TYPE_VORBIS_COMMENT));
451 for (
const auto &pair : tags->
GetRange()) {
453 const auto &v = pair.second;
461 FLAC::Metadata::VorbisComment::Entry
entry(n.mb_str(wxConvUTF8),
462 v.mb_str(wxConvUTF8));
463 if (! ::FLAC__metadata_object_vorbiscomment_append_comment(
mMetadata.get(),
468 n =
wxT(
"DESCRIPTION");
470 FLAC::Metadata::VorbisComment::Entry
entry(n.mb_str(wxConvUTF8),
471 v.mb_str(wxConvUTF8));
472 if (! ::FLAC__metadata_object_vorbiscomment_append_comment(
mMetadata.get(),
483 []{
return std::make_unique< ExportFLAC >(); }
486#ifdef HAS_CLOUD_UPLOAD
513 [](
const AudacityProject&) {
return std::make_unique<FlacCloudHelper>(); });
int AudacityMessageBox(const TranslatableString &message, const TranslatableString &caption, long style, wxWindow *parent, int x, int y)
void ShowExportErrorDialog(wxString ErrorCode, TranslatableString message, const TranslatableString &caption, bool allowReporting)
void ShowDiskFullExportErrorDialog(const wxFileNameWrapper &fileName)
unsigned min_residual_partition_order
unsigned rice_parameter_search_dist
bool do_exhaustive_model_search
static struct @40 flacLevels[]
static Exporter::RegisteredExportPlugin sRegisteredPlugin
unsigned max_residual_partition_order
bool loose_mid_side_stereo
std::unique_ptr< FLAC__StreamMetadata, FLAC__StreamMetadataDeleter > FLAC__StreamMetadataHandle
unsigned qlp_coeff_precision
ChoiceSetting FLACBitDepth
XXO("&Cut/Copy/Paste Toolbar")
wxString FileExtension
File extension, not including any leading dot.
an object holding per-project preferred sample rate
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...
bool Write(const wxString &value)
ProgressResult Export(AudacityProject *project, std::unique_ptr< BasicUI::ProgressDialog > &pDialog, unsigned channels, const wxFileNameWrapper &fName, bool selectedOnly, double t0, double t1, MixerSpec *mixerSpec=NULL, const Tags *metadata=NULL, int subformat=0) override
called to export audio into a file.
FLAC__StreamMetadataHandle mMetadata
void OptionsCreate(ShuttleGui &S, int format) override
bool GetMetadata(AudacityProject *project, const Tags *tags)
void PopulateOrExchange(ShuttleGui &S)
bool TransferDataFromWindow() override
ExportFLACOptions(wxWindow *parent, int format)
bool TransferDataToWindow() override
virtual ~ExportFLACOptions()
void AddExtension(const FileExtension &extension, int index)
int AddFormat()
Add a NEW entry to the list of formats this plug-in can export.
static void InitProgress(std::unique_ptr< BasicUI::ProgressDialog > &pDialog, const TranslatableString &title, const TranslatableString &message)
void SetFormat(const wxString &format, int index)
std::unique_ptr< Mixer > CreateMixer(const TrackList &tracks, bool selectionOnly, double startTime, double stopTime, unsigned numOutChannels, size_t outBufferSize, bool outInterleaved, double outRate, sampleFormat outFormat, MixerSpec *mixerSpec)
void SetDescription(const TranslatableString &description, int index)
void SetCanMetaData(bool canmetadata, int index)
void SetMaxChannels(unsigned maxchannels, unsigned index)
virtual bool Flush(bool bCurrentOnly=false) wxOVERRIDE
A matrix of booleans, one row per input channel, column per output.
static ProjectRate & Get(AudacityProject &project)
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
static TrackList & Get(AudacityProject &project)
Helper interface, that allows to setup the desired export format on the ExportPlugin.
virtual wxString GetExporterID() const =0
Identifier of the ExportPlugin to be used.
virtual FileExtension GetFileExtension() const =0
File extension that is expected with this plugin.
virtual void OnBeforeExport()=0
Setup the preferred format for the export.
bool RegisterCloudExporter(MimeType mimeType, CloudExporterPluginFactory factory)
Registers a factory for a specific mime type.