Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

VoIP For You - Full duplex 8bit/8KHz VoIP application for Windows98 & DirectX

0.00/5 (No votes)
31 Aug 2003 1  
Sending and receiving voice under TCP/IP and Windows 98 & Direct X.

Introduction

Hi friends, this is my second article in Code Project. Therefore, I�ll try to make it better.

The application is Windows 98.SE tested. When using Direct Sound objects, don�t forget to include in your application the following libs in your project settings - link:

  • dsound.lib
  • dxguid.lib
  • winmm.lib

It is very fashionable to talk about VoIP � Voice Over IP, but many of my friends think that this is too difficult to understand, how to urge? Therefore, I�ll try to explain VoIP from my side.

To make a commercial VoIP application is too difficult. For many of us, it is good to use some programs to talk in home networks with friends. Before starting to build a VoIP application, it was 2 years behind, I scraped with two main problems:

  • First � how to program network applications via TCP/IP?
  • Second � how to record and play waveform audio on my PC?

First problem was very easy to decide � read �Visual C++ 6� book published by SAMS. To solve the second problem, I encountered with hard to understand Windows Sound Programming. In the beginning, I started to read BIG BOOKS how to program DMA � Direct Memory Access and sound card direct programming using in/out ports, but soon I detected that this kind of programming is a very thankless job and I started to search additional ways to solve the problem. This is easily called Direct Sound. (DMA programming is a good choice, but only if you are programming device drivers or when programming on Assembler.)

Let me explain how I did it.

First, assume you and some of your friends have a need to talk inside a private network. This is easily to test applications at home network. Remember one! To develop and test network applications, there is no need to have a real Internet or TCP/IP WAN network. You can use �loopback� server with IP address 127.0.0.1 and some of the free ports between 3000 and 5000. (Before this, install TCP/IP protocols on your machine � using Start button, Control Panel, Networks and add new protocol � Microsoft TCP/IP.)

The main program is a full duplex 8KHz 8bit recording and playing waveform audio application that can send and receive captured audio data via Internet connection. In real conditions, to test the program, you must install and start 2 copies of this program on 2 different PCs in your network. One of these two programs must be set to work as a server, and another program must be set to work as a client. Start the server program to listen for network events and then activate another program to work as a client and try to connect with the first one (server). To make a connection, you must know the IP address, or name and port of the computer where the server program was started. If the IP and port are not the same as the IP and port of the server program, there will not be a connection.

When 2 programs are connected, you can use �8bit 8KHz DUPLEX� button to start recording and receiving the audio data from another computer. When you want to stop the recording and playing process, press the �Stop DUPLEX� button.

If you have no TCP/IP network at home, you can test the software using the second application. An echo receiver and transmitter program works as echo server that can be started on the same PC. In this case, you can connect your VoIP application to an already started echo server using IP -127.0.0.1 address and port 4000. Now, click on �8bit 8KHz DUPLEX� button and start to talk on the microphone, you will listen your voice echo on the headphones. You can make some experiments with this echo server even if you plan to test the program on a working TCP/IP network. This is a good choice, think about that, in some cases there will be difficulty to tell somebody to speak all day �1,2,3 check�.

Conclusions

VoIP program is working. In some cases, there will be problem with full duplex working regime. To start the program, you need a PCI full duplex sound card and DirectX installed on your PC. Software was tested on Windows 98 (CPU AMD 300MHz, 64MB RAM) machine with ALS4000 sound card and DirectX 8. There may be a problem to start the program on NT/2000 � these operating systems do not support 8KHz, 8bit Mono Full Duplex audio recording and playing without a proper DirectX version.

About software �FULL_DUPLEX�

Program contains 3 main classes: FULL_DUPLEX.dlg, CmySocket and Duplex.

First and the main class is Dlg class. CmySocket class takes care about network communications and Duplex class operates with waveform audio.

Duplex creates a streaming 1-second playing and recording audio buffer using functions HRESULT Duplex::CreateOutputBuffer() and HRESULT Duplex::SetBufferFormats(). This 1 second is divided by 15 different segments, and for each segment is specified NotificationEvent. So when the recording process comes to the next position in audio buffer, front segment can be read or written from the main program. This is done by thread UINT WaitThreadProc( LPVOID param ) in the FULL_DUPLEX.dlg class. Each time when WaitThreadProc detects that there are some audio data ready to be send via network, this function activates dlg->SendAudio(audio,lenght);. If there are some data to be written in audio buffer this is done using CopyMemory(receive_audio,dlg->audio_receive,500);. If there are no received data from network connection, we fill the playing buffer with silence using FillMemory(audio,500,128);. That is all.

Future features can be added later, so they will provide DSP � Digital Signal Processing techniques on the input and output audio signals, differential compression and decompression and noise filtering using low pass filters. This simple compression algorithm can provide effective decreasing in data transmitting rate from 8Kbits/s to 3.2Kbits/s.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here