| 83 | } |
| 84 | |
| 85 | void CircleBuffer::writeBuffer(const void* pSourceBuffer, const unsigned int iNumBytes, int audioTime) |
| 86 | { |
| 87 | unsigned int iBytesToWrite = iNumBytes; |
| 88 | BYTE* pSourceReadCursor = (BYTE*)pSourceBuffer; |
| 89 | |
| 90 | EnterCriticalSection(&this->m_csCircleBuffer); |
| 91 | //audioTimeQueue.push(audioTime); |
| 92 | // if (this->m_iInternalWriteCursor >= this->m_iInternalReadCursor) //2_9 avoid memcpy over |
| 93 | // { |
| 94 | unsigned int iChunkSize = this->m_iBufferSize - this->m_iInternalWriteCursor; |
| 95 | if (iChunkSize > iBytesToWrite) |
| 96 | iChunkSize = iBytesToWrite; |
| 97 | |
| 98 | memcpy(this->m_pBuffer + this->m_iInternalWriteCursor, pSourceReadCursor, iChunkSize); |
| 99 | pSourceReadCursor += iChunkSize; |
| 100 | iBytesToWrite -= iChunkSize; |
| 101 | this->m_iInternalWriteCursor += iChunkSize; |
| 102 | |
| 103 | if (this->m_iInternalWriteCursor >= this->m_iBufferSize) |
| 104 | this->m_iInternalWriteCursor -= this->m_iBufferSize; |
| 105 | // } |
| 106 | |
| 107 | if (iBytesToWrite) |
| 108 | { |
| 109 | memcpy(this->m_pBuffer + this->m_iInternalWriteCursor, pSourceReadCursor, iBytesToWrite); |
| 110 | this->m_iInternalWriteCursor += iBytesToWrite; |
| 111 | } |
| 112 | |
| 113 | SetEvent(this->m_evtDataAvailable); |
| 114 | LeaveCriticalSection(&this->m_csCircleBuffer); |
| 115 | } |
| 116 | |
| 117 | BOOL CircleBuffer::readBuffer(void* pDestBuffer, const unsigned int _iBytesToRead, unsigned int* pbBytesRead, int& audioTime) |
| 118 | { |