Changeset 378 for dsfilters/demux_mpc/src/mpc_file.cpp
- Timestamp:
- 01/03/08 23:50:40 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
dsfilters/demux_mpc/src/mpc_file.cpp
r373 r378 33 33 } 34 34 35 // I/O for MPC file 36 int CMPCFile::Open(CMPCReader *reader) 37 { 38 HRESULT hr; 35 int CMPCFile::Open_SV8() 36 { 37 bool done; 39 38 int ret; 40 bool done;41 42 // keep a local copy of the reader43 this->reader = reader;44 45 // According to stream specification the first 4 bytes should be 'MPCK'46 uint32 magick;47 reader->Seek(0);48 ret = reader->GetMagick(magick); if (ret < 0) return ret;49 if (magick != 0x4d50434b) {50 // not a Musepack file51 return -1;52 }53 39 54 40 // means no seek table … … 121 107 } 122 108 109 int CMPCFile::Open_SV7() 110 { 111 int ret; 112 bool done; 113 114 // means no seek table 115 seek_table_position = 0; 116 seek_table_size = 0; 117 118 done = false; 119 120 // init extradata 121 extradata[0] = 'M'; 122 extradata[1] = 'P'; 123 extradata[2] = '+'; 124 extradata[3] = stream_version; 125 extradata_size = 4; 126 127 uint8 hdr[8*4]; 128 ret = reader->Read(extradata + 4, 6*4); 129 if (ret < 0) return -1; // not enough data 130 memcpy(hdr, extradata+4, 5*4); 131 extradata_size += 6*4; 132 Bitstream b(hdr); 133 134 b.NeedBits32_MPC(); 135 audio_block_frames = (b.UGetBits(16)<<16) | b.UGetBits(16); 136 137 b.NeedBits32_MPC(); 138 b.UGetBits(1); // intensity stereo, should be 0 139 b.UGetBits(1); // mid-side 140 b.UGetBits(6); // max-band 141 b.UGetBits(4); // profile 142 b.UGetBits(2); // link 143 int samplerateidx = b.UGetBits(2); // samplerate 144 145 switch (samplerateidx) { 146 case 0x00: sample_rate = 44100; break; 147 case 0x01: sample_rate = 48000; break; 148 case 0x02: sample_rate = 37800; break; 149 case 0x03: sample_rate = 32000; break; 150 } 151 channels = 2; 152 block_pwr = 0; 153 b.UGetBits(16); // max-level 154 155 b.NeedBits32_MPC(); 156 gain_title_db = b.SGetBits(16) / 100.0; // title gain 157 gain_title_peak_db = b.UGetBits(16); // title peak 158 159 b.NeedBits32_MPC(); 160 gain_album_db = b.SGetBits(16) / 100.0; // album gain 161 gain_album_peak_db = b.UGetBits(16); // album peak 162 163 164 165 b.NeedBits32_MPC(); 166 true_gapless = b.UGetBits(1); // true gapless 167 int last_frame = b.UGetBits(11); // last-frame samples 168 total_samples = (audio_block_frames * 1152); 169 if (true_gapless) { 170 total_samples -= (1152 - last_frame); 171 } else { 172 total_samples -= 481; // synth delay 173 } 174 duration_10mhz = (total_samples * 10000000) / sample_rate; 175 176 fast_seeking = b.UGetBits(1); 177 b.UGetBits(16); // 19 zero bits 178 b.UGetBits(3); 179 180 b.NeedBits32_MPC(); 181 int ver = b.UGetBits(8); 182 183 //------------------------------------------------------------------------- 184 // Seek table 185 //------------------------------------------------------------------------- 186 seek_pwr = 6; 187 if (block_pwr > seek_pwr) seek_pwr = block_pwr; 188 189 // calculate size as seen in mpc_demux.c 190 int64 tmp = 2+total_samples / (1152 << seek_pwr); 191 if (tmp < seek_table_size) tmp = seek_table_size; 192 193 // alloc memory for seek table 194 seek_table = (uint32*)malloc(tmp * sizeof(uint32)); 195 if (!seek_table) return -1; 196 197 int64 pos, av; 198 reader->GetPosition(&pos, &av); 199 seek_table[0] = pos*8; // current position in bits 200 seek_table_size = 1; 201 202 // TODO: loop through file to get complete seeking table 203 204 return 0; 205 } 206 207 208 // I/O for MPC file 209 int CMPCFile::Open(CMPCReader *reader) 210 { 211 HRESULT hr; 212 int ret; 213 214 // keep a local copy of the reader 215 this->reader = reader; 216 217 // According to stream specification the first 4 bytes should be 'MPCK' 218 uint32 magick; 219 reader->Seek(0); 220 ret = reader->GetMagick(magick); if (ret < 0) return ret; 221 if (magick == 0x4d50434b) { // MPCK 222 return Open_SV8(); 223 } else 224 if ((magick&0xffffff00) == 0x4d502b00) { // MP+ 225 // stream version... only 7 is supported 226 stream_version = magick & 0x0f; 227 if (stream_version != 7) return -1; 228 return Open_SV7(); 229 } 230 return -1; 231 } 232 123 233 void CMPCFile::StoreExtraDataPacket(CMPCPacket *packet) 124 234 {
Note: See TracChangeset
for help on using the changeset viewer.