Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wavpack: support of DSD #2010

Merged
merged 1 commit into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 37 additions & 15 deletions Source/MediaInfo/Audio/File_Wvpk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,15 @@ File_Wvpk::File_Wvpk()
block_index_FirstFrame=0;
block_index_LastFrame=0;
SamplingRate=(int8u)-1;
SamplingRate_Shift=0;
num_channels=0;
channel_mask=0;
mono=false;
hybrid=false;
resolution0=false;
resolution1=false;
correction=false;
dsf=false;
}

//***************************************************************************
Expand All @@ -137,18 +140,19 @@ File_Wvpk::File_Wvpk()
//---------------------------------------------------------------------------
void File_Wvpk::Streams_Finish()
{
Fill(Stream_Audio, 0, Audio_BitRate_Mode, "VBR");

//Specific case
if (FromMKV)
return;

//Duration
if (SamplingRate<15)
{
int64u Duration=(((int64u)(block_index_LastFrame+block_samples_LastFrame-block_index_FirstFrame))*1000/Wvpk_SamplingRate[SamplingRate]); //Don't forget the last frame with block_samples...
int64u Samples=(int64u)(block_index_LastFrame+block_samples_LastFrame-block_index_FirstFrame); //Don't forget the last frame with block_samples...
int64u SampleRate=Wvpk_SamplingRate[SamplingRate]<<SamplingRate_Shift<<(3*dsf);
int64u BitDepth=dsf?1:(Wvpk_Resolution[(resolution1?1:0)*2+(resolution0?1:0)]);
int64u Duration=Samples*1000/(Wvpk_SamplingRate[SamplingRate]<<SamplingRate_Shift);
int64u CompressedSize=File_Size-TagsSize;
int64u UncompressedSize=Duration*(mono?1:2)*Wvpk_Resolution[(resolution1?1:0)*2+(resolution0?1:0)]*Wvpk_SamplingRate[SamplingRate]/8/1000;
int64u UncompressedSize=Duration*(mono?1:2)*BitDepth*SampleRate/8/1000;
float32 CompressionRatio=((float32)UncompressedSize)/CompressedSize;
Fill(Stream_Audio, 0, Audio_StreamSize, CompressedSize, 3, true);
Fill(Stream_Audio, 0, Audio_Duration, Duration, 10, true);
Expand Down Expand Up @@ -383,7 +387,7 @@ void File_Wvpk::Data_Parse()
Skip_Flags(flags, 28, "reserved");
Skip_Flags(flags, 29, "use IIR for negative hybrid noise shaping");
Skip_Flags(flags, 30, "false stereo");
Skip_Flags(flags, 31, "reserved");
Get_Flags (flags, 31, dsf, "dsf");
}
else
{
Expand Down Expand Up @@ -435,6 +439,7 @@ void File_Wvpk::Data_Parse()
{
case 0x07 : id_07(); break;
case 0x0D : id_0D(); break;
case 0x0E : id_0E(); break;
case 0x25 : id_25(); break;
default : if (word_size)
Skip_XX(Size, "data");
Expand Down Expand Up @@ -465,7 +470,8 @@ void File_Wvpk::Data_Parse_Fill()
Version_Minor.insert(0, 1, __T('0'));
Fill(Stream_Audio, 0, Audio_Format_Profile, Ztring::ToZtring(version/0x100)+__T('.')+Version_Minor);
Fill(Stream_Audio, 0, Audio_Codec, "Wavpack");
Fill(Stream_Audio, 0, Audio_BitDepth, Wvpk_Resolution[(resolution1?1:0)*2+(resolution0?1:0)]);
if (!dsf)
Fill(Stream_Audio, 0, Audio_BitDepth, Wvpk_Resolution[(resolution1?1:0)*2+(resolution0?1:0)]);
Fill(Stream_Audio, StreamPos_Last, Audio_Channel_s_, num_channels?num_channels:(mono?1:2));
if (channel_mask)
{
Expand Down Expand Up @@ -560,13 +566,22 @@ void File_Wvpk::Data_Parse_Fill()

if (!FromMKV && SamplingRate<15)
{
Fill(Stream_Audio, StreamPos_Last, Audio_SamplingRate, Wvpk_SamplingRate[SamplingRate]);
Fill(Stream_Audio, StreamPos_Last, Audio_SamplingRate, (Wvpk_SamplingRate[SamplingRate]<<SamplingRate_Shift)<<(3*dsf));
if (total_samples_FirstFrame!=(int32u)-1) //--> this is a valid value
Fill(Stream_Audio, 0, Audio_Duration, ((int64u)total_samples_FirstFrame)*1000/Wvpk_SamplingRate[SamplingRate]);
Fill(Stream_Audio, 0, Audio_Duration, ((int64u)total_samples_FirstFrame)*1000/(Wvpk_SamplingRate[SamplingRate]<<SamplingRate_Shift));
}
Fill(Stream_Audio, 0, Audio_Format_Settings, hybrid?"Hybrid lossy":"Lossless");
Fill(Stream_Audio, 0, Audio_Codec_Settings, hybrid?"hybrid lossy":"lossless");
Fill(Stream_Audio, 0, Audio_Encoded_Library_Settings, Encoded_Library_Settings);
Fill(Stream_Audio, 0, Audio_BitRate_Mode, "VBR");
const char* Mode=(hybrid && !correction)?"Lossy":"Lossless";
Fill(Stream_Audio, 0, Audio_Compression_Mode, Mode);
Fill(Stream_Audio, 0, Audio_Codec_Settings, Mode);
if (dsf)
{
Fill(Stream_Audio, 0, Audio_Format_Settings_Mode, "DSF");
Fill(Stream_Audio, 0, Audio_Format_Settings, "DSF");
}
if (correction)
Fill(Stream_Audio, 0, Audio_Format_AdditionalFeatures, "Correction");

//No more need data
File__Tags_Helper::GoToFromEnd(512*1024, "WavPack");
Expand All @@ -580,12 +595,9 @@ void File_Wvpk::Data_Parse_Fill()
void File_Wvpk::id_07()
{
//Parsing
Skip_XX(Size, "Data (Not decoded yet)");
Skip_XX(Size, "Data");

FILLING_BEGIN();
if (Retrieve(Stream_Audio, 0, Audio_Compression_Mode).empty())
Fill(Stream_Audio, 0, Audio_Compression_Mode, "Lossless", Unlimited, true, true);
FILLING_END();
correction=true;
}

//---------------------------------------------------------------------------
Expand Down Expand Up @@ -621,6 +633,16 @@ void File_Wvpk::id_0D()
}
}

//---------------------------------------------------------------------------
void File_Wvpk::id_0E()
{
//Parsing
int8u Temp;
Get_L1 (Temp, "framerate multiplier");
if (Temp<31)
SamplingRate_Shift=Temp;
}

//---------------------------------------------------------------------------
void File_Wvpk::id_25()
{
Expand Down
4 changes: 4 additions & 0 deletions Source/MediaInfo/Audio/File_Wvpk.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ private :
//Elements
void id_07();
void id_0D();
void id_0E();
void id_25();

//Temp - Technical info
Expand All @@ -72,7 +73,10 @@ private :
bool hybrid;
bool joint_stereo;
bool cross_channel_decorrelation;
bool correction;
bool dsf;
int8u SamplingRate;
int8u SamplingRate_Shift;
int8u num_channels;
int32u channel_mask;
int32u Size;
Expand Down
Loading