29#include<wavpack/wavpack.h>
37#define DESC XO("WavPack files")
51 std::unique_ptr<ImportFileHandle>
Open(
67 std::optional<LibFileFormats::AcidizerTags>& outAcidTags)
override;
98 return wxT(
"libwavpack");
108 char errMessage[100];
109 int flags = OPEN_WVC | OPEN_FILE_UTF8 | OPEN_TAGS | OPEN_DSD_AS_PCM | OPEN_NORMALIZE;
110 WavpackContext *wavpackContext = WavpackOpenFileInput(filename, errMessage, flags, 0);
112 if (!wavpackContext) {
114 wxLogDebug(
"WavpackOpenFileInput() failed on file %s, error = %s", filename, errMessage);
118 auto handle = std::make_unique<WavPackImportFileHandle>(filename, wavpackContext);
120 return std::move(handle);
124 std::make_unique< WavPackImportPlugin >()
132 WavpackContext *wavpackContext)
134 mWavPackContext(wavpackContext),
135 mNumChannels(WavpackGetNumChannels(mWavPackContext)),
136 mSampleRate(WavpackGetSampleRate(mWavPackContext)),
137 mBitsPerSample(WavpackGetBitsPerSample(mWavPackContext)),
138 mBytesPerSample(WavpackGetBytesPerSample(mWavPackContext)),
139 mNumSamples(WavpackGetNumSamples64(mWavPackContext))
163 std::optional<LibFileFormats::AcidizerTags>&)
176 uint32_t totalSamplesRead = 0;
179 const uint32_t bufferSize =
mNumChannels * SAMPLES_TO_READ;
183 uint32_t samplesRead = 0;
186 int16Buffer.
reinit(bufferSize);
188 floatBuffer.
reinit(bufferSize);
192 samplesRead = WavpackUnpackSamples(
mWavPackContext, wavpackBuffer.get(), SAMPLES_TO_READ);
196 for (int64_t c = 0; c < samplesRead *
mNumChannels; c++)
197 int16Buffer[c] =
static_cast<int16_t
>(wavpackBuffer[c] * 256);
199 for (int64_t c = 0; c < samplesRead *
mNumChannels; c++)
200 int16Buffer[c] =
static_cast<int16_t
>(wavpackBuffer[c]);
205 channel.AppendBuffer(
218 channel.AppendBuffer(
228 for (int64_t c = 0; c < samplesRead *
mNumChannels; c++)
229 floatBuffer[c] =
static_cast<float>(wavpackBuffer[c] /
static_cast<double>(std::numeric_limits<int32_t>::max()));
234 channel.AppendBuffer(
245 totalSamplesRead += samplesRead;
270 if (wavpackMode & MODE_VALID_TAG) {
271 bool apeTag = wavpackMode & MODE_APETAG;
276 for (
int i = 0; i < numItems; i++) {
277 int itemLen = 0, valueLen = 0;
278 wxString value,
name;
282 std::string item (itemLen + 1,
'\0');
283 WavpackGetTagItemIndexed(
mWavPackContext, i, item.data(), itemLen + 1);
284 item.resize(itemLen);
289 std::string itemValue (valueLen + 1,
'\0');
290 WavpackGetTagItem(
mWavPackContext, item.data(), itemValue.data(), valueLen + 1);
291 itemValue.resize(valueLen);
294 for (
int j = 0; j < valueLen; j++) {
305 if (value.length() == 4 && value.ToLong(&val)) {
Declare functions to perform UTF-8 to std::wstring conversions.
The interface that all file import "plugins" (if you want to call them that) must implement....
std::vector< std::shared_ptr< Track > > TrackHolders
static Importer::RegisteredImportPlugin registered
std::vector< TranslatableString > TranslatableStrings
This simplifies arrays of arrays, each array separately allocated with NEW[] But it might be better t...
void reinit(Integral count, bool initialize=false)
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
bool IsStopped() const noexcept
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 ShowMessageBox(const TranslatableString &message, const TranslatableString &caption=XO("Import Project"))
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.
Holds a msgid for the translation catalog; may also bind format arguments.
An ImportFileHandle for WavPack data.
TranslatableString GetFileDescription() override
void Import(ImportProgressListener &progressListener, WaveTrackFactory *trackFactory, TrackHolders &outTracks, Tags *tags, std::optional< LibFileFormats::AcidizerTags > &outAcidTags) override
void SetStreamUsage(wxInt32 StreamID, bool Use) override
WavpackContext * mWavPackContext
ByteCount GetFileUncompressedBytes() override
wxInt32 GetStreamCount() override
WavPackImportFileHandle(const FilePath &filename, WavpackContext *wavpackContext)
const TranslatableStrings & GetStreamInfo() override
~WavPackImportFileHandle()
An ImportPlugin for WavPack data.
std::unique_ptr< ImportFileHandle > Open(const FilePath &Filename, AudacityProject *) override
TranslatableString GetPluginFormatDescription() override
wxString GetPluginStringID() override
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.
A Track that contains audio waveform data.
Extend wxArrayString with move operations and construction and insertion fromstd::initializer_list.
wxString ToWXString(const std::string &str)
const char * end(const char *str) noexcept
const char * begin(const char *str) noexcept