Click here to Skip to main content
15,860,972 members
Articles / Desktop Programming / MFC
Article

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

Rate me:
Please Sign up or sign in to vote.
3.63/5 (41 votes)
31 Aug 20035 min read 297.9K   11.6K   88   117
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


Written By
Systems Engineer
Bulgaria Bulgaria
PhD, Cum Laude in digital automation systems
M.S. in Telemommunication management
B.S. in Telecommunication systems engineering
Programming: CUDA, C/C++, VHDL
Software and Hardware development and consulting:
data acquisition, image processing, medical instrumentation

Comments and Discussions

 
GeneralMy vote of 3 Pin
Mic6-Aug-13 14:29
Mic6-Aug-13 14:29 
QuestionI cant debug solution! Pin
diepa9k3920-Feb-12 21:27
diepa9k3920-Feb-12 21:27 
QuestionI need to develop a softphone to make calls to telephone Pin
Rinosh_sasidharan6-Nov-11 7:37
Rinosh_sasidharan6-Nov-11 7:37 
Generalvoip solution Pin
sdfsdfsdfsdfdfgdf30-Sep-10 2:56
sdfsdfsdfsdfdfgdf30-Sep-10 2:56 
QuestionXML data upload Pin
nilukachapterzero6-Sep-10 23:24
nilukachapterzero6-Sep-10 23:24 
QuestionTesting this program Pin
kurankar6-Dec-09 19:43
kurankar6-Dec-09 19:43 
GeneralChange Waveform Standard [modified] Pin
cun-cun10-Sep-09 16:49
cun-cun10-Sep-09 16:49 
GeneralRe:Voip Pin
jomoal998-Sep-09 1:13
jomoal998-Sep-09 1:13 
General[Message Deleted] Pin
it.ragester28-Mar-09 5:34
it.ragester28-Mar-09 5:34 
Questionvoip security Pin
shankaranarayanan.m17-Feb-09 15:39
shankaranarayanan.m17-Feb-09 15:39 
GeneralGreat Knowlage Pin
SIN123456785-Dec-08 22:42
SIN123456785-Dec-08 22:42 
GeneralReplacement For Skype Pin
edwardking5-Oct-08 13:29
edwardking5-Oct-08 13:29 
GeneralSIP Dialer Pin
sdaeesh3-Oct-08 19:06
sdaeesh3-Oct-08 19:06 
GeneralCan't Download the files Pin
Member 259783720-Sep-08 8:25
Member 259783720-Sep-08 8:25 
GeneralDetect Voice and Echo Canceller Pin
Member 467834318-Jun-08 0:19
Member 467834318-Jun-08 0:19 
Generalneed help to apply AES with the application Pin
quoc phong4-Jun-08 22:21
quoc phong4-Jun-08 22:21 
QuestionCan any one provide me a project with source code Pin
sanei0521-Mar-08 21:19
sanei0521-Mar-08 21:19 
AnswerRe: Can any one provide me a project with source code Pin
Georgi Petrov22-Mar-08 6:58
Georgi Petrov22-Mar-08 6:58 
GeneralRe: Can any one provide me a project with source code Pin
sanei0522-Mar-08 18:43
sanei0522-Mar-08 18:43 
GeneralNeed code in VC++ for voice over ip Pin
sanei0521-Mar-08 21:08
sanei0521-Mar-08 21:08 
Generalin symbian Pin
adien16-Mar-08 14:44
adien16-Mar-08 14:44 
Generalneed code for VOIP in java Pin
sekarbright21-Sep-07 0:06
sekarbright21-Sep-07 0:06 
GeneralRequest for the project Pin
<..???....>??///9-Jun-07 21:00
<..???....>??///9-Jun-07 21:00 
GeneralRe: Request for the project Pin
mari ram26-Jun-07 18:38
mari ram26-Jun-07 18:38 
GeneralRe: Request for the project Pin
<..???....>??///29-Jun-07 0:01
<..???....>??///29-Jun-07 0:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.