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());
240#define CODEC_TRANSFER_SIZE 4096u
244#define SAMPLES_PER_CALLBACK 100000
252 int testvar = 1, endian;
253 if (*(
char *)&testvar)
259 long samplesRead = 0;
261 int samplesSinceLastCallback = 0;
272 bytesRead = ov_read(
mVorbisFile.get(), (
char *)mainBuffer.get(),
279 if (bytesRead == OV_HOLE) {
281 wxLogError(
wxT(
"Ogg Vorbis importer: file %s is malformed, ov_read() reported a hole"),
289 else if (bytesRead < 0) {
292 wxLogError(
wxT(
"Ogg Vorbis importer: ov_read() returned error %i"),
297 samplesRead = bytesRead /
mVorbisFile->vi[bitstream].channels /
sizeof(short);
305 channel.AppendBuffer(
306 (char *)(mainBuffer.get() + chn),
309 mVorbisFile->vi[bitstream].channels,
316 samplesSinceLastCallback += samplesRead;
318 const auto timeTotal = ov_time_total(
mVorbisFile.get(), bitstream);
347 for (
int c = 0; c <
mVorbisFile->vc[0].comments; c++) {
349 wxString
name = comment.BeforeFirst(
wxT(
'='));
350 wxString value = comment.AfterFirst(
wxT(
'='));
353 if (value.length() == 4 && value.ToLong(&val)) {
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 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
const TranslatableStrings & GetStreamInfo() override
TranslatableStrings mStreamInfo
void SetStreamUsage(wxInt32 StreamID, bool Use) override
std::vector< TrackListHolder > mStreams
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...
TrackListHolder CreateMany(size_t nChannels)
Creates tracks with project's default rate and format and the given number of channels.
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