PDA

View Full Version : voice chat via network



Con Nít
1st February 2011, 17:26
I want to write an online voice chat program used QTcpSocket
I refer to examples of code input / output audio in the QT example, but I had trouble reading the code, I do not understand in the QT example, which part is input / output ....
similar to the code below I have found it is written win32API :


#include <windows.h>
#include <mmsystem.h>
#include <iostream>
#include <stdio.h>

using namespace std;

#pragma comment(lib, "winmm.lib")

int main()
{
const int NUMPTS = 441000;
int sampleRate = 44100;
short int waveIn[NUMPTS];
HWAVEIN hWaveIn;
WAVEHDR WaveInHdr;
MMRESULT result;
HWAVEOUT hWaveOut;
WAVEFORMATEX pFormat;
pFormat.wFormatTag = WAVE_FORMAT_PCM;
pFormat.nChannels = 1;
pFormat.nSamplesPerSec = sampleRate;
pFormat.nAvgBytesPerSec = 2 * sampleRate;
pFormat.nBlockAlign = 2;
pFormat.wBitsPerSample = 16;
pFormat.cbSize = 0;
result = waveInOpen(&hWaveIn, WAVE_MAPPER, &pFormat, 0, 0, WAVE_FORMAT_DIRECT);
if(result)
{
char fault[256];
waveInGetErrorTextA(result, fault, 256);
MessageBoxA(NULL, fault, "open error.", MB_OK | MB_ICONEXCLAMATION);
return 1;
}
WaveInHdr.lpData = (LPSTR)waveIn;
WaveInHdr.dwBufferLength = 2 * NUMPTS;
WaveInHdr.dwBytesRecorded = 0;
WaveInHdr.dwUser = 0;
WaveInHdr.dwFlags = 0;
WaveInHdr.dwLoops = 0;
waveInPrepareHeader(hWaveIn, &WaveInHdr, sizeof(WAVEHDR));
result = waveInAddBuffer(hWaveIn, &WaveInHdr, sizeof(WAVEHDR));
if(result)
{
MessageBoxA(NULL, "add error", NULL, MB_OK | MB_ICONEXCLAMATION);
return 1;
}
result = waveInStart(hWaveIn);
if(result)
{
MessageBoxA(NULL, "start error", NULL, MB_OK | MB_ICONEXCLAMATION);
return 1;
}
cout << "Recording..." << endl;
Sleep((NUMPTS/sampleRate) * 1000);
cout << "Playing..." << endl;
if(waveOutOpen(&hWaveOut, WAVE_MAPPER, &pFormat, 0, 0, WAVE_FORMAT_DIRECT))
{
MessageBoxA(NULL, "outopen error", NULL, MB_OK | MB_ICONEXCLAMATION );
}
waveOutWrite(hWaveOut, &WaveInHdr, sizeof(WaveInHdr));
Sleep((NUMPTS/sampleRate) * 1000);
waveOutUnprepareHeader(hWaveOut, &WaveInHdr, sizeof(WAVEHDR));
waveInUnprepareHeader(hWaveIn, &WaveInHdr, sizeof(WAVEHDR));
waveInClose(hWaveIn);
waveOutClose(hWaveOut);
return 0;
}

I need a similar code is written with QT. or can anyone give me demo code simple voice chat with QT.

tbscope
1st February 2011, 17:49
Wouldn't it be better to use UDP for voice?

Con Nít
1st February 2011, 18:45
i need a simple example input>send/receive>output audio easy to read and analyze code.can you help me?

squidge
1st February 2011, 19:55
There are separate examples in Qt for input and for output, so you should easily be able to analyse.