1 /*  Copyright (c) MediaArea.net SARL. All Rights Reserved.
2  *
3  *  Use of this source code is governed by a BSD-style license that can
4  *  be found in the License.html file in the root of the source tree.
5  */
6 
7 //---------------------------------------------------------------------------
8 // Pre-compilation
9 #include "MediaInfo/PreComp.h"
10 #ifdef __BORLANDC__
11     #pragma hdrstop
12 #endif
13 //---------------------------------------------------------------------------
14 
15 //---------------------------------------------------------------------------
16 #include "MediaInfo/Setup.h"
17 //---------------------------------------------------------------------------
18 
19 //---------------------------------------------------------------------------
20 #if defined(MEDIAINFO_PS2A_YES)
21 //---------------------------------------------------------------------------
22 
23 //---------------------------------------------------------------------------
24 #include "MediaInfo/Audio/File_Ps2Audio.h"
25 //---------------------------------------------------------------------------
26 
27 namespace MediaInfoLib
28 {
29 
30 //***************************************************************************
31 // Buffer - Global
32 //***************************************************************************
33 
34 //---------------------------------------------------------------------------
Read_Buffer_Continue()35 void File_Ps2Audio::Read_Buffer_Continue()
36 {
37     //Parsing
38     while (Element_Offset<Element_Size)
39     {
40         int32u ID;
41         Peek_B4(ID);
42         switch (ID)
43         {
44             case 0x53536264 :   SSbd(); break;
45             case 0x53536864 :   SShd(); break;
46             default         :   Element_Offset=Element_Size; Reject("PS2 Audio");
47         }
48     }
49 }
50 
51 //---------------------------------------------------------------------------
SSbd()52 void File_Ps2Audio::SSbd()
53 {
54     if (Count_Get(Stream_Audio)!=1)
55     {
56         Trusted_IsNot("Element should not be here");
57         return;
58     }
59 
60     Element_Begin1("SSbd (Body)");
61         int32u Size;
62         Skip_C4(                                                "ID");
63         Get_L4 (Size,                                           "Size");
64         Skip_XX(Element_Size-Element_Offset,                    "Data (Partial)");
65     Element_End0();
66 
67     FILLING_BEGIN();
68         Fill(Stream_Audio, 0, Audio_StreamSize, Size);
69         if (BitRate)
70             Fill(Stream_Audio, 0, Audio_Duration, ((int64u)Size)*1000*8/BitRate);
71 
72         Finish("PS2 Audio");
73     FILLING_END();
74 }
75 
76 //---------------------------------------------------------------------------
SShd()77 void File_Ps2Audio::SShd()
78 {
79     Element_Begin1("SShd (Header)");
80         //Parsing
81         int32u Size, Format, SamplingRate, Channels;
82         Skip_C4(                                                "ID");
83         Get_L4 (Size,                                           "Size");
84         if (Size!=0x18)
85         {
86             Trusted_IsNot("Bad size");
87             return;
88         }
89         Get_L4 (Format,                                         "Format");
90         Get_L4 (SamplingRate,                                   "Sampling rate");
91         Get_L4 (Channels,                                       "Channels");
92         Skip_L4(                                                "Bytes per channel");
93         Skip_L4(                                                "Reserved");
94         Skip_L4(                                                "Reserved");
95     Element_End0();
96 
97     FILLING_BEGIN();
98         Accept("PS2 Audio");
99 
100         BitRate=SamplingRate*Channels*16; //Always 16 bits
101 
102         Stream_Prepare(Stream_Audio);
103         Ztring FormatS;
104         switch(Format)
105         {
106             case 0x00000001 : FormatS=__T("PCM"); break;
107             case 0x00000010 : FormatS=__T("ADPCM"); break;
108             default         : ;
109         }
110         Fill(Stream_Audio, 0, Audio_Format, FormatS);
111         Fill(Stream_Audio, 0, Audio_Codec,  FormatS);
112         Fill(Stream_Audio, 0, Audio_MuxingMode, "PS2");
113         Fill(Stream_Audio, 0, Audio_SamplingRate, SamplingRate);
114         Fill(Stream_Audio, 0, Audio_Channel_s_, Channels);
115         Fill(Stream_Audio, 0, Audio_BitRate, BitRate);
116     FILLING_END();
117 }
118 
119 } //NameSpace
120 
121 #endif //MEDIAINFO_PS2A_YES
122 
123