A kind of point-to-point voice communication based on LAN

Source: Internet
Author: User

Introduction

With the increasing popularity of computer network, people communicate through the network becomes more and more important, so a series of voice communication software, such as NetMeeting, Ipphone, mediaring and Voxphone, but these software are functional, relatively independent, Not conducive to integrating into your own software, sometimes we also want to integrate this voice communication into our software, especially when a unit of local area network users are scattered across different rooms. In this paper, a flexible and simple implementation method, based on the dialog box programming, hardware only need a dual DMA channel of the sound card (the current sound card most support dual DMA channel) and a headset, the rest of all by software programming. Programs are compiled with windows98/2000, Visual c++6.0, and run well on Windows NT 100M Ethernet.

Design ideas

To achieve point-to-point voice communication, the principle is very simple, as long as a point to achieve real-time voice acquisition, processing, playback, and reliable transmission and reception, so that 2.1 can call. For the former, it is appropriate to use the low-level audio service of Windows MDK, because the callback mechanism in the low-level audio service provides us with great convenience. When the application continues to provide audio data to the device driver, the device Driver program control audio device in the background to complete the recording and playback of the specific operation, through the callback mechanism, we can detect when the use of a block of data, and timely transmission of the next block, so as to ensure the sound of continuous, With this single machine on the real-time collection, playback function, the next task is to transmit voice data on the network. In the context of point-to-point network transmission, select connection-oriented TCP protocol, TCP transport protocol automatically deal with packet loss and delivery disorder, so that we do not worry about these issues, we need to make good use of this connection, in the acquisition of voice playback on the one hand to the network, on the other hand to receive the voice of the network, In this way, point-to-point voice communication is realized. The structure diagram is as follows:

Concrete implementation

First, the voice of real-time acquisition, processing, playback

The first is to introduce Windows low-level waveform audio block structure WAVEHDR, which is declared as follows:

Type struct{

LPSTR lpdata; A pointer to a locked data buffer

DWORD dwbufferlength; The size of the data buffer

DWORD dwbyterecorded; Indicates the amount of data in the buffer when recording

DWORD Dwuser; User Data

DWORD Dwflag; Flags that provide buffer information

DWORD Dwloops; Number of loops played

struct Wavehdr_tag * LPNEXT; Keep

DWORD reserved; Keep

} WAVEHDR;

Sound collection and playback are in the operation of the audio block structure, in fact, the main use is the first member variable lpdata, so we just allocate the buffer (memory) at the same time allocate the WAVEHDR block structure, and then assign the buffer pointer to the corresponding block structure of the member variable Lpdata, so when a buffer is filled, that is, a block of audio data is filled, through the message mechanism can be processed and played in the message function, after the play can be sent through the message function buffer to the audio device input driver, continue to collect and play, When you assign multiple buffers and block structures at once and assign them to an audio device to enter the driver, as to which buffer to fill, and then the empty buffer assigned to the device input driver, without human intervention, completely by Windows control, this is a dynamic loop buffer to achieve real-time voice acquisition, A simple and ingenious way to play. Implementation steps:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.