24#include <vorbis/vorbisenc.h>
30#include "../ShuttleGui.h"
34#include "../widgets/AudacityMessageBox.h"
35#include "../widgets/ProgressDialog.h"
81 S.StartHorizontalLay(wxEXPAND);
83 S.SetSizerProportion(1);
84 S.StartMultiColumn(2, wxCENTER);
121#define SAMPLES_PER_RUN 8192u
133 std::unique_ptr<ProgressDialog> &pDialog,
140 const Tags *metadata = NULL,
141 int subformat = 0)
override;
160 std::unique_ptr<ProgressDialog> &pDialog,
161 unsigned numChannels,
167 const Tags *metadata,
168 int WXUNUSED(subformat))
172 double quality = (
gPrefs->Read(wxT(
"/FileFormats/OggExportQuality"), 50)/(float)100.0);
186 ogg_stream_state stream;
191 vorbis_comment comment;
192 vorbis_dsp_state dsp;
196 auto cleanup1 =
finally( [&] {
197 vorbis_info_clear(&info);
205 vorbis_info_init(&info);
206 if (vorbis_encode_init_vbr(&info, numChannels, (
int)(rate + 0.5), quality)) {
212 auto cleanup2 =
finally( [&] {
213 ogg_stream_clear(&stream);
215 vorbis_block_clear(&block);
216 vorbis_dsp_clear(&dsp);
217 vorbis_comment_clear(&comment);
227 if (vorbis_analysis_init(&dsp, &info) ||
228 vorbis_block_init(&dsp, &block)) {
237 if (ogg_stream_init(&stream, rand())) {
250 ogg_packet bitstream_header;
251 ogg_packet comment_header;
252 ogg_packet codebook_header;
254 if(vorbis_analysis_headerout(&dsp, &comment, &bitstream_header, &comment_header,
257 ogg_stream_packetin(&stream, &bitstream_header) ||
258 ogg_stream_packetin(&stream, &comment_header) ||
259 ogg_stream_packetin(&stream, &codebook_header)) {
266 while (ogg_stream_flush(&stream, &page)) {
267 if ( outFile.
Write(page.header, page.header_len).GetLastError() ||
268 outFile.
Write(page.body, page.body_len).GetLastError()) {
282 ?
XO(
"Exporting the selected audio as Ogg Vorbis")
283 :
XO(
"Exporting the audio as Ogg Vorbis") );
284 auto &progress = *pDialog;
291 if (samplesThisRun == 0) {
293 err = vorbis_analysis_wrote(&dsp, 0);
297 for (
size_t i = 0; i < numChannels; i++) {
298 float *temp = (
float *)mixer->GetBuffer(i);
303 err = vorbis_analysis_wrote(&dsp, samplesThisRun);
312 while (!err && vorbis_analysis_blockout(&dsp, &block) == 1) {
315 err = vorbis_analysis(&block, NULL);
317 err = vorbis_bitrate_addblock(&block);
319 while (!err && vorbis_bitrate_flushpacket(&dsp, &packet)) {
322 err = ogg_stream_packetin(&stream, &packet);
328 while (!err && !eos) {
329 int result = ogg_stream_pageout(&stream, &page);
334 if ( outFile.
Write(page.header, page.header_len).GetLastError() ||
335 outFile.
Write(page.body, page.body_len).GetLastError()) {
341 if (ogg_page_eos(&page)) {
355 updateResult = progress.Update(mixer->MixGetCurrentTime() - t0, t1 - t0);
359 if ( !outFile.
Close() ) {
376 if (metadata == NULL)
379 vorbis_comment_init(comment);
382 for (
const auto &pair : metadata->
GetRange()) {
384 const auto &v = pair.second;
388 vorbis_comment_add_tag(comment,
389 (
char *) (
const char *) n.mb_str(wxConvUTF8),
390 (
char *) (
const char *) v.mb_str(wxConvUTF8));
397 []{
return std::make_unique< ExportOGG >(); }
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)
static Exporter::RegisteredExportPlugin sRegisteredPlugin
an object holding per-project preferred sample rate
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...
void OptionsCreate(ShuttleGui &S, int format) override
bool FillComment(AudacityProject *project, vorbis_comment *comment, const Tags *metadata)
ProgressResult Export(AudacityProject *project, std::unique_ptr< 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.
ExportOGGOptions(wxWindow *parent, int format)
virtual ~ExportOGGOptions()
bool TransferDataToWindow() override
void PopulateOrExchange(ShuttleGui &S)
bool TransferDataFromWindow() override
void AddExtension(const FileExtension &extension, int index)
int AddFormat()
Add a NEW entry to the list of formats this plug-in can export.
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)
static void InitProgress(std::unique_ptr< ProgressDialog > &pDialog, const TranslatableString &title, const TranslatableString &message)
void SetMaxChannels(unsigned maxchannels, unsigned index)
virtual bool Flush(bool bCurrentOnly=false) wxOVERRIDE
wxOutputStream & Write(const void *buffer, size_t size)
static ProjectRate & Get(AudacityProject &project)
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
static TrackList & Get(AudacityProject &project)