CrazyPlaya
September 30th, 2008, 05:19 AM
to play out sound on windows where frames of 152Bytes which I get from RTP I need a buffer.
First the buffer has to collect some packets and order it by sequencenumber. That I do in a sorted linked list.
Know this buffer has to give over to the WaveOut Class. I have a function in the class that gets the buffer as
parameter and do it into the wavehdr struct. As the dwBufferLength I use the strlen(buffer) because I donīt have
information of the real size of this frame.
Here is the playout method and the call:
//This is my waveform structure
//It will be set by constructing the class
//m_wfx is of WAVEFORMATEX Structure
m_wfx.wFormatTag = WAVE_FORMAT_PCM;
m_wfx.nChannels = 1;
m_wfx.nSamplesPerSec = 8000;
m_wfx.wBitsPerSample = 8;
m_wfx.cbSize = 0;
m_wfx.nBlockAlign = (m_wfx.nChannels * m_wfx.wBitsPerSample)/8;
m_wfx.nAvgBytesPerSec = (m_wfx.nSamplesPerSec*m_wfx.nBlockAlign);
m_mmr = waveOutOpen(&m_hWaveOut,WAVE_MAPPER,&m_wfx,m_dwAudioOut,0,CALLBACK_THREAD);
bool CWaveOut::Play(char* szBuffer, UINT uSize)
{
char* p;
LPWAVEHDR lpWaveHdr = new WAVEHDR;
if(!lpWaveHdr)
return false;
p = (char*)malloc(uSize);
int iBuf = 0;
ZeroMemory(lpWaveHdr, sizeof(WAVEHDR));
char szErr[1024];
CG711* pG711 = new CG711();
for(int i = 0; i < uSize; i++)
{
if(pG711->decodeULaw(szBuffer[i]) > 0)
{
p[iBuf] = pG711->decodeULaw(szBuffer[i]);
iBuf++;
}
}
delete pG711;
pG711 = NULL;
lpWaveHdr->dwBufferLength = uSize;
lpWaveHdr->lpData = p;
m_mmr = waveOutPrepareHeader(m_hWaveOut, lpWaveHdr, sizeof(WAVEHDR));
if(m_mmr)
{
waveOutGetErrorTextA(m_mmr, szErr, sizeof(szErr));
return false;
}
m_mmr = waveOutWrite(m_hWaveOut, lpWaveHdr, sizeof(WAVEHDR));
if(m_mmr)
{
waveOutGetErrorTextA(m_mmr, szErr, sizeof(szErr));
return false;
}
if(waveOutUnprepareHeader(m_hWaveOut, lpWaveHdr, sizeof(WAVEHDR))== WAVERR_STILLPLAYING)
{
Sleep(100);
}
}
//and here is the call
.
.
buffer = getOutputBuffer(); // returns the databuffer of collected packets
PlayOut(buffer, strlen(buffer));
But i just get a curios noise instead of speech. Is it right how I do the Playout?
I donīt know on? The G711 decoding seems to be correct because I ask for it
in divers other forums. There all say itīs correct.
Greetings CrazyPlaya
First the buffer has to collect some packets and order it by sequencenumber. That I do in a sorted linked list.
Know this buffer has to give over to the WaveOut Class. I have a function in the class that gets the buffer as
parameter and do it into the wavehdr struct. As the dwBufferLength I use the strlen(buffer) because I donīt have
information of the real size of this frame.
Here is the playout method and the call:
//This is my waveform structure
//It will be set by constructing the class
//m_wfx is of WAVEFORMATEX Structure
m_wfx.wFormatTag = WAVE_FORMAT_PCM;
m_wfx.nChannels = 1;
m_wfx.nSamplesPerSec = 8000;
m_wfx.wBitsPerSample = 8;
m_wfx.cbSize = 0;
m_wfx.nBlockAlign = (m_wfx.nChannels * m_wfx.wBitsPerSample)/8;
m_wfx.nAvgBytesPerSec = (m_wfx.nSamplesPerSec*m_wfx.nBlockAlign);
m_mmr = waveOutOpen(&m_hWaveOut,WAVE_MAPPER,&m_wfx,m_dwAudioOut,0,CALLBACK_THREAD);
bool CWaveOut::Play(char* szBuffer, UINT uSize)
{
char* p;
LPWAVEHDR lpWaveHdr = new WAVEHDR;
if(!lpWaveHdr)
return false;
p = (char*)malloc(uSize);
int iBuf = 0;
ZeroMemory(lpWaveHdr, sizeof(WAVEHDR));
char szErr[1024];
CG711* pG711 = new CG711();
for(int i = 0; i < uSize; i++)
{
if(pG711->decodeULaw(szBuffer[i]) > 0)
{
p[iBuf] = pG711->decodeULaw(szBuffer[i]);
iBuf++;
}
}
delete pG711;
pG711 = NULL;
lpWaveHdr->dwBufferLength = uSize;
lpWaveHdr->lpData = p;
m_mmr = waveOutPrepareHeader(m_hWaveOut, lpWaveHdr, sizeof(WAVEHDR));
if(m_mmr)
{
waveOutGetErrorTextA(m_mmr, szErr, sizeof(szErr));
return false;
}
m_mmr = waveOutWrite(m_hWaveOut, lpWaveHdr, sizeof(WAVEHDR));
if(m_mmr)
{
waveOutGetErrorTextA(m_mmr, szErr, sizeof(szErr));
return false;
}
if(waveOutUnprepareHeader(m_hWaveOut, lpWaveHdr, sizeof(WAVEHDR))== WAVERR_STILLPLAYING)
{
Sleep(100);
}
}
//and here is the call
.
.
buffer = getOutputBuffer(); // returns the databuffer of collected packets
PlayOut(buffer, strlen(buffer));
But i just get a curios noise instead of speech. Is it right how I do the Playout?
I donīt know on? The G711 decoding seems to be correct because I ask for it
in divers other forums. There all say itīs correct.
Greetings CrazyPlaya