| 165 | } |
| 166 | |
| 167 | bool CPCMDecoderInstance::GetPCMData(signed long *pDataOut, int nSamples, bool bLoop) |
| 168 | { |
| 169 | if (!m_pDecoder->m_pFile) |
| 170 | return false; |
| 171 | int nOfs=0; |
| 172 | if (m_nPos<0) |
| 173 | { |
| 174 | if (-m_nPos>=nSamples) |
| 175 | { |
| 176 | memset(pDataOut, 0, nSamples*m_pDecoder->m_pMusicSystem->GetBytesPerSample()); |
| 177 | m_nPos+=nSamples; |
| 178 | return true; |
| 179 | }else |
| 180 | { |
| 181 | nOfs=-m_nPos; |
| 182 | m_nPos=0; |
| 183 | nSamples-=nOfs; |
| 184 | memset(pDataOut, 0, nOfs*m_pDecoder->m_pMusicSystem->GetBytesPerSample()); |
| 185 | } |
| 186 | } |
| 187 | if (!SeekBytes(m_nPosBytes)) |
| 188 | return false; |
| 189 | int nSamplesToRead; |
| 190 | for (;;) |
| 191 | { |
| 192 | if ((m_nPos+nSamples)>m_pDecoder->m_FileInfo.nSamples) |
| 193 | nSamplesToRead=m_pDecoder->m_FileInfo.nSamples-m_nPos; |
| 194 | else |
| 195 | nSamplesToRead=nSamples; |
| 196 | if(m_pDecoder->Is44KHz()) |
| 197 | { |
| 198 | if (!m_pDecoder->ReadFile(&(pDataOut[nOfs]), m_pDecoder->m_PCMFileInfo.nBytesPerSample, nSamplesToRead, &m_nPosBytes)) |
| 199 | return false; |
| 200 | } |
| 201 | else |
| 202 | { |
| 203 | //decode for 44 KHz |
| 204 | if (!FillPCMBuffer22KHz(&(pDataOut[nOfs]), nSamplesToRead)) |
| 205 | return false; |
| 206 | } |
| 207 | // FIXME: conversation of samplerate might be needed here |
| 208 | m_nPos+=nSamplesToRead; |
| 209 | if (nSamplesToRead==nSamples) |
| 210 | break; |
| 211 | nOfs+=nSamplesToRead; |
| 212 | if (!bLoop) |
| 213 | { |
| 214 | memset(&(pDataOut[nOfs]), 0, (nSamples-nSamplesToRead)*m_pDecoder->m_pMusicSystem->GetBytesPerSample()); |
| 215 | break; |
| 216 | } |
| 217 | nSamples-=nSamplesToRead; |
| 218 | Seek0(); |
| 219 | } |
| 220 | return true; |
| 221 | } |
| 222 | |
| 223 | //! fills a dest buffer with uncompressed data |
| 224 | const bool CPCMDecoderInstance::FillPCMBuffer22KHz(signed long *pBuffer, int nSamples) |
no test coverage detected