Open Collections

UBC Theses and Dissertations

UBC Theses Logo

UBC Theses and Dissertations

Real-time implementation and evaluation of an adaptive silence deletion algorithm for speech compression Rose, Christopher 1991

Your browser doesn't seem to have a PDF viewer, please download the PDF to view this item.

Item Metadata

Download

Media
831-UBC_1991_A7 R67.pdf [ 9.5MB ]
Metadata
JSON: 831-1.0065462.json
JSON-LD: 831-1.0065462-ld.json
RDF/XML (Pretty): 831-1.0065462-rdf.xml
RDF/JSON: 831-1.0065462-rdf.json
Turtle: 831-1.0065462-turtle.txt
N-Triples: 831-1.0065462-rdf-ntriples.txt
Original Record: 831-1.0065462-source.json
Full Text
831-1.0065462-fulltext.txt
Citation
831-1.0065462.ris

Full Text

REAL-TIME IMPLEMENTATION AND EVALUATION OF AN ADAPTIVE SILENCE DELETION ALGORITHM FOR SPEECH COMPRESSION By Christopher Rose B. A. Sc., Simon Fraser University, 1987 A THESIS SUBMITTED IN PARTIAL FULFILLMENT OF THE REQUIREMENTS FOR THE DEGREE OF MASTER OF APPLIED SCIENCE in THE FACULTY OF GRADUATE STUDIES DEPARTMENT OF ELECTRICAL ENGINEERING We accept this thesis as conforming to the required standard THE UNIVERSITY OF BRITISH COLUMBIA August 1991 © Christopher Rose, 1991 In presenting this thesis in partial fulfilment of the requirements for an advanced degree at the University of British Columbia, I agree that the Library shall make it freely available for refer-ence and study. I further agree that permission for extensive copying of this thesis for scholarly purposes may be granted by the head of my department or by his or her representatives. It is understood that copying or publication of this thesis for financial gain shall not be allowed without my written permission. Department of Electrical Engineering The University of British Columbia 2075 Wesbrook Place Vancouver, Canada V6T 1W5 Date: Abstract The removal of nonessential acoustic material or silence from speech can significantly reduce the average bit rate required for speech coding. Silence deletion can be used to reduce the channel capacity required for speech transmission, or to reduce the storage requirements for voice mail applications. This thesis describes the real-time implementation of a silence compression algorithm us-ing a TMS320C25 digital signal processor. Substantial modifications were made to an earlier silence detection algorithm to enable its implementation in real time, as well as to improve the performance of the algorithm in a variety of speech environments. Up to 50% compression on single speaker speech is possible with our silence compression algorithm without significant loss of playback signal quality. The silence compression algorithm was implemented in a way that enabled source coding techniques to be used to further compress the speech portions of the acoustic signal. The use of 4-bit A D P C M to code the speech resulted in an average bit rate below 19.2 kbit/s. i i Table of Contents Abstract ii List of Tables vi List of Figures vii Acknowledgement viii 1 Introduction 1 1.1 Silence Compression 1 1.2 Review of Previous Work 3 1.3 Organization of Thesis 6 2 Silence Detection Algorithm Description and Development 8 2.1 Detection of Silence Intervals 8 2.1.1 Decision Criteria 8 2.1.2 Hysteresis in Energy Threshold 9 2.1.3 Classification of Speech/Silence Intervals 10 2.2 Adaptation to Noise and Signal Levels 12 2.3 Noise Insertion During Silence Intervals 16 2.4 Final Algorithm 17 2.5 Parameter Selection 19 2.5.1 Frame Size 19 2.5.2 Energy Thresholds 21 2.5.3 Zero Crossing Rate 21 iii 2.5.4 Minimum Speech/Silence Intervals 23 2.5.5 Speech and Silence Interval Averages 23 2.5.6 Final Parameter Values 24 3 Real - t ime Implementation of Silence Compress ion A l g o r i t h m 26 3.1 Coding of Silence Intervals 27 3.1.1 Silence Code 27 3.1.2 Interval Length Coding 29 3.1.3 Interval Energy Coding 30 3.2 Coding of Speech Intervals 31 3.3 Long Term Signal Averaging 32 3.4 Data Transfer 34 3.5 Noise Playback 36 4 A l g o r i t h m Performance Evaluat ion 38 4.1 Speech Compression 38 4.2 Algorithm Complexity 39 4.3 Subjective Evaluation 39 5 S u m m a r y and Conclusions 44 5.1 Summary 44 5.2 Areas for Further Research 45 Bib l iography 47 A H a r d w a r e Design 51 A . l Hardware Description 51 A.2 Firmware Listings 60 B Software Listings 65 iv B.l Simulation Listings 65 B.2 Real-time Implementation Listings 72 B.2.1 Tms320c25 Program Listings 72 B.2.2 PC Host Program Listings 102 v List of Tables 2.1 Optimum Algorithm Parameters for Various Framesizes 25 4.1 Compression Results for Various Frame Sizes 38 4.2 Algorithm Parameters for Processing Quiet Speech Sample 41 4.3 Algorithm Parameters for Processing Noisy Speech Sample 41 4.4 Listening Test Results Quiet Original Speech Sample 42 4.5 Listening Test Results Noisy Original Speech Sample 42 vi List of Figures 1.1 Speech Utterance Showing Silence Intervals 2 2.1 Effect of Speech Detection with Constant E-Thresholds 12 2.2 Effect of Speech Detection with Background Noise Level Adaptation 14 2.3 Effect of Speech Detection with Speech Level Adaptation 15 2.4 Effect of Speech Detection with Both Speech and Noise Level Adaptation .... 16 2.5 Block Diagram of the Silence Detection Algorithm 18 2.6 Percentage Silence for Various Framesizes with Fixed Thresholds 20 2.7 Percent Silence Deletion with Dual Thresholds 22 3.1 Format for Silence Interval Coding 27 3.2 Data Memory Pointer Organization 35 A.l Block Diagram of Speech Compression System 51 vii Acknowledgement I would like to thank my supervisor, Dr. Robert Donaldson, who suggested this topic, was a constant source of encouragement and helpful advice, and who provided financial support through NSERC operating grant A-3308. I would also like to thank the many conscientious participants who assisted in the subjective evaluation of the speech compression algorithm. Finally, I would like to acknowledge the financial assistance provided by the Natural Sciences and Engineering Research Council of Canada (NSERC), by the British Columbia Advanced Systems Institute (BC ASI), and by the University of British Columbia in the form of post-graduate scholarships. viii Chapter 1 Introduction 1.1 Silence Compression For many years, there has been active research to devise more bandwidth efficient methods of communicating and recording speech signals. With the evolution of digital technology, many methods of speech compression have been developed, generally utilizing one or more redundan-cies present in a speech signal [1,2]. Recent work has been done to find methods of coding toll quality speech at low bit rates (below 16 kb/s), as well as improving the speech quality at exist-ing bit rates (32 and 64 kb/s) [3]. Modern coding techniques, such as vector quantization, can provide high compression rates (toll quality speech at 16 kb/s) but have a large computational requirement [4]. A simple and fairly effective method of speech compression involves the detection and re-moval of the numerous silence or non-speech intervals present during a conversation. These acoustically non-essential intervals exist in speech between sentences, phrases, and words; very short silence intervals are also present within words, such as before stop consonants. Studies have shown that for a normal two-way conversation, silence intervals comprise up to 65% of the utilization of each one-way communication channel [5,6]. Figure 1.1 shows a plot of the average short-term signal level for the speech utterance "A Simple Test". The plot clearly shows the low level silence intervals before and after the phrase as well as between the words 'simple' and 'test'. Careful observation also reveals the much shorter intra-word silence intervals just before the 'p' in 'simple' and before the final 't' in 'test'. There are several applications for a system that can detect the silence periods within speech, 1 Chapter 1. Introduction 2 > CD _J £> CD C LU A S I M P L E T E S T Figure 1.1: Speech Utterance Showing Silence Intervals or conversely, the speech portions of an acoustic sample, as follows: • The detection and removal of silence periods can greatly increase the storage capacity of speech recording and voice mail systems [7,8,9]; • Communication transmission systems can benefit from the detection and removal of si-lence periods; system transmission capacity can be increased by either not transmitting the silences as in a packet speech system [10], or by switching the channel to an active conversation or to a data channel during silence intervals [11]; • Speech recognition systems require that the start and end points of words be accurately isolated to facilitate the recognition process [12]; and • Systems which perform adaptive filtering require periods of speech activity to be detected; applications include echo control systems for long distance communications, and adaptive Chapter 1. Introduction 3 noise filtering systems. For all of these applications, the utility of a speech detection system is strongly dependent on its complexity, and on the associated processing power that is required for its implementation. An important consideration which can limit the range of silence detection or deletion ap-plications is processing delay. A speech detector that is used for two-way communications applications requires a low processing delay and must inherently be implemented in real-time to reduce the end-to-end transmission delay. In a voice mail system, the real-time constraint is less critical; it would be feasible to detect the silence intervals off-line after initial recording. However, in most applications, there are definite advantages to real-time processing; exces-sive speech storage requirements are avoided, and the requirement for additional resources to reprocess the data off-line is reduced. 1.2 Review of Previous Work Silence intervals in telephone conversations were first studied by Norwine and Murphy in 1938 [13]. In more recent years, research has been performed to develop accurate statistical models of silence intervals in conversational speech, as well as to determine the speech activity — talkspurt frequency trade-offs involved in developing a speech compression system [6,14]. In 1960, silence intervals were first utilized for increasing channel capacity in voice communi-cations [5]. This system, known as Time Assignment Speech Interpolation (TASI), deallocated communication channels during periods of inactivity or silence for use with other conversations. Using this time division multiplexing method, TASI could carry more conversations than there were actual channels, thereby providing an apparent increase in channel capacity. The original TASI systems were implemented using analog electronics to perform the speech detection and circuit switching. Later systems took advantage of digital signal processing to combine the time division multiplexing with digital speech encoding techniques to achieve Digital Speech In-terpolation (DSI) [15,16]. Combining new digital speech coding techniques with DSI provided a further increase in channel capacity. Most notably, much work has been done to combine Chapter 1. Introduction 4 adaptive differential P C M (ADPCM) with DSI to obtain a 4:1 increase in channel capacity over that of conventional u-l&w coded P C M [17,18]. The performance characteristics desired in a silence or speech detector varies greatly de-pending on the particular application at hand. A speech interpolation system typically has a large overhead associated with each silence interval to facilitate channel switching; it is therefore desirable to detect only the larger silence intervals to lower the talkspurt frequency and prevent excessive switching. Conversely, a speech storage facility typically has a very low silence coding overhead; therefore, the detection of very short intervals can increase the overall compression efficiency of the system. The majority of work done on silence or speech detectors has been tailored towards use in speech interpolation systems. However, much has been learned about silence detection from the TASI systems such as the effects of speech clipping, and the speech characteristics pertinent to speech detection. The first speech detectors for TASI were based on an analog averaging detector operating on a 500 to 3000 Hz bandwidth, with a fixed threshold to differentiate speech and silence intervals [19]. To prevent the loss of weak syllables, a hangover was incorporated to prevent the release of the speech detector until the speech power remained below the threshold for 240 ms. This type of speech detector has two major drawbacks: the averaging speech detector is slow to respond to the onset of speech utterances, causing excessive speech clipping; and the hangover is inefficient, activating the speech detector for a portion of the acoustic signal which may or may not contain speech to compensate for the inability of the averaging detector to recognize low level speech. Improved speech detectors were developed that used peak detection, rather than an averag-ing RMS detector [20,21]. The peak to average ratio of speech is 6 to 8 dB larger than the peak to average ratio of gaussian noise; therefore, if large peaks were detected, speech was assumed to be present. Since the speech was not averaged over a fixed period of time, the resulting detector is able to respond much more quickly to speech onsets. Fariello combined this peak detection approach with a zero crossing rate detector to enable the detection of low amplitude, Chapter 1. Introduction 5 high frequency fricatives [20]. The peak detection scheme reported by Jankowski incorporated threshold adaptation based on the background noise level to improve the detection performance under varying conditions [21]. One draw back of this technique is that a hangover period of 150 to 160 ms is required to maintain activation of the speech detector between successive peaks in the speech signal. Drago [22] developed a speech detector based on a speech model of a high frequency carrier modulated by a low frequency envelope. Speech — non-speech decisions were based on the dynamic variations of the low frequency envelope or energy of the acoustic signal, rather than the absolute level as with conventional speech detectors. The resulting detector had better performance for speech onsets, and was less sensitive to acoustic signal level than conventional detectors. A hangover period of 250 ms was used. TJn and Lee [23] developed a speech — silence discriminator based on bit alternation rates of delta modulation recorded speech. The high sampling rates used in delta modulation (typically 24,000 to 32,000 samples per second) enable silence intervals to be detected by a high rate of 0/1 bit alternations which typically result when the delta modulator dithers to track a very low level signal such as which occur between speech utterances. Cho and Un [24] later used this speech detector to reduce the overall bit rate in delta modulation coded speech. De Souza [12] developed an adaptive, self-normalizing silence detector for use in continuous speech recognition applications. The detector was based on the concept of "pattern recogni-tion", performing a statistical test on a series of parameters calculated for each frame of acoustic signal. The parameters included frame energy, number of zero-crossings, and autocorrelation calculations. The silence detector required a 500 ms training interval of background noise at the beginning of a speech recording in order to function correctly. However, the parameters for typical silence frames were updated continuously in order to adapt to any variations in the background noise. Recent work has been performed towards the development of a simple yet effective method of detecting and utilizing silence intervals for speech compression [25,26], Compression rates Chapter 1. Introduction 6 of 35 to 40% were obtained using a relatively noisy recording of a single talker reading from a prepared text. In this previous work, the author developed an adaptive method for adjusting the speech - silence energy thresholds based on the level of the background noise. However, using the adaptive threshold scheme proposed, the algorithm performance for relatively noise-free speech is inconsistent; there is a tendency for the thresholds to approach zero, resulting in reduced compression. Since compression of good quality speech is desirable, the algorithm as described [25] is problematic. 1.3 Organization of Thesis The primary objective of this thesis is to describe the design, real-time implementation, and evaluation of a silence compression algorithm. Also described is the substantial work done to enhance the robustness, playback quality, and efficiency of the basic silence detection al-gorithm, which serves as a starting point for this thesis research. Our evaluations are. based on subjective speech quality assessments using listening tests, measured compression statistics, and implementation simplicity. Chapter 2 details the development of the silence interval detection algorithm, which is based in part on one developed earlier [25,26]. Described are the substantial steps taken to ensure efficient compression, good quality speech, and robust performance in various operating environments, as well as means to enable real-time implementation using standard electronic components. The chapter includes a section on the selection of the optimum algorithm param-eters. Chapter 3 details the real-time implementation of our silence compression algorithm. In-cluded are discussions on the coding of silence intervals into the speech data, source coding of the speech data to further improve compression, and the manipulation of the acoustic data to facilitate a real-time speech storage or transmission system. The evaluation of the silence compression algorithm is detailed in Chapter 4. The results of subjective evaluations of the speech compression system are presented, along with an analysis Chapter 1. Introduction 7 of compression efficiency and implementation complexity. The results show that up to 50% of single speaker continuous speech can be deleted from 32 kbit/s ADPCM speech with minimal loss in quality. Chapter 5 summarizes the contributions of the thesis, and suggests some topics for further research. Chapter 2 Silence Detection Algorithm Description and Development This chapter presents the algorithm used to detect the silence periods within the speech samples. The basic algorithm was adapted from one developed previously [25]; however, substantial modifications were devised to accomplish the following: 1. make the algorithm easier to implement in a real-time system; 2. improve the compression performance and playback quality; and 3. improve the robustness of the algorithm for use with less noisy speech. 2.1 Detection of Silence Intervals In processing the input speech, the samples are divided into non-overlapping intervals or frames of size K samples. Each frame will be classified as either speech or silence based on decision criteria calculated on the data within that frame, and on the classification of previous frames. 2.1.1 Decision Criteria Two basic decision criteria are used to classify the input frames as either speech or silence: short-time average amplitude and mean zero crossing rate. The short-time average amplitude criteria is designed to act on the large variation of signal levels present in the speech waveform [2]. It will detect the large levels during vowels and vowel-like consonants. Zero crossing rate facilitates detection of the low level, high frequency components of speech such as unvoiced fricative and stop consonants. Gan found [25] zero crossing rate to be an effective means of detecting these portions of speech, particularly with noisy speech signals. A zero crossing is 8 Chapter 2. Silence Detection Algorithm Description and Development 9 denned as a position within the signal where the sign of the signal level changes between two successive samples. For each frame of speech Fj, the average signal amplitude Ei and the number of zero crossings Zi for the interval are calculated as follows: 1 K Ei=-EY,\XKi+i\ (2-1) K Zi = J2S(XKi+j) (2.2) j=i where ' 0 if sgn(Jrn) = sgn(Xn_a) 1 otherwise. S(Xn) = { The function S(Xn) has a value of 1 only if Xn and Xn-\ have different signs, which occurs if and only if a zero crossing falls between them. The value of Z,, as calculated by equation 2.2, is equal to the total number of zero crossings that occur within the frame F{. The notation Xjci+j represents the jth digital sample within the ith frame of size K. The short-time amplitude average is used as a decision criteria, instead of the short-time energy (in which the square of each sample is summed) to reduce the sensitivity of varying input signal levels due to the squaring operation [27], and to simplify the calculation of the short-time energy. In this thesis, the average amplitude Ei calculated from equation 2.1 shall be loosely referred to as the signal energy. Initially, each frame is evaluated as being either speech or silence based solely on that frame's average energy and number of zero crossings. In particular, the frame F{ is classified as speech if E{ > E-Threshold, or if Zi > Z-Threshold. The frame is classified as silence if neither of these two conditions hold true. 2.1.2 Hysteresis in Energy Threshold The basic algorithm described above can be improved by taking advantage of some of the speech waveform features. The start of speech utterances display a larger average signal energy than Chapter 2. Silence Detection Algorithm Description and Development 10 the termination. Hence, the implementation of a dual threshold scheme can be used to increase the threshold for speech onsets to prevent triggering by noise, and to decrease the threshold during speech to prevent clipping which occurs when the threshold is too large. The hysteresis nature of this dual threshold scheme also prevents frequent speech/silence transitions when the speech level is near the energy threshold. Such transitions increase overhead for silence interval coding. Hysteresis is easily implemented through the use of two energy thresholds. Once a state of silence has been reached, the larger threshold is used in identifying silence-to-speech transitions. Similarly, once a state of speech is present, the smaller threshold is used in identifying speech-to-silence transitions. There are times, however, when it is advantageous to maintain the smaller threshold for a short period after silence has been detected. A low threshold facilitates detection of weak stop consonants, which are always preceded by a short period of silence. This effect is increasingly important as the framesize K increases, because the consonant energy becomes blurred in the surrounding silence. As the framesize becomes smaller, the speech energy becomes more re-sponsive to short-term variations, and this hang-over is not necessary. In fact, due to the larger number of silence intervals present when computing with the smaller framesizes, incorporating a significant hang-over could maintain the energy threshold at its low value, effectively can-celling the energy threshold hysteresis and reducing the effectiveness of our silence compression algorithm. 2.1.3 Classification of Speech/Silence Intervals Operation of the algorithm in the basic form, as described in the previous section, can give very good performance results as measured by both compression and speech quality. However, as the frame size gets smaller, the silence intervals have a tendency to occur in rapid succession. This effect can be harmful if the overhead involved with coding silence intervals is high. The overhead can be reduced somewhat if the absolute speech/silence decisions are based on previous frames Chapter 2. Silence Detection Algorithm Description and Development 11 as well as on the current frame. Previous work has considered the use of both a minimum speech constraint [25] and a min-imum silence duration [28]. The minimum speech constraint is designed to classify as silence those input samples initially classified as speech, but which are too short to convey useful infor-mation. The minimum silence constraint is designed to classify as speech the silence intervals too short to be efficiently handled by the speech compression application. By using both of these criteria, the speech compression algorithm can be tailored to suit various application needs. Care must be exercised in the selection of the minimum speech and minimum silence criteria. Increasing the minimum silence duration alone will not degrade the reconstructed speech quality, but can drastically reduce the efficiency of the compression algorithm. Increasing the minimum speech duration, on the other hand, will have the reverse effect; the compression capabilities of the algorithm will increase at the cost of causing the potential for increased speech clipping. Implementation of minimum speech and minimum silence constraints is relatively straight forward using the system concept of speech and silence states. In the silence state, any additional silence frames simply add to the duration of the current silence interval. There must be at least N consecutive speech frames to transfer to the speech state, where N is the minimum speech constraint. If there are fewer than N consecutive speech frames, then those frames are discarded, the current silence interval duration is increased, and the silence state remains in effect. Likewise, if the speech state is active, speech frames are directly added to the outgoing data stream. There must be at least M consecutive silence frames to begin another silence interval and transfer to a silence state, where M is the minimum silence interval duration. If the number of consecutive silence intervals is less than M, the silence frames are added to the outgoing data stream, and the speech state remains in effect. Chapter 2. Silence Detection Algorithm Description and Development 12 2.2 Adaptation to Noise and Signal Levels To this point, we have treated the value for E-Threshold as being constant. In a speech detection system, it is very difficult to obtain optimum performance with a constant value for E-threshold. Speech levels, as well as background noise levels, can vary from call to call. Even within the duration of a single call, the background noise level can vary significantly. In a fixed threshold system, a greater percentage of the speech will fall below threshold and be treated as silence as the input speech level decreases. Similarly, a louder speech level will cause a lower percentage of silence detection. Figure 2.1 shows the effect of using a constant E-threshold with varying input speech levels, as a function of framesize. The quieter —6 dB c o T5 3 a> Q a o c _a> £75 55 50 45 \-40 35 30 25 -6 dB Speech Sample 0 dB Speech Sample +6 dB Speech Sample 16 32 64 128 Frame Size (Samples) Figure 2.1: Effect of Speech Detection with Constant E-Thresholds speech sample has a much higher % silence deletion than the +6 dB sample. Any use of constant values for E-threshold must compromise between different speech and background noise levels. Such compromise leads to excessive speech clipping in some cases, Chapter 2. Silence Detection Algorithm Description and Development 13 and highly non-optimum speech detection performance in others. In order to achieve robust performance, the energy threshold value should be adaptive to both the speech signal and background noise levels. Silence detection performance when the energy thresholds are made to adapt to the back-ground noise level has been investigated in previous work [25], where the energy threshold was calculated as follows: In (2.3), E-Avgi is the current long term average background noise energy level, and Kj is a threshold constant. A preset threshold value KT is multiplied by the current average background noise energy E-Avg^ to produce the actual threshold. We found that this approach works fairly well, particularly with noisy speech; however, as the background noise level drops to zero, so do the threshold values. This results is a much lower percentage of silence detection than would be expected for the given input sample. Figure 2.2 shows the percentage silence detection for 3 input speech samples, each with a different level of background noise. The algorithm works well for moderate amounts of background noise, but shows reduced compression for the sample with no added noise. A first approach to making the background noise level adaptation work with low levels of background noise is to place a fixed lower limit on the energy threshold. However, such a fixed lower limit would be sub-optimal in an environment where speech levels can fluctuate widely. A better solution is to make this lower limit dependent on the input speech level, or in other words, make the energy threshold adapt to both the average speech level as well as to the average background noise level. To make the energy thresholds adaptive to both the speech and background noise levels, two calculations for the current energy threshold are made. One is based solely on the background noise level, while the other is based only on the current averaged speech level. The actual threshold used is then calculated as E-Thresholdi = KT • E-Avg{. (2.3) E-Threshold= KT • MAX(SilAvg, SpeechAvg/lS) (2.4) Chapter 2. Silence Detection Algorithm Description and Development 14 4 8 16 32 64 128 Frame Size (Samples) Figure 2.2: Effect of Speech Detection with Background Noise Level Adaptation where M A X ( X , Y) = X if X > Y; else Y. (2.5) In (2.4), SilAvg is the current long term average background noise energy level, SpeechAvg is the current long term average speech energy level, and Kj is a threshold constant. If the input speech sample is very noisy, the background noise level threshold calculation will dominate, and the algorithm will behave in a similar manner to that of one reported earlier [25]. However, if the speech sample is relatively noise-free, the speech level threshold calculation' will dominate, and will prevent the threshold levels from approaching zero. The effect, then, is to place a lower limit on the energy threshold that is dependent on the input speech level. This approach enables good compression statistics on loud or high level recordings to be maintained without causing excessive clipping on quiet or low level recordings. Figure 2.3 shows the effectiveness of speech level adaptation with varying levels of input Chapter 2. Silence Detection Algorithm Description and Development 15 g T5 o oS Q CD O £Z o 00 65 60 55 50 45 h 40 35 r 30 -25 -6 dB Speech Sample 0 dB Speech Sample +6 dB Speech Sample I L_ 16 32 64 128 Frame Size (Samples) Figure 2.3: Effect of Speech Detection with Speech Level Adaptation speech. As can be seen, there is less than a 0.5% difference in silence detection when the input speech is varied over a 12dB dynamic range. This is a dramatic improvement over the case of no adaptation as shown in figure 2.1, where the three graphs vary by up to 23% in silence detection. Figure 2.4 shows the combined effect of adaptation based on both speech and noise levels for speech samples with varying amounts of background noise. At a high background noise level, the graph in figure 2.4 is similar to that in figure 2.2, indicating that the noise level dominates in the dual adaptive system under this condition. For the speech sample with very little background noise, the dual adaptive system performs well and prevents the thresholds from dropping to zero, as is the case with noise-only adaptation. The middle graph corresponds to a voice sample with an amount of noise which approximates the maximum specified for a long distance telephone link. This background noise level was chosen as the cross-over point between Chapter 2. Silence Detection Algorithm Description and Development 16 cz g a> Q o c CO 70 60 30 20 10 16 Noise Energy = 50 —B-Noise Energy = 20 —&-Noise Energy = 0 —e-32 64 128 Frame Size (Samples) Figure 2.4: Effect of Speech Detection with Both Speech and Noise Level Adaptation noise level and speech level adaptation. 2.3 Noise Insertion During Silence Intervals In tests with silence compression, some of the silence intervals were quite noticeable during playback, because of the replacement of the deleted acoustic material with complete silence. Gan [25] determined that this effect could be reduced by replacing the pure silence during playback with a copy of the original background noise. In a practical situation, a copy of the original background noise may not be available, or at least it may not be practical to utilize extra resources for its transmission or storage. In this thesis, the possibility of inserting random noise during playback was investigated. During playback, randomly generated noise was inserted during the silence intervals at a level equal to the background noise at the time of the recording. The background noise level Chapter 2. Silence Detection Algorithm Description and Development 17 is obtained as part of the compression algorithm for use in determining the appropriate energy threshold. This same level is, therefore, available for coding in the outgoing data stream for use in generating the noise in the playback process. This approach allows the playback noise level to adapt to the background noise level at the time of recording, throughout the speech segment. White noise was used during playback due to its simplicity in generation, and its generally acceptable sound quality during playback. The algorithm could easily be adapted to incorporate some type of digital filter to colour the noise if such filtering would improve the perceived playback quality. 2.4 Final Algorithm Figure 2.5 shows a block diagram of the complete algorithm that was implemented in both a real-time system, and in an off-fine software simulator for evaluating the effect of the various parameters. The modified silence detection algorithm has a number of parameters that can be used to tailor its performance for different operating environments. The algorithm parameters include: 1. Frame Size 2. Upper and Lower Energy Thresholds, and Threshold Hangover 3. Zero Crossing Threshold, and 4. Minimum Speech and Silence Interval Duration. Also of importance is the interval over which long term averages of the speech and silence energies are calculated. The effect of each of these parameters on algorithm performance is presented in the next section. Chapter 2. Silence Detection Algorithm Description and Development ( START ") Initialize Avgs SIILen - 0 SpaachLen . 0 CurStale-SILENCE CurThresh - HIGH Calculate E-Thresh 3L Calculate Energy and Crossings for Curframe YES Inc SpeechLen SPEECH 1 Classlty Curframe and SIILen Previous Frames as SPEECH Inc SpeechLen by SIILen SIILen - 0 Update SpeechAvg SILENCE Classify Curframe and (SpeechLen -1) Previous Frames as SPEECH CurStale - SPEECH SIILen • 0 Update SpeechAvg > Classify Curframe and SpeechLen Previous Frames as SILENCE Inc SIILen by SpeechLen SpeechLen - 0 Update SIIAvg Ctasslfy Curframe and (SIILen -1) Previous Frames as SILENCE CurStale . SILENCE SpeechLen - 0 Update SIIAvg CurThresh. LOW Update E-Thresh SIILen 2 Hangover^ NO YES CurThresh • HIGH Update E-Thresh J Ctasslfy any Outstanding Frames as CurStale I Figure 2.5: Block Diagram of the Silence Detection Algorithm Chapter 2. Silence Detection Algorithm Description and Development 19 2.5 Parameter Selection Optimization of the algorithm parameters was performed using a PC-based 'simulation' pro-gram on pre-recorded files. This approach enabled accurate evaluation of the parameter effects using identical input speech files. Also, the speech files could be modified in a controlled manner to simulate various input speech samples. Once parameters were characterized and selected, the results of the compression trials could then be compared to those obtained using a real-time speech compression system. Informal listening tests were performed by the author to characterize the effects of the parameters on the silence detection algorithm performance. With the effect of each parameter known, the task of selecting a parameter set to provide a pre-determined level of performance for a particular application is simplified. It was found, however, that there are strong inter-dependencies between the various parameters, and that the selection of one influenced the selection of the others. The parameters can be adjusted to give very good performance under different conditions (ie, noise levels) although a well chosen set will give acceptable although non-optimum (in some cases) performance all-round. This section describes the results of the tests to evaluate parameter values, and presents the effects on speech quality and compression of each of the algorithm parameters. Considerations in selecting optimum parameter values are also presented. 2.5.1 Frame Size The number of speech samples used to calculate the short term statistics of the input signal is an important consideration in the performance of the silence detection algorithm. As the framesize becomes smaller, the short term energy is averaged over a smaller number of samples, and hence has a much larger and more rapid variation than if averaged over a larger number of samples. This larger variation gives a much greater ability to detect low level consonants which might otherwise be 'blurred' into the surrounding noise, and clipped. As the framesize becomes larger, small silence intervals are averaged into the surrounding speech (and vice versa) and as Chapter 2. Silence Detection Algorithm Description and Development 20 a result, the talkspurt frequency decreases. This decreased talkspurt frequency, however, comes at a cost of decreased silence detection, and possible increased speech clipping. The dependance of short term energy variance on framesize implies that the most appropri-ate energy threshold values are also dependent on framesize. Figure 2.6 shows a plot of detected silence percentage vs framesize for different energy thresholds. The graphs were compiled by running the algorithm on a prepared speech sample, with an added background noise energy level of 20 units. The algorithm was run in basic form, with no minimum speech, minimum silence, or zero-crossing criteria, and no hysteresis. The actual energy thresholds used to gener-ate this graph were calculated by multiplying the threshold values displayed in figure 2.6 by 20, the average energy of the background noise level in the input speech sample. The graph clearly 60 55 j— 50 o o CD 45 CD Q CD 40 O I 35 CO 25 20 4 8 16 32 64 128 Frame Size (Samples) Figure 2.6: Percentage Silence for Various Framesizes with Fixed Thresholds shows that for a given energy threshold, a larger silence percentage can usually be detected by using a smaller framesize. The one exception is the plot for Threshold = 1.5, where for small T Threshold - 3.5 — * -Threshold = 3.0 — • -Threshold » 2.5 — & Threshold - 2.0 —A-Threshold - 1.5 — & Chapter 2. Silence Detection Algorithm Description and Development 21 framesizes the large interframe variation in silence interval energy causes an increased portion of the silence intervals to exceed the threshold level, and be classified as speech. An even more substantial advantage to using a smaller framesize can be seen if the recon-structed speech quality is taken into account. The line labeled Maximum in figure 2.6 shows the maximum percent silence deletion that can be obtained for each framesize before noticeable speech clipping occurs. As the frame size gets larger, more speech clipping is apparent for a given threshold multiplier; therefore, smaller frames can use larger thresholds and hence yield more compression for a given speech playback quality. 2.5.2 Energy Thresholds Figure 2.6 shows that the optimum energy threshold for the silence detection algorithm is strongly dependent on the framesize used to calculate the short term statistics. Figure 2.7 shows a similar graph, except with the data obtained using a dual threshold algorithm with hysteresis. This graph shows a similar dependance of the optimum thresholds on the framesize. For each of the thresholds shown, the ratio of Min to Max is the same. The maximum percent silence deletion line is very similar to that seen in figure 2.6, being the same for larger framesizes, and only 1 to 2 percent higher at a framesize of 4. Figures 2.6 and 2.7 show that adding hysteresis provides very little enhancement to the maximum silence deletion possible by the algorithm. However, the simulations with hysteresis had a significant reduction in the number of silence intervals obtained (or number of talkspurts). Such reduction is important in a practical system where there is a finite overhead involved in coding each silence interval, or where there is a need to keep the talkspurt frequency low. 2.5.3 Zero Crossing Rate For large framesizes, the zero-crossing rate criterion is required to avoid classifying the low amplitude consonants as silence, resulting in clipped speech. This fact was reported earlier [25]. Chapter 2. Silence Detection Algorithm Description and Development 22 60 55 50 45 40 35 30 25 20 Maximum Min 3.5, Max 4.2 Min 3.0, Max 3.6 Min 2.5, Max 3.0 Min 2.0, Max 2.4 Min 1.5, Max 1.8 I L —o~ A-16 32 64 128 Frame Size (Samples) Figure 2.7: Percent Silence Deletion with Dual Thresholds For small framesizes, the use of the zero-crossing rate criterion can actually be counter-productive. A small framesize implies only a few zero-crossings are possible within each frame, and the large variability inherent in small sample populations causes an excessive portion of the background noise to be classified as speech. Small framesizes, however, show a much larger variation in the short-term energy than a large framesize for the same speech waveform. As such, the weak consonants are more pronounced from the background noise, removing the need for the zero-crossing criterion. When the zero-crossing rate criterion is required, the selection of the zero-crossing threshold is a compromise; too low a value results in an excessive portion of silence being classified as speech, while too large a value results in the threshold rarely being exceeded, reducing its effectiveness significantly. It was found that a threshold corresponding to slightly less than half of the successive samples in a frame exhibiting zero-crossings provided the best compromise. Chapter 2. Silence Detection Algorithm Description and Development 23 2.5.4 Minimum Speech/Silence Intervals The inclusion of minimum speech and silence interval durations enables the tailoring of the silence detection algorithm to a particular application. Situations requiring a low talkspurt frequency can be facilitated by using a larger minimum silence duration. In this way, shorter silence durations coalesce, resulting in fewer talkspurts. There is a definite dependence between the two minimum interval duration parameters. A large minimum silence duration can lead to a very low percentage silence unless the minimum speech duration is also increased. If the minimum speech duration remains small, short bursts of acoustic signal will be detected as speech, and a full silence interval duration is required before silence classification continues. Likewise, if the minimum speech duration is made long, sections of speech will not be detected if interspersed with short silence intervals, leading to excessive speech dipping. Tests show that there is an improvement in reconstructed speech quality if a smaller frame-size is used with larger minimum speech/silence durations than if larger framesizes are used with smaller minimum intervals. However, the best silence percentage and reconstructed speech quality results are obtained when using a small framesize with small minimum speech and si-lence durations. The disadvantage of this choice of parameters is an increased talkspurt rate, making it unsuitable for some appbcations such as speech interpolation or other applications where there is a relatively large overhead associated with each silence interval. 2.5.5 Speech and Silence Interval Averages The silence detection algorithm relies on long term speech and background noise energy averages to adapt the energy thresholds for optimum performance. The appropriate number of acoustic samples required to form these averages is an important consideration. The number of samples must be large enough to 'average out' any short term variations in either the speech or silence portions of the acoustic signal, but small enough to enable tracking of the long term variations. The silence interval energy varies quite slowly, and hence only a short sampling of the silence Chapter 2. Silence Detection Algorithm Description and Development 24 is needed to give a fairly accurate long term silence energy. Tests show that good silence interval energy tracking can be obtained by averaging 128 ms of silence. The speech signal, on the other hand, is quite varied in amplitude, and changes rapidly. This implies that a relatively long sampling of speech is required to give an accurate value of average energy. Testing revealed that up to one second of speech information is required. Although the time period required to evaluate the long-term averages does not change with framesize, the number of frames required does change. This effect creates a disadvantage with using too small a framesize, as the number of frames (and hence the overhead) required to calculate the long-term statistics becomes excessive. Silence interval samples near a silence-to-speech transition typically have a relatively high short-term average amplitude. To prevent these samples from corrupting the long-term silence interval average energy, a parameter ECRIT was used [25]. A short-term average (ie, a frame) was included in the long-term average only if the frame did not exceed ECRIT • SilAvg, where SilAvg is the long-term silence energy average. The optimum value for ECRIT was determined by adjusting this parameter, and comparing the compression results with those obtained with a fixed energy threshold. The speech sample used had a constant level of background noise added to a voice sample recorded with a fairly constant long-term speech average. It was found that the best ECRIT value varied with the framesize K, from 1.20 for K=128 to 1.60 for K=4. 2.5.6 Final Parameter Values To determine an optimum set of parameters for a speech storage system, a speech file with constant levels of speech and background noise was used. The background noise level was set to correspond to the cross-over point from background noise to speech signal adaptation. With this file, a dual energy threshold silence detector with fixed threshold levels was used to determine the optimum threshold levels for various framesizes. The threshold levels were increased until speech clipping was just apparent, as judged by careful listening by the author. The compression statistics for these optimum thresholds were noted for later reference. Chapter 2. Silence Detection Algorithm Description and Development 25 The algorithm was then altered to one that used threshold adaptation based on background noise level only. The value of ECRIT could be varied until the compression statistics matched those of the fixed threshold system. The fixed case can be viewed as a limiting case where the background noise adaptation remains constant, due to a constant background noise level; any disturbances due to inclusion of speech onsets in the background noise average would be absent. Finally, the algorithm was altered to include both speech signal and background noise level adaptation; the speech file was changed to one containing no background noise, but the same recorded speech level. This enabled the SpeechScale parameter to be tuned until compression performance matched that with using fixed amplitude thresholds. A value for SpeechScale of 13 produced the best results, with an initial speech amplitude average estimate of 250. The required sample lengths for the long term averages for both the speech and background noise levels were determined by analyzing the energy tracking for various sample lengths. The long term statistics were averaged over an interval long enough to remain roughly constant for a constant level speech sample, but not so long as to disable tracking for a speech sample whose amplitude exhibited long-term variability. It was found that the speech should be averaged over approximately one second, and that background noise should be averaged over 128 ms. The optimum algorithm parameters for various framesizes are shown in table 2.1, where SilAvgLen and SpcAvgLen are the number of frames used in the calculation of the long term silence and speech averages respectively. Frame Size Min Max ECrit SilAvgLen SpcAvgLen 128 2.10 2.52 1.20 8 64 64 2.40 2.88 1.20 16 128 32 2.60 3.12 1.23 32 256 16 3.10 3.72 1.30 64 512 8 3.40 4.08 1.42 128 1024 4 3.90 4.68 1.60 256 2048 Table 2.1: Optimum Algorithm Parameters for Various Framesizes Chapter 3 Real-time Implementation of Silence Compression Algorithm The silence detection algorithm presented in chapter 2 provides a means for distinguishing silence intervals from the acoustically essential speech periods. To implement this algorithm into a practical system, the following concerns need resolution: 1. Silence intervals must be efficiently coded to enable speech compression, while allowing accurate reproduction during playback; 2. Coding of speech intervals to achieve overall compression better than that obtainable using conventional 64 kbit/s P C M must be accommodated; 3. An efficient means for computing the long-term average amplitude of the silence and speech intervals must be developed; 4. Compressed speech data must be efficiently transferable to the desired storage or trans-mission medium; and 5. White noise of appropriate energy level must be generated in an efficient manner for insertion in the silence intervals during playback. For this thesis, the silence compression algorithm was implemented in real time using a TMS320C25 digital signal processor. The compressed speech data was transferred to an IBM P C / A T compatible host computer for storage on a hard disk. This chapter describes the details of this real-time implementation. The details of the hardware to implement this system are contained in appendix A; the software listings for both the real-time system and the PC based simulator appear in appendix B. 26 Chapter 3. Real-time Implementation of Silence Compression Algorithm 27 8.1 Coding of Silence Intervals The silence detection algorithm described in chapter 2 divides the input speech into non-overlapping speech and silence intervals. To achieve speech compression with this algorithm, the silence intervals must be efficiently coded into the output data stream for low bit rate stor-age or transmission. During playback, the silence interval codes are detected by the decoder, and are used to accurately reproduce the original silence interval. The important parameters of a silence interval are its location within the speech segment, its length, and its average background noise amplitude. Figure 3.1 shows a silence code format Silence Code Interval Length Interval Mean Amplitude Figure 3.1: Format for Silence Interval Coding which contains the necessary parameters for accurate silence interval reproduction. The location of the silence intervals are indicated by the position of the silence codes within the speech data. To simplify the implementation for this thesis, each of the three fields of the silence interval code was allocated a 16-bit word. As discussed below, the field lengths could easily be modified in different applications to provide more efficient coding. 3.1.1 Silence Code The silence interval code begins with a unique bit sequence to distinguish it from the speech data. In previous research, a series of repetitive speech codes was used as the silence code [25]. By making the number of repetitions long enough, the probability of the silence code occurring naturally in the speech data was brought close to zero. While this method does provide a certain amount of flexibility, there are some drawbacks, including: Chapter 3. Real-time Implementation of Silence Compression Algorithm 28 • the silence code has the possibility of becoming quite long, increasing the overhead in coding the silence intervals; • the probability of a naturally occurring silence code cannot be made zero, even with an arbitrarily long code sequence; and • the insertion of a repetitive code following a natural occurrence of a portion of the code will cause incorrect decoding (the addition of a non-removable dummy code, prior to the repetitive silence code, was required). For this work, a single unlikely bit sequence was used as the silence code. In particular, the code was a concatenation of two consecutive speech samples that swing from the negative to positive limits of the speech coder. For example, with Mu-law coded P C M speech, the silence code would be 0080 hex; the most negative value followed by the most positive value. At 8000 samples per second, this represents a large amplitude 4kHz signal, which is virtually impossible over a 3.4kHz bandlimited channel. In all the tests and experiments performed, this silence code-word never occurred naturally. To allow for the possibility of a silence code occurring naturally in the speech data, such an occurrence would be followed by a special marker sequence in a manner similar to that used in character oriented communication protocols such as IBM's BISYNC [29,30]. During playback, the decoder searches for the silence codes and examines the word immediately following for the marker. If it exists, the marker code is removed, and the preceding silence code is treated as speech data. If the silence code - marker code combination occurs naturally in the speech data, the encoder would insert another marker code after the silence code. In the decoder, the second marker code would be removed, leaving the correct speech data for playback. For this work, the marker sequence was an all zero word. A second marker sequence was used to indicate the end of the speech data file. This marker allows the speech compression system detect the end of speech data, and terminate speech playback. In the real-time system, this reduces the amount of communication necessary Chapter 3. Real-time Implementation of Silence Compression Algorithm 29 between the silence compression processor and the host file storage system. The end-of-speech-file marker was the hex word FFFF . 3.1.2 Interval Length Coding The second portion of the silence interval code specifies the length of the silence interval. While there are a number of ways to specify the silence interval length, the simplest is to use the number of frames of silence that comprise the interval, with a limit on the maximum length of the interval to some large value. This was the method used in this thesis, and it provided acceptable results. There is a disadvantage to this method, however, particularly when using a small frame size; the number of bits required to code long intervals can be excessive. There are a number of possible ways to improve the efficiency of the interval length coding, including: • A codebook could be provided that contains a variety of pre-determined interval lengths. A short code that represents the length closest to the actual interval length would then be sent to the decoder. • The interval lengths could be compressed in a manner similar to P C M companding. This would give high resolution for shorter intervals and still provide for larger intervals using relatively few bits to encode the length. • The interval length field in the silence interval code could be made variable in size. A small number of bits could encode the more common short intervals, with a single bit indicating additional length fields to encode the less common larger intervals. Although none of these methods were investigated in this thesis, their implementation would be relatively easy in the real-time environment. As was mentioned previously, the interval length field may also contain special markers. In this thesis, two special markers were used (based on a 16-bit field width): Chapter 3. Real-time Implementation of Silence Compression Algorithm 30 1. A code to indicate that the silence code had occurred naturally in the speech data (0000 hex); and 2. A code to mark the end of the speech data file (FFFF hex). A zero length interval was used to mark a naturally occurring silence code as it was easy to verify, and had no meaning as a real interval length. To mark the end of the speech data, the largest possible interval length code was used; the natural occurrence of this code was prevented (eg, during a very long silence interval) by limiting the interval length to F F F E hex. Even with this limiting, it was possible to represent up to 32 seconds of contiguous silence with 8000 samples per second and 4 samples per frame. 3.1.3 Interval Energy Coding The final field of the silence interval code provides information regarding the average background noise amplitude during the interval. Such knowledge enables a more accurate reproduction of the original silence interval during playback. This is an optional field, however, and is not required for all applications of the speech compression algorithm. For this thesis, the average background noise level calculated during silence detection was inserted into the final field of the silence interval code. The use of this average prevented the local variations of playback noise which would occur if the energy of a single frame only were used; however, the average did enable tracking of long term variations. The use of a 16 bit field to transmit the amplitude average was somewhat excessive, but did simplify implementation, since the TMS320 uses 16 bit words. The amplitude average for the silence interval could be directly coded using only 8 bits (allowing values of 0 to 255), and could most likely be reduced even further through the use of non-Unear quantizing (giving higher resolution to the lower levels, and less resolution to the larger levels). Other alternatives include the following: • A pre-determined level of noise could be inserted during playback, requiring no inter-val average amplitude code. With this method, the noise will not adapt to the source Chapter 3. Real-time Implementation of Silence Compression Algorithm 31 background noise level; however, an acceptable system may still be possible for most applications. • A reduced number of background noise level updates could be used, instead of being sent with every silence interval code. It may suffice to send an update at fixed intervals, or only when the noise level changes significantly. • The background noise average amplitude could be encoded differentially. Since the back-ground noise level typically remains fairly constant during a speech sample, fewer bits may be required if only the difference in noise levels was encoded for each interval. A l l of these modifications could easily be implemented in a real-time system. Through the use of a combination of the coding techniques mentioned for both the interval length and average amplitude, it would be possible to reduce the silence coding overhead by over 50%. This is of particular importance for smaller frame sizes, where the current coding overhead can be in excess of 5% of the original speech sample. 3.2 Coding of Speech Intervals The previous section provides a means for compressing the silence portions of speech into silence codewords. Further overall compression can be obtained by source coding the speech portions of the input signal using a common form of coding such as P C M , companded P C M , A D P C M , and A D M [1,2]. The main concern in coding the speech intervals is in dealing with the silence intervals; coding schemes which depend on previous speech samples could loose this vital information during silence intervals, thereby preventing accurate signal reconstruction during playback. Previous work has been done to show that some sample-to-sample dependent coding methods are robust, and can regain tracking following silence periods [25]. For non-memory coding schemes, such as P C M , this problem becomes trivial. Additionally, the speech coding algorithm must work with the silence compression algorithm in a one-pass format for real-time implementation. Chapter 3. Real-time Implementation of Silence Compression Algorithm 32 For this thesis, the input speech was in /z-law companded P C M format, a standard form for P C M networks which uses inexpensive speech CODECs. This ^-law P C M speech needs to be converted to linear P C M for the silence detection algorithm; however, in a basic system speech is stored in p-law form. For speech coding schemes which use intra-sample dependencies, the decoder parameters will not adapt during the silence intervals; the original speech samples are not present, and the inserted silence interval samples are generated in linear P C M form. If no compensating action i is taken, the speech decoder will contain the parameters from the end of the most recent speech interval at the start of the new speech interval. Mistrack between the speech coder and the decoder will occur and may cause an audible distortion in the reconstructed speech. One solution to this problem is to reset the coder parameters at the start of each new potential speech interval (if the speech frame is detected as a silence interval, then the coder will be reset for the start of the next frame). Resetting the speech coder places it into a known state, which can then be duplicated in the decoder at the start of each new speech interval. This resetting eliminates the mistracking between the coder and decoder. This coder resetting method was implemented using 4-bit A D P C M speech coding [31,32] providing a noticeable improvement over a direct A D P C M implementation. Audible clicks that were present at the start of reconstructed speech intervals when resetting was not used, were removed. 3.3 Long Term Signal Averaging The silence detection algorithm described in chapter 2 requires the calculation of long term signal averages in order to track varying speech and background noise levels. Since these averages are calculated over a large number of samples, special consideration must be given to the time required to calculate the average and the memory required to store the samples. This section describes the methods used to minimize both the calculation time and the memory storage requirement. Chapter 3. Real-time Implementation of Silence Compression Algorithm 33 The equation for calculating the long-term average A(t) at time t of N frame amplitude averages E{ is A(i) = ^ (3.1) where S(t)= £ E4. i=t-N+l One sees from (3.1) that as TV becomes large, the processing required to calculate A(t) in this direct form becomes excessive for a real-time implementation. Calculation of the long-term averages can be simplified by noting that A(t + 1) = l ( £ t + 1 + S(t) - Et+1-N). (3.2) Equation 3.2 requires only 2 additions, as opposed to the TY additions that are required for (3.1). The use of an integer based calculation for 5(t) in (3.2) maintains full precision, thereby sustaining accuracy of the average A(t). The computational requirements of (3.2) can be further reduced if the value TY is a power of two. In this case, the required division is reduced to a simple arithmetic shift. Independent of which method is used to actually calculate the long-term averages, it is required that all TV samples contained in the average are temporarily stored in memory. This storage requirement places a large demand on memory, particularly if TV is large, as is the case for calculating average speech amplitude. A block averaging scheme was used to reduce these memory requirements while still giving an accurate value for the long-term average speech energy. The block averaging scheme was not used in the calculation of the long-term silence average, as the number of frames used in this calculation was much less than for the speech average. The block averaging scheme first averages a smaller number of frame energies into block averages, and then uses these block averages to calculate the overall average speech amplitude. For example, if there are n blocks, each containing m frame amplitude averages (where m-n = Chapter 3. Real-time Implementation of Silence Compression Algorithm 34 N), the block averages B{ are evaluated as follows: Bx = Avg(E1,...,Em) B2 = A v g ( £ m + 1 , . . . , £ 2 m ) Bn = Avg(EN-m+1,...,EN). The long-term speech average A(t) is then calculated as Avg(J3 l 5 . . . , Bn). This average is updated at time t + m, using an equation similar to 3.2, when the block average 2?„+i becomes available. Since each frame amplitude average E{ is used only once in the calculation (to determine the block average), it is not required to be stored in memory. Only the block averages, which are used to update the long-term speech average A(i), are required to be saved. Using this method, the memory requirements are reduced substantially. The one disadvantage of this scheme is that the long-term speech average is updated only after m frames of speech are detected. However, if m is chosen appropriately, the effects of this do not significantly alter the performance of the silence detection algorithm. For this thesis, m was chosen so that the speech average was updated after every 32 ms of speech. 3.4 Data Transfer One problem in implementing the speech compression algorithm in a real-time environment is developing a method to efficiently transfer the silence compressed speech data between the DSP system and the storage or transmission medium. This problem is further compounded in that speech data must be temporarily stored before the silence detection algorithm can determine whether or not such data includes silence. The amount of speech to be stored depends on the values of MinSil and MinSpeech, but will be at least one frame in duration. The data cannot be transferred to the host computer until the current speech/silence interval classification is completed. Chapter 3. Real-time Implementation of Silence Compression Algorithm 35 For this thesis, the data memory used to store the speech data has two access ports, one for the DSP system, and one for the host computer. The DSP system can store the incoming speech data while simultaneously calculating the frame statistics. Depending upon the subsequent speech/silence decisions, this data can either be transferred to the host (speech interval), or over-written with new data (silence interval). Figure 3.2 shows the pointers that were used to manage the dual port data memory. The SAVED »-•4 NDP •4 CDP Available Memory Locations Data Ready to be Transferred to Host Unclassified Speech Data Figure 3.2: Data Memory Pointer Organization Current Data Pointer (CDP) and New Data Pointer (NDP) are managed by the DSP system, and the SAVED pointer is managed by the host system. The NDP is communicated to the host system when it is updated, to notify the host that data has been classified and is ready for storage or transmission. Incoming speech samples are stored at the CDP memory location while the short-term averages are calculated; the CDP is advanced one location after storage. If the samples are Chapter 3. Real-time Implementation of Silence Compression Algorithm 36 later classified as speech, the NDP is advanced to the first location past the speech data; the host system then knows this data has been classified, and either stores the data or transmits it. If the acoustic data is classified as silence, the CDP is reset back to the NDP (the end of the last SPEECH interval) and the silence code is written; new speech data is then stored after the silence code. If adjacent intervals of silence are detected, the CDP is reset to before the previous speech code (NDP) and the speech code is over-written with the new code with the new silence interval length. This continues until a speech interval is detected, at which point the NDP is advanced. 3.5 Noise Playback For optimum performance, the silence detection algorithm described in chapter 2 requires the insertion of random noise in the silence intervals during playback. For this thesis, white noise was generated with an average amplitude equal to that in the original silence interval. White noise was generated by first generating uniform random numbers based on the linear congruential method of number generation, where each new random number is calculated as Xi+i = (aXi + c) mod m (3.3) where a, c, and m are constants selected to give the desirable statistics to the random numbers [33]. Much work has been performed on the selection of these constants to provide randomness in all bits of Xi [34], however, for this work, ease of implementation and long cycle period are considered to be the most important characteristics. For this thesis, a — 67081293, c = 14181771, and m = 67108864 = 2 2 6 . This set of constants have been shown to have a long cycle time as well as good randomness properties [35]. Having m as a power of 2 reduces the modulus operation to a bit masking operation, greatly simplifying the implementation of the random number generator in a real-time environment. The generated uniform random variables are transformed into gaussian random variables using a method based on the central limit theorem. By summing 12 uniform [0,1] random Chapter 3. Real-time Implementation of Silence Compression Algorithm 37 variables as Gn = J£Xi (3.4) the resulting random variable Gn approximates a gaussian random variable with a mean of 6 and a variance of unity [36]. By subtracting 6 from each number Gn generated, zero mean white noise is produced. Using this method, the white noise generator had a period of 16,777,216 or 2 2 4 samples, which corresponds to 34.95 minutes at 8000 samples per second. Such time interval is more than sufficient to prevent the repetition from being audible during playback. The level required for the playback noise is inserted as part of the silence interval code, allowing the playback noise to change to accommodate changes in the background noise level in the original speech sample. To create the actual playback noise sample, the generated random value G„ was multiplied by the background noise level amplitude average and a correction factor of 1.248. The correction factor compensates for the fact that the average amplitude is used in the noise level calculation, rather than the true average energy which corresponds to the random variable variance. The correction factor was determined experimentally. Chapter 4 Algorithm Performance Evaluation To evaluate the silence compression algorithm, the following factors need to be considered: • the amount of speech compression obtainable; • the complexity involved in implementing the algorithm in real-time; and • the quality of the reconstructed speech to determine the degradation to the speech signal through compression. This chapter evaluates the silence compression algorithm described in chapters 2 and 3 based on these factors. 4.1 Speech Compression Table 4.1 presents the maximum compression obtainable using our silence compression algo-rithm on a recording of single speaker continuous speech from prepared text, using the algorithm parameters presented in table 2.1. Percent compression is defined as percent silence minus over-Frame Size % Silence % Speech % Overhead % Compression 128 41.46 58.54 0.19 41.27 64 44.02 55.98 0.26 43.75 32 46.64 53.36 0.48 46.16 16 50.62 49.38 1.23 49.39 8 53.73 46.27 2.77 50.96 4 58.51 41.49 7.41 51.10 Table 4.1: Compression Results for Various Frame Sizes head. 38 Chapter 4. Algorithm Performance Evaluation 39 Table 4.1 shows that speech compression of over 50% is attainable using our algorithm. The actual compression value depends on the block size. These results compare well with those of earlier work, where speech compression of 35 to 40% was obtained using a frame size of 100 samples [25]. Table 4.1 shows that almost 10% more speech compression can be obtained by using a framesize of 4 samples over a framesize of 128 samples. Using advanced speech coding methods (such as ADPCM) with the silence compression algorithm, average bit rates less than 19.2 kb/s are obtainable. 4.2 Algorithm Complexity The speech compression algorithm described in the previous two chapters provides a high level of speech compression for a relatively low cost in computing power. For this thesis, the silence compression algorithm was implemented in real-time using a TMS320c25 digital signal processor running at 40 MHz. With this system, only 25% of the processor capabilities was utilized for the algorithm. It is expected that a base version of the silence detection algorithm, which would exclude zero-crossing, MinSpeech, and MinSil parameters, and exhibit a reduced level of threshold adaptation, could possibly be implemented using a more general purpose and lower cost processor, or even with a custom integrated circuit. One advantage of using the higher power digital signal processor is the excess resources available for additional speech coding for higher compression rates, or for networking or other supervisory tasks that may be necessary for a particular speech compression application or system. 4.3 Subjective Evaluation The subjective evaluation was performed through listening tests based on executions of the silence compression algorithm on the following speech sample: It is claimed that young children up to the age of about seven or eight years are incapable of grasping the abstract fundamental that number and volume remain constant even through changes in the outward appearance of the object. For many Chapter 4. Algorithm Performance Evaluation 40 years the work of Piaget and his colleagues in Geneva has profoundly influenced the education of the young child. This portion of text was taken from that used in earlier work [25], but was recorded for these tests by the author, whose native language is English. The author's accent is representative of English speaking western Canadians. Two experiments were performed to evaluate the silence detection algorithm performance; one using a somewhat noisy speech sample, and one using a speech sample with very little background noise. The noisy speech sample was created from the low-noise original speech sample by adding a fixed level of random noise, roughly equivalent in level to that of a noisy long-distance telephone link. Speech samples based on both silence playback and noise playback during silence classified segments were included in both of the experiments. The experimental speech files were generated in a way that enabled a meaningful comparison of the results. It was suspected, from informal listening tests by the author, that a larger percentage of speech could be removed using a smaller framer size, while maintaining a constant playback speech quality. As such, the experimental speech segments consisted of processed speech samples with frame sizes of 128, 32, and 8, with the MIN and M A X thresholds selected so there was a small amount of speech clipping in each case (the thresholds were slightly larger than the optimal values shown in table 2.1). Also included were processed speech samples with frame sizes of 32 and 8 with thresholds selected to give roughly the same amount of speech removal as did the slightly clipped sample with a frame size of 128. Tables 4.2 and 4.3 give the parameters used to generate the experiment files for the low noise level and moderate noise level speech samples, respectively. Also included in these tables are the compression statistics obtained for each of the files. The % Overhead columns show the overhead in compressing the silence intervals, based on a 6-byte code per silence interval. The files created using the parameters shown in tables 4.2 and 4.3 were combined with the corresponding original speech files into two experimental sessions. In each, two random speech samples, along with the originals, were repeated; once towards the start of each listening session, Chapter 4. Algorithm Performance Evaluation 41 File # Frame Size Min Max ECrit % Silence % Overhead % Compression 1,2 128 2.50 3.00 1.20 44.56 0.21 44.35 3,4 32 2.20 2.64 1.23 44.50 0.44 44.07 5,6 8 2.00 2.40 1.42 44.80 2.20 42.60 7,8 32 2.90 3.48 1.23 48.57 0.55 48.07 9,10 8 3.50 4.20 1.42 56.06 3.00 53.07 11,12 8 3.20 3.84 1.42 53.81 2.80 51.01 Table 4.2: Algorithm Parameters for Processing Quiet Speech Sample File # Frame Size Min Max ECrit % Silence % Overhead % Compression 1,2 128 2.50 3.00 1.20 44.56 0.21 44.35 3,4 32 2.20 2.64 1.23 44.50 0.44 44.07 5,6 8 2.00 2.40 1.42 44.80 2.20 42.60 7,8 32 2.90 3.48 1.23 48.57 0.55 48.07 9,10 8 3.50 4.20 1.42 56.06 3.00 53.07 Table 4.3: Algorithm Parameters for Processing Noisy Speech Sample and again towards the end. This repetition of samples enabled a check on the consistency of the listeners. In all, there were 16 test samples in each session. Each of the two sessions began with the original samples to orient the test participants. The test participants were given the following instructions: The purpose of this subjective listening test is to evaluate the overall effect of silence compression on speech. Please state the degree of acceptability of the test samples as recorded messages on a scale of 1 to 5. 1 means that the sample is unacceptable, and 5 denotes the highest degree of acceptance. Rate each sample on its own, rather than by comparison with other samples. The test consists of 16 samples, each of a 30 second duration. The samples are numbered 1 through 16, with the current sample number being displayed at the top of the computer screen. For your orientation, the first sample is an unprocessed original. Chapter 4. Algorithm Performance Evaluation 42 The test samples are played through the telephone handset. Pressing any key on the keyboard will begin the playback of each speech sample. Please record your evaluations on the response sheet provided. Tables 4.4 and 4.5 summarize the results of the listening tests for the low noise level and moderate noise level speech samples, respectively. For the low noise speech samples, 15 test participants evaluated the playback speech quality (10 male, 5 female); for the noisy speech samples, there were 25 test participants (16 male, 9 female). Al l of the participants were adults. File # Frame Size Mean Score Standard Deviation Silent Noisy Silent Noisy Original 4.9/4.7 0.3/0.4 1,2 128 3.8 3.6 1.1 1.1 3,4 32 4.0 4.0 0.9 0.8 5,6 8 4.1/4.0 4.3 0.6/0.9 0.6 7,8 32 3.1/3.6 3.7 0.9/1.1 0.8 9,10 8 3.3 3.1 0.8 1.0 11,12 8 3.7 3.2 0.9 1.0 Mean Standard Deviation 0.79 0.88 Table 4.4: Listening Test Results Quiet Original Speech Sample File # Frame Size Mean Score Standard Deviation Silent Noisy Silent Noisy Original 4.8/4.6 3.5/3.5 0.4/0.7 0.7/0.9 1,2 128 2.4 3.2 1.2 1.0 3,4 32 2.5 3.6 1.2 0.9 5,6 8 2.9/2.6 3.5 1.1/0.9 0.9 7,8 32 2.3/2.4 3.5 1.0/1.2 0.9 9,10 8 2.2 3.1 0.9 1.0 Mean Standard Deviation 0.96 0.90 Table 4.5: Listening Test Results Noisy Original Speech Sample The experimental results shown in tables 4.4 and 4.5 show that the listening groups as a whole were fairly consistent; the repeated speech samples of file numbers 5 and 7, and the original differ by at most 0.5 on a scale of 1 to 5. There is a relatively high standard deviation of approximately one rating unit on almost all of the processed speech samples test scores. This Chapter 4. Algorithm Performance Evaluation 43 indicates that the tolerance to the degradation in speech quality varies considerably between individuals. It was also noticed that while some individuals were less tolerant of speech clips and speech—silence transitions, others appeared to object to higher levels of background noise. For the low noise level test samples, the difference in scores between noise playback and silence playback was small. This was expected, as the playback noise level was set to equal the original noise level which was low in this case. The results in table 4.4 do show that 44% removal of acoustic material can be obtained from a high quality speech sample, while degrading the speech quality less than 0.8 rating units. Removal of approximately 50% acoustic material results in a degradation of 1.1 rating unit at 8 sample block size. For the moderate noise level test samples, the addition of noise at a level roughly equal to the original background noise upon playback improved the perceived speech quality by approximately one rating unit. The overall quality rating of the processed speech samples with noise insertion on playback varied by at most 0.4 rating units from the noisy, unprocessed original, even when well over 50% of the acoustic signal was removed. Chapter 5 Summary and Conclusions 5.1 Summary This thesis described the development, real-time implementation, and evaluation of a new silence deletion algorithm for speech compression. The algorithm was implemented in real time using a TMS320C25 digital signal processor, and produced speech compression rates of over 50% in highly active samples of readings by a single speaker from prepared texts. The reconstructed speech quality was acceptable for both noisy and relatively noise free speech. Improved reconstruction quahty was obtained by inserting noise during the silence intervals on playback; such improvement was particularly apparent for noisy speech. Using our real-time system with 4-bit A D P C M voice coding, it would be possible to transmit speech with an average transmission rate of below 19.2 kbit/s, with a relatively low computational effort. Encoding and playback processing delays would be one or two milliseconds, which is insignificant. Modifications made to the silence detection algorithm reported by Gan [25] to improve real-time performance also enhanced the performance of our silence detection. The framesize for short-term statistics was reduced to enhance compression. The algorithm amplitude thresholds were made adaptive to the speech level as well as to the background noise level, to provide more robust and consistent performance for both noisy and noise free speech. A minimum silence duration parameter was added to enhance flexibility in tailoring the algorithm to particular applications. While some work was done towards selecting an optimum set of algorithm param-eters, it was found that the parameters need to be optimized for a particular appbcation and operating environment. It was also determined that one set of parameters can give relatively good performance with respect to speech compression and reconstructed speech quality under 44 Chapter 5. Summary and Conclusions 45 a variety of operating conditions. The primary contributions of this thesis research then, are as follows: • a new algorithm was developed for a real-time speech storage and playback system uti-lizing compression of silence intervals; • the algorithm was implemented on one circuit board, in real-time, using standard elec-tronic hardware; • optimization of a speech detection algorithm and associated parameters for robust per-formance under different operating conditions and high speech compression was achieved; • evaluation of the silence compression algorithm was completed based on subjective listen-ing tests, and compression statistics. 5.2 Areas for Further Research This thesis was primarily concerned with the real-time implementation of a silence deletion algorithm. While some performance evaluation and parameter optimization was done, further work in these areas is required. The silence detector performance in the presence of different types of background noise (different spectra and statistics), particularly burst noise common in telephone environments, needs to be investigated. As well, further testing of the compression performance, robustness, and playback quality for various speakers and speech environments is needed. In particular, our algorithm needs to be tested with different speakers, languages other than English, and a variety test material. This thesis identified the characteristics of each of the parameters of the silence detection algorithm, and used these characteristics to determine a good set of parameters for the speech compression application that our experimental setup emulated. Further work is required, how-ever, to develop a set of optimum algorithm parameters for use in various speech compression environments. Chapter 5. Summary and Conclusions 46 For this thesis, the silence interval code consisted of three 16-bit words to store the silence code, the silence interval length, and the silence interval average amplitude. Some suggestions for optimizing the silence interval code were presented in this thesis; these ideas and others should be investigated. Optimization of the silence interval code becomes more important as the frame size decreases and the number of silence intervals increases; under these circumstances, the silence interval coding overhead can account for up to a 7% reduction in the overall compression. The silence compression algorithm was implemented using /z-law coded P C M , and 4-bit A D P C M coded speech. The investigation of the algorithm performance with other speech coding techniques should be performed. Finally, the implementation of our silence compression algorithm with either a lower cost processor, or custom integrated circuits should be investigated. Bibliography [1] J. L. Flanagan et al, "Speech coding," IEEE Transactions on Communications, vol. COM-27, pp. 710-737, Apr. 1979. [2] T. W. Parsons, Voice and Speech Processing. McGraw-Hill Book Company, 1986. [3] N . S. Jayant, "High quality coding of telephone speech and wideband audio," IEEE Com-munications Magazine, pp. 10-20, Jan. 1990. [4] A. Gersho and V. Cuperman, "Vector quantization: a pattern-matching technique for speech coding," IEEE Communications Magazine, pp. 15-21, Dec. 1983. [5] K. Burlington and J. M . Fraser, "Engineering aspects of TASI," The Bell System Technical Journal, vol. 38, pp. 353-364, March 1959. [6] P. T. Brady, "A statistical analysis of on-off patterns in 16 conversations," The Bell System Technical Journal, vol. 47, pp. 73-91, Jan. 1968. [7] J. L. Flanagan, J. D. Johnston, and J. W. Upton, "Digital voice storage in a microproces-sor," IEEE Transactions on Communications, vol. COM-30, pp. 336-345, Feb. 1982. [8] P. Mermelstein, "Voice message systems," IEEE Communications Magazine, pp. 8-10, Dec. 1983. [9] N . F. Maxemchuk, "An experimental speech storage and editing facility," The Bell System Technical Journal, vol. 59, pp. 1383-1395, Oct. 1980. [10] S. A. Webber, C. J. Harris, and J. L. Flanagan, "Use of variable-quality coding and time-interval modification in packet transmission of speech," The Bell System Technical Journal, vol. 56, pp. 1569-1573, Oct. 1977. 47 Bibliography 48 [11] H. P. Stern, "Design issues relavant to developing an integrated voice/data mobile radio system," IEEE Transactions on Vehicular Technology, vol. 39, pp. 281-288, Nov. 1990. [12] P. de Souza, "A statistical approach to the design of an adaptive self-normalizing silence detector," IEEE Transactions on Acoustics, Speech, and Signal Processing, vol. ASSP-31, pp. 678-684, June 1983. [13] A. C. Norwine and 0. J. Murphy, "Characteristic time intervals in telephonic conversa-tion," The Bell System TechnicalJournal, vol. 17, pp. 281-291, Apr. 1938. [14] H. H. Lee and C. K. Un, "A study of on-off characteristics of conversational speech," IEEE Transactions on Communications, vol. COM-34, pp. 630-637, June 1986. [15] S. J. Campanella, "Digital speech interpolation," COMSAT Technical Review, vol. 6, pp. 127-158, Spring 1976. [16] K. Feher et al., Telecommunications Measurements, Analysis, and Instrumentation. New Jersey: Prentice-Hall Inc., 1987. [17] G. G. Langenbucher, "Efficient coding and speech interpolation: principles and perfor-mance characterization," IEEE Transactions on Communications, vol. COM-30, pp. 769-779, Apr. 1982. [18] J. Ishida et al., "High-gain DSI equipment using VLSI signal processor," in IEEE Globecom 84 Conference Proceedings, (Atlanta, Georgia), pp. 292-297, Nov. 1984. [19] H. Miedema and M . G. Schachtman, "TASI quality — effect of speech detectors and interpolation," The Bell System Technical Journal, vol. 41, pp. 1455-1473, July 1962. [20] E. Fariello, "A novel digital speech detector for improving effective satellite capacity," IEEE Transactions on Communications, vol. COM-20, pp. 55-60, Feb. 1972. [21] J. A. Jankowski, Jr., " A new digital voice activated switch," COMSAT Technical Review, vol. 6, pp. 159-178, Spring 1976. Bibliography 49 [22] P. G. Drago, A. M . Molinari, and F. C. Vagliani, "Digital dynamic speech detectors," IEEE Transactions on Communications, vol. COM-26, pp. 140-145, Jan. 1978. [23] C. K. Un and H. H. Lee, "Voiced / unvoiced / silence discrimination of speech by delta modulation," IEEE Transactions on Acoustics, Speech, and Signal Processing, vol. ASSP-28, pp. 398-407, Aug. 1980. [24] D. H. Cho and C. K. Un, "Hybrid companding delta modulation with silence detection," in IEEE Global Communications Conference Proceedings, (Miami, Florida), pp. 1340-1344, Nov. 1982. [25] C. K. Gan, "Efficient speech storage via compression of silence periods," Dept. of Electrical Engineering MASc Thesis, University of British Columbia, Dec. 1984. [26] C. K. Gan and R. W. Donaldson, "Adaptive silence deletion for speech storage and voice mail applications," IEEE Transactions on Acoustics, Speech, and Signal Processing, vol. ASSP-36, pp. 924-927, June 1988. [27] L. R. Rabiner and R. W. Schafer, Digital Processing of Speech Signals. New Jersey: Prentice-Hall Inc., 1978. [28] J. G. Gruber, "A comparison of measured and calculated speech temporal parameters relevent to speech activity detection," IEEE Transactions on Communications, vol. COM-30, pp. 728-738, Apr. 1982. [29] A. S. Tanenbaum, Computer Networks. New Jersey: Prentice-Hall Inc., 1981. [30] D. P. Bertsekas and R. G. Gallager, Data Networks. New Jersey: Prentice-Hall Inc., 1987. [31] W. R. Daumer et al, "Overview of the A D P C M coding algorithm," in IEEE Globecom 84 Conference Proceedings, (Atlanta, Georgia), pp. 774-777, Nov. 1984. Bibliography 50 [32] J. Reimer, M . McMahan, and M . Arjmand, "32-kbit/s A D P C M with the TMS32010," in Digital Signal Processing Applications with the TMSS20 Family, ch. 17, pp. 469-530, Texas Instruments Incorporated, 1986. [33] R. P. Chambers, "Random-number generation on digital computers," IEEE Spectrum, vol. 4, pp. 48-56, Feb. 1967. [34] S. K. Park and K. W. Miller, "Random number generators: good ones are hard to find," Communications of the ACM, vol. 31, pp. 1192-1201, Oct. 1988. [35] E. F. Casas, " O F D M / F M for mobile radio data communication," Dept. of Electrical En-gineering PhD Thesis, University of British Columbia, Sep. 1989. [36] M . Scwartz and L. Shaw, Signal Processing: Discrete Spectral Analysis, Detection, and Estimation. McGraw-Hill Book Company, 1975. [37] Second Generation TMS320 User's Guide. Texas Instruments Incorporated, 1987. [38] L. Pagnucco and C. Erskine, "Companding routines for the TMS32010/TMS32020," in Digital Signal Processing Applications with the TMS320 Family, ch. 5, pp. 169-212, Texas Instruments Incorporated, 1986. Appendix A Hardware Design A . l Hardware Description Figure A . l shows a block diagram of the hardware used to implement the silence compression algorithm. The system uses a TMS320C25 digital signal processor [37] to perform the actual PC/AT Host PC/AT Interface Hard Disk -»»> Control Status 4 -<•! 1>- Comm. Port .*] •> •« • Data RAM -a] »*• Prog. RAM TMS320 CODEC Telephone Interface Telephone Figure A . l : Block Diagram of Speech Compression System silence compression, and an D3M-PC/AT compatible computer to facilitate the storage of the processed data. The majority of the silence compression algorithm is contained in the DSP system, with the PC acting as a host to store, manipulate, and retrieve the compressed speech data. There are five basic blocks that form the interface between the TMS320 and the PC. They are as follows: 1. A control register to control the operation of the TMS320 processor; 51 Appendix A. Hardware Design 52 2. A status register to monitor the status of the TMS320 processor; 3. A bi-directional communications port for passing critical data between the TMS320 and the PC in a synchronized format; 4. Dual-port R A M for passing general data between the TMS320 and the PC in an unsyn-chronized format; and 5. Program R A M for down-loading and running programs on the TMS320. The control and status registers enable the PC host to control the TMS320 processor, and to monitor status signals from the TMS320. Control bits include TMS320 reset, processor hold, basic I/O, and interrupt lines. Status bits include processor hold status, external flag status, and the status of the TMS320 reset, basic I/O, and interrupt lines. These registers are mapped into the PC address space, and are accessed as memory locations. The 16-bit bi-directional communications port is used to pass information between the PC and the TMS320. This port is designed to handle the synchronization problem associated with passing data between two processors with different clock speeds. As a result, the port can be written to, or read from by either the PC, or the TMS320 at any time, and will yield valid data. The dual-port R A M is also used to pass information between the PC and the TMS320. This memory, however, is not synchronized, and care must be used to ensure that the same location is not simultaneously accessed by both the PC and the TMS320. The communications port can be used to provide information as to which memory locations are being accessed by which processor, and therefore avoid conflict. The program R A M is used to down-load TMS320 programs from the PC host for subsequent execution by the DSP. This interface block was provided so that programs could be easily updated, and changed to provide different functions for the TMS320. To digitize the voice samples, a low cost combo CODEC was used. This microelectronic chip provided sampling at 8000 samples per second, and coding into /z-law P C M format, and also Appendix A. Hardware Design 53 provided anti-alias and reconstruction filtering. This device easily interfaced to the TMS320 processor to transfer the digitized voice data to the DSP. A standard telephone was used to detect and amplify the speech samples, as well as provide a speaker for voice playback. Interfacing the telephone to the voice digitization and compression system was easily accomplished with the use of a telephone Subscriber Line Interface Circuit (SLIC) integrated circuit. The following pages contain the complete schematics for the silence compression develop-ment system. Appendix A. Hardware Design 54 iiiiJiiliiiiiiiU M Y B ( D O N * C ( R g f t « C i a Q N t f fi« «fi C l f l C l A ...... •* »> » * » »* fl» N ? ** Q N t t g o c K C t p N t o s o n t «• S M « S e . f t n A r f l B S J r r r r r N N N N S f l r i C m Mr A A A ODD z z z Appendix A. Hardware Design 55 < fflgoum g j Q O O O O O O O O O til D <cor jQuju .oz uJwOSto 4 o |o 1 ^tii III 8 8 8 eg 00 Q 01] < i * o - N n » IO 80SSSSS0S8000000 / / / / / > / / / / <<< 1A1 < h V ffl 0) m tr m . W A V E 0 » < i 5 3 -i Appendix A. Hardware Design Appendix A. Hardware Design 57 Li AA aQ 2 D 5 C i _ 1 1 1 1 H 1 to cjaj 58888883 58888888 dd P 1 z 4^ 85SS3SSB S5SS3S8S 8°g 8598888o o >- h n t1"> C Q D 3 D C H U H 7777T 8 8 ^ ^ 5888888 ISoSSSSSB 8e 85888888 8° 85888888 3 2 0 1 1 1 \l S5SS3SSS 8„ 58888888 58888888 dd • • h f l f I S D N 5 3 2 C 0 0 1 1 1 Q . U n t s i n t s s r aSS3oSoS ^58888888 5i 0 3 D D D D 0 C 1 1 1 U 1 1 1 8 5* < 5 < J o 0 cc a AAAA • b ^  N Appendix A. Hardware Design 58 winmnnnr, > 0 c 1 k. c i < • 1Ul ! V i 0 S 0 < 5 j i i < E 1 0 D 3 0 1 i? E 3 0 0 J t h ffl Appendix A. Hardware Design A.2 Firmware Listings The following pages contain the firmware listings for the programmable logic devices used the TMS320 DSP system hardware design. This f i l e contains the l i s t i n g s for the PALS used i n the TMS320c25 processor system HOSTPAL.V2 ** HostPal, version 2 ** 01 ** ** Pal to decode the memory address block from the PC host computer DEVICE HOSTPAL (P16L8) PIN 51 - 1 (INPUT combinatorial) 52 - 2 (INPUT combinatorial) 53 - 3 (INPUT combinatorial) 54 - 4 (INPUT combinatorial) SA16 - 5 (INPUT combinatorial) SA17 - 6 (INPUT combinatorial) SA18 - 7 (INPUT combinatorial) SA19 - 8 (INPUT combinatorial) RESET_DRV - 9 (INPUT combinatorial) /SMEMW - 11 (INPUT combinatorial) /WRITE - 12 (OUTPUT combinatorial active_low) /SUEUR - 13 (INPUT combinatorial active_low) /PHRD - 14 (10 combinatorial active_low) /PMWR - 15 (10 combinatorial active_lov) /SEGSEL - 16 (OUTPUT combinatorial active_low) /T2 - 17 (io combinatorial active_low) / T l - 18 (IO combinatorial active_low) /PRST - 19 (OUTPUT combinatorial active_low) 4 switch inputs for segment decoding" 4 MSB address lines for segment decoding" "Reset from PC, active high" "PC write request" "Host data latch direction" "PC read request" "Buffered read request" "Buffered write request" "Segment selected output" "2 intermediate lines for" " segment calculation" "Buffered PC reset, act. low" ((/S2) % SA17); ((/S4) % SA19); /RESET_DRV) + PMWR + PMRD; T2 * /RESET_DRV) + PMWR; T2 * /RESET_DRV; T2 * /RESET DRV; "Logic Equation Section" BEGIN Tl - ((/SI) % SA16) T2 - (</S3) % SA18) SEGSEL - (Tl * T2 WRITE - (SMEMW * Tl PRST - RESETJDRV; PMWR - SMEMW * Tl PMRD - SMEMR * Tl ENABLE (Tl) ," ENABLE (T2); ENABLE (SEGSEL); ENABLE (WRITE); ENABLE (PRST) ; ENABLE (PMWR); ENABLE (PMRD) ; END. "Test Vector Section" TEST_VECTORS IN SI, S2, S3, S4, SA16, SA17, SA18, SA19,RESETDRV, /SMEMW, /SMEMR; I_0 /Tl,/T2,/PMWR,/PMRD; OUT /SEGSEL,/PRST,/WRITE; BEGIN 0 1 1 0 0 0 0 0 0 0 0 H H H H H H H ; 0 1 1 0 0 0 0 1 0 0 1 H H H H H H H ; 0 1 1 0 0 0 1 0 0 1 0 H L H H H H H ; 0 1 1 0 0 0 1 1 0 1 1 H H H H H H H 0 1 1 0 0 1 0 0 0 0 0 L H H H H H H 0 1 1 0 0 1 0 1 0 0 1 L H H H H H H 0 1 1 0 0 1 1 0 0 1 0 L L H L L H H 0 1 1 0 0 1 1 1 0 1 1 L H H H H H H 0 1 1 0 1 0 0 0 0 1 1 H H H H H H H 0 1 1 0 1 0 0 1 0 1 0 H H H H H H H 0 1 1 0 1 0 1 0 0 0 1 H L H H H H H 0 1 1 0 1 0 1 1 0 0 0 H H H H H H H 0 1 1 0 1 1 0 0 0 1 1 H H H H H H H 0 1 1 0 1 1 0 1 0 1 0 H H H H H H H 0 1 1 0 1 1 1 0 0 0 1 H L H H H H H 0 1 1 0 1 1 1 1 0 0 0 H H H H H H H 0 1 1 0 0 1 1 0 1 1 0 L L H H H L H 0 1 1 0 0 1 1 0 0 1 0 L L H L L H H 0 1 1 0 0 1 1 0 0 0 1 L L L H L H L 0 1 1 0 0 1 1 0 0 0 0 L L L L L H L 0 1 1 0 0 1 1 0 0 1 1 L L H H L H H PCDATA.VO PCData, Version 0 ** U28 ** Pal to decode accesses by the PC to the dual port data memory DEVICE PCDATA (P16L8) PIN PA15 PA14 PA13 PA12 PAO /PMWR /PMRD - 1 - 2 - 3 - 4 - 5 - 6 - 7 /PLADDR - 12 - 13 - 14 /PCWR /PCRD /PED1H - 15 /PED1L - 16 /PEDOH - 17 /PEDOL - 18 /PDWR - 19 (INPUT combinatorial) (INPUT combinatorial) (INPUT combinatorial) (INPUT combinatorial) (INPUT combinatorial) (INPUT combinatorial) (INPUT combinatorial) (OUTPUT combinatorial active_low) (OUTPUT combinatorial active_low) (OUTPUT combinatorial active_low) (OUTPUT combinatorial active_low) (OUTPUT combinatorial active_low) (OUTPUT combinatorial active_low) (OUTPUT combinatorial active_low) (OUTPUT combinatorial active low) ** Logic Equations ** n * * A * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * • * * * # " BEGIN PDWR - (PMWR * PA15 * /(PA14 * PA13)); PEDOL - ((PMWR + PMRD) * PA15 * /PA14 * /PA13 * /PA12 * /PAO); PEDOH = ((PMWR + PMRD) * PA15 * /PA14 * /PA13 * /PA12 * PAO); PED1L - ((PMWR + PMRD) * PA15 * /PA14 * /PA13 * PA12 * /PAO); PED1H - ((PMWR + PMRD) * PA15 * /PA14 * /PA13 * PA12 * PAO); PCRD - (PMRD * PA15 * PA14 * PA13 * /PA12 * /PAO); PCWR - (PMWR * PA15 * PA14 * PA13 * /PA12 * /PAO); PLADDR - ((PMWR + PMRD) * PA15 * PA14 * PA13 * PA12); ENABLE (PDWR); ENABLE (PEDOL); ENABLE (PEDOH) ENABLE (PEDlL) ENABLE (PED1H) ENABLE (PCRD); ENABLE (PCWR); ENABLE (PLADDR); ** Test vector specification t * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * TEST_VECTORS IN PA15, PA14, PA13, PA12, PAO, /PMWR, /PMRD; OOT /PDWR, /PEDOL, /PEDOH, /PEDlL, /PEDlH, /PCRD, BEGIN /PCHR, /PLADDR; 1 0 0 0 0 0 1 L L H H H H H H. 1 0 0 0 1 0 1 L H L H H H H H; 1 0 0 1 0 0 1 L H H L H H H H; 1 0 0 1 1 0 1 L H H H L H H H. 1 0 1 0 0 0 1 L H H H H H H H; 1 0 1 0 1 0 1 L H H H H H H H; 1 0 1 1 0 0 1 L H H H H H H H; 1 0 1 1 1 0 1 L H H H H H H H; 1 1 0 0 0 0 1 L H H H H H H H; 1 1 0 0 1 0 1 L H H H H a H H; 1 1 0 1 0 0 1 L H H H H H H H; 1 1 0 1 1 0 1 L H H H H H R H; 1 1 1 0 0 0 1 H H H H H H L H; 1 1 1 0 1 0 1 H H H H H H H H; 1 1 1 1 0 0 1 H H H H H H H L; 1 1 1 1 1 0 1 H H H H H H H L; 0 0 0 0 0 0 1 H H H H H H H H; 1 1 1 0 0 1 0 H H H H H L H H; PCPROG.VO ** PCProg, Version 0 ** U29 ** ** Pal to control the latches connecting the IMS bus to the PC bus; enabling ** the PC to access the TMS program memory. *" DEVICE PCPROG (P16L8) PIN /PLADDR - 1 (INPUT combinatorial) PA15 - 2 (INPUT combinatorial) PAO 3 (INPUT combinatorial) /PMWR - 4 (INPUT combinatorial) /PMRD - 5 (INPUT combinatorial) /THOLDA e (INPUT combinatorial) PLIE - 7 (INPUT combinatorial) /SYNCHW - 8 (INPUT combinatorial) /PPADDR - 12 (OUTPUT combinatorial active_lo»r) PLNH - 13 (OUTPUT combinatorial active_ low) PLWL - 14 (OUTPUT combinatorial active_ "low) /PLRH - 15 (OUTPUT combinatorial active_ "low) /PLRL - 16 (OUTPUT combinatorial active_ "low) /PPDH - 17 (OUTPUT combinatorial active" "low) /PPDL - 18 (OUTPUT combinatorial active_ 'low) /PPWR - 19 (OUTPUT combinatorial active_ "low) ** Logic Equations «**************************************************************************" BEGIN PPADDR PPWR -PPDL PPDH PLRL PLRH -/PLWL /PLWH ENABLE ENABLE ENABLE ENABLE ENABLE ENABLE ENABLE ENABLE END. - (THOLDA * (PMWR + PMRD) * /PA15) ; (THOLDA * PMWR * /PA15); (PMWR + PMRD) * /PA15 * /PAO) ; (PMWR + PMRD) * /PA15 * PAO) ; PMRD * /PAO) ; PMRD * PAO); SYNCHW * PMWR * /PAO); PMWR * PAO) ; (THOLDA (THOLDA (PLADDR * /PLIE (PLADDR * /PLIE (PLADDR (PLADDR * SYNCHW (PPADDR); (PPWR) (PPDL) (PPDH) (PLRL) (PLRH) (PLWL) (PLWH) ** Test Vector Specification **************************************************************************" TEST VECTORS IN ~ PA15, PAO, /PMWR, /PMRD, /THOLDA, /PLADDR, PLIE, /SYNCHW; OUT /PPADDR, /PPWR, /PPDL, /PPDH, /PLRL, /PLRH, PLWL, PLWH; BEGIN 0 0 0 1 0 1 1 1 L L L H H H L L; 0 1 0 1 0 1 1 1 L L H L H H L L; 0 0 1 0 0 1 1 1 L H L H H H L L; 0 1 1 0 0 1 1 1 L H H L H H L L; 0 0 0 1 1 1 1 1 H H H H H H L L; 1 0 0 1 0 1 1 1 H H H H H H L L; 1 0 1 0 1 0 0 1 H H H H L H L L; 1 1 1 0 1 0 0 1 H H H H H L L L; 1 1 1 0 1 0 1 1 H H H H H H L L; 1 0 0 1 1 0 1 0 H H H H H H H L; 1 1 0 1 1 0 1 0 H H H H H H L H; 1 1 0 1 1 0 1 1 H H H H H H L L; TMSDATA. VO ** TMSData, Version 0 ** U31 ** Pal to decode the accesses by the THS320 to the dual port data memory DEVICE TMSDATA (P16L8) PIN TA15 - 1 (INPUT combinatorial) TA14 - 2 (INPUT combinatorial) TA13 - 3 (INPUT combinatorial) TA12 - 4 (INPUT combinatorial) TA11 - 5 (INPUT combinatorial) /TDS - « (INPUT combinatorial) /TWR - 7 (INPUT combinatorial) /TSTRB - 8 (INPUT combinatorial) /TMSC - 9 (INPUT combinatorial) /TRST 11 (INPUT combinatorial) /TIS - 13 (INPUT combinatorial active low) /TLRD - 14 (OUTPUT combinatorial active low) /TLWR 15 (OUTPUT combinatorial active^ "low) TREADY - 16 (OUTPUT combinatorial active_ "low) /TED1 - 17 (OUTPUT combinatorial active_ "low) /TEDO - 18 (OUTPUT combinatorial active_ "low) /TDWR - 19 (OUTPUT combinatorial active_ "low) co ** Logic Equations ***************************************************************************** BEGIN TDWR TEDO TED1 /TREADY TLWR TLRD ENABLE ENABLE ENABLE ENABLE ENABLE ENABLE END. (TDS * TWR * TSTRB * /TRST * /TA15 * /TA14 * (TA13 + TA12)); (TDS * /TA15 * /TA14 * /TA13 * TA12 * /TA11) ; (TDS * /TA15 * /TA14 * /TA13 * TA12 * TA11); - (/TDS + TA15 + TA14 + (/TA13 * /TA12) + /TMSC); (TIS * TSTRB * TWR * /TRST) ; (TIS * /TWR); (TDWR) ; (TEDO) ; (TED1) ; (TREADY) ; (TLWR); (TLRD); ** Test Vector S p e c i f i c a t i o n *" it ************************************************************** ************* TEST_VECTORS IN TA15, TA14, TA13, TA12, TA11, /TDS, /TWR, /TSTRB, /TMSC, /TRST, /TIS; OUT /TDWR, /TEDO, /TED1, TREADY, /TLWR, /TLRD; BEGIN 0 0 0 0 0 0 0 0 0 1 1 H H R H H H 0 0 0 0 1 0 0 0 0 1 1 H H H H H H 0 0 0 1 0 0 0 0 0 1 1 L L H L H H 0 0 0 1 1 0 0 0 0 1 1 L H L L H H 0 0 1 0 0 0 0 0 0 1 1 L H H L H H 0 0 1 0 1 0 0 0 0 1 1 L H H L H H 0 0 1 1 0 0 0 0 0 1 1 L H H L H H 0 0 1 1 1 0 0 0 0 1 1 L H H L H H 0 1 0 0 0 0 0 0 0 1 1 H H H H H H 0 1 0 0 1 0 0 0 0 1 1 H H H H H H 0 1 0 1 0 0 0 0 0 1 1 H H H H H H 0 1 0 1 1 0 0 0 0 1 1 H H H H H H 0 1 1 0 0 0 0 0 0 1 1 0 1 0 0 0 0 1 1 1 0 0 0 0 0 1 1 1 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 1 1 0 0 0 1 0 0 0 0 END. 0 1 1 H H H H H H 0 1 1 H H H H H H , 0 1 1 H H H H H H 0 1 1 H H H H H H ; 0 1 1 H H H H H H 0 1 0 R H H H L H ; 0 1 0 H H H H H L ; 1 1 1 L L H H H H ; PROGMEM.VO ** ProgMem, Version 0 ** U30 ** ** Pal to control the enable l i n e s on the actual program memory *» DEVICE PROGMEM (P16L8) PIN /PPADDR 1 (INPUT combinatorial) PAO - 2 (INPUT combinatorial) /PMWR - 3 (INPUT combinatorial) /PMRD - 4 (INPUT combinatorial) /TPS - 5 (INPUT combinatorial) /TWR - 6 (INPUT combinatorial) /TSTRB - 7 (INPUT combinatorial) TA15 _ 8 (INPUT combinatorial) TA14 - 9 (INPUT combinatorial) TA13 - 11 (INPUT combinatorial) /FFSET - 12 (OUTPUT combinatorial active_low) /PLADDR 13 (INPUT combinatorial active_low) /TRST m 14 (IO combinatorial active_low) /PRST m 15 (INPUT combinatorial active_low) /SRST - 16 (INPUT combinatorial active_low) /WRHP - 17 (OUTPUT combinatorial active_low) /WRLP - 18 (OUTPUT combinatorial active_low) /ENP0 - 19 (OUTPUT combinatorial active_low) ** Logic Equations *" **************************************************************************** BEGIN ENP0 - (((PPADDR * (PMWR + PMRD)) + TPS) * /TA15 * /TA14 * /TA13) ; WRLP - ((PPADDR * PMWR * /PAO) + (TPS * TWR * TSTRB * /TRST)); WRHP - ((PPADDR * PMWR * PAO) + (TPS * TWR * TSTRB * /TRST)); FFSET - (/PLADDR + TRST); TRST - (PRST + SRST); ENABLE (ENP0); ENABLE (WRLP) ENABLE (WRHP) ENABLE (FFSET); ENABLE (TRST); END. "* ** Test Vector Specification TEST VECTORS IN 10 OUT BEGIN 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 TA15, TA14, TA13, PAO, /PPADDR, /PMWR, /PMRD, /TPS, /TWR, /TSTRB, /PLADDR, /PRST, /SRST; /TRST; /ENPO, /WRLP, /WRHP, /FFSET; 0 0 0 0 0 0 0 1 1 1 1 1 END. H H H H L H H L H H H H L L L L H H H H L H L L L H H H L H H H L H H H Appendix B Software Listings B . l Simulation Listings The development of the silence detection algorithm relied heavily on the use of a software sim-ulator. This enabled the use of identical speech samples to be used on various derivatives of the silence detection algorithm, enabling meaningful comparisons between the various compression statistics. The software simulator operated on a previously stored speech file, removing the silence intervals and created a new output speech file as well as the compression statistics obtained. Playback of the compressed speech file enabled evaluations of speech quality to be made. The following pages contain the listings of the C language programs that comprise the software simulator for the silence detection algorithm. 65 This f i l e contains the program used to simulate the silence compression algorithm on an IBM-PC/AT. SilSim.h /* ** SilSim.h ** March 27, 1990 ** Chris Rose #* ** Header f i l e for s i l e n c e deletion simulation program. Number of samples to calc, Threshold for speech */ energy, etc */ /* Zero-crossings threshold */ /* Default parameters */ •define FRAMESIZE 16 •define MINTHRESH 2.0 •define MAXTHRESH 2.5 •define ZEROCROSS 8 •define MINSPEECH 10 •define MINSIL 4 •define HANGOVER 20 •define ECRIT 1.28 •define SPCAVGBLKLEN 32 •define SPCAVGNUMBLK 32 •define SILAVGLEN 64 •define INITSPEECHAVG 500 •define INITSILAVG 20 •define SPEECHSCALE 20 •define INITSCALE 20 •define SILCODE 0x0080 •define ZERO OxFF typedef enum { NONE, NOISE, BOTH } AdaptType; typedef enum ( NO, YES ) Query; /* Global v a r i a b l e declaration */ FrameSize, ZeroCross, MinSpeech, MinSil, Hangover; SpcAvgBlkLen, SilAvgLen, InitSilAvg, InitSpeechAvg; SpeechScale, InitScale, SpcAvgNumBlk; MinThresh, MaxThresh, E C r i t ; Adaptation; Noiseln, Trace, ECritOn; **Frame; MaxValue, MinValue; MaxEnergy, MinEnergy; NumFrames, SilFrames, SpeechFrames; S i l l n t e r v a l s , Speechlntervals; ZFrames, EFrames, BFrames, NFrames; extern i n t extern i n t extern i n t extern double extern AdaptType extern Query extern char extern i n t extern unsigned extern unsigned extern unsigned extern unsigned SilSim.c ** SilSim.c ** March 26, 1990 ** Chris Rose ** ** Program to perform silence deletion on a speech data f i l e . •include <stdio.h> •include <stdlib.h> •include " s i l s i r a . h " /* Global v a r i a b l e declaration */ i n t Framesize, ZeroCross, MinSpeech, MinSil, Hangover; i n t SpcAvgBlkLen, SilAvgLen, InitSilAvg, InitSpeechAvg; in t SpeechScale, InitScale, SpcAvgNumBlk; double MinThresh, MaxThresh, E C r i t ; AdaptType Adaptation; Query Noiseln, Trace, ECritOn; char "Frame; in t MaxValue, MinValue; unsigned MaxEnergy, MinEnergy; unsigned NumFrames, SilFrames, SpeechFrames; unsigned S i l l n t e r v a l s , Speechlntervals; unsigned ZFrames, EFrames, BFrames, NFrames; /* Function Prototypes */ char **GetMatrix( i n t Rows, i n t Columns ); void FreeMatrix < char **Frame ); void DeleteSilence( FILE * I n F i l e , FILE *OutFlle ); void main( i n t Argc, char *Argv[] ) ( FILE * I n F i l e , *OutFile; char *InFileName, *Str; i n t StoreFrames; double PercentSil, PercentSpeech, AvgSilLength, AvgSpeechLength; long NumCodeBytes, NumSpeechBytes, TotalBytes; double Compression, PercentOH; /* Set default values */ FrameSize - FRAMESIZE; MinThresh - MINTHRESH; MaxThresh - MAXTHRESH; ZeroCross - ZEROCROSS; MinSpeech - MINSPEECH; MinSil — MINSIL; Hangover - HANGOVER; SilAvgLen - SILAVGLEN; SpcAvgBlkLen - SPCAVGBLKLEN; SpcAvgNumBlk - SPCAVGNUMBLK; InitSpeechAvg - INITSPEECHAVG; Ini t S i l A v g - INITSILAVG; ECrit - ECRIT; SpeechScale - SPEECHSCALE; InitScale - INITSCALE; Adaptation - BOTH; Noiseln -YES; Trace — NO; ECritOn - YES; i f (Argc < 2) { f p r i n t f ( s t d e r r , "Osage: SILSIM <OutFile>"); exit(EXIT_FAILORE) : ) /* Get environment variable options */ i f ((InFileName - getenv("INFILE")) — NULL) { f p r i n t f ( s t d e r r , " E r r o r : Cannot get input f i l e - s p e c " ) ; e x i t (EXIT_FAILURE) ; ) i f (<Str - getenv("FRAMESIZE")) !- NULL) FrameSize - atoi(Str) i f ((Str - getenv("MINTHRESH")) !- NULL) MinThresh - atof(Str) i f K S t r - getenv("MAXTHRESH")) !- NULL) MaxThresh - atof(Str) i f ((Str - getenv("ZEROCROSS")) !- NULL) ZeroCross - atoi(Str) i f ((Str » getenv("MINSPEECH")) !- NULL) MinSpeech - atoi(Str) i f ((Str - getenv("MINSIL")) !- NULL) MinSil - atoi(Str) i f ((Str - getenv("HANGOVER")) !- NULL) Hangover - atoi(Str) i f ((Str » getenv("ECRIT")) !- NULL) ECrit - atof(Str) i f ((Str - getenv("SILAVGLEN")) !- NULL) SilAvgLen - atoi(Str) i f ((Str - getenv("SPCAVGBLKLEN")) !- NULL) SpcAvgBlkLen - atoi(Str) i f ((Str - getenv("SPCAVGNUMBLK")) !- NULL) SpcAvgNumBlk - atoi(Str) i f ((Str getenv("INITSPEECHAVG")) !- NULL) InitSpeechAvg - atoi(Str) i f ((Str - getenv("INITSILAVG")) !- NULL) InitSil A v g - atoi(Str) i f ((Str - getenv("SPEECHSCALE")) !- NULL) SpeechScale - atoi(Str) i f ((Str - getenv ("MITSCALE")) !- NULL) i n i t S c a l e - atoi(Str) i f ((Str - getenv("ADAPTATION")) !- NULL) Adaptation - atoi(Str) i f ((Str - getenv("NOISEIN")) !- NULL) Noisein - atoi(Str) i f ((Str - getenv("TRACE")) !- NULL) Trace - atoi(Str) i f ((Str getenv("ECRITON")) !- NULL) ECritOn - atoi(Str) i f ( ( i n F i l e - fopen(InFileName, "rb" ) ) — NULL) ( f p r i n t f ( s t d e r r , "Error: Cannot open f i l e \"%s\"", InFileName): e x i t (EXIT_FAILURE) ; ) i f ((OutFile - fopen(Argv[l], "wb")) — NULL) ( f p r i n t f ( s t d e r r , "Error: Cannot open f i l e \"%s\"", Argv[l]); e x i t (EXIT_FAILURE) ; ) StoreFrames - max(MinSpeech, Mi n S i l ) ; i f ((Frame - GetMatrix(StoreFrames, FrameSize)) — NULL) ( f p r i n t f ( s t d e r r , "Error: Cannot allocate FRAME matrix"); e x i t (EXIT_FAILURE) ; ) /* Perform the actual silence removal */ DeleteSilence(InFile, OutFile); FreeMatrix(Frame); f c l o s e ( I n F i l e ) ; f c l o s e ( O u t F i l e ) ; /* Display the compression r e s u l t s */ PercentS i l - 100.0*SilFrames/NuraFrames; PercentSpeech - 100.0*SpeechFrames/NumFrames; AvgSilLength - ((double)SilFrames)/Sillntervals; AvgSpeechLength - ((double)SpeechFrames)/Speechlntervals; TotalBytes = (long) FrameSize * NumFrames; NumCodeBytes - ((long) S i l l n t e r v a l s * 6) + 4; NumSpeechBytes - (long) FrameSize * SpeechFrames; Compression - 100.0*(NumCodeBytes+NumSpeechBytes)/TotalBytes; PercentOH - 100.0*NumCodeBytes/TotalBytes: printf("\nAlgorithm Parameters:\n"); p r i n t f ! " FrameSize - %d, MinThresh - %4.21f, ", FrameSize, MinThresh); printf("MaxThresh - %4.21f, ZeroCross - %d\n", MaxThresh, ZeroCross); p r i n t f ( " MinSpeech - %d, MinSil - %d, ", MinSpeech, M i n S i l ) ; printf("Hangover - %d\n". Hangover); printf("\nSpeech F i l e : \ n " ) ; p r i n t f ( " Minvalue - %d, MazValue - %d, ", MinValue, MaxValue); p r i n t f ("MinEnergy - tu, MaxEnergy - %u\n", MinEnergy, MaxEnergy); p r i n t f ( " NumFrames - %u, NumBytes - %ld\n", NumFrames, TotalBytes); printf("\nAlgorithm Results:\n"); p r i n t f ( " SilFrameS - %u (%5.21f\%) ", SilFrames, PercentSil); p r i n t f ( " ( % l u ) , ", ((unsigned long)SilFrames*FrameSize)); printf("SpeechFrames - %u (%5.21f\*) ", SpeechFrames, PercentSpeech); p r i n t f ( " ( % l u ) \ n " , ((unsigned long)SpeechFrames*FrameSize)); p r i n t f ( " Overhead - %5.21f\% ", PercentOH); p r i n t f ( " ( % l u ) , ", NumCodeBytes); printf("Percent F i l e Compression - %5.21f\%\n". Compression); p r i n t f ! " S i l l n t e r v a l s - %u, ", S i l l n t e r v a l s ) ; printf("Speechlntervals - %u\n", Speechlntervals); p r i n t f ( " AvgSilLength - %5.21f ", AvgSilLength); printf!"(%5.11f), ", AvgSilLength*FrameSize) ; printf("AvgSpeechLength - %S.21f ", AvgSpeechLength); printf("(*5.11f)\n", AvgSpeechLength*FrameSize); p r i n t f ( " ZFrames - %u, EFrames - %u, ", ZFrames, EFrames); p r i n t f ("BFrames - lu, NFrames - %u\n", BFrames, NFrames); exit(EXIT_SUCCESS) ; > NoiseDel.c /* ** NoiseDel.c ** May 18, 1990 ** Chris Rose ** ** Routines to perform the actual silence deletion on the speech sample. ** This version w i l l substitute gaussian noise i n the silence i n t e r v a l s . */ •include <stdio.h> •include <stdlib.h> •include "silsim.h" typedef union { unsigned w; char b[2]; ) DATAMORD; typedef enum ( SPEECH, SILENCE ) StateType; i n t MuLawExpand( i n t MuLawCode ); void SaveSilenceFrame( i n t AvgEnergy, PILE *OutFile ); void SaveSpeechFrame( i n t FrameNumber, FILE *OutFile ); i n t MuLawCompress ( i n t LinearCode ); i n t GenerateGauss( i n t Avg ) ; void DeleteSilenceC FILE *InFile, FILE *OutFile ) /************#*#*#*********************************************************/ { i n t Index, Energy, LinValue, CurThresh, Previous, Crossings; i n t FrameCount, StoreLevel; unsigned SilLength, SpeechLength; long EnergySum, AvgSum; DATAKORD CurKord; StateType State, CurrentFrame; i n t AvgList [NUMAVG], Avg, AvgPoint; srand(12345); for (Index - 0; Index < NUMAVG; Index++) ( AvgList [Index) - TUITAVG; > AvgSum - INITAVG*NUMAVG; Avg - INITAVG; AvgPoint - 0; MaxValue — MinValue - MaxEnergy - 0; MinEnergy - 1000; NumFrames - SilFrames - SpeechFrames - 0; S i l l n t e r v a l s ~ Speechlntervals — 0; SilLength - SpeechLength - 0; Store Level - 0; State - SILENCE; CurThresh - MaxThresh; Previous - 0; while (1) ( /* Calculate the frame energy, and zero-crossings */ FrameCount - Crossings - 0; EnergySum - 0L; while (FrameCount < FrameSize) ( /* Get next two bytes from the f i l e */ for (Index - 0; Index < 2; Index++) ( CurKord.b[Index] - get c ( I n F i l e ) ; ) /* Check for an End Of Data code, i f present, stop reading */ i f (CurKord.w — SILCODE) break; /* Add these two bytes components to energy and crossings */ for (Index - 0; Index < 2; Index++) ( Frame[StoreLevelJ[FrameCount++] - CurKord.btlndex]; LinValue - MuLawExpand( (int) CurKord.b[Index]) ; EnergySum +- (long) abs(LinValue); i f ((LinValue * Previous) £ 0x8000) Crossings++; Previous - LinValue; i f (LinValue > MaxValue) MaxValue - LinValue; i f (LinValue < MinValue) MinValue - LinValue; ) ) /* Check i f end of data was detected */ i f (CurKord.w — SILCODE) break; /* Calculate frame energy average */ Energy - (int)(EnergySum / FrameSize); i f (Energy > MaxEnergy) MaxEnergy " Energy; i f (Energy < MinEnergy) MinEnergy - Energy; /* Check i f frame was speech or sil e n c e */ i f ((Energy >- CurThresh) I! (Crossings >" ZeroCross)) ( CurrentFrame - SPEECH; ) e l s e ( CurrentFrame - SILENCE; ) i f ((State — SILENCE)ss(CurrentFrame — SILENCE)) ( for (Index - 0; Index < (SpeechLength+1); Index++) ( i f (Energy < (Avg * AVGCRIT)) { AvgSum — AvgList [AvgPoint] ; AvgSum +- Energy; Avg - (int) AvgSum/NUMAVG; AvgList[AvgPoint++] - Energy; i f (AvgPoint >- NUMAVG) AvgPoint - 0; ) SaveSilenceFrame(Avg, OutFlle); NumFrames++; SilFrames++; SilLength++; ) i f (SilLength >- Hangover) CurThresh - MaxThresh; SpeechLength - StoreLevel - 0; ) else i f ((State — SILENCE)SS(CurrentFrame — SPEECH)) ( CurThresh - MinThresh; SpeechLength++; i f (SpeechLength — MinSpeech) ( State - SPEECH; for (Index - 0; Index < SpeechLength; Index++) ( SaveSpeechFrame(Index, OutFile); NumFrames++; SpeechFrames++; ) i f (SilLength > 0) Sillntervals++; SilLength - StoreLevel - 0; ) e l s e ( StoreLevel++; ) ) else i f ((State — SPEECH)ts(CurrentFrame ~ SPEECH)) ( CurThresh - MinThresh; for (Index - 0; Index < (SilLength+1); lndex++) ( SaveSpeechFrame(Index, OutFile); NumFrames++; SpeechFrames++; SpeechLength++; ) SilLength - StoreLevel - 0; i I i n t Index; i e l s e { /* State - SPEECH, CurrentFrarae - Silence */ SilLength++; i f (SilLength >- Hangover) CurThresh - MaxThresh; i f (SilLength ~ MinSil) ( State - SILENCE; i f (Energy < (Avg * AVGCRIT)) ( AvgSum — AvgList[AvgPoint]; AvgSum +- Energy; Avg - (Int) AvgSum/NUMAVG; AvgList [AvgPoint++] - Energy; i f (AvgPoint >- NUMAVG) AvgPoint - 0; ) for (Index - 0; Index < SilLength; Index++) ( SaveSilenceFrame(Avg, OutFile); NumFrames-H-; SilFrames++; i , for (Index - 0; Index < FrameSize; Index++) ( putc(Frame[FrameNumber][Index], OutFile); ) ) uLawExp.c /* ** uLawExp.c ** March 16, 1990 ** Chris Rose ** ** Routine to perform Mu-law expansion i n C-code. */ / i f (SpeechLength > 0) Speechlntervals++; SpeechLength - StoreLevel - 0; i / •define BIAS 33 i e l s e ( StoreLevel++; ) ) ) /************************************************************************** j i n t MuLawExpand( i n t MuLawCode ) /**************************************************************************/ ( i n t Sign, LinSeg, Quant, LinVal, CompVal; /* Save any stored frames of speech or silence */ i f (State — SILENCE) ( for (Index - 0; Index < SpeechLength; Index++) { SaveSilenceFrame(Avg, OutFile); ) CompVal - -MuLawCode; Sign - (CompVal s 0x0080): LinSeg - ((CompVal £ 0x0070) » 4); Quant - (CompVal S OxOOOF); ) e l s e i f (State — SPEECH) ( for (Index - 0; Index < SilLength; Index++) ( SaveSpeechFrame(Index, OutFile); ) > Quant - ((Quant * 2) + BIAS); LinVal - (Quant « LinSeg); LinVal — BIAS; i f (Sign — 0) ( return(LinVal); i /* Mark end of speech f i l e */ putw(SILCODE, OutFile); ( i e l se ( return(-LinVal); 1 /************************************************************************** / void SaveSilenceFrame( i n t Avg, FILE *OutFile ) /**************************************************************************/ ( i n t Index, MuLawCode, LinearCode; ) uLawComp.c LinearCode - GenerateGauss (Avg) ; MuLawCode - MuLawCompress(LinearCode) ; for (Index - 0; Index < FrameSize; Index++) ( putc(MuLawCode, OutFile); ) ) ** uLawComp. c ** March 20, 1990 ** Chris Rose ** ** Routine to perform Mu-law compression. */ /•A************************************************************************/ void SaveSpeechFrame! i n t FrameNumber, FILE *OutFile ) /**************************************************************************/ •define BIAS 33 /*«****>**+* ********************** *******^ j i n t MuLawCompress( i n t LinearCode ) /**************************************************************************/ ( i n t ShiftCount, Quant, LinSeg, Compressed; —J O ShiftCount - 0; i f (LinearCode < 0) { LinearCode - -LinearCode + BIAS; /* Check for overflow of 13 b i t magnitude */ i f ((LinearCode t OxEOOO) > 0) LinearCode - OxlFFF; while ((ShiftCount < 7)ss((LinearCode t 0x1000)—0)) ( LinearCode « - 1; ShiftCount++; ) LinSeg - 7 - ShiftCount; Quant - (LinearCode s OxOFOO) » 8; Compressed - (-((LinSeg « 4) | Quant)) t 0x007F; 1 e l s e ( LinearCode +— BIAS; /* Check for overflow of 13 b i t magnitude */ i f ((LinearCode s OxEOOO) > 0) LinearCode - OxlFFF; while ((ShiftCount < 7) *s ((LinearCode £ 0x1000)—0)) ( LinearCode « - 1; ShiftCount++; ) LinSeg - 7 - ShiftCount; Quant - (LinearCode £ OxOFOO) » 8; Corapressed - (-((LinSeg « 4) | Quant)) t OxOOFF; ) return(Compressed); Gauss.c •include <stdio.h> •include <stdlib.h> •include <math.h> •include <dos.h> double Norraf void ); double Uni form( void ) ; double Seed - 0.0; i n t GenerateNoise( i n t Avg ) I double Number; Number - Avg * 1.248 * Norm() ; return!(int) Number); ) /* ** Norm ** This routine generates a roughly Gaussian random number that has zero ** mean, and variance of 1 (the normal d i s t r i b u t i o n ) . The method i s based ** on the "central l i m i t theorem" i n the sum of independantly dis t r i b u t e d ** random variables approaches the gaussian d i s t r i b u t i o n i n the l i m i t . Here, ** 12 'independant' uniform numbers are added, which gives a unit variance, ** but a mean of 6. Therefore, 6 i s subtracted from the r e s u l t to give a ** zero mean. This method i s used as i t uses only simple arithmetic ** operations; no "sine" or "logarithmic" transformations are necessary. */ /**************************************************************************/ double Norm( void ) ************************************************************************/ { i n t i ; double sum; sum - -6.0; for ( i -0; i<12; i++) ( sum +- Uniform!); ) return (sum); ) double Uniform( void ) ( Seed - fmod(Seed*67081293.0 + 14181771.0, 67108864.0); return(Seed/67108864.0); ) Matrix.c /* ** Matrix.c ** March 27, 1990 ** Chris Rose ** ** Routines to perform dynamic al l o c a t i o n and de-allocation of matricies. */ •include <stdio.h> •include <stdlib.h> void A l l o c E r r o r ( char *String ); /**************************************************************************/ char **GetMatrix( i n t Rows, i n t Columns ) /**************************************************************************/ ( i n t i ; char **Matrix; /* Allocate row pointers plus 1 extra for NULL */ Matrix - (char **) malloc((size_t) ((Rows + 1) * si z e o f ( c h a r * ) ) ) ; i f (Matrix — NULL) A l l o c E r r o r ( " A l l o c a t i o n f a i l u r e 1 i n GetMatrix"); /* Alloc a t e rows, and i n i t i a l i z e pointers to them */ for ( i - 0; i < Rows; i++) ( Matrix[i] - (char *) malloc((size_t) (Columns * s i z e o f ( c h a r ) ) ) ; i f (Matrix[i) — NULL) ( A l l o c E r r o r ( " A l l o c a t i o n f a i l u r e 2 i n GetMatrix"); ) ) /* Terminate Row pointers with a NOLL pointer */ Matrix(Rows) - NULL; /* Return pointer to array of row pointers */ return(Matrix) ; ) /**********#*#**************#************#*********************#*********** void FreeMatrix( char **Matrix ) ( i n t i ; i - 0; /* Free matrix rows, u n t i l NULL pointer i s found (after l a s t row) */ while (Matrix [i] !- NULL) ( fr e e ! (char *) Matrix[i++]) ; ) freeMchar *) Matrix); ) void A l l o c E r r o r ( char *String ) /********************************************•***************************** ( f p r i n t f ( s t d e r r , "Run Time A l l o c a t i o n Error: %s\n". String); e x i t (EXIT_FAILURE) ; ) Appendix B. Software Listings 72 B.2 Real-time Implementation Listings The real-time implementation of the speech compression algorithm required two basic divisions of programs; the code for the PC host, and the code for the TMS320 DSP system. The TMS320 DSP system program was written in TMS320c25 assembler language and implements the entire silence compression algorithm. The PC host program was written in the C language, and implements the hard disk transfers that are essential to the operation of a real-time speech storage system. B.2.1 Tms320c25 Program Listings The following pages contain the listings of the Tms320c25 assembler language code to implement the real-time silence compression algorithm. The routines to convert between /x-law coded P C M speech and linear P C M for computation of short-term statistics were modified from [38]. The routines to convert between linear P C M and 4-bit A D P C M were modified from [32]. This f i l e contains the TMS320c25 routines that implement the silence compression and playback algorithms. S i l R e c . i n c ;* SilRec.inc ;* May 1, 1990 ;* Chris Rose ; * ;* Include f i l e for SilRec modules. This f i l e contains general defines that ;* are used i n the Silence Deletion algorithm. .************************************************************************** ; * ;* Memory mapped registers DRR .set 0 S e r i a l port data receive register DXR .set 1 S e r i a l port data transmit register TIM • set 2 • Timer r e g i s t e r PRD .set 3 • Period r e g i s t e r IMR .set 4 • Interupt mask reg i s t e r GREG . * .set 5 Global memory a l l o c a t i o n register :* Hardware configuration constants IntrptMask .set OOlOh Enables RINT only (Serial port receive). CommLatch .set 0 I/O port for Communication Latch to PC. Dataoffset .set lOOOh Offset to s t a r t of external data memory DataMemSize • * • set lOOOh Size (in words) of external data memory ;* Silence d e l e t i o n algorithm constants SilCodeWord .set OOSOh Code word to signal silence frame EndCodetford .set OFFFFh End of data code word MaxSil . * .set OFFFEh Maximum number of frames of silence stored ;* Silence d e l e t i o n algorithm parameters FrameSize • set 16 The number of speech samples per frame FSShift .set 4 Number of s h i f t s to divide by FrameSize HighThresh .set 3B86h High energy threshold (3.72) Low Thresh • set 319Ah Low energy threshold (3.10) ZCThresh • set 200 Zero crossing threshold MinSpeech .set 1 Minimum number of frames of speech stored M i n S i l .set 1 Minimum number of frames of silence stored LTHangOver . * .set 1 Number of silence frames u n t i l EThresh-High ;* Adaptation constants REGPAGE .set 0 SPEECHPAGE .set 6 Speech Avg variables are on page 6 SILPAGE .set 7 Silence Avg variables are on page 7 SPCBLKLEN .set 16 Number of frames per averaging block SPCAVGSFT .set 4 S h i f t count to divide by SpcBlkLen SPCNUMBLK .set 32 Number of blocks of averages for Speech SPCBLKSFT .set 5 S h i f t count to divide by SpcNumBlk SILAVGLEN .set 64 Number of frames for averaging Silence SILAVGSFT .set 6 S h i f t count to divide by SilAvgLen INITSPCAVG .set 250 I n i t i a l value for speech average INITSILAVG .set -1 I n i t i a l value for silence average CECRIT .set 147Bh 1.28 CSPCSCALE .set 13 INITSCALE .set 20 TMP .set ARO ; Temporary pointer f o r general use CDP .set AR1 ; Current Data Pointer NDP .set AR2 ; New Data Pointer FSC .set AR3 ; Frame Samples Counter ZCR . set AR4 ; Zero crossings running counter SIL .set AR5 ; Number of consecutive s i l e n c e i n t e r v a l s SPC .set AR6 ; Number of consecutive speech in t e r v a l s AVG .set AR7 ; Pointer to average silence/speech arrays * Define Auxilary Register Variables * Auxilary Register Uses: * ARO - (TMP) Used as a temporary pointer. Values i n t h i s register are * not guaranteed outside of " l o c a l " code. This register w i l l also * be used by subroutines such as MuLawExp and MuLawComp. * AR1 - (CDP) Current Data Pointer. Used to address the current data * storage l o c a t i o n i n external data memory. * AR2 - (NDP) New Data Pointer. Points to the f i r s t data location that * has not yet been v e r i f i e d . Any previous data locations are ready * to be transferred to the PC. * AR3 - (FSC) Frame Sample Count; Counts down the remaining number of * samples required u n t i l the frame i s completed. * AR4 - (ZCR) Zero Crossing Rate; Counts the number of zero-crossings * present i n a frame of speech samples. * AR5 - (SIL) Silence Interval Length; Counts the number of consecutive * silence frames encountered i n the current s i l e n c e i n t e r v a l . * AR6 - (SPC) Speech Interval Length; Counts the number of consecutive * speech frames encountered i n the current speech i n t e r v a l . * AR7 - (ASE) Average Silence Energy pointer; Points to the f i r s t entry * to be over-written i n the table of most recent silence i n t e r v a l s * average energy values. SilRec.asm ;* SilRec.asm ;* May 17, 1990 ;* Chris Rose . * ;* This f i l e contians the main routine f o r the Mu-law s i l e n c e compressed ;* record program. .************************************************************************** . * ;* Include defines f i l e .include " s i l r e c . i n c " . * ;* External references .ref lnitTms320, initDataTransfer, initMuLawExp, InitSilenceCompress .ref GetSpeechFrame, EvaluateFrame, ProcessFrame .ref NriteEndCode, Receive, Unused, initAvgs . * . ************************************************************************** .sect "IRUPTS" . ************************************************************************** ;* Interupt Vectors Rsvect: B Start ; Reset vector lOVect: B Unused ; Hardware interupt 0 vector IlVect: B UnUsed ; Hardware interupt 1 vector -a I2Vect: B UnUsed ; Hardware interupt 2 vector .space lOOh ; reserved interupt vector space TmVect: B UnUsed ; Internal timer interupt vector RxVect: B Receive : S e r i a l port receive interupt vector TxVect: B UnUsed : S e r i a l port transmit interupt vector TpVect: B UnUsed ; Software TRAP instruction vector . * . ************************************************************************** .text ; ************************************************************************** S t a r t : ;* Main Routine for speech 'recording' using silence compression. . ************************************************************************** Set the i n i t i a l TMS320 configuration I n i t i a l i z e data transfer variables I n i t i a l i z e Mu-law expansion routine I n i t i a l i z e the silence compression variables I n i t i a l i z e speech and silence i n t e r v a l avgs. Read the next speech frame into memory Is t h i s frame 'speech' or 'silence' Process the frame (speech or silence) Get next frame, unless BIO high to quit Write the end of data code to memory Setting external flag signals finished to PC Disable a l l interupts And halt. ************************************************************************** .end ************************************************************************** CALL InitTms320 CALL InitDataTransfer CALL InitMuLawExp CALL InitSilenceCompress CALL InitAvgs MainLoop: CALL GetSpeechFrame CALL EvaluateFrame CALL ProcessFrame BIOZ MainLoop StopSampling: CALL WriteEndCode SXF ZAC SACL IMR IDLE . * SilPly.asm ;* SilPly.asm ,-* May 17, 1990 ;* Chris Rose . * ;* This f i l e contains the main routine for the silence inserted Mu-law ;* playback program. . ************************************************************************** . * ;* Include defines f i l e .include " s i l r e c . i n c " ; * ;* External references .ref lnitTms320, InitDataTransfer .ref UnUsed, Transmit, DataTransmit, CheckSilCode, CheckOverflow .ref GetNoise, Mult, NoiseVal, InitNoise . ref MuLawComp, InitMuLawComp, MuLawVal .def LinVal, SilAvg . * LinVal .usect "B2", 1 SilAvg .usect "B2", 1 ************************************************************************** .sect "IRUPTS" . * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * :* Interupt Vectors Rsvect: B Start ; Reset vector IOVect: B UnUsed ; Hardware interupt 0 vector I l v e c t : B UnUsed ; Hardware interupt 1 vector I2Vect: B UnUsed ; Hardware interupt 2 vector .space lOOh ; reserved interupt vector space TmVect: B UnUsed ; Internal timer interupt vector RxVect: B UnUsed ; S e r i a l port receive interupt vector TxVect: B Transmit ; S e r i a l port transmit interupt vector TpVect: B Unused ; Software TRAP i n s t r u c t i o n vector ;************************************************** .text .************************************************************************** Start: .************************************************************************** CALL InitTms320 ; Set TMS320 & s e r i a l port configuration CALL InitDataTransfer ; i n i t i a l i z e data transfer variables CALL InitNoise CALL InitMuLawComp MainLoop: CALL CheckSilCode ; Check i f si l e n c e code i s next. BNC MainNotCode ; Branch to play i f i t i s not a code LARP CDP ; Make data pointer active LAC * ; Load the si l e n c e i n t e r v a l length SBLK EndCodeword ; Check for end-code BZ MainEnd ; Branch i f 'end code' i s present LAR SIL,*+ ; Load the s i l e n c e i n t e r v a l length (in frames) CALL CheckOverflow LAC *+ SACL Mult CALL CheckOverflow LARP SIL MAR *_ ; Adjust loop count i n SIL re g i s t e r SilenceDelay: LARK AR7,(FrameSize-1) ; Load the i n t e r v a l count for each frame InnerDelay: CALL GetNoise LAC NoiseVal SACL U n v a l CALL MuLawComp LAC MuLawVal SACL DXR IDLE ; wait for s i l e n c e to transmit LARP AR7 BANZ InnerDelay,*- ; Branch u n t i l frame i s complete LARP SIL BANZ SilenceDelay,*- ; Branch for a l l frames of si l e n c e B MainLoop ; Check for second s i l e n c e code MainNotCode CALL DataTransmit ; Move data to transmit r e g i s t e r and transmit B MainLoop ; Branch f o r next data MainEnd: LALK OOFFh SACL DXR ; 'Zero' the transmit data register ZAC SAC I, SXF IDLE ; Disable a l l interupts : Set the external f l a g t o signal finished. ; And hal t . .************************************************************************** .end .************************************************************************** SilComp.asm •* SilComp.asm •* May 17, 1990 * Chris Rose . * * This f i l e contains the routines that implement the si l e n c e compression - * algorithm. This i s the f i n a l version of the silence compression algorithm * containing f l e x i b l e parameters such as FrameSize, Thresholds, MinSpeech, * MinSilence, and threshold Hangover. .************************************************************************** • * * Include defines f i l e •include " s i l r e c . i n c " . * * External references . def GetSpeechFrame, EvaluateFrame, ProcessFrame, initSilenceCompress . def Threshold, ThreshMult, FmEnergy .ref WriteSilCode, LinVal, ResetCDP, UpdateNDP .ref UpdateSilAvg, UpdateSpeechAvg, UpdateThreshold * * Define external data variables (Block B2) LowEnergy .usect "B2", HighEnergy .usect "B2", PrevSample .usect "B2n, FmZeroCross .usect "B2", FmEnergy .usect "B2", Threshold .usect "B2", ThreshMult .usect "B2", SpeechState .usect "B2", FrameType .usect "B2", MaxSilVar .usect "B2", TempData .usect "B2", ; Stores low 16 b i t s of energy t o t a l ; Stores high 16 b i t s of energy t o t a l ; Stores l i n e a r version of previous sample ; Stores the frame zero crossing rate ; Stores the frame energy average ; Stores the current energy threshold ; Stores the current threshold m u l t i p l i e r : 0 - Silence, 1 - Speech (current state) : 0 - Silence, 1 - Speech (for current frame) ; Variable storage for MaxSil constant ; Temporary storage l o c a t i o n ************************************************************************** .text ************************************************************************** GetSpeechFrame: ;* Routine to acquire a f u l l frame of speech samples, and calculate the frame ;* average energy, and number of zero-crossings. ; * ;* Assumes: ;* DP - 0 Data page containing the l o c a l variables :* SSXM Sign extension mode must be on (for ABS function to work) . * ;* Returns: ;* FmEnergy The average energy of the samples i n the frame ;* FmZeroCross The number of zero-crossings i n the frame * Modifies: * ARP Used to point t o the various temporary registers ************************************************************************** ZAC SACL SACL LARK LARK GSFGetNextSample: IDLE LowEnergy HighEnergy ZCR,0 FSC,(FrameSize - 1) I n i t i a l i z e Frame Energy to 0. Both high and low words need to be i n i t i a l i z e d I n i t i a l i z e frame zero crossings t o 0 I n i t i a l i z e the frame counter Enable interupts, and wait for sample * Interupt returns with the l i n e a r version of the received sample stored * i n LinVal. * * Add t h i s sample's energy to the running t o t a l . Each sample i s pre-shifted * before adding so that at end of frame, the average i s i n the high accum. * rather than having to divide the t o t a l by the frame s i z e . * Move l i n e a r value to accumulator Convert to absolute value Store absolute value to variable Restore running energy c a l c u l a t i o n to the accumulator ; Add component to the accum. Save 32-bit sum f o r next sample * Add t h i s sample's zero crossing rate contribution by checking i f the sign * of the current sample d i f f e r s from that of the previous sample. A zero i s * considered p o s i t i v e for t h i s c a l c u l a t i o n . LAC LinVal ABS SACL TempData ZALS LowEnergy ADDH HighEnergy ADD TempData,(16-FSShift) SACL LowEnergy ; SACH HighEnergy ZALS LinVal XOR PrevSample ANDK 8000h BZ GSFNoCross,*,ZCR MAR *+ GSFNoCross: LAC LinVal SACL PrevSample * * Check i f t h i s frame i s f u l l LARP BANZ FSC GSFGetNextSample,*-; Load LinVal to low accum. ; XOR with previous sample ; Mask o f f sign b i t i n top b i t of low accum ,* Branch i f both were same sign ; Increment counter Store current sample for next time Make frame s i z e counter active Branch i f there i s more data to get ;* Here, the frame i s complete. Move the frame calculations (energy and number .-* of zero crossings) to the appropriate variables, and return. . * LAC HighEnergy SACL FmEnergy ; Store the average frame energy SAR ZCR,FmZeroCross ; Store the number of zero-crossings RET . * .************************************************************************** EvaluateFrame: ;* Routine to c l a s s i f y the current frame as speech or silence based on the ;* frame's energy l e v e l and zero-crossings. This routine considers the ;* current frame only; further c l a s s i f i c a t i o n based on adjacent frames i s ;* done by ProcessFrame. ; * ZALS TempData and load i t to the accumulator, no ext. ;* Assumes: SAR SPCTempData - Store current speech length ... ;* DP - 0 Data page containing the l o c a l variables ADDS TempData and add to SIL i n accumulator, no ext. ;* ?SXM Sign extension can be either on or off ADDK 1 Increment SIL for current frame . * SACL TempData - Store f i n a l value for SIL ;* Passed: SUBS MaxSilVar - Compare with max allowed value, no ext. ;* FmEnergy The frame energy average BGEZ PFSiSiMaxSil • Check i f (SIL >- MaxSil) ... ;* FmZeroCross The frame zero crossings LAR SIL,TempData SIL ok, so save i t (. * B PFSiSiSilOK ;* Returns: PFSiSiMaxSil: ;* FrameType A f l a g s t a t i n g the type of the current frame (0 - S i l , 1 - Sp) LRLK SIL,MaxSil SIL too large, save max allowed . ************************************************************************** PFSiSiSilOK: ZALS Threshold ,- Load the current energy threshold ... LARK SPCO * Set current speech length to 0 SOBS FmEnergy ; and compare with current frame energy CALL ResetCDP • Reset the CDP to the s t a r t of the silence BLEZ EFCurSpeech ; Branch i f (FmEnergy >- Threshold) CALL WriteSilCode • Write the silence code and i n t e r v a l length LACK ZCThresh : Load the zero-crossing threshold ... LARP SIL • Make sil e n c e length counter active again SOBS FmZeroCross ; and compare with frame zero-crossings LARK AR0,LTHangOver - Load the low threshold hangover amount BLEZ EFCurSpeech ; Branch i f (FmZeroCross >- Threshold) CMPR 0 • Check i f (SIL - LTHangOver) ... EFCurSilence: BBZ PFSiSiHangOverOK branch i f not ZAC ; Current frame i s 'silence' ... LALK HighThresh Load the high energy threshold ... SACL FrameType : so store 0 as FrameType SACL ThreshMult and save as the current threshold RET PFSiSiHangOverOK: EFCurSpeech: CALL UpdateThreshold Update the energy threshold LACK 1 ; Current frame i s 'speech' ... RET SACL FrameType ; so store 1 as FrameType ; * RET PFSilSpeech: ; State - Silence, Current Frame - Speech .* LARP SPC Make speech length counter active .******** ****************************************************************** MAR *+ Increment the number of speech i n t e r v a l s ProcessFrame: LALK LowThresh Load the low energy threshold ... .-* Routine to process a frame that has been previously sampled, based on the SACL ThreshMult and save as the current threshold ;* current FrameType, and the current silence/speech state (SpeechState). LARK AR0, MinSpeech Load the minimum stored speech allowed ; * CMPR 0 Test i f (SPC - MinSpeech) ... ; * Assumes: BBZ PFSiSpStateOK and branch i f not ,.* DP - 0 Data page containing the l o c a l variables CALL UpdateSpeechAvg Add speech frame energy to speech average ;* ?SXM Sign extension can be either on or off LACK 1 Load 1 to the accumulator ;* SACL SpeechState and store to signal SpeechState (1) ;* Passed: LARK SIL.O Update current silence length to zero ;* FrameType A f l a g stating the type of the current frame (0 - S i l , 1 - Sp) CALL UpdateNDP Update NDP to current location, o/p block * ;* SpeechState A f l a g s t a t i n g the current state (0 - S i l , 1 - Sp) PFSiSpStateOK: ; * CALL UpdateThreshold Opdate the energy threshold ;* Returned: RET ;* SpeechState The speech state f l a g i s modified based on the current frame ; * . * PFSpeechSil : : State - Speech Current Frame - Silence ;* Modified: LARP SIL Make Silence Length counter active ;* ARP Used to point t o the various auxilary registers MAR *+ Increment the number of silence i n t e r v a l s .************************************************************************** LARK AR0,LTHangOver Load the low energy thresh hangover amount LAC SpeechState ; Load the current State to accum. CMPR 0 Test i f (SIL - LtHangover) ... BNZ PFSpeechState ; Branch i f State-Speech (1) BBZ PFSpSiHangOverOK and branch i f not. PFSilState: LALK HighThresh Load the high energy threshold ... LAC FrameType ; Load the current frame type to accum. SACL ThreshMult and save as the current threshold BNZ PFSilSpeech ; Branch i f Frame-Speech (1) PFSpSiHangOverOK: B P F S i l S i l ; Otherwise go to handle Silence frame (0) LARK ARO,MinSil Load the minimum stored silence allowed PFSpeechState: CMPR 0 Test i f (SIL - MinSil) ... LAC FrameType ; Load the current frame type to accum. BBZ PFSpSiStateOK and branch i f not. BNZ PFSpeechSpeech ; Branch i f Frame-Speech (1) CALL UpdateSilAvg Add s i l e n c e frame energy to silence average B PFSpeechSil ; otherwise go to handle Silence frame (0) ZAC Zero the accumulator ... ; * SACL SpeechState and store to signal SilenceState (0) P F S i l S i l : ; State - Silence, Current Frame - Silence LARK SPC,0 Update current speech length to zero CALL UpdateSilAvg ; Add silence frame energy to silence average CALL ResetCDP Reset the CDP to s t a r t of silence SAR SIL,TempData ; Store SIL to a memory loca t i o n ... CALL WriteSilCode Write the silence code and silence length PFSpSiStateOK: . * CALL UpdateThreshold • Update the energy threshold ;* Define variables for tracking the Speech Avg (Block B l , Page 6) RET SpeechAvgs .usect "P6", SPCBLKLEN • Array f o r 1 block of speech energies ; * SpeechBlks .usect "P6", SPCNUMBLK Array f o r block averages of speech PFSpeechSpeech: ; State - Speech, Current Frame - Speech ESpeechAvgs .usect "P6", 1 Last entry i n the SpeechAvgs array CALL UpdateSpeechAvg Add speech frame energy to speech average E SpeechBlks .usect "P6", 1 Last entry i n the SpeechBlks array CALL UpdateNDP • Update NDP to current location, o/p block # SpeechAvg .usect "P6", 1 • The current speech average energy LARK SIL,0 - Update current silence length to 0 SpcBlkAvg .usect "P6", 1 The avg energy of the current block LALK LOwThresh • Load the low energy threshold ... SpcAvgPnt .usect "P6", 1 Pointer into SpeechAvgs SACL ThreshMult and save as the current threshold SpcBlkPnt •usect "P6", 1 • Pointer i n t o SpeechBlks CALL UpdateThreshold • Update the energy threshold HSpcAvgSum .usect "P6", 1 Running sum of speech energies ... RET LSpcAvgSum .usect "P6", 1 (2 words) ; * HSpcBlkSum .usect "P6", 1 Running sum of speech block energies ... ; ************************************************************************** LSpcBlkSum .usect "P6", 1 (2 words) InitSilenceCompress: SpcEnergy .usect "P6", 1 The current speech frame energy ;* Routine to i n i t i a l i z e constants and variables used i n both the data ; * :* transfer algorithm and the s i l e n c e deletion algorithm. This routine must ;* Define variables for tracking the Silence Avg (Block B l , Page 7) ;* be c a l l e d before the f i r s t speech frame i s obtained. SilAvgs .usect "P7", SILAVGLEN Array f o r s i l e n c e energies . * ESilAvgs .usect "P7", 1 Last entry i n the SilAvgs array ;* Assumes: SIIAvg .usect "P7", 1 The current silence average energy ;* DP - 0 Data page containing the l o c a l variables SilAvgPnt .usect "P7", 1 Pointer i n t o SilAvgs ;* ?SXM Sign extension can be either on or o f f HSilAvgSum .usect "P7", 1 Running sum of s i l e n c e energies ... (. ******** ************** ******** ****** ************ ****** ******** ************ LSilAvgSum .usect "P7", 1 (2 words) ZAC SilEnergy .usect nP7", 1 The current silence frame energy SACL SpeechState Set to 0, not detected speech yet ECrit .usect "P7", 1 Max s i l e n c e avg. update m u l t i p l i e r SACL PrevSample I n i t i a l previous sample - 0 Scale .usect "P7", 1 Energy threshold adaptation scaler LARK SIL.O I n i t i a l consecutive silence frames - 0 SpeechScale .usect "P7", 1 Amount to scale speech for adaptation LARK SPC.O I n i t i a l consecutive speech frames - 0 TempData .usect "P7", 1 Temporary data storage LALK HlghThresh Load the high energy threshold ... ; * SACL Threshold and save as the i n i t i a l current threshold ;************************************************************************** LALK MaxSil Load the maximum silence Interval length ... InitAvgs: SACL MaxSilVar and save as a variable for unsigned calc. ;* This routine w i l l i n i t i a l i z e the long term averages for both the silence RET ;* and the speech i n t e r v a l s . The average arrays are also i n i t i a l i z e d , along . * ;* with the associated pointers. . ************************************************************************** .************************************************************************** .end ;* I n i t i a l i z e speech average variables f i r s t ; ************************************************************************** LDPK SPEECH?AGE Switch to data page with Speech variables ;* I n i t i a l i z e the speech i n t e r v a l average, and associated array. The Adapt.asm :* SpeechAvgs need not be i n i t i a l i z e d as t h i s array i s summed from the s t a r t ;* for each new block. LARP AVG use A V U r e g i s t e r as a pointer . * LRLK AVG,SpeechBlks Point to f i r s t entry i n SpeechBlks array ;* Adapt.asm LALK INITSPCAVG Load the i n i t i a l value f o r SpeechAvg ;* August 14, 1990 RPTK (SPCNUMBLK-1) F i l l complete SpeechBlks array ... ;* Chris Rose SACL *+ with the i n i t i a l value f o r SpeechAvg . * SACL SpeechAvg Save i n i t i a l SpeechAvg ;* This f i l e contains the routines that handle the adaptation of the energy ;* threshold. The routines adapt the threshold based on both the long term ;* I n i t i a l i z e the two variables used i n c a l c u l a t i n g the array suns r* s i g n a l or speech average energy, and the background noise or silence ZALH INITSPCAVG Load InitSpcAvg*SpcNumBlks to accum. :* average energy. SACL LSpcBlkSum Save i n SpcBlkSum . • A * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * SACK HSpcBlkSum . * ZAC Zero the accumulator ... ;* Include defines f i l e SACL LSpcAvgSum and save i n SpcAvgSum .include " s i l r e c . i n c " , * SACH HSpcAvgSum ;* External references ;* I n i t i a l i z e the pointers for the two speech average arrays .def InitAvgs, UpdateSpeechAvg, UpdateSilAvg, UpdateThreshold LRLK AVG, SpeechAvgs I n i t i a l i z e SpeechAvgs pointer .def SilAvg SAR AVG,SpcAvgPnt .ref FmEnergy, Threshold, ThreshMult LRLK AVG,SpeechBlks I n i t i a l i z e SpeechBlks pointer -a oo SAR AVG,SpcBlkFnt PAC ; Place product i n accumulator (012) LRLK AVG, (SpeechAvgs+SPCBLKLEN) ; Evaluate end of SpeechAvgs array SACH TempData,4 ; Save r e s u l t for s h i f t i n g (Q0) SAR AVG,ESpeechAvgs LAC TempData ; Reload integer product LRLK AVG, (SpeechBlks+SPCNUMBLK) ; Evaluate end of SpeechBlks array SUB SilEnergy ; Check i f SilEnergy <- E C r i t "SilAvg ... SAR AVG,ESpeechBlks BLZ EndUpdateSil i f not, do not include t h i s energy ; * Update the s i l e n c e i n t e r v a l average and the associated array using the Now, i n i t i a l i z e silence average variables , * current frame energy. LDPK SILPAGE ; Switch to data page with silence variables LARP AVG ; Use AVG r e g i s t e r as a pointer LAR AVG,SilAvgPnt ; Point to current l o c a t i o n i n SilAvgs array I n i t i a l i z e the silence i n t e r v a l average and associated array ZALS LSilAvgSum ; Load the current array sum to the accum. LARP AVG ; Use AVG register as a pointer ADDH HSilAvgSum LRLK AVG,SilAvgs ; Point to f i r s t entry i n SilAvgs array SUB *, (16-SILAVGSFT) .- Subtract o ld frame energy from current loc. LALK INITSILAVG ; Load the i n i t i a l value for SilAvg ADD SilEnergy,(16-SILAVGSFT) ; Add new frame energy to sum RPTK (SILAVGLEN-1) ; F i l l complete SilAvgs array ... SACH SilAvg ; Save new s i l e n c e energy average (high acc.) SACL *+ ; with the i n i t i a l value for SilAvg SACL LSilAvgSum ,- Save new sum i n SilAvgSum SACL SilAvg : Save i n i t i a l SilAvg SACH HSilAvgSum LAC SilEnergy ; Reload new frame energy ... . * I n i t i a l i z e the variable used i n c a l c u l a t i n g the array sum SACL *+ and save to current array l o c a t i o n ZALH INITSILAVG ; Load InitSilAvg*SilAvgLen to accum. SAR AVG,SilAvgPnt ; Save updated array pointer SACL LSilAvgSum ; Save i n SilAvgSum SACH HSilAvgSum . * Check f o r wrap-around i n the s i l e n c e average array pointer LAR AR0,ESilAvgs ; Load the end-of-array pointer value to ARO . * I n i t i a l i z e the pointers for the silence average array CMPR 1 ; TC-1 i f (ESilAvgs > AVG) i e , not at end yet LRLK AVG,SilAvgs ; I n i t i a l i z e SilAvgs pointer BBNZ SilAvgPntOk ; Branch i f T O l SAR AVG.SilAvgPnt LRLK AVG, SilAvgs ; Wrap-around existed, so reset the array ... LRLK AVG, (SilAvgs+SILAVGLEN) ; Evaluate end of SilAvgs array SAR AVG,SilAvgPnt pointer to the s t a r t of the array SAR AVG.ESilAvgs SilAvgPntOk: B EndUpdateSil ; Update complete so jump to e x i t I n i t i a l i z e the "constant** variables LALK CECRIT ; I n i t i a l i z e the ECrit variable SACL E C r i t , * I n i t i a l i z e SilAvg and the associated array to the value of the silence LALK CSPCSCALE ; I n i t i a l i z e the SpeechScale variable , * i n t e r v a l frame energy. SACL SpeechScale I n i t i a l i z e S i l A v g : ; * I n i t i a l i z e the s i l e n c e i n t e r v a l average and the associated array LDPK REGPAGE ; Switch back to default data page LARP AVG ; Use AVG r e g i s t e r as a pointer RET LRLK AVG,SilAvgs ; Point to f i r s t entry i n SilAvgs array . * LAC SilEnergy ; Load the i n i t i a l value for SilAvg .****************************************************** RPTK (SILAVGLEN-1) ; F i l l complete SilAvgs array ... UpdateSilAvg: SACL *+ with the i n i t i a l value for SilAvg This routine updates the s i l e n c e i n t e r v a l average. The current frame i s SACL SilAvg ,- Save i n i t i a l SilAvg . * known to be silence, and that frames energy i s added to the average ; * c a l c u l a t i o n . ; * I n i t i a l i z e the v a r i a b l e used i n c a l c u l a t i n g the array sum • * Note: Sign extension must be set ZALH SilEnergy ; Load SilEnergy*SilAvgLen to accum. ; ************************************************************************** SACL LSilAvgSum ; Save i n SilAvgSum F i r s t , copy the frame energy into l o c a l data space SACH HSilAvgSum LAC FmEnergy ; Load the current frame energy (page 0) LDPK SILPAGE ; Change to page containing s i l e n c e variables . * I n i t i a l i z e the pointers for the silence average array SACL SilEnergy ; Store frame energy i n l o c a l space LRLK AVG, SilAvgs ; I n i t i a l i z e SilAvgs pointer SAR AVG,SilAvgPnt Check i f the SilAvg array needs to be i n i t i a l i z e d . This i s indicated by LRLK AVG,(SilAvgs+SILAVGLEN) ; Evaluate end of SilAvgs array ; * a negative number i n SilAvg (a flag) . SAR AVG,ESilAvgs LAC SilAvg ; I n i t i a l i z e SilAvgs array i f current ... BLZ I n i t i a l i z e S i l A v g ; SilAvg < 0 EndUpdateSil: • * Include t h i s value of frame energy only i f ENERGY < ECRIT * SILAVG. This LDPK REGPAGE ; Switch back to default data page prevents SilAvg from being distorted by unusually large frame energies. RET LT SilAvg ; Prepare to multiply by SilAvg (Q0) . * MPY E C r i t ; Multiply by ECrit (Q12) UpdateSpeechAvg: * This routine updates the speech i n t e r v a l average energy. The current frame * i s known t o be speech, and that frames energy i s added to the average * c a l c u l a t i o n . * Note: Sign extension must be set ************************************************************************** * F i r s t , copy the frame energy i n t o l o c a l data space LAC FmEnergy ; Load the current frame energy (page 0) LDPK SPEECHPAGE ; change to page containing speech variables SACL SpcEnergy ; Save the frame energy i n l o c a l data space ;* Check i f the SpeechAvg arrays need to be i n i t i a l i z e d . This i s indicated by :* a negative number i n SpeechAvg (a f l a g ) . LAC SpeechAvg ; I n i t i a l i z e SpeechAvgs and SpeechBlks ... BLZ InitializeSpcAvg ; arrays i f current SpeechAvg < 0 r* Update the speech i n t e r v a l energy average and the associated arrays using r * the current frame energy. :* F i r s t , update the current speech i n t e r v a l block average LARP AVG ; Use the AVG register as a pointer LAR AVG,SpcAvgPnt ; Point to the current l o c . i n block avg array ZALS LSpcAvgSum ; Load the current block sum to accum. ADDH HSpcAvgSum ADD SpcEnergy,(16-SPCAVGSFT) ; Add current energy to sum SACH SpcBlkAvg ; Save current block average (high accum) SACL LSpcAvgSum ; Save the updated sum to SpcAvgSum SACH HSpcAvgSum LAC SpcEnergy ; Reload the frame energy t o the accum ... SACL *+ ; and save to current array l o c a t i o n SAR AVG, SpcAvgPnt ; Save the updated speech block array pointer r * Check l f the current speech block average i s complete (end of block) LAR ARO,ESpeechAvgs ; Load the end of array pointer value to ARO CMPR 1 ; TC-1 i f (ESpeechAvgs > AVG) i e , not at end BBNZ SpcAvgPntOk ; Branch i f T O l * Current block i s f u l l , ZAC SACL LSpcAvgSum SACH HSpcAvgSum LALK SpeechAvgs SACL SpcAvgPnt so reset array pointer and array sum ; Zero the accumulator ... and save to SpcAvgSum ; Reset array pointer to s t a r t of the array ;* Now, add the block average to the speech i n t e r v a l energy average LARP AVG ,' Use the AVG reg i s t e r as a pointer LAR AVG,SpcBlkPnt ; Point to the current l o c . i n blocks array ZALS LSpcBlkSum ; Load the current array sum to the accum. ADDH HSpcBlkSum SUB *,(16-SPCBLKSFT) ; Subtract the old block average ... ADD SpcBlkAvg,(16-SPCBLKSFT) ; and add the new one SACH SpeechAvg ; Save the new speech average (high accum) SACL LSpcBlkSum ; Save the updated array sum SACH HSpcBlkSum LAC SpcBlkAvg ; Reload the block average ... SACL *+ and save to the current array location SAR AVG,SpcBlkPnt ,* Save the updated array pointer Check for wrap-around i n the array pointer LAR AR0,ESpeechBlks ; Load the pointer value for array end to ARO CMPR BBNZ LRLK SAR SpcBlkPntOk: SpcAvgPntOk: SpcBlkPntOk AVG,SpeechBlks AVG, SpcBlkPnt EndUpdateSpc TC-1 i f (ESpeechBlks > AVG) i e , not at end Branch i f T O l Wrap-around existed, so reset the ... pointer to the s t a r t of the array Average update i s done, so jump to ex i t ;* I n i t i a l i z e the speech average and the associated arrays to the current ;* frame energy value. InitializeSpcAvg: :* I n i t i a l i z e the speech i n t e r v a l average, and associated array. The .-* SpeechAvgs need not be i n i t i a l i z e d as t h i s array i s summed from the s t a r t ;* for each new block. LARP LRLK LAC RPTK SACL SACL AVG AVG,SpeechBlks SpcEnergy (SPCNUMBLK-1) *+ SpeechAvg Use AVG reg i s t e r as a pointer Point to f i r s t entry i n SpeechBlks array Load the i n i t i a l value for SpeechAvg F i l l complete SpeechBlks array ... with the I n i t i a l value for SpeechAvg Save i n i t i a l SpeechAvg * I n i t i a l i z e the two variables used i n cal c u l a t i n g the array ZALH SpcEnergy ; Load SpcEnergy*SpcNumBlks to accum. SACL LSpcBlkSum ; Save i n SpcBlkSum SACH HSpcBlkSum ZAC .* Zero the accumulator ... SACL LSpcAvgSum ; and save i n SpcAvgSum SACH HSpcAvgSum * I n i t i a l i z e the pointers for the two speech average arrays LRLK AVG,SpeechAvgs ; I n i t i a l i z e SpeechAvgs pointer SAR AVG, SpcAvgPnt LRLK AVG,SpeechBlks ; I n i t i a l i z e SpeechBlks pointer SAR AVG,SpcBlkPnt LRLK AVG, (SpeechAvgs+SPCBLKLEN) SAR AVG, ESpeechAvgs LRLK AVG, (SpeechBlks+SPCNUMBLK) SAR AVG, ESpeechBl ks Evaluate end of SpeechAvgs array Evaluate end of SpeechBlks array EndUpdateSpc: LDPK REGPAGE ; Switch back to default data page RET * ************************************************************************** UpdateThreshold: ;* This routine w i l l update the actual energy threshold based on the current ;* silence i n t e r v a l average energy, the speech i n t e r v a l average energy, and ;* the current energy l e v e l m u l t i p l i e r . • ************************************************************************** ;* F i r s t , check i f the speech i n t e r v a l energy average and the s i l e n c e i n t e r v a l ;* i s v a l i d (a negative number s i g n i f i e s the energy average has not yet been ;* i n i t i a l i z e d ) . LDPK SPEECHPAGE LAC SpeechAvg LDPK SILPAGE BLZ UselnitScale Change to speech variables page ... and load the speech i n t e r v a l energy avg. Change to silence page for l a t e r calcs. Branch i f speech average i s not v a l i d LAC SilAvg • Load the silence in t e r v a l energy avg. ;* Define i n t e r n a l variables used i n the routine (Block B2, page 0) BGEZ SilAvgOk - Branch i f the silence average i s Ok. HighSeed LowSeed .usect "B2", 1 .usect "B2", 1 ;* Here, e i t h e r the speech or silence energy average was i n v a l i d , therefore HighA .usect "B2", 1 ;* use a default threshold scaler. LowA .usect "B2", 1 DselnitScale: HighC .usect "B2", 1 LALK 1NITSCALE * Load the default scaler ... LowC .usect "B2", 1 SACL Scale and save to the scale variable Mult .usect "B2", 1 B CalcThresh Branch to calculate the threshold NoiseVal HighTemp .usect "B2", 1 .usect "B2", 1 ;* Now, calculate the threshold scaler based on the dual adaptive scheme LowTemp .usect "B2", 1 ;* using the long term silence and speech i n t e r v a l energy averages. RanU .usect "B2", 1 SilAvgOk: RanG .usect "B2", 1 LDPK SPEECHPAGE Switch to speech variables ... Scale .usect "B2", 1 ZALS SpeechAvg to reload the speech average ; * LDPK SILPAGE Switch back to silence variables ;************************************************************************** RPTK 15 Do next instruction 16 times ... .text SOBC SpeechScale to divide SpeechAvg by SpeechScale .************************************************************************** SACL TempData Store the temporary r e s u l t InitNoise : LAC SilAvg Load the silence i n t e r v a l energy average ... ;************************************************************************** SUB TempData and compare with scaled speech value ZAC BLZ UseSpeech Use the larger of silence or scaled speech SACL HighSeed UseSilence: SACL LowSeed LAC SilAvg Silence was larger, so save SilAvg ... LALK 03FFh SACL Scale i n the scale variable SACL HighA B CalcThresh Now calculate the actual threshold LALK 944Dh UseSpeech: SACL LowA LAC TempData Scaled speech was larger, so save SilAvg ... LALK 00D8h SACL Scale i n scale variable SACL LALK HighC 658Bh ,-* F i n a l l y , c a l c u late the actual energy threshold, based on the threshold SACL LowC ;* sca l e r calculated above, and the threshold multi p l i e r determined by the LALK 13F81) ;* speech detection algorithm. SACL Scale CalcThresh: RET LT Scale Load the scaler i n preparation for mult. .* LDPK REGPAGE Switch back to default variable page .************************************************************************** HPY ThreshMult Multiply by threshold m u l t i p l i e r (0.12) GetNoise: PAC Load result to accumulator (012) ;************************************************************************** SACH Threshold,4 Save the new energy threshold (QO) CALL GetGauss RET LT Scale ; * MPY RanG ; Scale the RanG value by 1.248 (Q24) ; ************************************************************************** PAC .end SACH RanG,4 ; Save scaled RanG (Q12) ; ************************************************************************** LT RanG MPY PAC Mult ; Multiply noise by desired energy value (Q12) Noise.asm SACH NoiseVal,4 ; Save noise desired noise value (QO) RET . * ;************************************************************************** ;* Noise.asm GetGauss: ;* June 26, 1990 .************************************************************************** ;* Chris Rose LALK OAOOOh ; Load -6 (Q12) to AccL ; * SACL RanG ; And save temporary value ;* This f i l e contains the routines to implement a Gaussian noise generator. LARK AR0,11 : Loop 12 times ; ********************************************************** **************** LARP ARO ; * GaussLoop ;* External References CALL Getuniform ; Get a uniform [0,1] Q12 number .def GetNoise, Mult, NoiseVal, InitNoise ZALS RanG : Load RanG running t o t a l . * ADDS RanU ; Add the current uniform number SACL RanG • Save updated RanG ;* routine (MuLawExp). This routine must be c a l l e d before the f i r s t Mu-law BANZ GaussLoop,*- ;* conversion. RET ; * . * ;* Assumes: ;************************************************************************** .* DP - 0 Data page containing the l o c a l variables GetUniform: ;* ?SXM Sign extension can be either on or o f f ; ************************************************************************** .************************************************************************* LT LowSeed T - XO LACK 33 • Load the Bias constant MPYO LowA T - XO, P - XO * AO SACL Bias • and store i t SPL LowTemp Save NO RET SPH HighTemp Save p a r t i a l Ml ; * MPYO HighA T - XO, P - XO * Al .************************************************************************* LTP HighSeed T - XI, P - XO * A l , ACC - XO * A l MuLawExp: MPYO LowA T - XI, P - XI * AO, ACC - XO * Al ,-* This routine performs the actual Mu-law PCM to l i n e a r PCM conversion. APAC ACC - X0*A1 + X1*A0 ; * ADDS HighTemp ACC - X0*A1 + X1*A0 + X0*A0*2**-16 ;* Assumes: ANDK 03FFh Mask o f f lower 10 b i t s to prevent overflow ; * DP - 0 Data page containing the l o c a l variables SACL HighTemp Save Nl ;* ?SXM Sign extension can be either on or o f f ZALH HighTemp ; * ADDS LowTemp Load NINO to ACC ; * passed: ADDS LowC ;* MuLawVal 8-bit Mu-law value to be converted to a l i n e a r value ADDH HighC Add C to Ace ; * SACL LowSeed ;* Returned: ANDK 3FF0h,12 Mask o f f 10 low b i t s i n AccH ;* LinVal 14-bit l i n e a r value, r i g h t j u s t i f i e d i n a 16-bit word SACH HighSeed And save new Seed . * ADDS LowSeed Restore new seed to accum. ;* Modified: SACH RanU,2 Store Uniform random number i n Q12 format ,-* ARO Used to point to LinVal t MuLawVal variables RET ;* ARP Used to point to ARO ; * .************************************************************************* ; ************************************************************************** LRLK ARO, MuLawVal Load ARO with address of MuLawVal .end LARP ARO use ARO for i n d i r e c t addressing (MuLawVal) ; ************************************************************************** BIT *,8 store sign b i t of MuLawVal i n TC for l a t e r use LAC *,12 load Rx byte i n t o Acc, straddle high & low nib ANDK 7F00h,4 zero sign and other unused b i t s i n acc. XORK 7F00h,4 invert Rx data b i t s uLawExp.asm SACH LinSeg store high acc., the segment SUBH LinSeg zero the high acc. ; * ADD Bias,11 add bias, o f f s e t one b i t ri g h t of Rx low nib. ;* uLawBxp.asm SFL s h i f t acc rig h t 1 b i t (gives 2Q+33) ;* May 16, 1990 SACH Sum, 4 store 20+33 (low 4 b i t s were i n low acc) ;* Chris Rose LT LinSeg load T reg with segment - s h i f t value . * LACT Sum re-load acc, with s h i f t s p e c i f i e d i n T reg :* This f i l e contains the routine to convert 8-bit Mu-law compressed PCM data SUB Bias subtract o f f the bias ;* to 14-b i t l i n e a r PCM data. BBNZ PosVal branch i f o r i g i n a l number p o s i t i v e (TOl) ;************************************************************************** NEG 2's complement negate to make negative ; * PosVal: :* External references LRLK ARO,LinVal point t o LinVal .def MuLawExp, InitMuLawExp SACL *,0,AR0 store converted value to LinVal v a r i a b l e .ref . * LinVal, MuLawVal RET and return ;* Define i n t e r n a l variables used i n the routine (Block B2, page 0) ;************************************************************************* Bias usect "B2", 1 Bias of 33 used i n conversion .end LinSeg . usect "B2", 1 Segment of l i n e a r i z a t i o n .************************************************************************* Sum . * usect "B2", 1 Intermediate storage for conversion . ************************************************************************* . text ;************************************************************************* InitMuLawExp: ;* This routine i n i t i a l i z e s the constant used i n the Mu-law expansion uLawComp.asm :* uLawComp.asm * May 16, 1990 •* Chris Rose : * •* This f i l e contains the routine to convert 14-bit l i n e a r PCM data to 8-bit •* Mu-law compressed data. .************************************************************************** . * * External references .def MuLawComp, InitMuLawComp .ref LinVal, MuLawVal > * * Define i n t e r n a l variables used i n the routine (Block B2, page 0) Bias2 .usect "B2", 1 ; Bias of 33 l e f t s h i f t e d 2 b i t s Neg7 .usect "B2", 1 ; Storage for -7 constant LinSeg .usect "B2n, 1 : Segment of l i n e a r i z a t i o n Quant .usect "B2", 1 ; Quantization bin . * ;************************************************************************* InitMuLawComp: ;* This routine i n i t i a l i z e s the constants used i n the Mu-law compression ; * routine (MuLawComp). This routine must be ca l l e d before the f i r s t Mu-law ;* conversion. Data page containing the l o c a l variables Sign extension can be either on or off * Assumes: * DP - 0 * ?SXM . ************************************************************************* LACK 132 ; load bias constant, 33 l e f t shifted 2 b i t s SACL Bias2 ; and store to bias variable ZAC SUBK 7 ; Load -7 to the accumulator SACL Neg7 ; and store i t RET ; and return to c a l l i n g routine * ************************************************************************** MuLawComp: * This routine performs the actual l i n e a r PCM to Mu-law PCM conversion. * Assumes: * DP - 0 * SSXM * * Passed: * LinVal Data page containing the l o c a l variables Sign extension mode must be on for -ve 16-bit values 14-bit, right j u s t i f i e d , sign-extended l i n e a r value * Returned: * MuLawVal 8-bit Mu-law representation of LinVal * Modified: * ARO Used to normalize exponents, and point to LinVal s MuLawVal * ARP Used to point to ARO ************************************************************************** LRLK ARO, LinVal LARP ARO LAC *, 2 make ARO point to LinVal for addressing use ARO for i n d i r e c t addressing (LinVal) Left j u s t i f y linear value i n t o low accum. SACL Quant ; Store l e f t j u s t i f i e d value to temp, l o c a t i o n ZALH Quant and restore i n high accumulator ; * BLZ NegCompute ; Test f o r negative number (Separate calc.) . * . * Here, a p o s i t i v e value i s being converted ADDH Bias2 ; add bias to l e f t j u s t i f i e d number LAR AR0,Neg7 ; load -7 t o ARO (already pointed to) RPTK 6 ; repeat NORM 7 times NORM *+ ; S h i f t 1 i n t o b i t 30 of acc. store s h i f t i n ARO ANDK OFOOOh, 14 ; zero a l l b i t 4 Q b i t s (2 MSB's and a l l LSB's) SACH Quant ; and store Q b i t s SAR ARO,LinSeg ; store negative segment count ZALH LinSeg ; and restore to high accumulator ABS ; convert t o p o s i t i v e value ADD Quant, 2 ; add Q b i t s , l e f t s h i f t e d 2 to MSB's of low acc XORK OFFOOh,4 ; in v e r t a l l 8 b i t s t o transmit B Compressed ; and jump to store converted word NegCompute: . • . * . * Here a negative value i s being converted ABS ,- negative number; convert to p o s i t i v e ADDH Bias2 ; add b i a s to l e f t j u s t i f i e d number LAR ARO,Neg7 ; load -7 t o ARO (already pointed to) RPTK 6 ; repeat NORM 7 times NORM *+ ; S h i f t 1 i n t o b i t 30 of acc. store s h i f t i n ARO ANDK OFOOOh, 14 ; zero a l l b i t 4 Q b i t s (2 MSB's and a l l LSB's) SACH Quant ; and store Q b i t s SAR ARO,LinSeg ; store negative segment count ZALH LinSeg ; and restore t o high accumulator ABS ; convert t o p o s i t i v e value ADD Quant, 2 ; add Q b i t s , l e f t s h i f t e d 2 to MSB's of low acc XORK 7F00h,4 ; invert 7 magnitude b i t s ; sign b i t - 0 Compressed: ;* Store the converted number t o the MuLawVal varia b l e ; * LRLK ARO,MuLawVal ; point ARO to MuLawVal SACH *,4 ; write converted number to MuLawVal storage RET . * ;************************************************************************** .end ;************************************************************************** Rxlntrpt.asm * Rxlntrpt.asm * May 1, 1990 * Chris Rose * * This f i l e contains the interupt handling routines to receive Mu-law data * from the s e r i a l port, and 'pack' i t into words i n external data memory. ************************************************************************** * * Include defines f i l e co Co .include " s i l r e c . i n c " ;* External references .def Receive, Unused, SamplePos, MuLawVal, LinVal .ref CheckOverflow, MuLawExp ;* Define external data variables (Block B2) SamplePos .usect "B2", 1 ; Signals p o s i t i o n i n word to save next sample MuLawVal .usect "B2", 1 : MuLaw version of the current sample LinVal .usect "B2", 1 ; Linear version of the current sample . * . ************************************************************************** .text ;************************************************************************** Receive: * S e r i a l port receive interupt handler. * This routine receives data from the s e r i a l port, packs i t into words, * and stores i t i n external memory. Assumes: DP - 0 ?SXM Returns: MuLawVal LinVal Data page containing the l o c a l variables Sign extension can be either on or o f f 8-bit received Mu-law data sample 14-bit (right just) version of the received value * Modified: * ARP Used to point to CDP and IMP auxilary registers **************************************************** * * Load the received 8-bit data . * LAC DRR ; Load the received data ANDK OOFFh : Mask o f f the low 8 b i t s SACL MuLawVal ; And save the Mu-law value CALL . * MuLawExp ; Convert Mu-law data t o li n e a r i n LinVal ;* Now save . * the 8-bit data to external memory LARP TMP ; Make TMP r e g i s t e r active LAR IMP,SamplePos ; Load H/L byte f l a g (1/0) to TMP BANZ RxHighByte, *+, CDP ; Branch i f Flag-1; Make data pointer active RxLowByte: SAR TMP,SamplePos ; Store the f l a g - 1 (Next sample high byte) LAC MuLawVal ; Load the received data into the accumulator SACL * : Store the low byte at the current location B RxEndSave RxHighByte: LARK TMP,0 ; Set TMP r e g i s t e r to 0 so w i l l reset f l a g SAR TMP,SamplePos ; Store the f l a g - 0 (Next sample low byte) LAC MuLawVal, 8 .- Load data t o high b i t s of low accum. OR * ; Add low b i t s from previous sample SACL * ; Store data word at current data location LAC *+ ; Reload the packed data word CALL CheckOverflow SBLK SilCodeWord ; Check i f current word - code word BNZ RxEndSave ; Branch i f not equal SACL *+ ; Store OOOOh i n next location CALL CheckOverflow RxEndSave: RET ; * • ************************************************************************** UnUsed: ,-* Default interupt handler for unused handlers (should not get called) .************************************************************************** EINT ; simply re-enable interupts, RET ; and return to previous task. ; * . ************************************************************************** .end . ************************************************************************** Txlntrpt.asm ;* Txlntrpt.asm ;* May 15, 1990 ;* Chris Rose . * ;* This f i l e contains the routine to extract the Mu-law data from external ;* data memory, and transmit i t through the s e r i a l port. This f i l e also ;* contains the interupt handlers. .************************************************************************** f. * ;* Include defines f i l e .include " s i l r e c . i n c " . • ;* External references .def Transmit, UnUsed, DataTransmit, SamplePos, MuLawVal .ref CheckOverflow, UpdateNDP . * ;* Define data variables SamplePos .usect "B2", 1 ; Signals p o s i t i o n i n word to save next sample MuLawVal .usect "B2", 1 ; 8-bit Mu-law version of the current sample . * ;************************************************************************** .text .************************************************************************** DataTransmit: * This routine extracts Mu-law PCM data from the current data location, and * transmits i t through the s e r i a l port. * * Assumes: * DP - 0 Data page containing the l o c a l variables * ?SXM Sign extension can be either on or o f f * * Returns: * MuLawVal 8-bit Mu-law version of current data sample * * Modified: * ARP Used to point to CDP and TMP auxilary registers ************************************************************************** * * Get 8-bit Mu-law data from external memory * LARP TMP ; Make TMP re g i s t e r active LAR TMP,SamplePos ; Load H/L byte f l a g (1/0) to TMP BANZ TxHighByte,*+,CDP ; Branch i f Flag-1; Make data pointer active TxLowByte: SAR TMP,SamplePos ; Store the f l a g - 1 (Next sample high byte) LAC * ,- Load new data value, do not a l t e r pointer ANDK OOFPh ,- Mask off low 6 b i t s SACL MuLawVal ; Store low 8 b i t s to MuLawVal B TxEndGet TxHighByte: LARK TMP.O .- Set TMP register to 0 so w i l l reset f l a g SAR TMP,SamplePos ; Store the f l a g - 0 (Next sample low byte) LAC *+,8 ; Get high byte (inc point) i n high accum ANDK 0FF0h,12 ; Mask off low 8 b i t s of high accumulator SACH MuLawVal ; Store high 8 b i t s to MuLawVal CALL CheckOverflow TxEndGet: ;* Now transmit the data LAC MuLawVal ; Load the current MuLaw sample SACL DXR ; Save sample to transmit register IDLE ; Wait for interupt (ie, data to be transmit) CALL UpdateNDP ,- update NDP to current position, o/p block t RET , ****** ******************************************************************** Transmit: ;* Actual transmit interupt handler. ;* This i s c a l l e d a f t e r the s e r i a l port has transmitted the previous data :* so simply return. ;* ;* Assumes: ;* Nothing . ************************************************************************** RET ; * . ************************************************************************** UnDsed: ;* Default interupt handler for unused interupts (should not get called) . * ;* Assumes: ;* Nothing . ************************************************************************** EINT ; Simply re-enable interupts RET ; and return . * ; ************************************************************************** .end . ************************************************************************** U t i l i t y . a s m :* U t i l i t y . a s m ;* May 16, 1990 ;* Chris Rose * This f i l e contains general purpose routines to maintain data transfer * to/from the PC host, to i n i t i a l i z e the Tms320, and to handle the silence * i n t e r v a l codes. ************************************************************************** * Include defines f i l e .include " s i l r e c . i n c " ; * ;* External references .def writeSilCode, WriteEndCode, OutputBlockNum, CheckOverflow .def CheckSilCode, InitTms320, InitDataTransfer, UpdateNDP, ResetCDP .ref SamplePos, SIIAvg ; * ;* Define i n t e r n a l variables usedby these procedures (Block B2, page 0) TempData .usect "B2", 1 ; General scratch variable DataMemSrt .usect "B2", 1 ; Offset of s t a r t of data memory DataMemEnd .usect "B2", 1 ; Last word of external data memory . * . ************************************************************************** .text > ************************************************************************** NriteSilCode: This routine w i l l write a si l e n c e i n t e r v a l code to the output data memory. It writes the silence code word, followed by the silence i n t e r v a l length. Assumes: DP - 0 ?SXM Modified: ARP Data page containing the l o c a l variables Sign extension can be e i t h e r on or o f f Used to point t o the CDP i n d i r e c t addressing r e g i s t e r ************************************************************************** LARP LALK SACL CALL SAR CALL LDPK LAC LDPK SACL CALL RET CDP SilCodeWord *+ CheckOverflow SIL,*+ CheckOverflow SILPAGE SilAvg REGPAGE *+ CheckOverflow Make the current data pointer active Load the s i l e n c e codeword ... and store t o memory Check for end of data memory write the i n t e r v a l length t o memory Check for end of data memory ;************************************************************************** WriteEndCode: This routine w i l l write the 'End of Data' code to the output data memory. I t writes the si l e n c e code, followed by the ' F i l e End' code, and then updates the NDP and outputs the f i n a l block number. Assumes: DP - 0 ?SXM Data page containing the l o c a l variables Sign extension can be e i t h e r on or o f f * Modified: * ARP Used to point t o the CDP i n d i r e c t addressing r e g i s t e r ************************************************************************** LARP LALK SACL CDP SilCodeWord *+ Make the current data pointer active Load the s i l e n c e codeword ... and store t o memory CALL LALK SACL SAR LAR CALL RET CheckOver flow EndCodeWord * CDP .TempData NDP,TempData OutputBlockNum Check for end of data memory Load the end of data code . . . and s tore to memory; d o n ' t i n c mem l o c . Save the current data pointer . . . t o update the new data pointer Output the f i n a l block number to the PC .************************************************************************** OutputBlockNum: : * Routine to output to the PC, through the CommLatch, the current block ; * number b e i n g used. The current block number i s based on the New Data ; * Pointer (NDP). This routine i s 'hard-coded' f o r 4 data b l o c k s , each of ; * which i s 2048 bytes long . . * ; * Assumes: ; * DP - 0 Data page containing the l o c a l v a r i a b l e s ; * ?SXM s i g n extension can be e i t h e r on or o f f *************************************************************************** SAR LAC ANDK SACH OUT RET NDP,TempData TempData,6 0C00h,6 TempData TempData, CommLatch Store new data pointer to xfer to accum. Load data l o c . so b l o c k num i n high accum. Mask o f f only block number b i t s i n accum. Save current block number . . . f o r output to PC ; ************************************************************************** CheckOver f low: * Routine to check i f the data pointer has gone passed the end of data * memory. I f i t has, i t i s reset to the s t a r t of data memory. * Assumes: * DP - 0 Data page containing the l o c a l v a r i a b l e s * ARP -> CDP The CDP r e g i s t e r must be ac t ive (remains active) * ?SXM Sign extension can be e i t h e r on or o f f * * M o d i f i e d : * TMP The TMP r e g i s t e r i s used and a l t e r e d i n t h i s routine * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * LAR TMP,DataMemEnd ; Load l a s t data address to ARO CMPR 2 ; Check i f CDP > DataMemEnd (overflow) BB2 CheckOverMemOk ; Branch i f pointer s t i l l w i t h i n memory LAR CDP,DataMemSrt ; Reset pointer to s t a r t of memory CheckOverMemOk: RET > * ************************************************************************** CheckSilCode: Routine to check i f a s i l e n c e code i s i n the data memory, s t a r t i n g at the current data l o c a t i o n . I f a s i l e n c e code i s found, CDP i s l e f t p o i n t i n g at the ' r u n - l e n g t h ' code, and the carry f l a g i s se t ; otherwise CDP i s l e f t p o i n t i n g t o the next data word, and the carry f l a g i s reset . Assumes: DP - 0 ?SXM Returns: Carry Data page containing l o c a l v a r i a b l e s Sign extension can be on or o f f F l a g set i f a code i s found, otherwise the f l a g i s reset * M o d i f i e d : * ARP Used to point to CDP i n d i r e c t addressing r e g i s t e r ************************************************************************** CDP,TempData CDP *+ SilCodeWord CheckNotCode CheckOverflow * CodelnData SilCodeWord SAR LARP LAC SBLK BNZ CALL LAC BZ SC RET CodelnData LALK SACL * RC RET CheckNotCode: LAR CDP,TempData RC RET Store CDP i n case needs r e s t o r i n g Make data pointer a c t i v e Load next data word. Compare with code-word Branch i f not a codeword Load run-length code Not a codeword i f - OOOOh Set carry f l a g , i t i s a code Return with CDP p o i n t i n g to s i l e n c e length Load the SilCode data (was followed by 0000) Overwrite 0000 with the o r i g i n a l data Reset carry f l a g to s i g n a l 'Not a Code' Restore data pointer ( i t i s data) Reset carry f l a g to s i g n a l 'Not a Code' ************************************************************************** UpdateNDP: * This rout ine w i l l update the new data p o i n t e r (NDP) to the current data * l o c a t i o n (CDP), and then output the new current block number to the PC. * * Assumes: * DP - 0 Data page containing l o c a l v a r i a b l e s * ?SXM Sign extension can be e i t h e r on or o f f ************************************************************************** SAR LAR CALL RET CDP,TempData NDP,TempData OutputBlockNum ************************************************************************** ResetCDP: ; * This rout ine w i l l reset the current data l o c a t i o n (CDP) back to the s t a r t ; * of the new data (NDP) i n preparation to overwrite un-needed data . ;* ; * Assumes: ; * DP - 0 Data page containing l o c a l v a r i a b l e s ; * ?SXM Sign extension can be e i t h e r on or o f f .************************************************************************** SAR NDP,TempData LAR CDP,TempData RET . 4 .************************************************************************** InitTms320: ; * Routine to set the configurat ion of the TMS processor, and s e r i a l port ; * by s e t t i n g the appropriate status b i t s . . * ; * Assumes: ; * Nothing .************************************************************************** * Set conf igurat ion for the s e r i a l port ; * FORT 1 • Configure s e r i a l port for 8-bit data SFSH - Require frame synch pulse for each byte RTXM • Start s e r i a l t r a n s i t on external FSX pulse LALK OOFFh SACL DXR • 'zero' the s e r i a l port transmit register ZAC zero the accumulator SACL DRR • and the s e r i a l port receive register . * Set IMS processor configuration CNFD configure mem-block BO as data SOVM Set overflow mode SSXM Turn on sign extension for -ve 16 b i t values SPM 0 Set P-register output s h i f t to 'no-shift' SHN Set hold mode (Hold halts e n t i r e TMS) LDPK 0 Use data page 0 for registers and B2 data • * RXF Reset XF (Setting XF signals finished) ; * ; * Set Interupt mask LALK IntrptMask load mask in t o accumulator SACL IMR and store to the mask reg i s t e r • * RET (. ************************** ** ****************** **************************** InitDataTrans f e r : ; * Routine to i n i t i a l i z e the constants and variable used i n transferring . * . * data between the PC host and the TMS320. ; * Assumes ; * DP - 0 Data page containing l o c a l variables ; * ?SXM Sign extension can be either on or o f f • *******************************< ******************************************* LALK Dataoffset Load data o f f s e t to accumulator ... SACL DataHemSrt and i n i t i a l i z e data memory st a r t constant ADLK (DataMemSize - 1) Find the l a s t available data word ... SACL DataMemEnd and i n i t i a l i z e data memory end constant LAR CDP, DataMemSrt Set data pointer to s t a r t of data memory LAR NDP, DataMemSrt Set new data pointer to s t a r t of memory CALL OutputBlockNum Output the i n i t i a l block number to the PC ZAC SACL SamplePos Set to 0, next sample i s f i r s t i n new word . * RET ; ************************************************************************** .end ; ************************************************************************** This f i l e contains the routines to implement conversion between li n e a r speech samples, and 4-bit ADPCM coded speech samples. AdpcmCom.asm ;* AdpcmCom.asm ;* May 3, 1990 :* Chris Rose . * ;* Routine to perform 32Kbps ADPCM encoding. The algorithm used i s modelled ••* a f t e r the CCITT standard, but i s not i d e n t i c a l l y b i t compatible. The ;* algorithm i s taken from "32-kbit/s ADPCM with the TMS32010", an application ;* note from Texas Instruments. The o r i g i n a l source code was modified s l i g h t l y ;* to be incorporated into the silence compression program. . * ;* Number formats: : * nb - number i s stored i n n b i t s :* Qn - there are n decimal b i t s ;* TC - two's compliment notation ;* POS - unsigned notation . ************************************************************************** . * ;* External references .ref LinVal, AdpcmVal .def AdpcmComp, ResetAdpcmComp, initAdpcmComp ;* Local constants AdpcraPage .set 4 A dp cm variables are on page 4 . ********** ****** it*** ************************ ******** .text . ************************************************************************** AdpcmComp: * This routine converts the input 14-bit l i n e a r PCM value into a 4-bit * Adpcm value. * Assumes: * DP - 0 * SSXM * * Passed: * LinVal * * Returned: * AdpcmVal Data page containing the interface variables Sign extension mode must be on 14-bit linear value to be compressed (right-just) 4-bit Adpcm value (right-just) * Modified: * ARP Used to point to the ARO temporary register * * F i r s t , load the l i n e a r value to the l o c a l data space LAC LinVal LDPK AdpcraPage SACL Sample ; Load the l i n e a r value ; change to Adpcm variables ; Store the l i n e a r sample i n a l o c a l variable ************************************************************************** SigDif: ;* Compute the p a r t i a l signal estimate (Sez), the f u l l s i g n a l estimate (Se), ;* and the quantizer scale factor (¥) from the previous sample's data. Then ;* compute the difference s i g n a l (D). .************************************************************************** . * ;* Compute Sez, the p a r t i a l s i g n a l estimate as: :* Sez(k) - Bl(k-l)*Dq(k-l) + ... + B6(k-l)*Dq(k-6) .-* Note: B i (16b TC Q14), Dqi (16b TC QO), Sez (16b TC QO) ZAC Zero accumulator to s t a r t c a l c u l a t i o n LT Dq5 Step through parameters, multiplying and MPY B6 accumulating i n reverse order. S h i f t LTD Dq4 Dqi's up 1 loc a t i o n aft e r m u l t i p l i c a t i o n MPY BS i n preparation for c a l c u l a t i o n on next LTD Dq3 sample. MPY B4 LTD Dq2 MPY B3 LTD Dql MPY B2 LTD Dq MPY Bl APAC Get Q14 r e s u l t i n 32 b i t accumulator SACH Sez, 2 Save as QO * Now compute Se, the f u l l s i g n a l estimate as: * Se(k) - A l ( k - l ) * S r ( k - l ) + A2(k-l)*Sr(k-2) + Sez(k) * Note: A i (16b TC Q14), S r i (16b TC QO), Se (16b TC QO) * LAC Sez,14 ; Load Sez as Q14 i n accumulator LT S r i ; Add components from A l and A2, and s h i f t MPY A2 : Sr i n t o S r i for c a l c u l a t i o n on next LTD Sr ; sample. MPY A l APAC ; Get Q14 r e s u l t i n accumulator SACH Se,2 ; Save as QO * * Calculate the l i m i t e d speed control parameter (Al) from the previous * unlimited speed control parameter (Ap). Al - 1 (64) i f Ap > 1 (256) ;* A l - Ap i f Ap <- 1 ;* Note: A l (7b POS Q6), Ap (10b POS Q8) LAC One, 6 SACL A l ; Store 1 (06) i n A l LAC Ap SUB One, 8 ; Check i f Ap > 1 (Q8) BGEZ GoodAl ; Ap > 1, so keep 1 i n A l LAC Ap,14 ; Ap <- 1, so load i n Q6 form SACH A l ; Save modified A l GoodAl: . * ;* Now compute Y, the adaptive quantizer scale factor as: ;* Y(k) - [1 - A l ( k ) ] * Y l ( k - l ) + Al(k)*Yu(k-l) ;* - Al(k)*[Yu(k-l) - Y l ( k - l ) ] + Y l ( k - l ) ;* Note: A l (7b POS Q6), Y l (19b POS Q15), Yu (13b POS Q9), Y (13b POS Q9) ;* Y l has both a low (Yll) and high (Ylh) word. . * LAC Yll,10 ; F i r s t convert Y l to (13b POS Q9) by SACH Temp3 dropping le a s t s i g n i f i c a n t 6 b i t s ExpO: LARK 0,0 ; exp - 0 LAC Temp3 and right j u s t i f y i n g r e s u l t . LAC Tempi, 7 AND M1023 ; Mask o f f 10 b i t s of Y l l (for sign extension) B GetMan ADD Ylh,10 Expl: LARK 0,1 ; exp - 1 SACL Temp3 ; Store (13b POS Q9) value of Y l i n Temp3 LAC Tempi,6 LAC Yu B GetMan SUB Temp3 .- Get Yu - Yl i n accumulator C2To3: SUB One,2 .• D - 8, exp - 2 -3 SACL Temp3 ; Store (13b POS Q9) value of Yu - Yl BGEZ Exp3 ZALH Ylh ; Load (19b POS Q1S) value of Y l to accum Exp2: LARK 0,2 ; exp - 2 ADDS Y l l LAC Tempi,5 LT A l ; Multiply Al*(Yu - Y l ) , r e s u l t i s Q15 B GetMan MPY Temp3 Exp3: LARK 0,3 ; exp - 3 APAC ; Add to Q15 Y l i n accum (accum - Y i n Q15) LAC Tempi,4 SACL Temp3 ; Now, convert Y to (13b POS Q9) B GetMan SACH Temp2 C4T07: SUB Three,4 ; D - 64, exp - 4-7 LAC Temp3,10 ,- Drop 6 b i t s o f f of low word of Y BGEZ C6To7 SACH Temp3 C4To5: ADD One, 5 : D - 32, exp - 4-•5 LAC Temp3 ; Right j u s t i f y i n accumulator BGEZ Exp 5 AND M1023 ; Mask 10 desired b i t s (remove sign extension) Exp4: LARK 0,4 ; exp - 4 ADD Temp2,10 ; Add top portion of Y LAC Tempi,3 AND M8191 ; Mask 13 desired b i t s of r e s u l t B GetMan SACL Y ; Save (13b POS Q9) re s u l t i n Y Exp 5: LARK 0,5 ; exp - 5 LAC Y,14 LAC Tempi,2 SACH Temp3 ; Save ( l i b POS Q7) version of Y i n Temp3 B GetMan ; * C6To7: SUB One, 6 : D - 128, exp - 6-7 ;* Now compute D, the difference signal as: BGEZ Exp7 ;* D(k) - Sl(k) - Se(k), where Sl(k) i s l i n e a r version of input sample Exp 6: LARK 0,6 ; exp - 6 ;* Note: A l l D, SI, and Se are (16b TC Q0) LAC Tempi,1 . * B GetMan LAC Sample ; Load the current l i n e a r sample Exp7: LARK 0,7 ; exp - 7 SUB Se : Subtract signal estimate LAC Tempi SACL D Store difference signal B GetMan ; * C8Tol4: SUB M15.8 ; D - 4096, exp - 8-14 . ************** ********************** ************************************** BGEZ C12T014 Aquan: CSToll: ADD Three,10 ; D - 1024, exp - 8-11 ;* Adaptive quantization section. From the previously computed difference BGEZ ClOToll ;* signal (D), and adaptive quantizer scale factor (Y), compute the 4-bit C8To9: ADD One,9 : D - 512, exp - 8-9 ;* quantized difference signal (I). BGEZ Exp9 .************************************************************************** Exp8: LARK 0,8 ; exp - 8 , * LAC Tempi,15 :* F i r s t get the log base 2 of the difference s i g n a l . This can be s i m p l i f i e d SACH Tempi ;* by using the approximation that log2(l + x) - x for small x. Therefore, LAC Tempi ;* determine the number of s h i f t s required u n t i l D - 1.x (the exponent), and B GetMan ,-* then store x i n a Q7 format. with the 4 b i t s of exponent above the Exp9: LARK 0,9 ; exp - 9 ;* 'mantissa'. LAC Tempi,14 SACH Tempi ABS ; Convert to p o s i t i v e value for log LAC Tempi SACL Tempi ; Store difference i n Tempi B GetMan . * ClOToll: SUB One,10 ; D - 2048, exp - 10-11 ;* Now, do binary search for left-most 1 to get exponent. Store exponent i n BGEZ Ex p l l ;* ARO, and load accumulator with D i n Q7 format. ExplO: LARK 0,10 ; exp - 10 . * LAC Tempi,13 Get Exp: SUB One,8 BGEZ C8Tol4 ; D - 256, exp - 0-14 SACH LAC Tempi Tempi C0To7: ADD H15,4 BGEZ C4T07 ; D - 16, exp - 0-7 E x p l l : B LARK GetMan 0,11 ; exp - 11 C0To3: ADD Three,2 BGEZ C2To3 ; D - 4, exp - 0-3 LAC SACH Tempi,12 Tempi COTol: ADD One, 1 BGEZ Expl .- D - 2, exp - 0-1 LAC B Tempi GetMan oo SOB B6EZ Three,12 Expl4 ; D - 16384, exp - 12-14 ADD One,13 ; D - 8192, exp - 13-14 B6EZ Expl3 LARK 0,12 ; exp - 12 LAC Tempi,11 SACH Tempi LAC Tempi B GetMan LARK 0,13 ; exp - 13 LAC Tempi,10 SACH Tempi LAC Tempi B GetMan LARK 0,14 ; exp - 14 LAC Tempi,9 SACH Tempi LAC Tempi C12T014: C12Tol3: Expl2: Expl3: Expl4: * Now, ARO contains the exponent, and accumulator has the Q7 mantissa * Store Log2(D) as 0000 0EEE EMMM MMMM (Q7). GetMan: AND M127 SAR 0,Tempi ADD Tempi,7 Mask o f f 7 b i t s (07) (remove leading 1) Store the exponent ... and add as integer part above 0.7 decimal * Now, subtract the scale factor from log2(D). An of f s e t i s added to avoid * negative numbers. ADD SOB AND one,11 Temp3 M4095 ; Add of f s e t , 2048 i s now 0 ; Temp3 has Y i n ( l i b POS 07) format ; Mask off low 12 b i t s Now, quantize the scaled difference signal with a 4 b i t quantizer. The table values are as follows (12b Q7): (note that 2048 - 0) ; * I - 0 acc < 2041 acc < -0.055 ; * I - l 2041 <- acc < 2171 -0.055 <- acc < 0.961 ; * 1 - 2 2171 <- acc < 2250 0.961 <- acc < 1.578 .. * 1 - 3 2250 <- acc < 2309 1.578 <- acc < 2.039 . * 1 - 4 2309 <- acc < 2358 2.039 <- acc < 2.422 1 - 5 2358 <- acc < 2404 2.422 <- acc < 2.781 . * 1 - 6 2404 <- acc < 2453 2.781 <- acc < 3.164 . * 1 - 7 2453 <- acc 3.164 <- acc ;* Do binary search for table . * entry SOB K2309 ; acc 2309, I - 0--7 BGEZ CI4T07 CI0To3: ADD K138 : acc - 2171, I - 0-•3 BGEZ CI2T03 ClOTol: ADD K130 ; acc - 2041, I - 0--1 BGEZ Ieql IeqO LACK 0 ; I - 0 B HavelMag Ie q l : LACK 1 ; I - 1 B HavelMag Cl2To3: SOB K79 : acc - 2250, I - 2-•3 BGEZ Ieq3 Ieq2: LACK 2 ; I - 2 B HavelMag Ieq3: LACK 3 ; I - 3 B HavelMag CI4To7: SOB K95 ; acc -BGEZ CI6T07 CI5T06: ADD K46 ; acc -BGEZ Ieq5 Ieq4: LACK 4 ; I - 4 B HavelMag Ieq5: LACK 5 ; I - 5 B HavelMag CI6To7: SUB K49 ; acc -BGEZ Ieq7 Ieq6: LACK 6 ; I - 6 B HavelMag Ieq7: LACK 7 ; I - 7 HavelMag: I - 4-7 I - 5-6 6-7 * Accumulator now holds the magnitude of the quantized difference I SACL SACL LAC LAC XOR SACL HaveADPCM: LAC LDPK SACL LDPK IM I D HaveADPCM IM Ml 5 I I 0 AdpcmVal AdpcmPage Save the quantized difference magnitude Save as quantized difference Load the l i n e a r difference I i s ok i f D >- 0 Need to i n v e r t b i t s of IM i f D < 0 Invert only lower 4 b i t s (the rest are 0) Save the inverted quantized difference Load the quantized Adpcm value Access page 0 values Store the returned Adpcm value Switch back to Adpcm variables IAquan: ;* Inverse adaptive quantizer section. From the quantized difference s i g n a l ;* (I) and the scale factor (Y), compute the reconstructed difference ;* signal (Dq). .ft*****************************************^  (. * ;* F i r s t , convert quantized d i f f e r e n c e magnitude to Log domain LAC IM ADD InvQTableOffset TBLR Tempi . * ;* Add back the scale factor (. * LAC Tempi ADD Temp3 AND M2047 SACL Temp2 Load the magnitude Add o f f s e t of inverse quantization t a b l e Read table value into Tempi (07) Move [log2(Dq) - Y) value t o accumulator Add ( l i b POS Q7) version of Y Mask lower 11 b i t s of r e s u l t Save log2(Dq) to Temp2 * Now compute Dq from log2(Dq). log2(Dq) i s 0000 0EEE EMMM MMM (07) * Dq i s (16b TC Q0) * Required s h i f t s are: * Exp 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 * S h i f t 09 10 11 12 13 14 15 00 01 02 03 04 05 06 07 * Where the result i s i n AccH for Exp - 0-6, and i n AccL for Exp - 7-14 * (Right s h i f t for Exp - 0-6, Left s h i f t for Exp - 7-14) . * LAC K544 ,- Load lower threshold, as i t was below LAC Temp2,9 ; Load exponent into high accumulator ... B StoreYu ; Branch to store lower l i m i t SACH Tempi and store i n Tempi CheckHi: LACK 127 ; Load mask for lower 7 b i t s ... SUB K4576 ; acc - 5120, check upper threshold AND Temp2 and mask lower 7 b i t s (mantissa) BLEZ GoodYu ; Branch i f within l i m i t s ADD One, 7 •• Add 1 (Q7) to get 1+x LAC K5120 ; Load upper threshold, as i t was above SACL Temp2 ; Store mantissa StoreYu: LT Temp2 : Prepare to s h i f t SACL Yu ; Store the modified Yu LAC Tempi ; Read s h i f t m u l t i p l i e r corresponding to ... GoodYu: ADD Shi ftTableOffset the exponent from a table ; * TBLR Temp3 ; * Update the slow scale factor as: MPY Temp3 ; Multiply by s h i f t constant . * Yl(k) - (1 - 2**-6)*Yl(k-l) + (2**-6)*Yu(k) PAC . * Note: Yu i s (13b POS Q9), Yl i s (19b POS Q15) BLZ L e f t S h i f t Branch i f l e f t s h i f t was required . * SACH Dq,l ; Right s h i f t 1 more, store i n Dq (mag) ZALH Ylh B AddSign ,- Branch to add sign ADDS Y l l ; Load Yl to accumulator L e f t S h i f t : RPTK 5 ABS ; Convert to positive value SFL ; S h i f t Y l l e f t 6 b i t s (Q21) SACL Dq ; Save result i n Dq (mag) SUBH Ylh AddSign: SUBS Y l l ; Subtract (2**-6)*Yl (Q21) LAC One,11 ADD Yu,6 ; Add (2**-6)*Yu (Q21) SACL SDq ; Save +1 (Qll) as Sgn(Dq) RPTK 5 LAC 1 ; Check sign of I (4th bit) SFR ; S h i f t Y l r i g h t 6 b i t s (Q15) SUB One,3 SACL Y l l BLZ HaveDq ,- Branch i f I +ve, SDq and Dq are correct SACH Ylh : Save modified Y l ZAC LACK 7 ; Mask 3 lower b i t s of Ylh SUB Dq ; Negate Dq, I i s -ve AND Ylh SACL Dq ,* Store modified Dq SACL Ylh LAC Minus,11 ; * SACL SDq ; Save -1 (Qll) as Sgn(Dq) ;************************************************************************** HaveDq: SpeedControl: • * • * Adaptation speed control section. Using the previously obtained quantized ; ************************************************************************** ; * signal magnitude (IM), compute the adaptation speed control (Ap). QSFA: ; ************************************************************************** ;* Quantizer scale factor adaptation section. Using the previously obtained ; * :* quantized difference signal (I), compute the new scale factors (Yu, Y l ) . ; * F i r s t compute the F[I] function . ************************************************************************** ; * ; * LAC FITableOffset ; Look-up value of FI function ;* F i r s t compute H[I] from the table ADD IM LAC HlTableOffset ,- Load table offset TBLR Tempi ; Load FI value i n t o Tempi (Q4) ADD IM ; Add magnitude of quantized difference ; * TBLR Tempi ; Lookup HT (Q4), store i n Tempi • * Now, update the short term average of FI as: . * . * Dms(k) - (1 - 2**-5)*Dms(k-l) + (2**-5) *FI (k) ; * Update the fast scale factor as: ; * Note: FI i s (7b POS Q4), Dms i s (12b POS Q9) ;* Yu(k) - (1 - 2**-5)*Y(k) + (2**-5>*HI(k) ;* ;* Note: Yu and X are (13b POS Q9), HI i s (12b TC Q4 sign extended to 16b) LAC Tempi,15 ; Load (2**-5)*FI (Q24) . * ADD Dms, 15 ; Add Dms(k-l) (Q24) LAC Y,12 ; Load Y l n Q21 form SUB Dms,10 ; Subtract (2**-5)*Dms (Q24) SUB Y,7 ; Subtract Y/32 (Q21) SACH Dms,l ; Save the new Dms (Q9) ADD Tempi,12 ; Add HI/32 (Q21) . * SACH Yu,4 ; Store Yu i n (13b POS Q») format . * Update long term average of FI as: LAC Yu ; Reload Yu ... . * Dml(k) - (1 - 2**-7)*Dml(k-l) + (2**-7)*FI(k) AND M8191 and mask lower 13 b i t s ; * Note: FI i s (7b POS Q4), Dml i s (14b POS QU) SACL Yu Save f i n a l Yu • * ; * LAC Tempi, 15 ; Load (2**-7)*FI (Q26) ;* Limit the fast scale factor 1.06 <- Yu <- 10.0 ADD Dml,15 .• Add Dml(k-l) (Q26) ;* Q9 form (544 <- Yu <- 5120) SUB Dml,8 ; Subtract (2**-7)*Dml (Q26) ; * SACH Dml,l ; Save the new Dml (Qll) SUB K544 ; Check low threshold ; * BGEZ CheckHi ; Branch i f above lower threshold ; * Now compute the speed control parameter as: * Ap(k) - (1 - 2**-4)*Ap(k-l) + (2**-3) * i f (Y < 3) or (|Dms - Dml| > (2**-3)*Dml) * - (1 - 2**-4)»Ap(k-l) * otherwise * Note: Dms i s (12b POS Q9), Dml i s (14b POS Q l l ) , Ap i s (10b POS Q8) ZALH Ap ; Load Ap (024) SUB Ap,12 : Subtract (2**-4)*Ap (Q24) SACH Ap ; Save (1 - 2**-4)*Ap (Q8) LAC Y SUB Three,9 ; Check i f Y < 3 (Q9) BLZ AddEighth ; Add 1/8 i f so. ZALH Dms ,- Load Dms (Q2S) SUB Dml,14 ; Subtract Dml (Q2S) ABS ; Get magnitude of re s u l t SUB Dml,11 ; Check i f greater than Dml/8 BLZ GoodAp ; Branck i f not AddEighth: LAC Ap ; Reload Ap ADD One, 5 : Add 1/8 (Q8) SACL Ap ; Save modified Ap GoodAp: . ****************************************************************** APred: ;* Adaptive predictor section. Using the previously obtained difference ;* s i g n a l (Dq), and the previous signal estimate (Se), compute the new ;* adaptive f i l t e r c o e f f i c i e n t s . ; ************************************************************************** ; * ;* F i r s t , compute the reconstructed signal (Sr) as: ;* Sr(k) - Dq(k) + Se(k) ;* Note: Dq, Se, and Sr are (16b TC QO) . * LAC Dq ADD - Se SACL Sr * Compute c o e f f i c i e n t s •* Bi(k) - (1 - 2*' * f o r i - 1 ., * Note: Bi are (16b TC * GetB6: GetB5: ; Save Sr - Dq + Se (QO) of 6th order FIR predictor f i l t e r -8)*Bi(k-l) + (2**-7>*sgn(pq(k))*sgn(Dq(k-i)) 6 (Bi i m p l i c i t l y l i m i t e d to +/- 2 Q14), SDqi are (16b TC Q l l ; +1 - +2048, -1 - -2048) GetB4: GetB3: LT SDq6 LAC B6.15 ; Load old Bi (Q29) SUB B6,7 ; Subtract (2**-8)*Bi (Q29) MPY SDq ; SDq * SDq6 * (2**-7) (Q29) LTD SDq5 ; Create new B i , s h i f t data for SACH B6,l ; Save new Bi i n (Q14) format LAC B5,15 SUB B5,7 MPY SDq LTD SDq4 SACH B5,l LAC B4.15 SUB B4,7 MPY SDq LTD SDq3 SACH B4,l LAC B3,15 SUB B3,7 MPY SDq LTD SDq2 SACH B3,1 GetB2: LAC B2.1S SUB B2,7 MPY SDq LTD SDql SACH B2,1 GetBl: LAC Bl,15 SUB Bl,7 MPY SDq LTD SDq SACH B l , l . * ,-* Update c o e f f i c i e n t s of 2nd order IIR prediction f i l t e r ; * ;* F i r s t get sign of the sum of difference signal (Dq), and the p a r t i a l s i g n a l ;* estimate (Sez). :* Note: Dq and Sez are (16b TC QO), Pki i s (10b TC Q9 sign extended to 16b) DMOV Pkl ; S h i f t Pkl—>Pk2 DMOV PkO ; S h i f t PkO—>Pkl LAC One, 9 SACL PkO ; Store +1 (Q9) as i n i t i a l sign LAC Sez ADD Dq ; Calculate (Sez + Dq) BGEZ GoodPk ; Branch i f r e s u l t i s +ve, already saved +1 LAC Minus,9 SACL PkO ; Result i s -ve, save -1 (Q9) GoodPk: LT . * PkO ; Load PkO to T-reg i n prep, f o r multiply ;* Now calculate f [ A l ( k - l ) l as: ;* f [ A l ( k - l ) ] - 4*A1, i f f A l l <- 1/2 ; * - 2*sgn(Al), i f |Al| > 1/2 .-* Note: A l . * i s (16b TC Q14), F i s (16b TC Q13) LAC A l , l ; Load 2*A1 (Q14) to accum SACL Temp3 ; Save as i n i t i a l F/2 BLZ NegAl ; Branch i f A l i s negative SUB One,14 ; Calculate 2*(A1 - 1/2) (Q14) BLZ HaveF ; F/2 i s ok i f |A1| < 1/2 LAC One,14 ; IAl| > 1/2, so load l i m i t 1 (Q14) B SaveF NegAl: ABS ; Make Al p o s i t i v e SUB One,14 ; Check i f IAll < 1/2 BLZ HaveF ; F/2 i s ok i f so LAC Minus,14 ; |Al| > 1/2, so load l i m i t -1 (Q14) SaveF: SACL Temp3 ; Save modified F/2 HaveF: ;* ;* Now calculate Al(k) as: ;* Al(k) - (1 - 2«*-8)*Al(k-l) + 3*(2**-8)*sgn[P(k)1*sgn[P(k-1)] ;* Note: A l i s (16b TC Q14), sgn(p) i s (10b TC Q9 sign extended to 16b) (. * LAC A1.12 ; Load Al (Q26) SUB Al,4 ; Subtract (2**-8)*Al (Q26) MPY Pkl ; Calculate sgn(Pkl)*sgn(pk), sgn(Pk) i s ... SACL A l ; Store l i m i t e d A l value APAC i n T register already. Result i s (Q18) GoodAl: APAC ; * APAC ; Add 3*(2**-8)*sgn(Pkl)*sgn(Pk) (Q26) .************************************************************************** SACH Al,4 ; Save new Al i n (Q14) ; * PAC • * ; Acc has sgn[p(k-1)]*sgn[p(k)] . * . * This pass of the encoding routine i s done. Return to c a l l i n g routine. ;* Now ca l c u l a t e A2(k) as: LDPK 0 ; Reset t o page 0 variables ;* A2(k) - <1 - 2**-7)*A2(k-l) + RET ; Return to c a l l i n g routine ; * + (2**-7)* sgn[P(k)]*sgn[P(k-2)]-f[Al(k-1)]*sgn[P(k)]*sgn[P(k-1))} ;* .-* Note: A2 i s (16b TC Q14), sgn(p) i s (10b TC Q9>, P i s (16b TC 013) ;************************************************************************** ; * InitAdpcmComp: BGEZ Subtract!" ; 1£ sgn(Pkl)*sgn(Pk) +ve then subtract F ;* Routine to i n i t i a l i z e the constants used by the ADPCM algorithm, and ZAC ; Otherwise, negate F then subtract . * reset the ADPCM algorithm variables. This routine must be c a l l e d before SOB Temp3 ; Temp3 has F/2 ; * the f i r s t Adpcm conversion. SACL Temp3 ; Save negated F/2 . * Subtract! -: . * Assumes: LAC A2,12 ; Load old A2 (Q26) ; * DP - 0 DP i s set to page 0 upon e x i t SOB A2,5 ; Subtract (2**-7)*A2 (Q26) ; * ?SXM Sign extension can be e i t h e r on or o f f MPY Pk2 ; Calculate sgn(Pk)*sgn(Pk2) (Q18) • ******** ****************************************************************** APAC ; * APAC ; Add (2**-7)*sgn(Pk)*sgn(Pk2) (Q26) LDPK AdpcmPage ; Switch to Adpcm variables SUB Temp3,6 : Subtract (2**-7)*F (Q26) . * SACH • * A2,4 ; Save new A2 (Q14) • * . * Define basic constants ;* Now l i m i t A2 to +/- 0.75, and prevent overflow. LACK 1 :* Note: A2 i s (16b TC Q14) SACL One ; * SUB One,l LAC A2 SACL Minus ABS ; Take absolute value of A2 LACK 3 SUB Three,12 ; Check that |A2| < 0.75 (Q14) SACL Three BLEZ GoodA2 ; Branch i f A2 i s within l i m i t s SUB Three,1 LAC A2 SACL Minus3 BGEZ A2PosLimit : Save +ve l i m i t i f A2 i s +ve ; * A2NegLimit: • * Define b i t masks LAC Mlnus3,12 ; Save -ve l i m i t of -0.75 (Q14) ; * B SaveA2 LACK 15 A2PosLimit: SACL M15 LAC Three,12 ; Save +ve l i m i t of +0.75 (Q14) LACK 127 SaveA2: SACL M127 SACL A2 ; Save li m i t e d A2 LAC One,10 GoodA2: SUB One ; * SACL M1023 ;* Now, l i m i t A l to +/- (1 - 2**-4 - A2) ADD One,10 ;* Note: Al and A2 are (16b TC Q14) SACL M2047 • * ADD One,11 LAC M15.10 ; Load (1 - 2**-4) (Q14) SACL M4095 SUB A2 ; Subtract A2 (Q14) ADD One,12 SACL Tempi ; Save l i m i t of (1 - 2**-4 - A2) i n Tempi SACL M8191 LAC A l . * ABS ; Load 1Al1 . * Define ADPCM s p e c i f i c constants SUB Tempi ; Compare with l i m i t LALK 544 BLEZ GoodAl ; Branch i f I A l l <- l i m i t SACL K544 LAC A l LALK 5120 BGEZ LimitAl ; Save positive l i m i t i f A l > 0 SACL K5120 ZAC LALK 4576 SUB Tempi : Calculate negative l i m i t SACL K4576 SACL Tempi ; Save negative l i m i t LALK 2309 Li m i t A l : SACL K2309 LAC Tempi ; Load l i m i t value to accumulator LACK 138 SACL K138 SACL A2 LACK 130 SACL Dms SACL K130 SACL Dml LACK 79 SACL Y l h SACL K79 . * LACK 95 ; * S e t d e f a u l t v a l u e s f o r t h e s c a l e f a c t o r s SACL K95 . * LACK 46 LAC K544 SACL K46 SACL Yu LACK 49 LAC One, I S SACL K49 ADD One,11 * SACL Y l l * I n i t i a l i ze d a t a t a b l e p o i n t e r s ; * * . * I n i t i a l i ze t h e s i g n s o f d e l a y e d v a l u e s LT One MPYK i n v Q T a b l e LAC One ,11 PAC SACL S D q l SACL I n v Q T a b l e O f f s e t SACL SDq2 MPYK S h i f t T a b l e SACL SDq3 PAC SACL SDq4 SACL S h i f t T a b l e O f f s e t SACL SDq 5 MPYK w i T a b l e SACL SDq6 PAC . * SACL N l T a b l e O f f s e t LAC One, 9 MPYK F I T a b l e SACL PkO PAC SACL P k l SACL F I T a b l e O f f s e t . * * F a l l t h r o u g h t o ResetAapcmComp t o r e s e t t h e ADPCM v a r i a b l e s LDPK 0 S w i t c h back t o page 0 v a r i a b l e s * RET ************************************************************************** • * R e s e t AdpcraCopjD: .************************************************************************** ; * R o u t i n e t o r e s e t t h e ADPCM c o m p r e s s i o n a l g o r i t h m v a r i a b l e s . . d a t a . * • ****************************** ************************************* ; * Assumes : ; * ; * DP - 0 DP i s s e t t o page 0 upon e x i t . * I n i t i a l i z e d d a t a t a b l e s ; * ?SXM S i g n e x t e n s i o n can be e i t h e r on o r o f f ; * .************************************************************************** ; * I n v e r s e q u a n t i z a t i o n t a b l e ; * I n v Q T a b l e : (16b TC Q7) LDPK AdpcmPage S w i t c h t o Adpcm v a r i a b l e s .word 65401 H I - 0 ( - 1 .05 ) . * . w o r d 68 | I | - 1 (0 .53) .-* Z e r o t h e p r e d i c t o r c o e f f i c i e n t s ;, and d e l a y e d v a l u e s .word 165 I I I - 2 (1 .29) .word 232 H I - 3 (1 .81) ZAC .word 285 I H - 4 (2 .23) SACL Dq .word 332 H I - 5 (2 .59) SACL D q l .word 377 H I - 6 (2 .95) SACL Dq2 .word 428 H I - 7 (3 .34) SACL Dq3 . * SACL Dq4 . * Log t o l i n e a r s h i f t f a c t o r t a b l e SACL Dq5 S h i f t T a b l e : (16b TC Q0) SACL B l .word 256 Exp - 0 ( S h i f t 9) - 1 SACL B2 .word 512 Exp - 1 ( S h i f t 10) - 1 SACL B3 .word 1024 Exp - 2 ( S h i f t 11) - 1 SACL B4 .word 2048 Exp - 3 ( S h i f t 12) - 1 SACL B5 • word 4096 Exp - 4 ( S h i f t 13) - 1 SACL B6 .word 8192 Exp - 5 ( S h i f t 14) - 1 SACL Ap .word 16384 Exp - 6 ( S h i f t 15) - 1 SACL S r .word - 1 Exp - 7 ( S h i f t 0) SACL S r i .word - 2 Exp - 8 ( S h i f t 1) SACL A l .word - 4 Exp - 9 ( S h i f t 2) -word -8 • Exp - 10 (Shift 3) .bss Y l l . l • Low word of unlocked scale factor .word -16 • Exp - 11 (Shift 4) .bss Y l h . l • High word of unlocked scale factor .word -32 • Exp - 12 (Shift 5) .bss Yu,l - Locked scale factor .word -64 • Exp - 13 (Shift 6) .bss Y,l • Adaptive quantizer scale factor .word -128 • Exp - 14 (Shift 7) .bss Dms,l • Short term average of ADPCM signal • * .bss Dml,l • Long term average of ADPCM signal ;* Scale fa c t o r m u l t i p l i e r table .bss Ap,l - Unlimited speed control factor HITable: • (16b TC Q4) .bss A l , l • Limited speed control factor .word 65524 • H I - 0 (-0.75) .bss 1,1 Quantized difference signal .word 4 • I I I - 1 (0.25) .bss IM,1 Quantized difference signal magnitude .word 27 • H I - 2 (1.69) .bss D,l - Difference signal .word 50 • H I - 3 (3.12) .bss Tempi, 1 • Temporary scratch variables .word 98 • H I - 4 (6.12) .bss Temp2,l .word 184 • H I - 5 (11.50) .bss Temp3,l ... .word 340 • H I - 6 (21.25) .bss Sample,1 Input l i n e a r speech sample .word 1108 H I - 7 (69.25) ; * . * Reserve space for constants ; * Rate of change weighting function table FITable: (16b POS Q4) .bss InvQTableOffset,1 O f f s e t to Inverse Quantization table .word 0 I I I - 0 (0) • bss ShiftTableOffset,1 O f f s e t to Log-to-Linear s h i f t table .word 0 in - i (0) .bss wiTableOffset,l O f f s e t to Scale Factor M u l t i p l i e r table .word 0 in - 2 (0) .bss FITableOffset.l O f f s e t to Rate-of-Change Weighting table .word 16 H I - 3 (1) .bss One, 1 1 .word 16 H I - 4 (1) .bss Three, 1 3 -word 16 m - 5 (1) .bss Minus, 1 -1 .word 48 H I - 6 (3) .bss Minus3,l -3 .word 112 H I - 7 (7) .bss M15,l 15 (000F) 4 b i t mask ; * .bss M127,l 127 (007F) 7 b i t mask .************************************************************************** .bss Ml023,1 1023 (03FF) 10 b i t mask . * .bss M2047.1 2047 (07FF) 11 b i t mask • * Variable declarations .bss M4095,l 4095.(0FFF) 12 b i t mask . * .bss M8191.1 8191 (3FFF) 13 b i t mask .bss A l , l C oefficients for 2nd order IIR predictor • bss K.2309,1 2309 .bss A2,l .bss K138.1 138 .bss B l , l C oefficients for 6th order FIR predictor .bss K130.1 130 .bss B2,l .bss K79,l 79 .bss B3,l .bss K95,l 95 .bss B4,l .bss K46.1 46 .bss B5,l .bss K49,l 49 .bss B6,l .bss KS44,1 544 .bss Dq, 1 Inverse quantized difference signal .bss K4576,l 4576 .bss D q l , l Delayed versions of Dq .bss K5120,l 5120 .bss Dq2,l ;* .bss Dq3,l ;************************************************************************** .bss Dq4,l .end .bss Dq5,l ;************************************************************************** .bss SDq.l Sign of inverse quantized difference signal .bss SDql.l Delayed versions of SDq .bss .bss SDq2,l SDq3,l AdpcmExp.asm .bss SDq4,l .bss SDq5,l . * .bss SDq6,l ; * AdpcmExp.asm .bss S r , l Reconstructed signal estimate ' * Hay 11, 1990 .bss S r l , l Delayed version of Sr . * Chris Rose .bss PkO,l Sign of p a r t i a l reconstructed signal ; * .bss P k l , l Delayed versions of PkO ; * Routine to perform 32Kbps ADPCM decoding. The algorithm used i s modelled .bss Pk2,l ... ; * a f t e r the CCITT standard, but i s not i d e n t i c a l l y b i t compatible. The .bss Se, 1 Signal estimate . * algorithm i s taken from "32-kbit/s ADPCM with the TMS32010", an application .bss Sez.l P a r t i a l signal estimate . * note from Texas Instruments. The o r i g i n a l source code was modified s l i g h t l y •* to be incorporated i n t o the s i l e n c e compression program. LTD Dql . * MPY B2 •* Number formats: LTD Dq * nb number i s s tored i n n b i t s MPY B l * Qn there are n decimal b i t s APAC .- Get Q14 r e s u l t i n 32 b i t accumulator •* TC - two's compliment notat ion SACH Sez, 2 ; Save as QO •* POS - unsigned notat ion (. * ************************************************************************** . * Now compute Se, the f u l l s i g n a l estimate as: * ; * Se(k) - A l ( k - l ) * S r ( k - l ) + A2(k-1)*Sr(k-2) + Sez(k) * External references . * Note: A i (16b TC Q14), S r i (16b TC QO), Se (16b TC QO) .def AdpcmExp, InitAdpcmExp, ResetAdpcmExp ; * . r e f L i n V a l , MuLawVal, AdpcmVal LAC Sez,14 ; Load Sez as Q14 i n accumulator • * LT S r i ; Add components from A l and A2, and s h i f t ; * Local constants MPY A2 Sr i n t o S r i f o r c a l c u l a t i o n on next AdpcraPage . set 4 * Page containing Adpcm v a r i a b l e s LTD Sr sample. . * MPY A l . ************************************************************************** APAC ; Get Q14 r e s u l t i n accumulator . text SACH Se,2 ; Save as QO • ************************************************************************** . * AdpcmExp: , * C a l c u l a t e the l i m i t e d speec 1 control parameter (Al) from the previous * This rout ine converts the input 4 - b i t Adpcm value i n t o a 14-bi t l i n e a r , * unl imi ted speed c o n t r o l parameter (Ap). * PCM value . • * A l - 1 (64) i f Ap > 1 (256) * . * A l - Ap i f Ap <- 1 * Assumes: ; * Note: A l (7b POS Q6), Ap (10b POS Q8) * DP - 0 Data page containing i n t e r f a c e v a r i a b l e s ; * * SSXM Sign extension mode must be on to handle 16-bit -ve numbers LAC One,6 * SACL A l ; Store 1 (Q6) i n A l * Passed: LAC Ap * AdpcmVal 4 - b i t Adpcm value to be expanded by t h i s routine ( r ight - just ) SUB One,8 ; Check i f Ap > 1 (Q8) * BGEZ GoodAl ; Ap > 1, so keep 1 i n A l * Returned: LAC Ap, 14 ; Ap <- 1, so load i n 06 form i n AccH * L i n V a l Linear , reconstructed PCM s i g n a l ( r ight - just ) SACH A l ; Save modified A l * GoodAl: * M o d i f i e d : (. * * ARP Used to point to the ARO temporary r e g i s t e r . * Now compute Y, the adaptive quantizer scale factor as : ************************************************************************** . * Y(k) - [1 - A l ( k ) | * Y l ( k - l ) + A l ( k ) * Y u ( k - l ) * ;* - A l ( k ) * [ Y u ( k - l ) - Y l ( k - l ) ] + Y l ( k - l ) LAC AdpcmVal Load the Adpcm value ; * Note: A l (7b POS Q6), Y l (19b POS Q15), Yu (13b POS 09), Y (13b POS Q9) LDPK AdpcmPage Switch to Adpcm v a r i a b l e s • * Y l has both a low (Yll ) and high (Ylh) word. SACL I Save the Adpcm value as a l o c a l v a r i a b l e ; * ; * LAC Y l l , 1 0 ; F i r s t convert Y l to (13b POS Q9) by . * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * SACH Temp3 dropping leas t s i g n i f i c a n t 6 b i t s S i g D i f : LAC Temp3 and r i g h t j u s t i f y i n g r e s u l t . ; * Compute the p a r t i a l s i g n a l estimate (Sez), the f u l l s i g n a l estimate (Se), AND M1023 ; Mask o f f 10 b i t s of Y l l (for s i g n extension) ; * and the quantizer sca le factor (Y) from the previous sample's data . ADD Ylh,10 . ************************************************************************** SACL Temp3 : Store (13b POS Q9) value of Y l i n Temp3 ; * LAC Yu ; * Compute Sez, the p a r t i a l s i g n a l estimate as : SUB Temp3 ; Get Yu - Y l i n accumulator ; * Sez(k) - Bl(k-1)*Dq(k-1) + . . . + B6(k-l)*Dq(k-6) SACL Temp3 ; Store (13b POS Q9) value of Xu - X I ; * Note: B i (16b TC Q14), Dqi (16b TC QO), Sez (16b TC QO) ZALH Y l h ; Load (19b POS Q15) value of X l to accum (. * ADDS Y l l ZAC Zero accumulator to s t a r t c a l c u l a t i o n LT A l ; M u l t i p l y A l * ( Y u - Y l ) , r e s u l t i s Q15 LT Dq5 Step through parameters, m u l t i p l y i n g and MPY Temp3 ; Add to Q15 Y l i n accum (accum - Y i n Q15) MPY B6 accumulating i n reverse order . S h i f t APAC LTD Dq4 D q i ' s up 1 l o c a t i o n af ter m u l t i p l i c a t i o n SACL Temp3 ; Now, convert Y to (13b POS Q9) MPY B5 i n preparat ion for c a l c u l a t i o n on next SACH Temp2 LTD Dq3 sample. LAC Temp3,10 ; Drop 6 b i t s o f f of low word of Y MPY B4 SACH Temp3 LTD Dq2 LAC Temp3 ; Right j u s t i f y i n accumulator MPY B3 AND M1023 ; Mask 10 desired b i t s (remove s i g n extension) ADD Temp2,10 ; Add top portion of Y ABS ; Convert to p o s i t i v e value AND M8191 ; Mask 13 desired b i t s of result SACL Dq ; Save r e s u l t i n Dq (mag) SACL Y ; Save (13b POS Q9) r e s u l t i n Y AddSign: LAC Y,14 LAC One,11 SACH Temp3 ; Save ( l i b POS Q7) version of Y i n Temp3 SACL SDq ,- Save +1 (Qll) as Sgn(Dq) ; * LAC I ; Check sign of I (4th b i t ) .************************************************************************** SOB One,3 IAquan: BLZ HaveDq ; Branch i f I +ve, SDq and Dq are correct ;* Inverse adaptive quantizer section. From the quantized difference signal ZAC ;* (I) and the scale factor (Y), compute the reconstructed difference SOB Dq ; Negate Dq, I i s -ve ;* signal (Dq). SACL Dq ; Store modified Dq .********************** ********** ********************** LAC Minus, 11 . * SACL SDq ; Save -1 (Qll) as Sgn(Dq) ;* F i r s t , convert quantized difference magnitude to Log domain HaveDq: LACK 7 (. **************************************************** ******* AND I ; Mask off lower 3 magnitude b i t s of I QSFA: SACL IM ; Save the magnitude (assume positive) ; * Quantizer scale factor adaptation section. Using the previously obtained LAC I . * quantized difference s i g n a l (I), compute the new scale factors (Yu, XI). SOB One,3 ; Check sign b i t of I .************************************************************************** BLZ GoodlM • Branch i f positive, IM i s good • * LACK 7 ; * F i r s t compute W[I] from the table XOR IM - Invert magnitude b i t s , I was negative LAC WITableOffset ; Load table o f f s e t SACL IM • Save modified IM ADD IM ; Add magnitude of quantized difference GoodlM: TBLR Tempi ; Lookup WI (Q4), store i n Tempi LAC IM • Load the magnitude ; * ADD InvQTableOffset - Add o f f s e t of inverse quantization table ; * Update the f a s t scale factor as: TBLR Tempi • Read table value into Tempi (07) ; * Yu(k) - (1 - 2**. -5)*x(k) + (2**-5)*wi(k) ; * ; * Note: Yu and Y are (13b POS 09), WI i s (12b TC Q4 sign extended to 16b) ;* Add back the scale factor ; * . * LAC Y,12 ; Load X i n Q21 form LAC Tempi • Move [log2(Dq) - Y] value to accumulator SOB Y,7 ; Subtract Y/32 (Q21) ADD Temp3 • Add ( l i b POS Q7) version of Y ADD Tempi,12 ; Add wi/32 (Q21) AND M2047 • Mask lower 11 b i t s of r e s u l t SACH Yu, 4 ; Store Yu i n (13b POS Q9) format SACL Temp2 - Save log2(Dq) to Temp2 LAC Yu ; Reload Yu ... ;* AND M8191 and mask lower 13 b i t s ;* Now compute Dq from log2(Dq). log2(Dq) i s 0000 0EEE EMMM MMM (07) SACL Yu ; Save f i n a l Yu ;* Dq i s (16b TC Q0) • * ;* Required s h i f t s are: ; * Limit the fast scale f a c t o r 1.06 <- Yu <- 10.0 :* Exp 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 ; * Q9 form (544 <- Yu <- 5120) ;* S h i f t 09 10 11 12 13 14 15 00 01 02 03 04 05 06 07 ; * ;* where the r e s u l t i s i n AccH for Exp - 0-6, and i n AccL for Exp - 7-14 SOB K544 ; Check low threshold ;* (Right s h i f t for Exp - 0-6, Left s h i f t for Exp - 7-14) BGEZ CheckHi ; Branch i f above lower threshold ; * LAC K544 ; Load lower threshold, as i t was below LAC Temp2,9 Load exponent into high accumulator ... B StoreYu ; Branch to store lower l i m i t SACH Tempi and store i n Tempi CheckHi: LACK 127 Load mask for lower 7 b i t s ... SOB K4576 ; acc - 5120, check upper threshold AND Temp2 and mask lower 7 b i t s (mantissa) BLEZ GoodYu : Branch i f within l i m i t s ADD One,7 Add 1 (Q7) to get 1+x LAC K5120 ; Load upper threshold, as i t was above SACL Temp2 Store mantissa StoreYu: LT Temp2 Prepare to s h i f t SACL Yu ; Store the modified Xu LAC Tempi Read s h i f t m u l t i p l i e r corresponding to ... GoodYu: ADD ShiftTableOffset the exponent from a table . * TBLR Temp3 . * Opdate the slow scale factor as: MPY Temp3 Multiply by s h i f t constant . * Yl(k) - (1 - 2**- 6)*Yl(k-l) + (2**-6)*Yu(k) PAC ; * Note: Yu i s (13b POS Q9), Yl i s (19b POS Q15) BLZ L e f t S h i f t Branch i f l e f t s h i f t was required ; * SACH Dq, 1 Right s h i f t 1 more, store i n Dq (mag) ZALH Ylh B AddSign Branch to add sign ADDS Y l l ; Load Y l to accumulator L e f t S h i f t RPTK 5 SFL ; S h i f t Y l l e f t 6 b i t s (Q21) AddEighth: SUBH Ylh LAC Ap Reload Ap SOBS Y l l ; Subtract (2**-6)*Yl (Q21) ADD One ,5 Add 1/8 (Q8) ADD Yu, 6 ; Add (2**-6)*Yu (Q21) SACL Ap Save modified Ap RPTK 5 GoodAp: SFR ; S h i f t Y l right 6 b i t s (Q15) ; * SACL Y l l .************************************************************************** SACH Ylh ; Save modified Y l APred: LACK 7 ; Mask 3 lower b i t s of Ylh .-* Adaptive predictor section. Osing the previously obtained difference AND Ylh ;* signal (Dq), and the previous signal estimate (Se), compute the new SACL Ylh :* adaptive f i l t e r c o e f f i c i e n t s . ; * .************************************************************************** .************************************************************** • * SpeedControl: ;* F i r s t , compute the reconstructed signal (Sr) as: • * Adaptation speed control section. Osing the previously obtained quantized (. * Sr(k) - Dq(k) + Se(k) ; * signal magnitude (IM), compute the adaptation speed control (Ap). ;* Note : Dq, Se, and Sr are (16b TC QO) ; ************************************************************************** . * . * LAC Dq ; * F i r s t compute the F[I] function ADD Se ; * SACL Sr Save Sr - Dq + Se (QO) LAC FlTableOffset ; Look-up value of FI function ; * ADD IM ;* Compute c o e f f i c i e n t s of 6th order FIR predictor f i l t e r TBLR Tempi ; Load FI value into Tempi (Q4) ; * Bi(k) - (1 - 2**-8)*Bi(k-l) + (2**-7)*sgn(Dq(k))*sgn(Dq(k-i)) ; * . * for i - 1 .. 6 (Bi i m p l i c i t l y l i m i t e d to +/- 2 • * Nov, update the short term average of FI as: ;* Note: Bi are (16b TC Q14), SDqi are (16b TC Q l l ; +1 - +2048, -1 - -2048) ; * Dms(k) - (1 - 2**-5)*Dms(k-l) + (2**-5)*FI(k) . * ; * Note: FI i s (7b POS Q4), Dms i s (12b POS Q9) GetB6: LT SDq 6 • * LAC B6,15 Load old Bi (Q29) LAC Tempi,15 ; Load (2**-5)*FT (Q24) SOB B6,7 Subtract (2**-8)*Bi (Q29) ADD Dms,15 ; Add Dms (k-1) (Q24) MPY SDq ' SDq * SDq6 * (2**-7) (Q29) SOB Dms,10 ; Subtract (2**-5)*Dms (Q24) LTD SDq 5 Create new B i , s h i f t data for next sample SACH Dms,l ; Save the new Dms (Q9) SACH B6,1 Save new Bi i n (Q14) format . * GetBS: LAC B5,15 ; * Opdate long term average of FI as: SOB B5,7 ;* Dml(k) - (1 - 2**-7)*Dml(k-l) + (2**-7) *FI (k) MPY SDq (. * Note: FI i s (7b POS Q4), Dml i s (14b POS Qll) LTD SDq 4 • * SACH B5,l LAC Tempi,15 ; Load (2**-7)*FI (Q26) GetB4: LAC B4,15 ADD Dml,15 ; Add Dml (k-1) (Q26) SOB B4,7 SOB Dml,8 ; Subtract (2**-7)*Dml (Q26) MPY SDq SACH Dml,l ; Save the new Dml (Qll) LTD SDq3 ; * SACH B4,l ; * Now compute the speed control parameter as: GetB3: LAC B3,15 .* Ap(k) - (1 - 2**-4>*Ap(k-l) + (2**-3) SOB B3,7 • * i f (Y < 3) or (IDms - Dml| > (2**-3)*Dml) MPY SDq . * - (1 - 2**-4)*Ap(k-l) LTD SDq2 ; * otherwise SACH B3,l . * Note: Dms i s (12b POS Q9), Dml i s (14b POS Q l l ) , Ap i s (10b POS Q8) GetB2: LAC B2.15 . * SOB B2,7 ZALH Ap ; Load Ap (Q24) MPY SDq SOB Ap,12 ; Subtract (2**-4)*Ap (Q24) LTD SDql SACH Ap ; Save (1 - 2**-4)*Ap (Q8) SACH B2,l LAC Y GetBl: LAC 81,15 SOB Three,9 ; Check i f Y < 3 (Q9) SOB Bl,7 BLZ AddEighth ; Add 1/8 i f so. MPY SDq ZALH Dms ; Load Dms (Q25) LTD SDq SOB Dml, 14 ; Subtract Dml (Q25) SACH B l , l ABS ; Get magnitude of re s u l t . * SOB Dml,11 ; Check i f greater than Dml/8 (Q25) ;* Opdate c o e f f i c i e n t s of 2nd order IIR prediction f i l t e r BLZ GoodAp ; Branck i f not ; * • * F i r s t g e t s i g n o f t h e s u m o f d i f f e r e n c e s i g n a l ( D q ) , a n d t h e p a r t i a l s i g n a l L A C A 2 , 1 2 ; L o a d o l d A 2 ( Q 2 6 ) • * e s t i m a t e ( s e z ) . S U B A 2 , 5 ; S u b t r a c t ( 2 * * - 7 ) * A 2 ( Q 2 6 ) • * N o t e : D q a n d S e z a r e ( 1 6 b T C Q O ) , P k i i s ( 1 0 b TC Q 9 s i g n e x t e n d e d t o 1 6 b ) M P Y P k 2 ; C a l c u l a t e s g n ( P k ) * s g n ( P k 2 ) ( Q 1 8 ) . * A P A C DMOV P k l ; S h i f t P k l — > P k 2 A P A C : A d d ( 2 * * - 7 ) * s g n ( P k ) * s g n ( P k 2 ) ( Q 2 6 ) DMOV P k O ; S h i f t P k O — > P k l S U B T e m p 3 , 6 ; S u b t r a c t ( 2 * * - 7 ) * F ( Q 2 6 ) L A C O n e , 9 S A C H A 2 , 4 ; S a v e n e w A 2 ( Q 1 4 ) S A C L P k O ; S t o r e +1 (Q9) a s i n i t i a l s i g n • * L A C S e z ; * N o w l i m i t A 2 t o + / - 0 . 7 5 a n d p r e v e n t o v e r f l o w . A D D D q ; C a l c u l a t e ( S e z + D q ) . * N o t e : A 2 i s ( 1 6 b T C Q 1 4 ) B G E Z G o o d P k : B r a n c h i f r e s u l t i s + v e , a l r e a d y s a v e d +1 ; * L A C M i n u s , 9 L A C A 2 S A C L P k O ; R e s u l t i s - v e , s a v e - 1 (Q9) A B S ; T a k e a b s o l u t e v a l u e o f A 2 G o o d P k : S O B T h r e e , 1 2 ; C h e c k t h a t | A 2 | < 0 . 7 5 (Q14) L T P k O ; L o a d P k O t o T - r e g i n p r e p , f o r m u l t i p l y B L E Z G o o d A 2 ; B r a n c h i f A 2 i s w i t h i n l i m i t s . * L A C A 2 ; * N o w c a l c u l a t e f [ A l ( k - l ) l a s : B G E Z A 2 P o s L i m i t ; S a v e + v e l i m i t i f A 2 i s + v e : * f [ A l ( k - l ) ] - 4 * A 1 , i f | A 1 | < - 1 / 2 A 2 N e g L i m i t : . # - 2 * s g n ( A l ) , i f | A 1 | > 1 / 2 L A C M i n u s 3 , 1 2 ; S a v e - v e l i m i t o f - 0 . 7 5 (Q14) ; * N o t e : A l i s ( 1 6 b T C Q 1 4 ) , F i s ( 1 6 b T C Q 1 3 ) B S a v e A 2 . * A 2 P O S L i m i t : L A C A l , l ; L o a d 2 * A 1 ( Q 1 4 ) t o a c c u m L A C T h r e e , 1 2 ; S a v e + v e l i m i t o f + 0 . 7 5 ( Q 1 4 ) S A C L T e m p 3 ; S a v e a s i n i t i a l F / 2 S a v e A 2 : B L Z N e g A l ; B r a n c h i f A l i s n e g a t i v e S A C L A 2 ; S a v e l i m i t e d A 2 S O B O n e , 1 4 ; C a l c u l a t e 2 * ( A 1 - 1 / 2 ) ( Q 1 4 ) G o o d A 2 : B L Z H a v e F ; F / 2 i s o k i f I A l l < 1 / 2 ;* L A C O n e , 1 4 ; I A l | > 1 / 2 , s o l o a d l i m i t 1 ( 0 1 4 ) ; * N o w , l i m i t A l t o + / - ( 1 - 2 * * - 4 - A 2 ) B S a v e F • * N o t e : A l a n d A 2 a r e ( 1 6 b T C Q 1 4 ) N e g A l : . * A B S ; M a k e A l p o s i t i v e L A C M 1 5 , 1 0 ; L o a d ( 1 - 2 * « - 4 ) ( Q 1 4 ) S O B O n e , 1 4 : C h e c k i f f A l l < 1 / 2 S U B A 2 ; S u b t r a c t A 2 ( Q 1 4 ) B L Z H a v e F .- F / 2 i s o k i f s o S A C L T e m p i ; S a v e l i m i t o f ( 1 - 2 * * - 4 - A 2 ) i n T e m p i L A C M i n u s , 1 4 ; | A l I > 1 / 2 , s o l o a d l i m i t - 1 (0.14) L A C A l S a v e F : A B S ; L o a d 1 A l | S A C L T e m p 3 ; S a v e m o d i f i e d F / 2 S U B T e m p i ; C o m p a r e w i t h l i m i t H a v e F : B L E Z G o o d A l : B r a n c h i f I A l l < - l i m i t * L A C A l * N o w c a l c u l a t e A l ( k ) a s : B G E Z L i m i t A l ; S a v e p o s i t i v e l i m i t i f A l > 0 * A l ( k ) - ( 1 - 2 * * - 8 ) * A l ( k - l ) + 3 * < 2 * * - 8 ) * s g n [ P ( k ) ] * s g n [ P ( k - l ) ] Z A C * N o t e : A l i s ( 1 6 b T C Q 1 4 ) , s g n ( p ) i s ( 1 0 b T C 09 s i g n e x t e n d e d t o 1 6 b ) S U B T e m p i ; C a l c u l a t e n e g a t i v e l i m i t * S A C L T e m p i ; S a v e n e g a t i v e l i m i t L A C A l , 1 2 ; L o a d A l ( Q 2 6 ) L i m i t A l : S O B A l , 4 ; S u b t r a c t ( 2 * * - 8 ) * A l ( Q 2 6 ) L A C T e m p i ; L o a d l i m i t v a l u e t o a c c u m u l a t o r M P Y P k l ; C a l c u l a t e s g n ( P k l ) * s g n ( P k ) , s g n ( P k ) i s . . . S A C L A l ; S t o r e l i m i t e d A l v a l u e A P A C i n T r e g i s t e r a l r e a d y . R e s u l t i s (Q18) G o o d A l : A P A C A P A C ; A d d 3 * ( 2 * * - 8 ) * s g n ( P k l ) * s g n ( P k ) (Q26) ;************************************************************************** S A C H A l , 4 ; S a v e n e w A l i n (Q14) . * P A C ; A c c h a s s g n [ p ( k - 1 ) ] * s g n [ p ( k ) ) ;* T h e d e c o d i n g i s c o m p l e t e . S a v e t h e r e c o n s t r u c t e d s i g n a l , a n d r e t u r n t o . * ; * t h e c a l l i n g r o u t i n e . ; * N o w c a l c u l a t e A 2 ( k ) a s : ; * ; * A 2 ( k ) - ( 1 - 2 * * - 7 ) * A 2 ( k - l ) + L A C S r . * + ( 2 * * - 7 ) * ( s g n [ P ( k ) * s g n [ P ( k - 2 ) ] - f [ A l ( k - 1 ) 1 * s g n [ P ( k ) ] * s g n [ P ( k - 1 ) ) ) S A C L S a m p l e ; S a v e t h e r e c o n s t r u c t e d s i g n a l ; * N o t e : A 2 i s ( 1 6 b T C Q 1 4 ) , s g n ( p ) i s ( 1 0 b T C Q 9 ) , F i s ( 1 6 b T C Q 1 3 ) L A C S a m p l e L D P K 0 ; S w i t c h b a c k t o p a g e 0 v a r i a b l e s B G E Z S u b t r a c t F ; I f s g n ( P k l ) * s g n ( P k ) + v e t h e n s u b t r a c t F S A C L L i n V a l ; S a v e t h e l i n e a r v a l u e Z A C ; O t h e r w i s e , n e g a t e F t h e n s u b t r a c t R E T ; R e t u r n t o c a l l i n g r o u t i n e S O B T e r a p 3 ; T e m p 3 h a s F / 2 ; * S A C L T e m p 3 ; S a v e n e g a t e d F / 2 .************************************************************************** S u b t r a c t F : I n i t A d p c m E x p : • * Routine to i n i t i a l i z e the constants used by the Adpcm ilgorithm, and ; * I n i t i a l i z e data table pointers . * reset the Adpcm algorithm variables. This routine must be c a l l e d before ; * the f i r s t Adpcm conversion. LT One MPYK InvQTable . * Assumes: PAC ; * DP - 0 DP i s set to equal page 0 upon e x i t SACL InvQTableOffset • * ?SXM Sign extension can be either on or o f f MPYK ShiftTable . **************************************************** PAC ; * SACL Shi f t r a b l e o f f set LDPK AdpcmPage ; Switch to Adpcm variables MPYK wiTable ; * PAC . * Define basic constants SACL WTableOffset MPYK FITable LACK 1 PAC SACL One SACL FlTableOffset SOB One,l ; * SACL Minus ; * F a l l through t o ResetAdpcmExp t o reset the ADPCM variables LACK 3 • * SACL Three .************************************************************************** SOB Three,1 ResetAdpcmExp: SACL Minus3 ; * . # Routine to reset the ADPCM compression algorithm v a r i a b l e s . • * Define b i t masks . * Assumes: ; * DP - 0 DP i s set to page 0 upon e x i t LACK 15 . * ?SXM Sign extension can be ei t h e r on or o f f SACL M15 .**##****************#*#*************##**#******* LACK 127 ; * SACL M127 LDPK AdpcmPage ; Switch to Adpcm variables LAC One,10 ; * SOB One , * Zero the predictor c o e f f i c i e n t s , and delayed values SACL M1023 ADD One,10 ZAC SACL M2047 SACL Dq ADD One,11 SACL Dql SACL M4095 SACL Dq2 ADD One,12 SACL Dq3 SACL M8191 SACL Dq4 ; * SACL Dq5 Define ADPCM s p e c i f i c constants SACL Bl LALK 544 SACL B2 SACL K544 SACL B3 LALK 5120 SACL B4 SACL K5120 SACL B5 LALK 4576 SACL B6 SACL K4576 SACL AP LALK 2309 SACL Sr SACL K2309 SACL S r i LACK 138 SACL A l SACL K138 SACL A2 LACK 130 SACL Dms SACL K130 SACL Dml LACK 79 SACL Ylh SACL K79 LACK 95 . * Set default values for the scale factors SACL K95 LACK 46 LAC K544 SACL K46 SACL Yu LACK 49 LAC One,15 SACL K49 ADD One,11 • * SACL Y l l o o • * .word 98 ; | I| - 4 (6.12) •* I n i t i a l i z e the signs of delayed values .word 184 • I I I - 5 (11.50) . * .word 340 • |I| - 6 (21.25) LAC One,11 .word 1108 • H I - 7 (69.25) SACL SDql . * SACL SDq2 . * Rate of change weighting function table SACL SDq3 FlTable: • (16b POS Q4) SACL SDq 4 .word 0 • H I - 0 (0) SACL SDq5 .word 0 • H I - 1 (0) SACL SDq 6 .word 0 • I I I - 2 (0) .word 16 • H I - 3 (1) LAC One, 9 .word 16 • H I - 4 (1) SACL PkO .word 16 • H I - 5 (1) SACL Pkl .word 48 H I - 6 (3) .word 112 • H I - 7 (7) LDPK RET 0 • Switch back to page 0 variables .************************************************* • * . * Variable declarations ; * .data .bss A l , l C oefficients for 2nd order IIR predictor *********•******#*********«******************** .bss A2,l . . . * .bss B l , l C o e f f i c i e n t s f o r 6th order FIR predictor * I n i t i a l i z e d data tables .bss B2,l * •bss B3,l * Inverse quantization table .bss B4,l InvQTable: (16b TC Q7) .bss B5,l .word 65401 I H - 0 (-1.05) .bss B6,l .word 68 I I I - 1 (0.53) .bss Dq,l Inverse quantized difference signal .word 165 I I I - 2 (1.29) .bss D q l , l Delayed versions of Dq .word 232 H I - 3 (1.81) .bss Dq2,l .word 285 H I - 4 (2.23) .bss Dq3,l .word 332 H I - 5 (2.59) .bss Dq4,l .word 377 H I - 6 (2.95) .bss Dq5,l .word 428 H I - 7 (3.34) .bss SDq.l Sign of inverse quantized difference signal ;* .bss SDql.l Delayed versions of SDq :* Log to l i n e a r s h i f t factor table .bss SDq2,l ShiftTable: (16b TC QO) .bss SDq3,l .word 256 Exp - 0 (Shi f t 9) - 1 .bss SDq4,l .word 512 Exp - 1 (Shift 10) - 1 .bss SDq5,1 .word 1024 Exp - 2 (Shift 11) - 1 .bss SDq6,l .word 2048 Exp - 3 (Shift 12) - 1 .bss S r , l Reconstructed s i g n a l estimate .word 4096 Exp - 4 (Shift 13) - 1 .bss S r l , l Delayed version of Sr . word 8192 Exp - 5 (Shift 14) - 1 .bss Pk0,l Sign of p a r t i a l reconstructed signal .word 16384 Exp - 6 (Shift 15) - 1 .bss P k l . l Delayed versions of PkO .word -1 Exp - 7 (Shift 0) .bss Pk2,l • word -2 Exp - 8 (Shift 1) .bss Se, 1 Signal estimate .word -4 Exp - 9 (Shift 2) .bss Sez,l P a r t i a l signal estimate .word -8 Exp - 10 (Shift 3) .bss Y l l , l Low word of unlocked scale factor .word -16 Exp - 11 (Shift 4) .bss Y l h , l High word of unlocked scale factor .word -32 Exp - 12 (Shi f t 5) •bss Yu,l Locked scale factor .word -64 Exp - 13 (Shift 6) .bss Y , l Adaptive quantizer scale factor .word -128 Exp - 14 (Shift 7) .bss Dms.l Short term average of ADPCM signal . * .bss Dml,l Long term average of ADPCM signal ;* Scale factor m u l t i p l i e r table .bss Ap, 1 Unlimited speed control factor NlTable: (16b TC Q4) .bss A l , l Limited speed control factor .word 65524 H I - 0 (-0.75) .bss 1,1 Quantized difference signal .word 4 H I - 1 (0.25) • bss IM, 1 Quantized difference signal magnitude .word 27 H I - 2 (1.69) .bss D,l Difference signal .word 50 I I I - 3 (3.12) .bss Tempi,1 Temporary scratch variables .bss Temp2,l .bss Terap3,l .bss Sample,1 • Input l i n e a r speech sample Reserve space for constants .bss InvQTableOffset, 1 Offset to Inverse Quantization table .bss ShiftTableOffset,1 Offset to Log-to-Linear s h i f t table .bss wiTableoffset.l Offset to Scale Factor M u l t i p l i e r table .bss F l T a b l e O f f s e t . l Offset to Rate-of-Change weighting table • bss One.l 1 .bss Three,1 3 .bss Minus, 1 -1 .bss Mlnus3,l -3 .bss M15,l 15 (OO0F) 4 b i t mask .bss M127,l 127 (007F) 7 b i t mask .bss M1023,l 1023 (03FF) 10 b i t mask .bss M2047.1 2047 (07FF) 11 b i t mask .bss M4095.1 4095 (0FFF) 12 b i t mask .bss M8191.1 8191 (3FFF) 13 b i t mask .bss K2309,l 2309 .bss K138.1 138 .bss K130.1 130 .bss K79,l 79 .bss K95.1 95 .bss K46.1 46 .bss K49.1 49 .bss K544,l 544 .bss K4576.1 4576 .bss K5120.1 5120 . ************************************************************************** .end . ********************************************************************* Appendix B. Software Listings 102 B.2.2 PC Host Program Listings The following pages contain the C language program listings for the IBM-PC/AT host computer. These programs are used to transfer compressed speech data between the PC's hard-disk, and the data memory of the TMS320 processor system. There are separate programs for speech storage and speech playback; this was done for simplicity, and it would be a straight-forward task to combine the two separate programs into one. Also included are the C language program listings used to download TMS320 software to the TMS320c25 processor system. This f i l e contains the programs that implement the transfer of data from (SilRec) and to (SilPlay) the TMS320c25 processor system. These programs assume that the appropriate TMS320 program has already been downloaded to the TMS320c25 processor system. TmsProc.h /* ** TMSPROC.H ** November 30, 1989 ** Chris Rose ** ** Include f i l e d efining constants for use with the TMS320c25 processor ** board. */ /* ** Define memory locations for accessing the TMS320 processor board. •define TMSSegment OxDOOO •define ControlWrite OxEOOO •define StatusRead OxEOOO •define ProgramMem 0x0000 •define TMSDataOffset 0x8000 •define DataSize 0x2000 •define TMSCommLatch OxFOOO •define LowComraLatch OxFOOO /* •define HighCommLatch OxFOOl /* /* ** Defines f o r use with the ControlWrite register ** as follows: /* Base address for board OxDOOOO */ /* Offset for control r e g i s t e r */ /* Offset for status register */ /* Offset for TMS external program memory */ /* Offset for TMS external data memory */ /* Size i n bytes of external data mem */ /* Offset for communication l a t c h word */ Offset for comm. l a t c h low byte */ Offset for comm. la t c h high byte */ The b i t s are set up bO b l b2 b3 b4 b5 b6 b7 - TMS hold request (active low) - TMS software reset (active low) - TMS Bio input l i n e - Interupt 0 (active low) - Interupt 1 (active low) - Interupt 2 (active low) - unused - unused ** WrBase describes the 'default' state for the control register while the ** processor i s running. The actual value to write to the control register ** i s obtained by ANDing the WrBase value with any other action to be taken, ** such as WrHold to put the TMS on hold (ie, WrBase s WrHold). */ •define WrBase 0x3F •define WrHold OxFE •define WrReset OxFD •define WrBioLow OxFB •define WrlntO 0xF7 •define Wrlntl OxEF •define Wrlnt2 OxDF /* ** Defines f o r the TMS status r e g i s t e r . This register i s set-up as follows: ** bO - TMS hold acknowledge (active low) ** b l - TMS External Flag ** b2 - Reset signal applied to TMS (active low) * * b3 - Bio signal applied to TMS ** b4 - Interupt 0 applied to TMS (active low) ** . b5 - Interupt 1 applied to TMS (active low) ** b6 - Interupt 2 applied t o TMS (active low) ** b7 - unused */ •define RdHoldAck 0x01 •define RdXF 0x02 •define RdReset 0x04 •define RdBio 0x08 •define RdlntO 0x10 •define Rdlntl 0x20 •define Rdlnt2 0x40 S i l R e c . c /* ** SilRec.c ** February 12, 1990 ** Chris Rose ** ** PC disk interface program for the s i l e n c e deletion algorithm. */ •include <stdio.h> •include <stdlib.h> •include <conio.h> •include <dos.h> •include <io.h> •include <fcntl.h> •include <sys\stat.h> •include "includeNtmsproc.h" •define WRITEFILEMODE 0_WR0NLY|0_BINARY|0_CREAT|0_TRUNC,S_IWRITE •define TMS INDEX (peekb(TMSSegment, TMSCommLatch)) ~ •define MAXBLOCRS 2500 •define BLOCKSIZE 2048 in t WriteBlocM unsigned FileHandle, unsigned DataOffset); /**************************************************************************/ void main( i n t Argc, char *Argv[l ) /**************************************************************************/ ( unsigned Index, NumBlocks, DataPointer; i n t FileHandle; char Response; i f (Argc < 2) ( p r i n t f ("Osage: SIL5REC filename f_/l\n"); e x i t ( l ) ; ) i f ((FileHandle - open (Argv [1 ], WRITEFILEMODE)) < 0) { p r i n t f ( " E r r o r : Cannot open f i l e \"%s\"\n", A r g v [ l ) ) ; e x i t ( l ) ; ) printf("Ready to begin recording. Continue [Y/H] ..."); Response - getcheO; i f ((Response !- 'y') ss (Response != ' Y')) ( close(FileHandle); exit(l); ) printf("\nRecording ...\n"); /* Reset the TMS320 */ pokeb(TMSSegment, ControlHrite, (WrBase £ HrReset £ HrBioLow)) NumBlocks - 1; Index - 1; DataPointer - TMSDataOffset: /* Start the TMS running */ pokeb(TMSSegment, ControlHrite, (HrBase £ HrBioLow)); while (UkbhitO) SS (NumBlocks < MAXBLOCKS)) ( i f (Index — TMSINDEX) ( NuraBlocks++; i f (HriteBlock(FileHandle, DataPointer) < 0) ( printf("Error: Cannot write data file\n"); pokeb(TMSSegment, ControlHrite, (HrBase £ HrHold)) exit(l); > i f (Index — 0) ( DataPointer - TMSDataOffset: ) else ( DataPointer +- BLOCKSIZE; > Index++; Index t- 0x03; ) ) i f (kbhitO) getch(); /* Signal to TMS to stop sampling and wait for XF */ pokeb(TMSSegment, ControlHrite, (HrBase)); /* BIO is high */ while ((peekb(TMSSegment, StatusRead) s RdXF) — 0) ( printf("Halting for TMS to stop ...\n"); ) pokeb(TMSSegment, ControlHrite, (HrBase t HrHold)); printf ("TMS stoppedW); /* Hrite any outstanding data to disk */ i f (HriteBlocMFileHandle, DataPointer) < 0) ( printf ("Error: Cannot write data f i l e W ) ; pokeb(TMSSegment, ControlHrite, (HrBase £ HrHold)); exit(l); ) i f (Index — TMSINDEX) ( i f (Index — 0) ( DataPointer - TMSDataOffset; ) else ( DataPointer +- BLOCKSIZE; ) i f (HriteBlocMFileHandle, DataPointer) < 0) ( printf ("Error: Cannot write data f i l e W ) ; pokeb(TMSSegment, ControlHrite, (HrBase £ HrHold)); exit(l); ) ) close(FileHandle); exit(0); ) /* ** HriteBlock ** Routine to transfer data from a memory location to disk. It uses ** a low level DOS routine for speed. */ /************************************************ int WriteBlock( unsigned FileHandle, unsigned DataOffset) /**********************************************^ ( union REGS Regs; struct SREGS SRegs; int Status; /* Use DOS interupt 0x40 to write the block of data to the disk */ Regs.h.ah - 0x40; Regs.x.bx - FileHandle; Regs.x.cx - BLOCKSIZE; /* Number of bytes to write */ Regs.x.dx - DataOffset; /* Offset to start of data to transfer */ SRegs.ds - TMSSegment; /* Segment of data */ i f ((Status - intdosx(£Regs, £Regs, £SRegs)) — 0) ( Status - -1; /* Error code for disk full */ return(Status); I /* If carry flag set, return the error code (AX) from intdosx */ return(Regs.x.cflag ? Status : 0); ) J S i l P l a y . c  /* ** SilPlay.c ** February 12, 1990 ** Chris Rose *• ** PC disk interface program for the silence deletion playback algorithm. */ •include <stdio.h> •include <stdlib.h> •include <conio.h> •include <dos.h> •include <io.h> •include <fcntl.h> •include <sys\stat.h> finclude "include\tmsproc.h" •define READFILEMODE O_RDONLY|O_BINARY •define TMSINDEX (peek(TMSSegment, TMSCommLatch)) •define BLOCKSIZE 2048 int ReadBlock ( unsigned FileHandle, unsigned DataOffset ); /************************************************************************** j void main( int Argc, char *Argv[) ) /**************************************************************************/ ( unsigned Index, DataPointer; int FileHandle, Status, NumTimes; char Response; i f (Argc < 2) ( printf("Usage: SIL5PLAY filename t/]\n"); exit(l); ) i f ((FileHandle - open(Argv[l], READFILEMODE)) < 0) ( printf("Error: Cannot open f i l e \"%s\"\n", Argv[lJ); exit(l); J /* F i l l TMS data memory first */ DataPointer - TMSDataOffset; NumTimes - 0; do ( Status - ReadBlock(FileHandle, DataPointer); DataPointer +- BLOCKSIZE; NumTiraes++; ) while ((Status >- 0) SS (NumTimes < 4)); printf("Ready to begin playback. Continue [Y/N] ..."); Response - getcheO; i f ((Response !- 'y') ££ (Response !- ' Y ' ) ) ( close(FileHandle); exit(l) ; ) printf("\nPlaying ...\n"); /* Reset the TMS320 */ pokeb(TMSSegment, ControlHrite, (HrBase s NrReset)); Index - 1; DataPointer - TMSDataOffset; /* Start the TMS320 running */ pokeb (TMSSegment, ControlHrite, (HrBase)); while (C.kbhitO) ££ (Status >- 0)) ( i f (Index — TMSINDEX) ( Status - ReadBlock(FileHandle, DataPointer); i f (index — 0) ( DataPointer - TMSDataOf fset; ) else ( DataPointer +- BLOCKSIZE; ) Index++; Index £- 0x03; ) ) i f (kbhit(l) ( getch(); pokeb(TMSSegment, ControlHrite, (HrBase £ HrHold)); printf("TMS forced to stop\n"); 1 else ( /* Halt for TMS to finish playing f i l e */ while ((peekb(TMSSegment, StatusRead) £ RdXF) — 0) ( printf("Halting for TMS to finish ...\n"); ) pokeb(TMSSegment, ControlHrite, (HrBase £ HrHold)); printf("TMS stopped\n"); ) close(FileHandle); exit(0); ) /* ** ReadBlock ** Routine to transfer data from disk to a memory location. It uses ** a low level DOS routine for speed. */ /**************************************************************************/ int ReadBlock) unsigned FileHandle, unsigned DataOffset ) /A*************************************************************************/ < union REGS Regs; struct SREGS SRegs; int Status; /* Use DOS interupt 0x3F to read the block of data from the disk */ Regs.h.ah - 0x3F; Regs.x.bx - FileHandle; Regs.x.cx - BLOCKSIZE; /* Number of bytes to read */ Regs.x.dx - DataOffset; /* Offset to start of data to transfer */ SRegs.ds - TMSSegment; /* Segment of data */ i f ((Status - intdosx(SRegs, £Regs, £SRegs)) — 0) ( Status - -1; /* Error code for end of f i l e */ return(Status); I /* If carry flag set, return the error code (AX) from intdosx */ return(Regs.x.cflag ? Status : 0); ) This f i l e contains the program used to download programs to the TMS320c25 processor system. TmsLoad.c /* ** TMSLOAD.C ** November 24, 1989 ** Chris Rose ** ** This program i s used to load a T l COFF format object f i l e onto the *» TMS320C25 processor board. I t uses the T l u t i l i t y DSPROM to f i r s t ** convert the COFF f i l e into two Intel Hex format f i l e s (one for the ** MSByte, one for the LSByte), which are then loaded i n t o the processor ** boards program memory. ** ** The I n t e l Hex format f i l e s have l i n e s with the following format: ** :NNAAAAXX< Data >CC ** where: ** NN i s an unsigned integer that contains the number of data bytes on ** the l i n e . ** AAAA i s an unsigned integer (high byte f i r s t ) that contains the s t a r t ** address that the following data should be loaded at. ** XX i s a code that describes the contents of the l i n e . ** CC i s a check sum for the l i n e (byte adding l i n e + check sum should give ** zero with a carry. ** ** NOTE: a l l information i n the f i l e s i s i n HEX format, and can be read with ** "scanf("%2x", SByteValue). */ •include <stdio.h> •include <stdlib.h> •include <process.h> •include <string.h> •define True 1 •define False 0 •define MAXNAMBLEN 8 •define MAXLINELEN 100 •define TMSSEGMENT OxDOOO •define PROGOFFSET 0x0000 •define CTRLADDR OxEOOO •define RESETHOLD 0x3C •define HOLDA 0x01 in t CorrectFileName(char *FileName, char *CorrectedName); i n t ConvertFile(char *FileName): i n t LoadFiles(char "FileName); i n t ReadLine(unsigned i n t *BinaryLine, unsigned i n t *Address, FILE * H i F i l e , FILE " L o F i l e ) ; unsigned i n t Read2Bytes(FILE *LoFile, FILE * H i F i l e ) : unsigned i n t ReadByte(FILE * I n F i l e ) ; /************************************************************************** i i n t main(argc, argv) i n t argc; char *argv[]; I************************************************************************** j ( i n t Status; char FileName [MAXNAMELEN+5]; i f (argc < 2) { fp r i n t f ( s t d e r r , "Error: I n s u f f i c i e n t arguments.\n"); f p r i n t f ( s t d e r r , "Osage: TMSLOAD <TMS executable object file>\n"); f p r i n t f ( s t d e r r , " Downloads the named f i l e to the TMS320"); f p r i n t f ( s t d e r r , " processor board.\n"); exit(EXIT_FAILORE); ) Status - CorrectFileName(argv[1], FileName); i f (Status) ( fp r i n t f ( s t d e r r , "Error: Incorrect input F i l e Name format.\n"); f p r i n t f ( s t d e r r , "Filenames should have a maximum of 8 l e t t e r s , with") f p r i n t f ( s t d e r r , " no filename\n extension (.OUT i s added)\n"); exit(EXIT_FAILURE); ) f p r i n t f ( s t d e r r , "\nConverting COFF f i l e '%s.OUT'", FileName); f p r i n t f ( s t d e r r , " to Int e l Hex format ...\n\n"); Status - ConvertFile(FileName); i f (Status) ( fp r i n t f ( s t d e r r , "\nError: Could not convert input f i l e " ) ; f p r i n t f ( s t d e r r , " '%s'\n", strcat(FileName, ".OUT")); e x i t (EXIT_FAILURE) ; ) f p r i n t f ( s t d e r r , "\nSuccessful conversion completed.\n"); f p r i n t f ( s t d e r r , "\nLoading f i l e s onto TMS processor board ...\n"); Status - LoadFiles(FileName); i f (Status) ( fp r i n t f ( s t d e r r , "\nError: Could not load f i l e t o TMS board\n"); e x i t (EXIT_FAILURE) ; } f p r i n t f ( s t d e r r , "\nSuccessful completion of Loading.\n"); exit(EXIT_SUCCESS); ) /* ** CorrectFileName ** ** This routine w i l l check the passed filename for format, while copying ** i t t o a new variab l e location. */ /ft*************************************************************************/ i n t CorrectFileName(PassedName, NewName) char PassedName[]; char NewName[]; /**************************************************************************/ ( i n t Index; Index - 0; while ((Index < MAXNAMELEN)££(PassedName[Index] !- ' . ' ) * ' (PassedName[Index])) ( NewName [Index J - PassedName [Index]; Index++; ) NewName[Index] - '\0'; strupr(Newname); i f ((PassedName[Index] — ' .') 11(PassedName[Index] — '\0')) ( return(0); ) else { r e t u r n ( l ) ; ) ) I* ** ConvertFile ** ** This routine w i l l execute the TI u t i l i t y DSPROM to convert the f i l e with ** the passed Filename (in TI-COFF object format) to two I n t e l Hex format ** f i l e s with the names Filename.HI and Filename. LO. */ /************************************************************************** / i n t ConvertFile(Filename) char *Filename; /************************************************************************** j ( i n t Status; char ObjFile[MAXNAMELEN+5].-strcpy(ObjFile, Filename); s t r c a t ( O b j F i l e , ".OUT"); Status - spawnlp(PWAIT, "dsprom.exe", "dsprom.exe","-i",ObjFile,HULL); return(Status); ) /* ** LoadFiles ** ** This routine w i l l take the two Intel Hex format f i l e s FileName.HI and ** Filename.LO and download them to the TMS processor board. V f************************************************************************** / i n t LoadFiles(FileName) char *FileName; f************************************************************************** i ( char HiFileName[MAXNAMELEN+5J, LoFileName[MAXNAMELEN+5]; char Done, ErrorStatus; unsigned i n t Address, TempAddress, BinaryLine[MAXLINELEN], Test; i n t NumWords, Index; FILE * H i F i l e , *LoFile; strcpy(HiFileName, FileName); strcpy(LoFileName, FileName); strcat(HiFilename, ".HI"); strcat(LoFileName, ".LO"); i f ( ( H i F i l e - fopen(HiFileName, "rt" ) ) — NULL) ( f p r i n t f ( s t d e r r , "\nError: Cannot open f i l e '*s' ", HiFileName); f p r i n t f ( s t d e r r , "for reading.\n") ; return(1); ) i f ((LoFile - fopen(LoFileName, " r t " ) ) — NULL) ( f p r i n t f ( s t d e r r , "\nError: Cannot open f i l e '%s' ", LoFileName); f p r i n t f ( s t d e r r , "for reading.\n"); f c l o s e ( H i F i l e ) ; return (1) ; ) /* Put TMS320 Processor on Hold and wait for acknowledgement */ pokeb(TMSSEGMENT, CTRLADDR, RESETHOLD); while (peekb(TMSSEGMENT, CTRLADDR) s HOLDA); ErrorStatus - 0; Done • 0; while (IDone) ( NumWords - ReadLine(BinaryLine, SAddress, H i F i l e , L o F i l e ) ; i f (NumWords <- 0) ( Done - 1; i f (numWords < 0) ( ErrorStatus - 1; ) ) el s e ( /* Write the data to the TMS board */ TempAddress - Address; for (Index - 0; Index < NumWords; Index++) ( poke (TMSSEGMENT, (PROGOFFSET+TempAddress), BinaryLine [Index]) ; TempAddress +- 2; ) /* Check that data i s correct */ TempAddress - Address; for (Index - 0; Index < NumWords; Index++) { Test - peek(TMSSEGMENT, (PROGOFFSET+TempAddress)); TempAddress +- 2; i f (Test !- BinaryLine[Index]) ( ErrorStatus - 1; Done - 1; ) ) ) ) f c l o s e ( H i F i l e ) ; f c l o s e ( L o F i l e ) ; system("del * . h i " ) ; systera("del * . l o " ) ; return(ErrorStatus); ) /* ** ReadLine ** ** This routine w i l l create an array of 16 b i t words of binary data created ** by reading a l i n e of Hex data from each of the two Intel Hex format f i l e s . */ /**************************************************************************/ i n t ReadLine(BinaryLine, StoreAddress, H i F i l e , LoFile) unsigned i n t BinaryLine[]; unsigned int *StoreAddress; FILE *HiFile; FILE "LoFile; I **************************************************************************i { char ReadChar, Error; unsigned int Address, NumToRead; int Index; Error - False; /* Move the f i l e pointers to the start of the next line */ do { ReadChar - fgetc(HiFile); i f (ReadChar — EOF) ( Error - True; ) ) while ((ReadChar !- ':')«(Error — False)); do ( ReadChar - fgetc(LoFile); i f (ReadChar — EOF) ( Error - True; ) ) while ((ReadChar !- ':')ss(Error — False)); i f (Error) f return(-1); ) /* Read in the number of bytes per line */ NumToRead - ReadByte(HiFile); i f (NumToRead !- ReadByte(LoFile)) ( return(-1); ) /* Read in the address at which to data i s to be stored */ Address - Read2Bytes(HiFile, HiFile); i f (Address !- Read2Bytes(LoFile, LoFile)) ( return(-l); ) /* Skip over unused code bytes */ ReadByte(HiFile); ReadByte(LoFile); /* Write address for loading data to, converting from 8bit data to 16 bit data by multiplying address by 2 */ *StoreAddress - (Address « 1) ; /* Read the data from the files */ for (Index - 0; Index < NumToRead; lndex++) ( BinaryLine[Index] - Read2Bytes(LoFile, HiFile); ) return((unsigned int) NumToRead); ) /* ** Read2Bytes ** ** This routine will read a byte value from each of 2 files, and will form ** a 16 bit word (unsigned int) with the result. Both bytes can be read from ** the same f i l e by providing the same Stream identifier as both arguments. ** The routine reads the High order byte first. */ / * ** ** ** * *******************************************************/ unsigned int Read2Bytes(LowFile, HighFile) FILE *LowFile; /* File to read low byte from */ FILE *HighFile; /* File to read high byte from */ /************************************************************************** / ( unsigned int LowByte, HighByte, Number; fscanf(HighFile, "%2xn, SHighByte); fscanf(LowFile, "%2x", SLowByte); Number - (HighByte « 8) I (LowByte); return(Number); ) /***********•*****•*********•*********************#*********#**************/ unsigned int ReadByte(InFile) FILE *InFile; /*•***#******************** A*********************************************/ ( unsigned int Number; fscanf(InFile, "%2x", SNumber); return(Number); ) 

Cite

Citation Scheme:

        

Citations by CSL (citeproc-js)

Usage Statistics

Share

Embed

Customize your widget with the following options, then copy and paste the code below into the HTML of your page to embed this item in your website.
                        
                            <div id="ubcOpenCollectionsWidgetDisplay">
                            <script id="ubcOpenCollectionsWidget"
                            src="{[{embed.src}]}"
                            data-item="{[{embed.item}]}"
                            data-collection="{[{embed.collection}]}"
                            data-metadata="{[{embed.showMetadata}]}"
                            data-width="{[{embed.width}]}"
                            async >
                            </script>
                            </div>
                        
                    
IIIF logo Our image viewer uses the IIIF 2.0 standard. To load this item in other compatible viewers, use this url:
http://iiif.library.ubc.ca/presentation/dsp.831.1-0065462/manifest

Comment

Related Items