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 .
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.cA 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.
|
Team-FLY |