Changeset 367
- Timestamp:
- 12/13/07 19:24:42 (17 years ago)
- Location:
- dsfilters/demux_mpc/src
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
dsfilters/demux_mpc/src/bits.cpp
r366 r367 113 113 } 114 114 115 int32 Bitstream::Get_Golomb(int k) 116 { 117 int32 len = 0; 118 NeedBits24(); 119 while (UGetBits(1) == 1) len++; 120 if (len == 0) return 0; 121 NeedBits24(); 122 123 //while (bits 124 125 int32 val = (1 << len) | UGetBits(len); 126 return val; 127 } 128 -
dsfilters/demux_mpc/src/bits.h
r366 r367 86 86 int32 Get_ME(int32 mode); 87 87 int32 Get_TE(int32 range); 88 int32 Get_Golomb(int k); 88 89 89 90 inline int32 Size_UE(uint32 val) -
dsfilters/demux_mpc/src/mpc_file.cpp
r366 r367 19 19 duration_10mhz(0), 20 20 reader(NULL), 21 packet(NULL) 21 packet(NULL), 22 seek_table(NULL), 23 seek_table_position(0) 22 24 { 23 25 key = 0; … … 31 33 CMPCFile::~CMPCFile() 32 34 { 35 if (seek_table) { 36 free(seek_table); 37 seek_table = NULL; 38 } 33 39 if (packet) { 34 40 free(packet); … … 42 48 HRESULT hr; 43 49 int ret; 50 bool done; 44 51 45 52 // keep a local copy of the reader … … 47 54 48 55 49 /* 50 According to stream specification the first 4 bytes should be 'MPCK' 51 */ 56 // According to stream specification the first 4 bytes should be 'MPCK' 52 57 uint32 magick; 53 58 reader->Seek(0); … … 58 63 } 59 64 65 // means no seek table 66 seek_table_position = 0; 67 seek_table_size = 0; 68 69 done = false; 70 60 71 // now loop through a few packets 61 72 do { 62 intret = ReadNextPacket();73 ret = ReadNextPacket(); 63 74 if (ret < 0) return -1; // end of file reached before initialization is done ? 64 75 … … 66 77 case MPC_KEY('S','H'): ret = ReadStreamHeader(); break; 67 78 case MPC_KEY('R','G'): ret = ReadReplaygain(); break; 68 69 // TODO: Seek Table 79 case MPC_KEY('S','O'): ret = ReadSeekOffset(); break; 70 80 71 81 // audio packet - initialization is over 72 case MPC_KEY('A','P'): return 0;82 case MPC_KEY('A','P'): done = true; break; 73 83 } 74 84 75 85 // if parsing failed we quit 76 86 if (ret < 0) return ret; 77 } while (1); 87 } while (!done); 88 89 // if there was a seek table, load it 90 if (seek_table_position != 0) { 91 ret = ReadSeekTable(); 92 if (ret < 0) return ret; 93 } 78 94 79 95 return 0; … … 86 102 int32 size_len; 87 103 int ret; 88 104 int64 avail; 105 106 reader->GetPosition(&packet_pos, &avail); 89 107 ret = reader->GetKey(key_val); if (ret < 0) return ret; 90 108 ret = reader->GetSizeElm(size_val, size_len); if (ret < 0) return ret; … … 96 114 // size_val is the total size including key, variable size field and payload 97 115 packet_size = size_val - 2 - size_len; 98 99 // !!!!100 116 ASSERT(packet_size <= packet_max_size); 101 117 … … 123 139 } 124 140 141 int CMPCFile::ReadSeekOffset() 142 { 143 Bitstream b(packet); 144 145 seek_table_position = b.GetMpcSize(); 146 seek_table_position += packet_pos; 147 148 // success 149 return 0; 150 } 151 152 int CMPCFile::ReadSeekTable() 153 { 154 reader->Seek(seek_table_position); 155 int ret; 156 157 ret = ReadNextPacket(); 158 if (ret < 0) return ret; 159 160 Bitstream b(packet); 161 162 // calculate size as seen in mpc_demux.c 163 int64 tmp = b.GetMpcSize(); b.NeedBits(); 164 seek_table_size = tmp; 165 int seek_pwr = block_pwr + b.UGetBits(4); 166 tmp = 2+total_samples / (1152 << seek_pwr); 167 if (tmp < seek_table_size) tmp = seek_table_size; 168 169 // alloc memory for seek table 170 seek_table = (uint32*)malloc(tmp * sizeof(uint32)); 171 172 uint32 *table = seek_table; 173 174 tmp = b.GetMpcSize(); 175 table[0] = (uint32)(tmp + header_position) * 8; 176 if (seek_table_size == 1) return 0; 177 178 tmp = b.GetMpcSize(); 179 table[1] = (uint32)(tmp + header_position) * 8; 180 for (int i=2; i<seek_table_size; i++) { 181 int code = b.Get_Golomb(12); 182 if (code&1) code = -(code&(-1 << 1)); 183 code <<= 2; 184 table[i] = code + 2*table[i-1] - table[i-2]; 185 } 186 187 return 0; 188 } 189 125 190 int CMPCFile::ReadStreamHeader() 126 191 { … … 157 222 // Stream Version 8 158 223 //----------------------------------------------------------------- 159 int64samples = b.GetMpcSize();224 total_samples = b.GetMpcSize(); 160 225 int64 silence = b.GetMpcSize(); 161 226 … … 173 238 174 239 // let's calculate duration 175 duration_10mhz = ( samples * 10000000) / sample_rate;240 duration_10mhz = (total_samples * 10000000) / sample_rate; 176 241 177 242 b.DumpBits(5); // bands … … 180 245 b.NeedBits(); 181 246 b.DumpBits(1); // mid side 182 int exp = b.UGetBits(3); 183 audio_block_frames = 1 << (2*exp); 247 block_pwr = b.UGetBits(3) * 2; 248 audio_block_frames = 1 << (block_pwr); 249 250 // store absolute position of stream header 251 header_position = packet_pos; 184 252 } 185 253 break; -
dsfilters/demux_mpc/src/mpc_file.h
r366 r367 27 27 int channels; 28 28 int audio_block_frames; 29 int block_pwr; 30 int seek_pwr; 31 int64 total_samples; 29 32 30 33 // replay gain … … 33 36 float gain_album_db; 34 37 float gain_album_peak_db; 38 39 // seeking table 40 int64 seek_table_position; // position of seeking table in file 41 int64 header_position; 42 uint32 *seek_table; 43 int64 seek_table_size; 35 44 36 45 // internals … … 42 51 int packet_max_size; // maximum allowed packet size 43 52 int packet_size; // size of currently loaded payload 53 int64 packet_pos; // absolute position in file 44 54 45 55 public: … … 54 64 int ReadStreamHeader(); 55 65 int ReadReplaygain(); 66 int ReadSeekOffset(); 67 int ReadSeekTable(); 56 68 57 69 };
Note: See TracChangeset
for help on using the changeset viewer.