decoder/wavpack: require libwavpack version 5

This commit is contained in:
Max Kellermann 2022-07-11 22:02:18 +02:00
parent 4464310e74
commit 349882ed75
3 changed files with 10 additions and 105 deletions

1
NEWS
View File

@ -7,6 +7,7 @@ ver 0.24 (not yet released)
* decoder * decoder
- hybrid_dsd: remove - hybrid_dsd: remove
- opus: implement bitrate calculation - opus: implement bitrate calculation
- wavpack: require libwavpack version 5
* player * player
- add option "mixramp_analyzer" to scan MixRamp tags on-the-fly - add option "mixramp_analyzer" to scan MixRamp tags on-the-fly
* tags * tags

View File

@ -41,16 +41,10 @@ using std::string_view_literals::operator""sv;
#define ERRORLEN 80 #define ERRORLEN 80
#ifdef OPEN_DSD_AS_PCM #ifdef ENABLE_DSD
/* libWavPack supports DSD since version 5 */
#ifdef ENABLE_DSD
static constexpr int OPEN_DSD_FLAG = OPEN_DSD_NATIVE; static constexpr int OPEN_DSD_FLAG = OPEN_DSD_NATIVE;
#else
static constexpr int OPEN_DSD_FLAG = OPEN_DSD_AS_PCM;
#endif
#else #else
/* no DSD support in this libWavPack version */ static constexpr int OPEN_DSD_FLAG = OPEN_DSD_AS_PCM;
static constexpr int OPEN_DSD_FLAG = 0;
#endif #endif
static WavpackContext * static WavpackContext *
@ -66,15 +60,13 @@ WavpackOpenInput(Path path, int flags, int norm_offset)
return wpc; return wpc;
} }
#ifdef OPEN_DSD_AS_PCM
static WavpackContext * static WavpackContext *
WavpackOpenInput(WavpackStreamReader64 *reader, void *wv_id, void *wvc_id, WavpackOpenInput(WavpackStreamReader64 *reader, void *wv_id, void *wvc_id,
int flags, int norm_offset) int flags, int norm_offset)
{ {
char error[ERRORLEN]; char error[ERRORLEN];
auto *wpc = WavpackOpenFileInputEx64(reader, wv_id, wvc_id, error, auto *wpc = WavpackOpenFileInputEx64(reader, wv_id, wvc_id, error,
flags, norm_offset); flags, norm_offset);
if (wpc == nullptr) if (wpc == nullptr)
throw FormatRuntimeError("failed to open WavPack stream: %s", throw FormatRuntimeError("failed to open WavPack stream: %s",
error); error);
@ -82,40 +74,14 @@ WavpackOpenInput(WavpackStreamReader64 *reader, void *wv_id, void *wvc_id,
return wpc; return wpc;
} }
#else
static WavpackContext *
WavpackOpenInput(WavpackStreamReader *reader, void *wv_id, void *wvc_id,
int flags, int norm_offset)
{
char error[ERRORLEN];
auto *wpc = WavpackOpenFileInputEx(reader, wv_id, wvc_id, error,
flags, norm_offset);
if (wpc == nullptr)
throw FormatRuntimeError("failed to open WavPack stream: %s",
error);
return wpc;
}
#endif
gcc_pure gcc_pure
static SignedSongTime static SignedSongTime
GetDuration(WavpackContext *wpc) noexcept GetDuration(WavpackContext *wpc) noexcept
{ {
#ifdef OPEN_DSD_AS_PCM
/* libWavPack 5 */
const auto n_samples = WavpackGetNumSamples64(wpc); const auto n_samples = WavpackGetNumSamples64(wpc);
if (n_samples == -1) if (n_samples == -1)
/* unknown */ /* unknown */
return SignedSongTime::Negative(); return SignedSongTime::Negative();
#else
const uint32_t n_samples = WavpackGetNumSamples(wpc);
if (n_samples == uint32_t(-1))
/* unknown */
return SignedSongTime::Negative();
#endif
return SongTime::FromScale<uint64_t>(n_samples, return SongTime::FromScale<uint64_t>(n_samples,
WavpackGetSampleRate(wpc)); WavpackGetSampleRate(wpc));
@ -156,7 +122,7 @@ format_samples_nop([[maybe_unused]] void *buffer, [[maybe_unused]] uint32_t coun
*/ */
static SampleFormat static SampleFormat
wavpack_bits_to_sample_format(bool is_float, wavpack_bits_to_sample_format(bool is_float,
#if defined(OPEN_DSD_AS_PCM) && defined(ENABLE_DSD) #ifdef ENABLE_DSD
bool is_dsd, bool is_dsd,
#endif #endif
int bytes_per_sample) int bytes_per_sample)
@ -164,7 +130,7 @@ wavpack_bits_to_sample_format(bool is_float,
if (is_float) if (is_float)
return SampleFormat::FLOAT; return SampleFormat::FLOAT;
#if defined(OPEN_DSD_AS_PCM) && defined(ENABLE_DSD) #ifdef ENABLE_DSD
if (is_dsd) if (is_dsd)
return SampleFormat::DSD; return SampleFormat::DSD;
#endif #endif
@ -191,12 +157,12 @@ static AudioFormat
CheckAudioFormat(WavpackContext *wpc) CheckAudioFormat(WavpackContext *wpc)
{ {
const bool is_float = (WavpackGetMode(wpc) & MODE_FLOAT) != 0; const bool is_float = (WavpackGetMode(wpc) & MODE_FLOAT) != 0;
#if defined(OPEN_DSD_AS_PCM) && defined(ENABLE_DSD) #ifdef ENABLE_DSD
const bool is_dsd = (WavpackGetQualifyMode(wpc) & QMODE_DSD_AUDIO) != 0; const bool is_dsd = (WavpackGetQualifyMode(wpc) & QMODE_DSD_AUDIO) != 0;
#endif #endif
SampleFormat sample_format = SampleFormat sample_format =
wavpack_bits_to_sample_format(is_float, wavpack_bits_to_sample_format(is_float,
#if defined(OPEN_DSD_AS_PCM) && defined(ENABLE_DSD) #ifdef ENABLE_DSD
is_dsd, is_dsd,
#endif #endif
WavpackGetBytesPerSample(wpc)); WavpackGetBytesPerSample(wpc));
@ -244,12 +210,7 @@ wavpack_decode(DecoderClient &client, WavpackContext *wpc, bool can_seek)
if (cmd == DecoderCommand::SEEK) { if (cmd == DecoderCommand::SEEK) {
if (can_seek) { if (can_seek) {
auto where = client.GetSeekFrame(); auto where = client.GetSeekFrame();
#ifdef OPEN_DSD_AS_PCM if (!WavpackSeekSample64(wpc, where)) {
bool success = WavpackSeekSample64(wpc, where);
#else
bool success = WavpackSeekSample(wpc, where);
#endif
if (!success) {
/* seek errors are fatal */ /* seek errors are fatal */
client.SeekError(); client.SeekError();
break; break;
@ -395,8 +356,6 @@ WavpackInput::ReadBytes(void *data, size_t bcount)
return i; return i;
} }
#ifdef OPEN_DSD_AS_PCM
static int64_t static int64_t
wavpack_input_get_pos(void *id) wavpack_input_get_pos(void *id)
{ {
@ -418,31 +377,6 @@ wavpack_input_set_pos_rel(void *id, int64_t delta, int mode)
return wpi.SetPosRel(delta, mode); return wpi.SetPosRel(delta, mode);
} }
#else
static uint32_t
wavpack_input_get_pos(void *id)
{
const auto &wpi = *wpin(id);
return wpi.GetPos();
}
static int
wavpack_input_set_pos_abs(void *id, uint32_t pos)
{
auto &wpi = *wpin(id);
return wpi.SetPosAbs(pos);
}
static int
wavpack_input_set_pos_rel(void *id, int32_t delta, int mode)
{
auto &wpi = *wpin(id);
return wpi.SetPosRel(delta, mode);
}
#endif
static int static int
wavpack_input_push_back_byte(void *id, int c) wavpack_input_push_back_byte(void *id, int c)
{ {
@ -450,8 +384,6 @@ wavpack_input_push_back_byte(void *id, int c)
return wpi.PushBackByte(c); return wpi.PushBackByte(c);
} }
#ifdef OPEN_DSD_AS_PCM
static int64_t static int64_t
wavpack_input_get_length(void *id) wavpack_input_get_length(void *id)
{ {
@ -459,17 +391,6 @@ wavpack_input_get_length(void *id)
return wpi.GetLength(); return wpi.GetLength();
} }
#else
static uint32_t
wavpack_input_get_length(void *id)
{
const auto &wpi = *wpin(id);
return wpi.GetLength();
}
#endif
static int static int
wavpack_input_can_seek(void *id) wavpack_input_can_seek(void *id)
{ {
@ -477,8 +398,6 @@ wavpack_input_can_seek(void *id)
return wpi.CanSeek(); return wpi.CanSeek();
} }
#ifdef OPEN_DSD_AS_PCM
static WavpackStreamReader64 mpd_is_reader = { static WavpackStreamReader64 mpd_is_reader = {
wavpack_input_read_bytes, wavpack_input_read_bytes,
nullptr, /* write_bytes */ nullptr, /* write_bytes */
@ -492,21 +411,6 @@ static WavpackStreamReader64 mpd_is_reader = {
nullptr, /* close */ nullptr, /* close */
}; };
#else
static WavpackStreamReader mpd_is_reader = {
wavpack_input_read_bytes,
wavpack_input_get_pos,
wavpack_input_set_pos_abs,
wavpack_input_set_pos_rel,
wavpack_input_push_back_byte,
wavpack_input_get_length,
wavpack_input_can_seek,
nullptr /* no need to write edited tags */
};
#endif
static InputStreamPtr static InputStreamPtr
wavpack_open_wvc(DecoderClient &client, std::string_view uri) wavpack_open_wvc(DecoderClient &client, std::string_view uri)
{ {

View File

@ -135,7 +135,7 @@ if libsndfile_dep.found()
decoder_plugins_sources += 'SndfileDecoderPlugin.cxx' decoder_plugins_sources += 'SndfileDecoderPlugin.cxx'
endif endif
wavpack_dep = dependency('wavpack', required: get_option('wavpack')) wavpack_dep = dependency('wavpack', version: '>= 5', required: get_option('wavpack'))
decoder_features.set('ENABLE_WAVPACK', wavpack_dep.found()) decoder_features.set('ENABLE_WAVPACK', wavpack_dep.found())
if wavpack_dep.found() if wavpack_dep.found()
decoder_plugins_sources += 'WavpackDecoderPlugin.cxx' decoder_plugins_sources += 'WavpackDecoderPlugin.cxx'