// WaveformStream.h - Derived CSoundStream for generated waveforms
static const size_t s_nBufferLen = 4096;
static const int s_nFrequency = 22050;
Assert(s_nBufferLen*sizeof(m_pBuffer) == sizeof(m_pBuffer));
int CWaveformStream::GetFrequency() const
int CWaveformStream::GetChannels() const
int CWaveformStream::GetLength() const
bool CWaveformStream::FillBuffer(void* pBuffer, size_t dwLength)
// Copy chunks from our buffer till we run out
// Are we able to just use what's in our buffer?
const size_t nLenRemain = (s_nBufferLen-m_dwBufferPos);
if(dwLength <= nLenRemain)
memcpy(pBuffer, m_pBuffer+m_dwBufferPos, dwLength);
m_dwBufferPos += dwLength;
m_fPos += (float)dwLength;
// Apparently not. Empty our buffer
memcpy(pBuffer, m_pBuffer+m_dwBufferPos, nLenRemain);
dwLength -= nLenRemain;
pBuffer = ((unsigned char*)pBuffer) + nLenRemain;
m_fPos += (float)nLenRemain;
while(m_fPos >= 44100.0f) m_fPos -= 44100.0f;
// Refill our buffer
bEOF = RefillBuffer();
if(bEOF && m_bLoop)
bEOF = false;
// End of file
for(size_t i=m_dwBufferPos; i
float fI = ((m_fPos+i)/22050.0f)*2.0f*3.1415926535897932384626433832795f;
fI *= 261.63f;
float fSample = sinf(fI);
m_pBuffer = (unsigned short)(fSample*65536.0f);
m_dwBufferPos = 0;
m_pBuffer is declared as: unsigned short m_pBuffer;.
I got my memory manager written, however. And it's tracking STL allocations too, which is nice. Although it can't track the file and line numbers, it can track the number of allocated bytes. It works perfectly, and I found and fixed 2 leaks in 5 minutes or so. One was me not deleting a manager singleton, and one was a bit more subtle - my sound manager's thread wasn't getting terminated properly, so it timed out and was forcefully terminated, leaking memory from a std::vector. Easy enough to fix - I posted the terminate event but forgot to signal the thread to pick up the event. So it sat in the even queue till the manager decided the thread was fubar and killed it.
I also discovered toggling to fullscreen wasn't working properly either - it wasn't changing the window style, so you could still click the taskbar. Fixed that on the train on the way home, then found that if the app is fullscreen and you hit the windows key, then restore the app again, the device won't reset (D3D tells me there's still objects allocated). So I'll have to find out what that's about. I have a feeling that I'm not resetting the flag that tells my device to call OnLostDevice() for all render objects after I reset the device. So it resets fine the first time (windowed -> fullscreen), but then forgets to do it in future. Anyway. That can be done on the train tomorrow.
I'm not going to do any coding tonight, I was in work late and I'm only just in (and it's 8:45pm). I was supposed to be going to a friends house to watch a film tonight, but I'd be half an hour late, and I'd have to get a taxi home. And this being Edinburgh, that costs about GBP8 which I don't have.
I'm off to watch some crap TV then goto bed.