29#include<wavpack/wavpack.h>
38#define DESC XO("WavPack files")
52 std::unique_ptr<ImportFileHandle>
Open(
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))
177 const size_t SAMPLES_TO_READ =
mChannels.begin()->get()->GetMaxBlockSize();
179 uint32_t totalSamplesRead = 0;
182 const uint32_t bufferSize =
mNumChannels * SAMPLES_TO_READ;
186 uint32_t samplesRead = 0;
189 int16Buffer.
reinit(bufferSize);
191 floatBuffer.
reinit(bufferSize);
195 samplesRead = WavpackUnpackSamples(
mWavPackContext, wavpackBuffer.get(), SAMPLES_TO_READ);
199 for (int64_t c = 0; c < samplesRead *
mNumChannels; c++)
200 int16Buffer[c] =
static_cast<int16_t
>(wavpackBuffer[c] * 256);
202 for (int64_t c = 0; c < samplesRead *
mNumChannels; c++)
203 int16Buffer[c] =
static_cast<int16_t
>(wavpackBuffer[c]);
205 for (
unsigned channel = 0; channel <
mNumChannels; channel++) {
212 for (
unsigned channel = 0; channel <
mNumChannels; channel++) {
219 for (int64_t c = 0; c < samplesRead *
mNumChannels; c++)
220 floatBuffer[c] =
static_cast<float>(wavpackBuffer[c] /
static_cast<double>(std::numeric_limits<int32_t>::max()));
222 for (
unsigned channel = 0; channel <
mNumChannels; channel++) {
229 totalSamplesRead += samplesRead;
236 XO(
"WavPack Importer" ), wxOK | wxICON_EXCLAMATION | wxCENTRE);
240 updateResult = ProgressResult::Failed;
249 outTracks.push_back(std::move(
mChannels));
251 if (wavpackMode & MODE_VALID_TAG) {
252 bool apeTag = wavpackMode & MODE_APETAG;
257 for (
int i = 0; i < numItems; i++) {
258 int itemLen = 0, valueLen = 0;
259 wxString value,
name;
263 std::string item (itemLen + 1,
'\0');
264 WavpackGetTagItemIndexed(
mWavPackContext, i, item.data(), itemLen + 1);
265 item.resize(itemLen);
270 std::string itemValue (valueLen + 1,
'\0');
271 WavpackGetTagItem(
mWavPackContext, item.data(), itemValue.data(), valueLen + 1);
272 itemValue.resize(valueLen);
275 for (
int j = 0; j < valueLen; j++) {
286 if (value.length() == 4 && value.ToLong(&val)) {
int AudacityMessageBox(const TranslatableString &message, const TranslatableString &caption, long style, wxWindow *parent, int x, int y)
Declare functions to perform UTF-8 to std::wstring conversions.
const TranslatableString name
std::vector< std::shared_ptr< WaveTrack > > NewChannelGroup
std::vector< std::vector< std::shared_ptr< WaveTrack > > > TrackHolders
The interface that all file import "plugins" (if you want to call them that) must implement....
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...
An ImportFileHandle for data.
unsigned long long ByteCount
std::unique_ptr< ProgressDialog > mProgress
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.
Base class for FlacImportPlugin, LOFImportPlugin, MP3ImportPlugin, OggImportPlugin and PCMImportPlugi...
Holds a msgid for the translation catalog; may also bind format arguments.
An ImportFileHandle for WavPack data.
TranslatableString GetFileDescription() override
ProgressResult Import(WaveTrackFactory *trackFactory, TrackHolders &outTracks, Tags *tags) override
ProgressResult mUpdateResult
void SetStreamUsage(wxInt32 StreamID, bool Use) override
WavpackContext * mWavPackContext
ByteCount GetFileUncompressedBytes() override
wxInt32 GetStreamCount() override
WavPackImportFileHandle(const FilePath &filename, WavpackContext *wavpackContext)
NewChannelGroup mChannels
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...
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.
wxString ToWXString(const std::string &str)