Welcome to mirror list, hosted at ThFree Co, Russian Federation.

File_MpcSv8.cpp « Audio « MediaInfo « MediaInfo « thirdparty « src - github.com/mpc-hc/mpc-hc.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7f34558c5760a729791997d849fb3ae48b803297 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
/*  Copyright (c) MediaArea.net SARL. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license that can
 *  be found in the License.html file in the root of the source tree.
 */

//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//
// Source: http://trac.musepack.net/trac/wiki/SV8Specification
//
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

//---------------------------------------------------------------------------
// Pre-compilation
#include "MediaInfo/PreComp.h"
#ifdef __BORLANDC__
    #pragma hdrstop
#endif
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
#include "MediaInfo/Setup.h"
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
#if defined(MEDIAINFO_MPCSV8_YES)
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
#include "MediaInfo/Audio/File_MpcSv8.h"
//---------------------------------------------------------------------------

namespace MediaInfoLib
{

//***************************************************************************
// Infos
//***************************************************************************

//---------------------------------------------------------------------------
extern const int16u Mpc_SampleFreq[];

//***************************************************************************
// Constants
//***************************************************************************

//---------------------------------------------------------------------------
namespace Elements
{
    const int32u AP=0x4150;
    const int32u CT=0x4354;
    const int32u EI=0x4549;
    const int32u RG=0x5247;
    const int32u SE=0x5345;
    const int32u SH=0x5348;
    const int32u SO=0x534F;
    const int32u ST=0x5354;
}

//***************************************************************************
// Constructor/Destructor
//***************************************************************************

//---------------------------------------------------------------------------
File_MpcSv8::File_MpcSv8()
:File__Analyze(), File__Tags_Helper()
{
    //File__Tags_Helper
    Base=this;
}


//***************************************************************************
// Static stuff
//***************************************************************************

//---------------------------------------------------------------------------
bool File_MpcSv8::FileHeader_Begin()
{
    //Element_Size
    if (Buffer_Size<4)
        return false; //Must wait for more data

    if (CC4(Buffer)!=0x4D50434B) //"MPCK"
    {
        File__Tags_Helper::Reject("Musepack SV8");
        return false;
    }

    //All should be OK...
    return true;
}

//***************************************************************************
// Buffer - File header
//***************************************************************************

//---------------------------------------------------------------------------
void File_MpcSv8::FileHeader_Parse()
{
    //Parsing
    Skip_C4(                                                    "Magic Number");

    FILLING_BEGIN();
        File__Tags_Helper::Accept("MpcSv8");

        File__Tags_Helper::Stream_Prepare(Stream_Audio);
        Fill(Stream_Audio, 0, Audio_Format, "Musepack SV8");
        Fill(Stream_Audio, 0, Audio_Codec, "SV8");
    FILLING_END();
}

//***************************************************************************
// Buffer - Per element
//***************************************************************************

//---------------------------------------------------------------------------
bool File_MpcSv8::Header_Begin()
{
    //Tags
    if (!File__Tags_Helper::Header_Begin())
        return false;

    return true;
}

//---------------------------------------------------------------------------
void File_MpcSv8::Header_Parse()
{
    //Parsing
    int64u Size;
    int16u Key;
    Get_C2 (Key,                                                "Key");
    Get_VS (Size,                                               "Size");

    //Filling
    Header_Fill_Code(Key, Ztring().From_CC4(Key<<16)); //Quick filling for CC2 with text
    Header_Fill_Size(Key==Elements::AP?Element_Offset:Size); //We don't need the data of audio packet, and we will stop here...
}

//***************************************************************************
// Elements
//***************************************************************************

//---------------------------------------------------------------------------
void File_MpcSv8::Data_Parse()
{
    #define CASE_INFO(_NAME, _DETAIL) \
        case Elements::_NAME : Element_Info1(_DETAIL); _NAME(); break;

    //Parsing
    switch (Element_Code)
    {
        CASE_INFO(AP,                                           "Audio Packet");
        CASE_INFO(CT,                                           "Chapter-Tag");
        CASE_INFO(EI,                                           "Encoder Info");
        CASE_INFO(RG,                                           "Replay Gain");
        CASE_INFO(SE,                                           "Stream End");
        CASE_INFO(SH,                                           "Stream Header");
        CASE_INFO(SO,                                           "Seek Table Offset");
        CASE_INFO(ST,                                           "Seek Table");
        default : Skip_XX(Element_Size,                         "Data");
    }
}

//***************************************************************************
// Elements
//***************************************************************************

//---------------------------------------------------------------------------
void File_MpcSv8::AP()
{
    //No more need data
    File__Tags_Helper::Finish("MpcSv8");
}

//---------------------------------------------------------------------------
void File_MpcSv8::EI()
{
    //Parsing
    int8u  Quality, Version1, Version2, Version3;
    bool   PNS;
    BS_Begin();
    Get_S1 (7, Quality,                                         "Quality");
    Get_SB (   PNS,                                             "PNS");
    BS_End();
    Get_B1 (Version1,                                           "Major version");
    Get_B1 (Version2,                                           "Minor version");
    Get_B1 (Version3,                                           "Build");
}

//---------------------------------------------------------------------------
void File_MpcSv8::RG()
{
    //Parsing
    int16u TitleGain, AlbumGain;
    Skip_B1(                                                    "Version");
    Get_L2 (TitleGain,                                          "Title gain"); Param_Info3(((float32)((int16s)TitleGain))/1000, 2, " dB");
    Skip_L2(                                                    "Title peak");
    Get_L2 (AlbumGain,                                          "Album gain"); Param_Info3(((float32)((int16s)TitleGain))/1000, 2, " dB");
    Skip_L2(                                                    "Album peak");
}

//---------------------------------------------------------------------------
void File_MpcSv8::SH()
{
    //Parsing
    int64u SampleCount;
    int8u  Version, SampleFrequency, ChannelCount;
    bool   MidSideStereo;
    Skip_B4(                                                    "CRC32");
    Get_B1 (Version,                                            "Version");
    Get_VS (SampleCount,                                        "Sample count");
    Skip_VS(                                                    "Beginning silence");
    BS_Begin();
    Get_S1 (3, SampleFrequency,                                 "Sample frequency"); Param_Info1(Mpc_SampleFreq[SampleFrequency]);
    Skip_S1(5,                                                  "Max used bands");
    Get_S1 (4, ChannelCount,                                    "Channel count");
    Get_SB (   MidSideStereo,                                   "Mid side stereo used");
    Skip_S1(3,                                                  "Audio block frames");
    BS_End();

    //Filling
    FILLING_BEGIN();
        Fill(Stream_Audio, 0, Audio_SamplingRate, Mpc_SampleFreq[SampleFrequency]);
        if (SampleCount)
        {
            Fill(Stream_Audio, 0, Audio_SamplingCount, SampleCount);
            Fill(Stream_Audio, 0, Audio_Duration, SampleCount*1000/Mpc_SampleFreq[SampleFrequency]);
            Fill(Stream_Audio, 0, Audio_BitRate, File_Size*8*Mpc_SampleFreq[SampleFrequency]/SampleCount); //Should be more precise...
        }
        Fill(Stream_Audio, 0, Audio_BitDepth, 16); //MPC support only 16 bits
    FILLING_END();
}

//---------------------------------------------------------------------------
void File_MpcSv8::SO()
{
    //Parsing
    Skip_VS(                                                    "Offset");
}

} //NameSpace

#endif //MEDIAINFO_MPCSV8_YES