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 Tags *tags)
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 >()
214 wxASSERT(
mFile->IsOpened());
235 link.resize(vi->channels);
237 for (
auto &channel : link)
243#define CODEC_TRANSFER_SIZE 4096u
247#define SAMPLES_PER_CALLBACK 100000
255 int testvar = 1, endian;
256 if (*(
char *)&testvar)
262 long samplesRead = 0;
264 int samplesSinceLastCallback = 0;
275 bytesRead = ov_read(
mVorbisFile.get(), (
char *)mainBuffer.get(),
282 if (bytesRead == OV_HOLE) {
284 wxLogError(
wxT(
"Ogg Vorbis importer: file %s is malformed, ov_read() reported a hole"),
292 else if (bytesRead < 0) {
295 wxLogError(
wxT(
"Ogg Vorbis importer: ov_read() returned error %i"),
300 samplesRead = bytesRead /
mVorbisFile->vi[bitstream].channels /
sizeof(short);
304 std::advance(iter, bitstream);
307 auto iter2 = iter->begin();
308 for (
int c = 0; c <
mVorbisFile->vi[bitstream].channels; ++iter2, ++c)
309 iter2->get()->Append((
char *)(mainBuffer.get() + c),
316 samplesSinceLastCallback += samplesRead;
318 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< TrackList > > 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< TrackList > MakeTracks(const NewChannelGroup &channels)
Flush the given channels and group them into tracks.
static std::shared_ptr< WaveTrack > NewWaveTrack(WaveTrackFactory &trackFactory, sampleFormat effectiveFormat, double rate)
Build a wave track with appropriate format, which will not be narrower than the specified one.
wxInt32 GetStreamCount() override
std::unique_ptr< wxFFile > mFile
TranslatableString GetFileDescription() override
void Import(ImportProgressListener &progressListener, WaveTrackFactory *trackFactory, TrackHolders &outTracks, Tags *tags) 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::list< ImportUtils::NewChannelGroup > mChannels
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.
auto end(const Ptr< Type, BaseDeleter > &p)
Enables range-for.
auto begin(const Ptr< Type, BaseDeleter > &p)
Enables range-for.