Merge branch 'v0.23.x'
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
#include "lib/xiph/FlacMetadataChain.hxx"
|
||||
#include "OggCodec.hxx"
|
||||
#include "input/InputStream.hxx"
|
||||
#include "input/LocalOpen.hxx"
|
||||
#include "fs/Path.hxx"
|
||||
#include "fs/NarrowPath.hxx"
|
||||
#include "Log.hxx"
|
||||
@@ -54,13 +55,30 @@ static bool
|
||||
flac_scan_file(Path path_fs, TagHandler &handler) noexcept
|
||||
{
|
||||
FlacMetadataChain chain;
|
||||
if (!chain.Read(NarrowPath(path_fs))) {
|
||||
const bool succeed = [&chain, &path_fs]() noexcept {
|
||||
// read by NarrowPath
|
||||
if (chain.Read(NarrowPath(path_fs))) {
|
||||
return true;
|
||||
}
|
||||
if (std::is_same_v<Path::value_type, char> ||
|
||||
chain.GetStatus() != FLAC__METADATA_CHAIN_STATUS_ERROR_OPENING_FILE) {
|
||||
return false;
|
||||
}
|
||||
// read by InputStream
|
||||
Mutex mutex;
|
||||
auto is = OpenLocalInputStream(path_fs, mutex);
|
||||
if (is && chain.Read(*is)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}();
|
||||
|
||||
if (!succeed) {
|
||||
FmtDebug(flac_domain,
|
||||
"Failed to read FLAC tags: {}",
|
||||
chain.GetStatusString());
|
||||
return false;
|
||||
}
|
||||
|
||||
chain.Scan(handler);
|
||||
return true;
|
||||
}
|
||||
|
@@ -546,7 +546,21 @@ parse_lame(struct lame *lame, struct mad_bitptr *ptr, int *bitlen) noexcept
|
||||
|
||||
mad_bit_skip(ptr, 16);
|
||||
|
||||
lame->peak = MAD_F(mad_bit_read(ptr, 32) << 5); /* peak */
|
||||
/* The lame peak value is a float multiplied by 2^23 and stored as an
|
||||
* unsigned integer (it is always positive). MAD's fixed-point format uses
|
||||
* 28 bits for the fractional part, so shift the 23 bit fraction up before
|
||||
* converting to a float.
|
||||
*/
|
||||
unsigned long peak_int = mad_bit_read(ptr, 32);
|
||||
|
||||
#define LAME_PEAK_FRACBITS 23
|
||||
#if MAD_F_FRACBITS > LAME_PEAK_FRACBITS
|
||||
peak_int <<= (MAD_F_FRACBITS - LAME_PEAK_FRACBITS);
|
||||
#elif LAME_PEAK_FRACBITS > MAD_F_FRACBITS
|
||||
peak_int >>= (LAME_PEAK_FRACBITS - MAD_F_FRACBITS);
|
||||
#endif
|
||||
|
||||
lame->peak = mad_f_todouble(peak_int); /* peak */
|
||||
FmtDebug(mad_domain, "LAME peak found: {}", lame->peak);
|
||||
|
||||
lame->track_gain = 0;
|
||||
|
Reference in New Issue
Block a user