Results 1 to 4 of 4

Thread: voice chat via network

  1. #1
    Join Date
    Jan 2011
    Posts
    33
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default voice chat via network

    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 :

    Qt Code:
    1. #include <windows.h>
    2. #include <mmsystem.h>
    3. #include <iostream>
    4. #include <stdio.h>
    5.  
    6. using namespace std;
    7.  
    8. #pragma comment(lib, "winmm.lib")
    9.  
    10. int main()
    11. {
    12. const int NUMPTS = 441000;
    13. int sampleRate = 44100;
    14. short int waveIn[NUMPTS];
    15. HWAVEIN hWaveIn;
    16. WAVEHDR WaveInHdr;
    17. MMRESULT result;
    18. HWAVEOUT hWaveOut;
    19. WAVEFORMATEX pFormat;
    20. pFormat.wFormatTag = WAVE_FORMAT_PCM;
    21. pFormat.nChannels = 1;
    22. pFormat.nSamplesPerSec = sampleRate;
    23. pFormat.nAvgBytesPerSec = 2 * sampleRate;
    24. pFormat.nBlockAlign = 2;
    25. pFormat.wBitsPerSample = 16;
    26. pFormat.cbSize = 0;
    27. result = waveInOpen(&hWaveIn, WAVE_MAPPER, &pFormat, 0, 0, WAVE_FORMAT_DIRECT);
    28. if(result)
    29. {
    30. char fault[256];
    31. waveInGetErrorTextA(result, fault, 256);
    32. MessageBoxA(NULL, fault, "open error.", MB_OK | MB_ICONEXCLAMATION);
    33. return 1;
    34. }
    35. WaveInHdr.lpData = (LPSTR)waveIn;
    36. WaveInHdr.dwBufferLength = 2 * NUMPTS;
    37. WaveInHdr.dwBytesRecorded = 0;
    38. WaveInHdr.dwUser = 0;
    39. WaveInHdr.dwFlags = 0;
    40. WaveInHdr.dwLoops = 0;
    41. waveInPrepareHeader(hWaveIn, &WaveInHdr, sizeof(WAVEHDR));
    42. result = waveInAddBuffer(hWaveIn, &WaveInHdr, sizeof(WAVEHDR));
    43. if(result)
    44. {
    45. MessageBoxA(NULL, "add error", NULL, MB_OK | MB_ICONEXCLAMATION);
    46. return 1;
    47. }
    48. result = waveInStart(hWaveIn);
    49. if(result)
    50. {
    51. MessageBoxA(NULL, "start error", NULL, MB_OK | MB_ICONEXCLAMATION);
    52. return 1;
    53. }
    54. cout << "Recording..." << endl;
    55. Sleep((NUMPTS/sampleRate) * 1000);
    56. cout << "Playing..." << endl;
    57. if(waveOutOpen(&hWaveOut, WAVE_MAPPER, &pFormat, 0, 0, WAVE_FORMAT_DIRECT))
    58. {
    59. MessageBoxA(NULL, "outopen error", NULL, MB_OK | MB_ICONEXCLAMATION );
    60. }
    61. waveOutWrite(hWaveOut, &WaveInHdr, sizeof(WaveInHdr));
    62. Sleep((NUMPTS/sampleRate) * 1000);
    63. waveOutUnprepareHeader(hWaveOut, &WaveInHdr, sizeof(WAVEHDR));
    64. waveInUnprepareHeader(hWaveIn, &WaveInHdr, sizeof(WAVEHDR));
    65. waveInClose(hWaveIn);
    66. waveOutClose(hWaveOut);
    67. return 0;
    68. }
    To copy to clipboard, switch view to plain text mode 

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

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: voice chat via network

    Wouldn't it be better to use UDP for voice?

  3. #3
    Join Date
    Jan 2011
    Posts
    33
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: voice chat via network

    i need a simple example input>send/receive>output audio easy to read and analyze code.can you help me?

  4. #4
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: voice chat via network

    There are separate examples in Qt for input and for output, so you should easily be able to analyse.

Similar Threads

  1. Network Chat Client in a multihomed environment.
    By drescherjm in forum Qt Programming
    Replies: 1
    Last Post: 7th December 2010, 17:28
  2. Specialised Network Chat Application
    By TropicalPenguin in forum Jobs
    Replies: 0
    Last Post: 28th September 2010, 22:40
  3. Network chat system with pop-up window
    By kernel.roy in forum Qt Tools
    Replies: 1
    Last Post: 9th September 2010, 12:36
  4. Network chat system with pop-up window
    By kernel.roy in forum Newbie
    Replies: 1
    Last Post: 8th September 2010, 13:41
  5. Network chat system with pop-up window
    By kernel.roy in forum Qt Programming
    Replies: 0
    Last Post: 8th September 2010, 13:38

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.