35#define DESC XO("Ogg Vorbis files")
49#include <vorbis/vorbisfile.h>
68 std::unique_ptr<ImportFileHandle>
Open(
77 std::unique_ptr<wxFFile> &&file,
78 std::unique_ptr<OggVorbis_File> &&vorbisFile)
86 auto strinfo =
XO(
"Index[%02x] Version[%d], Channels[%d], Rate[%ld]")
104 std::optional<LibFileFormats::AcidizerTags>& outAcidTags)
override;
123 if (StreamID < mVorbisFile->links)
147 wxUnusedVar(OV_CALLBACKS_DEFAULT);
148 wxUnusedVar(OV_CALLBACKS_NOCLOSE);
149 wxUnusedVar(OV_CALLBACKS_STREAMONLY);
150 wxUnusedVar(OV_CALLBACKS_STREAMONLY_NOCLOSE);
152 auto vorbisFile = std::make_unique<OggVorbis_File>();
153 auto file = std::make_unique<wxFFile>(filename,
wxT(
"rb"));
155 if (!file->IsOpened()) {
160 int err = ov_open(file->fp(), vorbisFile.get(), NULL, 0);
167 message =
XO(
"Media read error");
170 message =
XO(
"Not an Ogg Vorbis file");
173 message =
XO(
"Vorbis version mismatch");
176 message =
XO(
"Invalid Vorbis bitstream header");
179 message =
XO(
"Internal logic fault");
187 return std::make_unique<OggImportFileHandle>(filename, std::move(file), std::move(vorbisFile));
191 std::make_unique< OggImportPlugin >()
208 std::optional<LibFileFormats::AcidizerTags>&)
214 wxASSERT(
mFile->IsOpened());
242#define CODEC_TRANSFER_SIZE 4096u
246#define SAMPLES_PER_CALLBACK 100000
254 int testvar = 1, endian;
255 if (*(
char *)&testvar)
261 long samplesRead = 0;
263 int samplesSinceLastCallback = 0;
274 bytesRead = ov_read(
mVorbisFile.get(), (
char *)mainBuffer.get(),
281 if (bytesRead == OV_HOLE) {
283 wxLogError(
wxT(
"Ogg Vorbis importer: file %s is malformed, ov_read() reported a hole"),
291 else if (bytesRead < 0) {
294 wxLogError(
wxT(
"Ogg Vorbis importer: ov_read() returned error %i"),
299 samplesRead = bytesRead /
mVorbisFile->vi[bitstream].channels /
sizeof(short);
307 channel.AppendBuffer(
308 (char *)(mainBuffer.get() + chn),
311 mVorbisFile->vi[bitstream].channels,
318 samplesSinceLastCallback += samplesRead;
320 const auto timeTotal = ov_time_total(
mVorbisFile.get(), bitstream);
345 for (
int c = 0; c <
mVorbisFile->vc[0].comments; c++) {
347 wxString
name = comment.BeforeFirst(
wxT(
'='));
348 wxString value = comment.AfterFirst(
wxT(
'='));
351 if (value.length() == 4 && value.ToLong(&val)) {
const TranslatableString name
static Importer::RegisteredImportPlugin registered
#define SAMPLES_PER_CALLBACK
#define CODEC_TRANSFER_SIZE
The interface that all file import "plugins" (if you want to call them that) must implement....
std::vector< std::shared_ptr< Track > > TrackHolders
std::vector< TranslatableString > TranslatableStrings
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
bool IsStopped() const noexcept
FilePath GetFilename() const override
bool IsCancelled() const noexcept
unsigned long long ByteCount
Base class for FlacImportPlugin, LOFImportPlugin, MP3ImportPlugin, OggImportPlugin and PCMImportPlugi...
Interface used to report on import state and progress.
virtual void OnImportResult(ImportResult result)=0
Used to report on import result for file handle passed as argument to OnImportFileOpened.
virtual void OnImportProgress(double progress)=0
static std::shared_ptr< WaveTrack > NewWaveTrack(WaveTrackFactory &trackFactory, unsigned nChannels, sampleFormat effectiveFormat, double rate)
static void ForEachChannel(TrackList &trackList, const std::function< void(WaveChannel &)> &op)
Iterates over channels in each wave track from the list.
static void FinalizeImport(TrackHolders &outTracks, const std::vector< std::shared_ptr< WaveTrack > > &importedStreams)
Flushes the given channels and moves them to outTracks.
wxInt32 GetStreamCount() override
std::unique_ptr< wxFFile > mFile
void Import(ImportProgressListener &progressListener, WaveTrackFactory *trackFactory, TrackHolders &outTracks, Tags *tags, std::optional< LibFileFormats::AcidizerTags > &outAcidTags) override
TranslatableString GetFileDescription() override
ArrayOf< int > mStreamUsage
OggImportFileHandle(const FilePath &filename, std::unique_ptr< wxFFile > &&file, std::unique_ptr< OggVorbis_File > &&vorbisFile)
ByteCount GetFileUncompressedBytes() override
std::vector< WaveTrack::Holder > mStreams
const TranslatableStrings & GetStreamInfo() override
TranslatableStrings mStreamInfo
void SetStreamUsage(wxInt32 StreamID, bool Use) override
std::unique_ptr< OggVorbis_File > mVorbisFile
wxString GetPluginStringID() override
std::unique_ptr< ImportFileHandle > Open(const FilePath &Filename, AudacityProject *) override
TranslatableString GetPluginFormatDescription() override
Holds a msgid for the translation catalog; may also bind format arguments.
Used to create or clone a WaveTrack, with appropriate context from the project that will own the trac...
Extend wxArrayString with move operations and construction and insertion fromstd::initializer_list.
const char * end(const char *str) noexcept
const char * begin(const char *str) noexcept