18.11 Exercise: Transmission of Audio

Team-FLY

This section extends the UICI server and client of Program 18.1 and Program 18.3 to send audio information from the client to the server. These programs can be used to implement a network intercom, network telephone service, or network radio broadcasts, as described in Chapter 21.

Start by incorporating audio into the UICI server and client as follows .

  • Run Programs 18.1 and 18.3 with redirected input and output to transfer files from client to server, and vice versa. Use diff to verify that each transfer completes correctly.

  • Redirect the input to the client to come from the audio device (microphone) and redirect the output on the server to go to the audio device ( speakers ). You should be able to send audio across the network. (See Section 6.6 for information on how to do this.)

  • Modify the bidirectional server and client to call the audio functions developed in Section 6.6 and Section 6.7 to transmit audio from the microphone of the client to the speaker of the server. Test your program for two-way communication.

The program sends even if no one is talking because once the program opens the audio device, the underlying device driver and interface card sample the audio input at a fixed rate until the program closes the file. The continuous sampling produces a prohibitive amount of data for transmission across the network. Use a filter to detect whether a packet contains voice, and throw away audio packets that contain no voice. A simple method of filtering is to convert the u -law ( m -law) data to a linear scale and reject packets that fall below a threshold. Program 18.15 shows an implementation of this filter for Solaris. The hasvoice function returns 1 if the packet contains voice and 0 if it should be thrown away. Incorporate hasvoice or another filter so that the client does not transmit silence.

Program 18.15 hasvoice.c

A simple threshold function for filtering data with no voice .

 #include <stdio.h> #include <stdlib.h> #include "/usr/demo/SOUND/include/multimedia/audio_encode.h" #define THRESHOLD 20   /* amplitude of ambient room noise, linear PCM */                /* return 1 if anything in audiobuf is above THRESHOLD */ int hasvoice(char *audiobuf, int length) {     int i;     for (i = 0; i < length; i++)         if (abs(audio_u2c(audiobuf[i])) > THRESHOLD)             return 1;     return 0; } 

Write the following enhancements to the basic audio transmission service.

  1. Develop a calibration function that allows the threshold for voice detection to be adjusted according to the current value of the ambient room noise.

  2. Use more sophisticated filtering algorithms in place of simple thresholds.

  3. Keep track of the total number of packets and the actual number of those that contain voice data. Display the information on standard error when the client receives a SIGUSR1 signal.

  4. Add volume control options on both client and server sides.

  5. Design an interface for accepting or rejecting connections in accordance with sender information.

  6. Devise protocols analogous to caller ID and call-waiting.

  7. Add an option on the server side to record the incoming audio to a file for later playback. Recording is easy if the client is sending all the packets. However, since the client is sending only packets with voice, straight recording does not sound right on playback because all silences are compressed. Keep timing information as well as the audio information in the recorded data.

Team-FLY


Unix Systems Programming
UNIX Systems Programming: Communication, Concurrency and Threads
ISBN: 0130424110
EAN: 2147483647
Year: 2003
Pages: 274

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net