Must run before Read: scans forward from just after the format to the 'data' chunk to descend into, skipping leading chunks such as 'fact'.
| 146 | // Must run before Read: scans forward from just after the format to the 'data' |
| 147 | // chunk to descend into, skipping leading chunks such as 'fact'. |
| 148 | void WaveFile::StartDataRead() |
| 149 | { |
| 150 | if (error) |
| 151 | { |
| 152 | return; |
| 153 | } |
| 154 | |
| 155 | RiffChunk chunk; |
| 156 | int lastPos = -1; |
| 157 | for (;;) |
| 158 | { |
| 159 | // A huge/overflowing chunk length can leave the cursor at or before its prior |
| 160 | // position (the seeks below clamp or fail), looping the search forever; bail |
| 161 | // if an iteration made no forward progress. |
| 162 | const int pos = _file.tellg(); |
| 163 | if (pos <= lastPos) |
| 164 | { |
| 165 | error = true; |
| 166 | break; |
| 167 | } |
| 168 | lastPos = pos; |
| 169 | _file.read(&chunk, sizeof(chunk)); |
| 170 | if (_file.fail()) |
| 171 | { |
| 172 | error = true; |
| 173 | break; |
| 174 | } |
| 175 | if (chunk.id == RIFF_fact) |
| 176 | { |
| 177 | DWORD fact; |
| 178 | _file.read(&fact, sizeof(fact)); |
| 179 | _file.seekg(chunk.len - sizeof(fact), QIOS::cur); |
| 180 | _samples = fact; |
| 181 | } |
| 182 | else if (chunk.id == RIFF_data) |
| 183 | { |
| 184 | _dataSize = chunk.len; |
| 185 | _dataRest = chunk.len; |
| 186 | _dataOffset = _file.tellg(); |
| 187 | break; |
| 188 | } |
| 189 | else |
| 190 | { |
| 191 | // skip chunk |
| 192 | _file.seekg(chunk.len, QIOS::cur); |
| 193 | continue; |
| 194 | } |
| 195 | } |
| 196 | } |
| 197 | |
| 198 | // Reads from the data chunk; StartDataRead must have descended into it first. |
| 199 | UINT WaveFile::Read(UINT cbRead, char* Dest) |
no test coverage detected