TEXT-TO-SPEECH SYSTEM USING VECTOR QUANTIZATION BASED SPEECH ENCODING/DECODING

Abstract: A text-to-speech system includes a memory storing a set of quantization vectors. A first processing module is responsive to the sound segment codes generated in response to text in the sequence to identify strings of noise compensated quantization vectors for respective sound segment codes in the sequence. A decoder generates a speech data sequence in response to the strings of quantization vectors. An audio transducer is coupled to the processing modules, and generates sound in response to the speech data sequence. The quantization vectors represent a quantization of a sound segment data having a pre-emphasis to de-correlate the sound samples used for quantization and the quantization noise. In decompressing the sound segment data, an inverse linear prediction filter is applied to the identified strings of quantization vectors to reverse the pre-emphasis. Also, the quantization vectors represent quantization of results of pitch filtering of sound segment data. Thus, an inverse pitch filter is applied to the identified strings of quantization vectors in the module for generating the speech data sequence.

Description: TEXT-TO-SPEECH SYSTEM USING VECTOR QUANTIZATION BASED SPEECH ENCODING/DECODING LIMITED COPYRIGHT WAIVER A portion of the disclosure of this patent document contains material to which the claim of copyright protection is made. The copyright owner has no objection to the facsimile reproduction by any person of the patent document or the patent disclosure, as it appears in the U.S. Patent and Trademark Office file or records, but reserves all other rights whatsoever. BACKGROUND OF THE INVENTION Field of the Invention The present invention relates to translating text in a computer system to synthesized speech; and more particularly to techniques used in such systems for storage and retrieval of speech data. Description of the Related Art In text-to-speech systems, stored text in a computer is translated to synthesized speech. As can be appreciated, this kind of system would have wide spread application if it were of reasonable cost. For instance, a text-to-speech system could be used for reviewing electronic mail remotely across a telephone line, by causing the computer storing the electronic mail to synthesize speech representing the electronic mail. Also, such systems could be used for reading to people who are visually impaired. In the word processing context, text-to-speech systems might be used to assist in proofreading a large document. However in prior art systems which have reasonable cost, the quality of the speech has been relatively poor making it uncomfortable to use or difficult to understand. In order to achieve good quality speech, prior art speech synthesis systems need specialized hardware which is very expensive, and/or a large amount of memory space in the computer system generating the sound. In text-to-speech systems, an algorithm reviews an input text string, and translates the words in the text string into a sequence of diphones which must be translated into synthesized speech. Also, text- to-speech systems analyze the text based on word type and context to generate intonation control used for adjusting the duration of the sounds and the pitch of the sounds involved in the speech. Diphones consist of a unit of speech composed of the transition between one sound, or phoneme, and an adjacent sound, or phoneme. Diphones typically start at the center of one phoneme and end at the center of a neighboring phoneme. This preserves the transition between the sounds relatively well. American English based text-to-speech systems, depending on the particular implementation, use about fifty different sounds referred to as phones. Of these fifty different sounds, the standard language uses about 1800 diphones out of possible 2500 phone pairs. Thus, a text-to- speech system must be capable of reproducing 1 800 diphones. To store the speech data directly for each diphone would involve a huge amount of memory. Thus, compression techniques have evolved to limit the amount of memory required for storing the diphones. However, to be successful, the computational complexity of the decoder for decompressing the diphone data must be very low so that the system is capable of running across a broad range of hardware platforms with very high quality reproduction. Prior art systems which have addressed this problem are described in part in United States Patent No. 8,452, 1 68, entitled COMPRESSION OF STORED WAVE FORMS FOR ARTIFICIAL SPEECH, invented by Sprague; and United States Patent No. 4,692,941 , entitled REAL-TIME TEXT-TO-SPEECH CONVERSION SYSTEM, invented by Jacks, et al. Further background concerning speech synthesis may be found in United States Patent No. 4,384, 1 69, entitled METHOD AND APPARATUS FOR SPEECH SYNTHESIZING, invented by Mozer, et al. Notwithstanding the prior work in this area, the use of text-to- speech systems has not gained widespread acceptance. It is desireable therefore to provide a software only text-to-speech system which is portable to a wide variety of microcomputer platforms, and conserves memory space in such platforms for other uses. SUMMARY OF THE INVENTION The present invention provides a software only real time, text-to- speech system suitable for application a wide variety of personal computer platforms which uses a relatively small amount of host system memory for execution. The system is based on a speech compression algorithm which takes advantage of certain specialized knowledge concerning speech including the following: 1 ) Adjacent samples of the speech data are highly correlated. Thus a fixed linear prediction filter may be used to partially remove the correlation between adjacent samples. 2) In the case of voice to speech (e.g., vowels, nasals, etc.), the speech wave forms can be regarded as slowly varying periodic signals. Thus, an adaptive pitch predictor can be used to remove the redundancy in speech data and achieve a high data compression. 3) Finally, vector quantization is an extremely efficient approach to code correlated data vectors. It can be applied to partially de-correlated speech data according to the present invention, and noise shaping can be incorporated into the vector quantization process to improve the subjective quality of the synthesized speech. Further, a variety of different compression rates can be achieved by simply varying the vector size used for vector quantization. Thus, according to one aspect, the invention can be characterized as an apparatus for synthesizing speech in response to a sequence of sound segment codes representing speech. The system includes a memory storing a set of noise compensated quantization vectors. A processing module in the apparatus is responsive to the sound segment codes in the sequence to identify strings of noise compensated quantization vectors in the set for respective sound segment codes in the sequence. A second processing module generates a speech data sequence in response to the strings of noise compensated quantization vectors. Finally, an audio transducer is coupled to the processing modules, and generates sound in response to the speech data sequence. For noise compensation according to this aspect, sounds are encoded using noise shaped data and first set of quantization vectors adapted for the noise shaped data. In decoding, a second set of noise compensated vectors different from the first set are used to recover improved quality sound. Another aspect of the invention involves utilizing the quantization vectors to represent filtered sound segment data, and providing for a module for applying an inverse filter to the strings of quantization vectors in the generation of the speech data sequence. According to this aspect, the quantization vectors may represent a quantization of results of linear prediction filtering of sound segment data for spectral flattening to de-correlate the sound samples used for quantization and the quantization noise. In decompressing the sound segment data, an inverse linear prediction filter is applied to the identified strings of quantization vectors to recover the sound data. Also, the quantization vectors represent quantization of results of pitch filtering of sound segment data. Thus, an inverse pitch filter is applied to the identified strings of quantization vectors in the module of generating the speech data sequence. In systems using the inverse linear prediction filter and the inverse pitch filter, the sound segment codes also include parameters used in executing the inverse filtering steps. In the preferred system, these parameters are chosen, along with filter coefficients used in the decoding, so that the decoding can be executed without multiplication. That is, shifts and adds replace any multiplication required by these specifically chosen values. The invention can also be characterized as an apparatus for synthesizing speech in response to text. This system includes a module that translates received text into a sequence of sound segments codes which are decoded as described above. The text translator includes a table of encoded diphones having entries that include data identifying a string of quantization vectors in the set for the respective diphones. The sequence of sound segment codes thus comprises a sequence of indices to the table of encoded diphones representing the text. The strings of the quantization vectors for a given sound segment code are identified by accessing the entries in the table of encoded diphones. The module for generating the speech data waveform may also include modules for improving the quality of the synthesized speech. Such modules include a routine for blending the ending of a particular diphone in the sequence with beginning of an adjacent diphone to smooth discontinuities between the particular and adjacent diphone data strings. Further, the string of quantized speech data may be applied to a system which adjusts the pitch and duration of the sounds represented by the strings of quantization vectors. According to yet another aspect of the invention, the apparatus for synthesizing speech may include an encoder for generating the table of encoded diphones. In this aspect, the encoder receives sampled speech for the respective diphones, applies a fixed linear prediction filter to partially de-correlate the speech samples and the quantization noise, applies a pitch filter to the output of the linear prediction filter, and applies a noise shaping filter to generate a resulting set of vectors. The resulting set of vectors is then matched to vectors in a vector quantization table. The vectors in the vector quantization table are related to the quantization vectors used for decoding the speech data by the same noise shaping filter or a derivative of it to subjectively improve the quality of the decompressed speech. This encoding technique allows use of the decoding technique which is very simple, requires a small amount of memory, and produces very high quality speech. Accordingly, the present invention is concerned with a speech compression/decompression technique for use in a text-to-speech system in which a higher level of compression is achieved while keeping the decoder complexity to an absolute minimum. The compression ratio can be varied depending on the available RAM in the computer. In order to store speech in an uncompressed form, normally 8-1 6 bits per sample is required. Using the speech compression technique of the present invention, the number of bits required to store each sample can be reduced to 0.5 bits (i.e., about 1 6 samples of speech can be stored using 8 bits of memory). However, higher quality synthesized speech can be produced when larger RAM space is available, using about 4 bits per sample. Other aspects and advantages of the present invention can be seen upon review of the figures, the detailed description and the claims which follow. BRIEF DESCRIPTION OF THE FIGURES Fig. 1 is a block diagram of a generic hardware platform incorporating the text-to-speech system of the present invention. Fig. 2 is a flow chart illustrating the basic text-to-speech routine according to the present invention. Fig. 3 illustrates the format of diphone records according to one embodiment of the present invention. Fig. 4 is a flow chart illustrating the encoder for speech data according to the present invention. Fig. 5 is a graph discussed in reference to the estimation of pitch filter parameters in the encoder of Fig. 4. Fig. 6 is a flow chart illustrating the full search used in the encoder of Fig. 4. Fig. 7 is a flow chart illustrating a decoder for speech data according to the present invention. Fig. 8 is a flow chart illustrating a technique for blending the beginning and ending of adjacent diphone records. Fig. 9 consists of a set of graphs referred to in explanation of the blending technique of Fig. 8. Fig. 10 is a graph illustrating a typical pitch versus time diagram for a sequence of frames of speech data. Fig. 1 1 is a flow chart illustrating a technique for increasing the pitch period of a particular frame. Fig. 1 2 is a set of graphs referred to in explanation of the technique of Fig. 1 1 . Fig. 13 is a flow chart illustrating a technique for decreasing the pitch period of a particular frame. Fig. 14 is a set of graphs referred to in explanation of the technique of Fig. 13. Fig. 1 5 is a flow chart illustrating a technique for inserting a pitch period between two frames in a sequence. Fig. 1 6 is a set of graphs referred to in explanation of the technique of Fig. 1 5. Fig. 1 7 is a flow chart illustrating a technique for deleting a pitch period in a sequence of frames. Fig. 18 is a set of graphs referred to in explanation of the technique of Fig. 17. DETAILED DESCRIPTION OF PREFERRED EMBODIMENTS A detailed description of preferred embodiments of the present invention is provided with reference to the figures. Figs. 1 and 2 provide a overview of a system incorporating the present invention. Fig. 3 illustrates the basic manner in which diphone records are stored according to the present invention. Figs. 4-6 illustrate the encoding methods based on vector quantization of the present invention. Fig. 7 illustrates the decoding algorithm according to the present invention. Figs. 8 and 9 illustrate a preferred technique for blending the beginning and ending of adjacent diphone records. Figs. 10-1 8 illustrate the techniques for controlling the pitch and duration of sounds in the text-to-speech system. I. System Overview (Figs. 1 -3) Fig. 1 illustrates a basic microcomputer platform incorporating a text-to-speech system based on vector quantization according to the present invention. The platform includes a central processing unit 10 coupled to a host system bus 1 1 . A keyboard 12 or other text input device is provided in the system. Also, a display system 13 is coupled to the host system bus. The host system also includes a non-volatile storage system such as a disk drive 14. Further, the system includes host memory 1 5. The host memory includes text-to-speech (TTS) code, including encoded voice tables, buffers, and other host memory. The text-to-speech code is used to generate speech data for supply to an audio output module 1 6 which includes a speaker 1 7. According to the present invention, the encoded voice tables include a TTS dictionary which is used to translate text to a string of diphones. Also included is a diphone table which translates the diphones to identified strings of quantization vectors. A quantization vector table is used for decoding the sound segment codes of the diphone table into the speech data for audio output. Also, the system may include a vector quantization table for encoding which is loaded into the host memory 1 5 when necessary. The platform illustrated in Fig. 1 represents any generic microcomputer system, including a Macintosh based system, an DOS based system, a UNIX based system or other types of microcomputers. The text-to-speech code and encoded voice tables according to the present invention for decoding occupy a relatively small amount of host memory 1 5. For instance, a text-to-speech decoding system according to the present invention may be implemented which occupies less than 640 kilobytes of main memory, and yet produces high quality, natural sounding synthesized speech. The basic algorithm executed by the text-to-speech code is illustrated in Fig. 2. The system first receives the input text (block 20). The input text is translated to diphone strings using the TTS dictionary (block 21 ). At the same time, the input text is analyzed to generate intonation control data, to control the pitch and duration of the diphones making up the speech (block 22). After the text has been translated to diphone strings, the diphone strings are decompressed to generate vector quantized data frames (block 23). After the vector quantized (VQ) data frames are produced, the beginnings and endings of adjacent diphones are blended to smooth any discontinuities (block 24). Next, the duration and pitch of the diphone VQ data frames are adjusted in response to the intonation control data (block 25 and 26). Finally, the speech data is supplied to the audio output system for real time speech production (block 27). For systems having sufficient processing power, an adaptive post filter may be applied to further improve the speech quality. The TTS dictionary can be implemented using any one of a variety of techniques known in the art. According to the present invention, diphone records are implemented as shown in Fig. 3 in a highly compressed format. As shown in Fig. 3, records for a left diphone 30 and a record for a right diphone 31 are shown. The record for the left diphone 30 includes a count 32 of the number NL of pitch periods in the diphone. Next, a pointer 33 is included which points to a table of length NL storing the number LP. for each pitch period, i goes from 0 to NL-1 of pitch values for corresponding compressed frame records. Finally, pointer 34 is included to a table 36 of ML vector quantized compressed speech records, each having a fixed set length of encoded frame size related to nominal pitch of the encoded speech for the left diphone. The nominal pitch is based upon the average number of samples for a given pitch period for the speech data base. A similar structure can be seen for the right diphone 31 . Using vector quantization, a length of the compressed speech records is very short relative to the quality of the speech generated. The format of the vector quantized speech records can be understood further with reference to the frame encoder routine and the frame decoder routine described below with reference to Figs. 4-7. II. The Encoder/Decoder Routines (Figs. 4-7) The encoder routine is illustrated in Fig. 4. The encoder accepts as input a frame s of speech data. In the preferred system, the speech samples are represented as 1 2 or 1 6 bit two's complement numbers, sampled at 22,252 Hz. This data is divided into non-overlapping frames s having a length of N, where N is referred to as the frame size. The value of N depends on the nominal pitch of the speech data. If the nominal pitch of the recorded speech is less than 165 samples (or 135 Hz), the value of N is chosen to be 96. Otherwise a frame size of 1 60 is used. The encoder transforms the N-point data sequence s into a byte stream of shorter length, which depends on the desired compression rate. For example, if N = 1 60 and very high data compression is desired, the output byte stream can be as short as 12 eight bit bytes. A block diagram of the encoder is shown in Fig. 4. Thus, the routine begins by accepting a frame s (block 50). To remove low frequency noise, such as DC or 60 Hz power line noise, and produce offset free speech data, signal s is passed through a high pass filter. A difference equation used in a preferred system to accomplish this is set out in Equation 1 for 0 < n < N. x = s - s s + 0.999 *x s n n n-1 n-1 Equation 1 The value x is the "offset free" signal. The variables s „ and x n -1 -1 are initialized to zero for each diphone and are subsequently updated using the relation of Equation 2. x -1 = X N and s -1 = S N Equation 2 This step can be referred to as offset compensation or DC removal (block 51 ). In order to partially decorrelate the speech samples and the quantization noise, the sequence x is passed through a fixed first order linear prediction filter. The difference equation to accomplish this is set forth in Equation 3. y = x - 0.875 * x s ' n n n-1 Equation 3 The linear prediction filtering of Equation 3 produces a frame y (block 52). The filter parameter, which is equal to 0.875 in Equation 3, will have to be modified if a different speech sampling rate is used. The value of x 1 is initialized to zero for each diphone, but will be updated in the step of inverse linear prediction filtering (block 60) as described below. It is possible to use a variety of filter types, including, for instance, an adaptive filter in which the filter parameters are dependent on the diphones to be encoded, or higher order filters. The sequence y produced by Equation 3 is then utilized to determine an optimum pitch value, P , and an associated gain factor, β. P ^ is computed using the functions s (P), s (P), s (P), and the opt xy xx yy coherence function Coh(P) defined by Equations 4, 5, 6 and 7 as set out below. N-1 s xy (P) = ∑ Vn * PBUF p ■ P + n n =0 max Equation 4 N-1 s XX (P) = ∑ y r n * y 7 n n = 0 Equation 5 N-1 s (P) = Σ PBUF D D , * PBUF D D , yy P - P + n P - P + n • l == 0 max max Equation 6 and Coh(P) = s (P) * s (P) / (s (P) * s (P)) xy xy xx yy Equation 7 PBUF is a pitch buffer of size P , which is initialized to zero, max and updated in the pitch buffer update block 59 as described below. P . is the value of P for which Coh(P) is maximum and s (P) is opt xy positive. The range of P considered depends on the nominal pitch of the speech being coded. The range is (96 to 350) if the frame size is equal to 96 and is (1 60 to 414) if the frame size is equal to 1 60. P is ^ max 350 if nominal pitch is less than 1 60 and is equal to 414 otherwise. The parameter P can be represented using 8 bits. The computation of P can be understood with reference to Fig. 5. In Fig. 5, the buffer PBUF is represented by the sequence 100 and the frame y is represented by the sequence 101 . In a segment of speech data in which the preceding frames are substantially equal to the frame y , PBUF and y will look as shown in Fig. 5. P _ will have the y n * n * *■ opt value at point 102, where the vector y 101 matches as closely as possible a corresponding segment of similar length in PBUF 100. The pitch filter gain parameter β is determined using the expression of Equation 8. β = s (P J / s (P J. xy opt yy opt Equation 8 β is quantized to four bits, so that the quantized value of β can range from 1 /1 6 to 1 , in steps of 1 /1 6. Next, a pitch filter is applied (block 54). The long term correlations in the pre-emphasized speech data y are removed using the relation of Equation 9. . = y n - fi • PBUF p . p 0 ≤ n < N. max opt c * • Equation 9 This results in computation of a residual signal r . Next, a scaling parameter G is generated using a block gain estimation routine (block 55). In order to increase the computational accuracy of the following stages of processing, the residual signal r is rescaled. The scaling parameter, G, is obtained by first determining the largest magnitude of the signal r and quantizing it using a 7-level quantizer. The parameter G can take one of the following 7 values: 256, 51 2, 1024, 2048, 4096, 8192, and 1 6384. The consequence of choosing these quantization levels is that the rescaling operation can be implemented using only shift operations. Next the routine proceeds to residual coding using a full search vector quantization code (block 56). In order to code the residual signal r , the n point sequence r is divided into non-overlapping blocks of length M, where M is referred to as the "vector size". Thus, M sample blocks b.. are created, where i is an index from zero to M-1 on the block 'J number, and j is an index from zero to N/M-1 on the sample within the block. Each block may be defined as set out in Equation 10. b.. = r. .. , . , (0 < i < N/M and j < 0 < M) IJ Mi -l-j ' Equation 10 Each of these M sample blocks b.. will be coded into an 8 bit number using vector quantization. The value of M depends on the desired compression ratio. For example, with M equal to 1 6, very high compression is achieved (i.e., 1 6 residual samples are coded using only 8 bits). However, the decoded speech quality can be perceived to be somewhat noisy with M = 1 6. On the other hand, with M = 2, the decompressed speech quality will be very close to that of uncompressed speech. However the length of the compressed speech records will be longer. The preferred implementation, the value M can take values 2, 4, 8, and 1 6. The vector quantization is performed as shown in Fig. 6. Thus, for all blocks b.. a sequence of quantization vectors is identified (block 120). First, the components of block b.. are passed through a noise shaping filter and scaled as set out in Equation 1 1 (block 1 21 ). w. = 0.875 * w. s - 0.5 * w. + 0.4375 * w. + b.., J J-1 J-2 j-3 IJ' 0 < j < M v.. = G w. 0 ≤ j < M 'J Equation 1 1 Thus, v.. is the jth component of the vector v., and the values w s. ,, w .. 2 and w _ are the states of the noise shaping filter and are initialized to zero for each diphone. The filter coefficients are chosen to shape the quantization noise spectra in order to improve the subjective quality of the decompressed speech. After each vector is coded and decoded, these states are updated as described below with reference to blocks 1 24-126. Next, the routine finds a pointer to the best match in a vector quantization table (block 122). The vector quantization table 123 consists of a sequence of vectors C n through C,.,-,- (block 1 23). Thus, the vector v. is compared against 256 M-point vectors, which are precomputed and stored in the code table 1 23. The vector C . which is closest to v. is determined according to Equation 1 2. The qι ' th value C for p = 0 through 255 represents the p encoding vector from the vector quantization code table 123. M-1 rs , 2 min . (v.. - C . • rs 'J PJ P j = 0 Equation 1 2 The closest vector C . can also be determined efficiently using the technique of Equation 13. v i. T • C q .i ≤ v i. T • C p for all p i -"(.0 < p *- < 255) Equation 13 T In Equation 13, the value v represents the transpose of the vector v, and "•" represents the inner product operation in the inequality. The encoding vectors C in table 123 are utilized to match on the noise filtered value v... However in decoding, a decoding vector table 1 25 is used which consists of a sequence of vectors QV . The values QV are selected for the purpose of achieving quality sound data using the vector quantization technique. Thus, after finding the vector C ., the pointer q is utilized to access the vector QV .. The decoded samples corresponding to the vector b. which is produced at step 55 of Fig. 4, is the M-point vector (1 /G) * QV .. The vector C is related to qi p the vector QV by the noise shaping filter operation of Equation 1 1 . Thus, when the decoding vector QV is accessed, no inverse noise shaping filter needs to be computed in the decode operation. The table 1 25 of Fig. 6 thus includes noise compensated quantization vectors. In continuing to compute the encoding vectors for the vectors b.. which make up the residual signal r , the decoding vector of the pointer to the vector b. is accessed (block 124). That decoding vector is used for filter and PBUF updates (block 1 26). For the noise shaping filter, after the decoded samples are computed for each sub-block b., the error vector (b.-QV .) is passed through the noise shaping filter as shown in Equation 14. W. = 0.875 * W. s - 0.5 * W. „ + 0.4375 * W. „ + [b.. - J J-1 J-2 J-3 IJ QV q .(j)] 0 < j < M Equation 14 In Equation 14, the value QV .(j) represents the j component of the decoding vector QV .. The noise shaping filter states for the next block are updated as shown in Equation 1 5. W -1 = W M-1 W -2 = W M-2 W -3 = W M-3 Equation 1 5 This coding and decoding is performed for all of the N/M sub- blocks to obtain N/M indices to the decoding vector table 1 25. This string of indices Q , for n going from zero to N/M-1 represent identifiers for a string of decoding vectors for the residual signal r . Thus, four parameters represent the N-point data sequence y : 1 ) Optimum pitch, P (8 bits), 2) Pitch filter gain, β (4 bits), 3) Scaling parameter, G (3 bits), and 4) A string of decoding table indices, Q (0 < n < N/M). The parameters β and G can be coded into a single byte. Thus, only (N/M) plus 2 bytes are used to represent N samples of speech. For example, suppose nominal pitch is 100 samples long, and M = 1 6. In this case, a frame of 96 samples of speech are represented by 8 bytes: 1 byte for P , 1 byte for β and G, and 6 bytes for the decoding table indices Q . If the uncompressed speech consists of 1 6 bit samples, then this represents a compression of 24: 1 . Back to Fig. 4, four parameters identifying the speech data are stored (block 57). In a preferred system, they are stored in a structure as described with respect to Fig. 3 where the structure of the frame can be characterized as follows: #define NumOfVectorsPerFrame (FrameSize / VectorSize) struct frame { unsigned Gain : 4; unsigned Beta : 3; unsigned UnusedBit: 1 ; unsigned char Pitch ; unsigned char VQcodes[NumOfVectorsPerFrame]; }; The diphone record of Fig. 3 utilizing this frame structure can be characterized as follows: DiphoneRecord { char LeftPhone, RightPhone; short LeftPitchPeriodCount,RightPitchPeriodCount; short *LeftPeriods, *RightPeriods; struct frame *LeftData, *RightData; } These stored parameters uniquely provide for identification of the diphones required for text-to-speech synthesis. As mentioned above with respect to Fig. 6, the encoder continues decoding the data being encoded in order to update the filter and PBUF values. The first step involved in this is an inverse pitch filter (block 58). With the vector r' corresponding to the decoded signal formed by concatenating the string of decoding vectors to represent the residual signal r' , the inverse filter is implemented as set out in Equation 1 6. y ' = r ' + β * PBUF D D + , 0 ≤ n < N. ' n n Pmax - Popt + n Equation 1 6 Next, the pitch buffer is updated (block 59) with the output of the inverse pitch filter. The pitch buffer PBUF is updated as set out in Equation 1 7. PBUF n = PBUF , , ... 0 ≤ n < (P mav - N) n (n + N) max PBUF ._ = y' 0 < n < N (Pmax - N + n) r n Equation 1 7 Finally, the linear prediction filter parameters are updated using an inverse linear prediction filter step (block 60). The output of the inverse pitch filter is passed through a first order inverse linear prediction filter to obtain the decoded speech. The difference equation to implement this filter is set out in Equation 1 8. x' = 0.875 * x' , n n-1 + V n Equation 1 8 In Equation 18, x' is the decompressed speech. From this, the value of x 1 for the next frame is set to the value x w for use in the step of block 52. Fig. 7 illustrates the decoder routine. The decoder module accepts as input (N/M) + 2 bytes of data, generated by the encoder module, and applies as output N samples of speech. The value of N depends on the nominal pitch of the speech data and the value of M depends on the desired compression ratio. In software only text-to-speech systems, the computational complexity of the decoder must be as small as possible to ensure that the text-to-speech system can run in real time even on slow computers. A block diagram of the encoder is shown in Fig. 7. The routine starts by accepting diphone records at block 200. The first step involves parsing the parameters G, β, P , and the vector quantization string Q (block 201 ). Next, the residual signal r' is decoded (block 202). This involves accessing and concatenating the decoding vectors for the vector quantization string as shown schematically at block 203 with access to the decoding quantization vector table 1 25. After the residual signal r' is decoded, an inverse pitch filter is applied (block 204). This inverse pitch filter is implemented as shown in Equation 1 9: y' = r' + £*SPBUF(P - P + n), 0 < n < N. y n n max opt Equation 1 9 SPBUF is a synthesizer pitch buffer of length P initialized as zero for 7 3 max each diphone, as described above with respect to the encoder pitch buffer PBUF. For each frame, the synthesis pitch buffer is updated (block 205). The manner in which it is updated is shown in Equation 20: SPBUF = SPBUF. , ... 0 < n < (P - N) n (n + N) max SPBUF /D = y' 0 n < N (Pmax - N + n) 7 n Equation 20 After updating SPBUF, the sequence y' is applied to an inverse linear prediction filtering step (block 206). Thus, the output of the inverse pitch filter y' is passed through a first order inverse linear prediction filter to obtain the decoded speech. The difference equation to implement the inverse linear prediction filter is set out in Equation 21 : x' = 0.875 * x' , n n-1 + y' n Equation 21 In Equation 21 , the vector x' corresponds to the decompressed speech. This filtering operation can be implemented using simple shift operations without requiring any multiplication. Therefore, it executes very quickly and utilizes a very small amount of the host computer resources. Encoding and decoding speech according to the algorithms described above, provide several advantages over prior art systems. First, this technique offers higher speech compression rates with decoders simple enough to be used in the implementation of software only text-to-speech systems on computer systems with low processing power. Second, the technique offers a very flexible trade-off between the compression ratio and synthesizer speech quality. A high-end computer system can opt for higher quality synthesized speech at the expense of a bigger RAM memory requirement. III. Waveform Blending For Discontinuity Smoothing (Figs. 8 and 9) As mentioned above with respect to Fig. 2, the synthesized frames of speech data generated using the vector quantization technique may result in slight discontinuities between diphones in a text string. Thus, the text-to-speech system provides a module for blending the diphone data frames to smooth such discontinuities. The blending technique of the preferred embodiment is shown with respect to Figs. 8 and 9. Two concatenated diphones will have an ending frame and a beginning frame. The ending frame of the left diphone must be blended with the beginning frame of the right diphone without audible discontinuities or clicks being generated. Since the right boundary of the first diphone and the left boundary of the second diphone correspond to the same phoneme in most situations, they are expected to be similar looking at the point of concatenation. However, because the two diphone codings are extracted from different context, they will not look identical. This blending technique is applied to eliminate discontinuities at the point of concatenation. In Fig. 9, the last frame, referring here to one pitch period, of the left diphone is designated L (0 < n < PL) at the top of the page. The first frame (pitch period) of the right diphone is designated R (0 < n < PR). The blending of L and R according to the present invention will alter these two pitch periods only and is performed as discussed with reference to Fig. 8. The waveforms in Fig. 9 are chosen to illustrate the algorithm, and may not be representative of real speech data. Thus, the algorithm as shown in Fig. 8 begins with receiving the left and right diphone in a sequence (block 300). Next, the last frame of the left diphone is stored in the buffer L (block 301 ). Also, the first frame of the right diphone is stored in buffer R (block 302). Next, the algorithm replicates and concatenates the left frame L to form extend frame (block 303). In the next step, the discontinuities in the extended frame between the replicated left frames are smoothed (block 304). This smoothed and extended left frame is referred to as El in Fig. 9. The extended sequence El (0 < n < PL) is obtained in the first step as shown in Equation 22: El = L n = 0, 1 PL-1 EI PL + n n = L n n = 0< 1 PL - 1 Equation 22 Then discontinuity smoothing from t thhee ppooiinntt nn == PP iis conducted according to the filter of Equation 23: EI PL + n = E, PL + n + [E, (PL-1 ) - E, '(PL-1 ) l # Δn + 1 ' n = 0, 1 (PL/2). Equation 23 In Equation 23, the value Δ is equal to 1 5/1 6 and EI' (p i ) = El ? + 3 * (E -El n ). Thus, as indicated in Fig. 9, the extended sequence El is substantially equal to L on the left hand side, has a smoothed region beginning at the point P. and converges on the original shape of L toward the point 2P. . If L was perfectly periodic, then El p . _ 1 = B- p . In the next step, the optimum match of R with the vector El is found. This match point is referred to as P . (Block 305.) This is accomplished essentially as shown in Fig. 9 by comparing R with El to find the section of El which most closely matches R . This optimum blend point determination is performed using Equation 23 where W is the minimum of PL and PR, and AMDF represents the average magnitude difference function. W-1 AMDF(p) = Σ I ' El n + , p - R n | ' n = 0 Equation 24 This function is computed for values of p in the range of 0 to PL- 1 . The vertical bars in the operation denote the absolute value. W is the window size for the AMDF computation. P is chosen to be the value at which AMDF(p) is minimum. This means that p = P corresponds to the point at which sequences El (0 < n < W) and R (0 < n < W) are very close to each other. After determining the optimum blend point P , the waveforms are blended (block 306). The blending utilizes a first weighting ramp WL which is shown in Fig. 9 beginning at P in the El trace. In a second ramp, WR is shown in Fig. 9 at the R trace which is lined up with P . Thus, in the beginning of the blending operation, the value of El is emphasized. At the end of the blending operation, the value of R is emphasized. Before blending, the length PL of L is altered as needed to ensure that when the modified L and R are concatenated, the waveforms are n n as continuous as possible. Thus, the length P'L is set to P if P is greater than PL/2. Otherwise, the length P'L is equal to W + P and the sequence L is equal to El for 0 < n < (P'L-1 ). The blending ramp beginning at P is set out in Equation 25: R = El , D + + (R - El _ L DΛn+ ) * (n + 1 )/W 0 ≤ n < W n n + Popt n n + Popt R = R W ≤ n < PR n n Equation 25 Thus, the sequences L and R are windowed and added to get the blended R . The beginning of L and the ending of R are preserved to prevent any discontinuities with adjacent frames. This blending technique is believed to minimize blending noise in synthesized speech produced by any concatenated speech synthesis. IV. Pitch and Duration Modification (Fiαs. 10-1 8) As mentioned above with respect to Fig. 2, a text analysis program analyzes the text and determines the duration and pitch contour of each phone that needs to be synthesized and generates intonation control signals. A typical control for a phone will indicate that a given phoneme, such as AE, should have a duration of 200 milliseconds and a pitch should rise linearly from 220Hz to 300Hz. This requirement is graphically shown in Fig. 10. As shown in Fig. 10, T equals the desired duration (e.g. 200 milliseconds) of the phoneme. The frequency f. is the desired beginning pitch in Hz. The frequency f is the desired ending pitch in Hz. The labels P.. , P 2 ...,P β indicate the number of samples of each frame to achieve the desired pitch frequencies f. , f n ...,f». The relationship between the desired number of samples, P., b i and the desired pitch frequency f. (f- = f. ), is defined by the relation: P. = F /f., where F is the sampling frequency for the data. As can be seen in Fig. 10, the pitch period for a lower frequency period of the phoneme is longer than the pitch period for a higher frequency period of the phoneme. If the nominal frequency were P„, then the algorithm would be required to lengthen the pitch period for frames P.. and P« and decrease the pitch periods for frames P . , P,- and P~. Also, the given duration T of the phoneme will indicate how many pitch periods should be inserted or deleted from the encoded phoneme to achieve the desired duration period. Figs. 1 1 through 18 illustrate a preferred implementation of such algorithms. Fig. 1 1 illustrates an algorithm for increasing the pitch period, with reference to the graphs of Fig. 12. The algorithm begins by receiving a control to increase the pitch period to N + Δ, where N is the pitch period of the encoded frame. (Block 350). In the next step, the pitch period data is stored in a buffer x (block 351 ). x is shown in n n Fig. 1 2 at the top of the page. In the next step, a left vector L is generated by applying a weighting function WL to the pitch period data x with reference to Δ (block 352). This weighting function is illustrated in Equation 26 where M = N-Δ: L = x for 0 n < Δ n n L = x * (N-n)/(M + 1 ) for Δ ≤ n < N n n Equation 26 As can be seen in Fig. 1 2, the weighting function WL is constant from the first sample to sample Δ, and decreases from Δ to N. Next, a weighting function WR is applied to x (block 353) as can be seen in the Fig. 12. This weighting function is executed as shown in Equation 27: R = x , * (n + 1 )/(M + 1 ) for O < n < N-Δ n n + Δ R = x , Λ for N-Δ ≤ n < N. n n + Δ Equation 27 As can be seen in Fig. 1 2, the weighting function WR increases from 0 to N-Δ and remains constant from N-Δ to N. The resulting waveforms L and R are shown conceptually in Fig. 1 2. As can be seen, L maintains the beginning of the sequence x , while R maintains the ending of the data x . M n The pitch modified sequence y is formed (block 354) by adding the two sequences as shown in Equation 28: y = L + R. Λ . y n n (n-Δ) Equation 28 This is graphically shown in Fig. 1 2 by placing R shifted by Δ below L . The combination of L and R shifted by Δ is shown to be y at the n n n 7 n bottom of Fig. 12. The pitch period for y is N + Δ. The beginning of y is the same as the beginning of x , and the ending of y is substantially the same as the ending of x . This maintains continuity with adjacent frames in the sequence, and accomplishes a smooth transition while extending the pitch period of the data. Equation 28 is executed with the assumption that L is 0, for n ≤ N, and R is 0 for n < 0. This is illustrated pictorially in Fig. 12. An efficient implementation of this scheme which requires at most one multiply per sample, is shown in Equation 29: y = x 0 < n < Δ ' n n y = x + [x x ]*(n-Δ + 1 )/(N-Δ + 1 ) Δ ≤ n < N n n-Δ y n = X n - Δ N < n < N^ d Equation 29 This results in a new pitch period having a pitch period of N + Δ. There are also instances in which the pitch period must be decreased. The algorithm for decreasing the pitch period is shown in Fig. 1 3 with reference to the graphs of Fig. 14. Thus, the algorithm begins with a control signal indicating that the pitch period must be decreased to N-Δ. (Block 400). The first step is to store two consecutive pitch periods in the buffer x (block 401 ). Thus, the buffer x as can be seen in Fig. 14 consists of two consecutive pitch periods, with the period N. being the length of the first pitch period, and N being the length of the second pitch period. Next, two sequences L and R are conceptually created using weighting functions WL and WR (blocks 402 and 403). The weighting function WL emphasizes the beginning of the first pitch period, and the weighting function WR emphasizes the ending of the second pitch period. These functions can be conceptually represented as shown in Equations 30 and 31, respectively: L = x for 0<n<N. - W n n I = x (N.-n)/(W + 1) W n<N. L = 0 otherwise, n Equation 30 and R = x (n-N, + W-Δ+1)/(W+1) for N,-W + Δ<n<N, + Δ n r R = for N. + Δ<n<N. + N n I I r R = 0 otherwise, n Equation 31 In these equations, Δ is equal to the difference between N. and the desired pitch period N .. The value W is equal to 2*Δ, unless 2*Δ is greater than N ., in which case W is equal to N .. These two sequences L and R are blended to form a pitch modified sequence y (block 404). The length of the pitch modified sequence y will be equal to the sum of the desired length and the length of the right phoneme frame N . It is formed by adding the two sequences as shown in Equation 32: y = L + R. , Λ . ■ n n (n + Δ) Equation 32 Thus, when a pitch period is decreased, two consecutive pitch periods of data are affected, even though only the length of one pitch period is changed. This is done because pitch periods are divided at places where short-term energy is the lowest within a pitch period. Thus, this strategy affects only the low energy portion of the pitch periods. This minimizes the degradation in speech quality due to the pitch modification. It should be appreciated that the drawings in Fig.1 are simplified and do not represent actual pitch period data. An efficient implementation of this scheme, which requires at most one multiply per sample, is set out in Equations 33 and 34. The first pitch period of length N . is given by Equation 33: y = x 0≤n<N.-W 7 n n I y = x + [x -x ]*(n-N. + W + 1)/(W+1) N.-W<n<N . n n n + Δ n I I α Equation 33 The second pitch period of length N is generated as shown in Equation 34: V n = X n-Δ + > n - Δ l * (n~Δ~N l + W+ 1)/(W+1) N | • ≤n<N l +Δ y = x N. , Λ <n<N. + N y n n l + Δ I r Equation 34 As can be seen in Fig.14, the sequence L is essentially equal to the first pitch period until the point N.-W. At that point, a decreasing ramp WL is applied to the signal to dampen the effect of the first pitch period. As also can be seen, the weighting function WR begins at the point N.-W + Δ and applies an increasing ramp to the sequence x until the point N. + Δ. From that point, a constant value is applied. This has the effect of damping the effect of the right sequence and emphasizing the left during the beginning of the weighting functions, and generating a ending segment which is substantially equal to the ending segment of x emphasizing the right sequence and damping the left. When the two functions are blended, the resulting waveform y is substantially equal to the beginning of x at the beginning of the sequence, at the point N.-W a modified sequence is generated until the point N-. From N. to the ending, sequence x shifted by Δ results. A need also arises for insertion of pitch periods to increase the duration of a given sound. A pitch period is inserted according to the algorithm shown in Fig. 1 5 with reference to the drawings of Fig. 1 6. The algorithm begins by receiving a control signal to insert a pitch period between frames L and R (block 450). Next, both L and R n n n n are stored in the buffer (block 451 ), where L and R are two adjacent n n ' pitch periods of a voice diphone. (Without loss of generality, it is assumed for the description that the two sequences are of equal lengths N.) In order to insert a pitch period, x of the same duration, without causing a discontinuity between L and x and between x and R , the n n n n pitch period x should resemble R around n = 0 (preserving L to x continuity), and should resemble L around n = N (preserving x to R continuity). This is accomplished by defining x as shown in Equation 35: x = R + (L - R ) * [(n + 1 )/(N + 1 )] 0 < n < N-1 n n n n Equation 35 Conceptually, as shown in Fig. 1 5, the algorithm proceeds by generating a left vector WL(L ), essentially applying to the increasing ramp WL to the signal L . (Block 452). A right vector WR (R ) is generated using the weighting vector WR (block 453) which is essentially a decreasing ramp as shown in Fig. 1 6. Thus, the ending of L is emphasized with the left vector, and the beginning of R is emphasized with the vector WR. Next, WR (L ) and WR (R ) are blended to create an inserted n n period x (block 454). The computation requirement for inserting a pitch period is thus just a multiplication and two additions per speech sample. Finally, concatenation of L , x and R produces a sequence with ' n n n an inserted pitch period (block 455). Deletion of a pitch period is accomplished as shown in Fig. 1 7 with reference to the graphs of Fig. 1 8. This algorithm, which is very similar to the algorithm for inserting a pitch period, begins with receiving a control signal indicating deletion of pitch period R which follows L (block 500). Next, the pitch periods L and R are stored in the buffer (block 501 ). This is pictorially illustrated in Fig. 18 at the top of the page. Again, without loss of generality, it is assumed that the two sequences have equal lengths N. The algorithm operates to modify the pitch period L which precedes R (to be deleted) so that it resembles R , as n approaches N. This is done as set forth in Equation 36: L' = L + (R - L ) * [(n + 1 )/(N + 1 )] 0 ≤ n < N-1 n n n n Equation 36 In Equation 36, the resulting sequence L' is shown at the bottom of Fig. 1 8. Conceptually, Equation 36 applies a weighting function WL to the sequence L (block 502). This emphasizes the beginning of the sequence L as shown. Next, a right vector WR (R ) is generated by applying a weighting vector WR to the sequence R that emphasizes the ending of R (block 503). WL (L ) and WR (R ) are blended to create the resulting vector n n L' . (Block 504). Finally, the sequence L -R is replaced with the sequence L' in the pitch period string. (Block 505). IV. Conclusion Accordingly, the present invention presents a software only text- to-speech system which is efficient, uses a very small amount of memory, and is portable to a wide variety of standard microcomputer platforms. It takes advantage of knowledge about speech data, and to create a speech compression, blending, and duration control routine which produces very high quality speech with very little computational resources. A source code listing of the software for executing the compression and decompression, the blending, and the duration and pitch control routines is provided in the Appendix as an example of a preferred embodiment of the present invention. The foregoing description of preferred embodiments of the present invention has been provided for the purposes of illustration and description. It is not intended to be exhaustive or to limit the invention to the precise forms disclosed. Obviously, many modifications and variations will be apparent to practitioners skilled in this art. The embodiments were chosen and described in order to best explain the principles of the invention and its practical application, thereby enabling others skilled in the art to understand the invention for various embodiments and with various modifications as are suited to the particular use contemplated. It is intended that the scope of the invention be defined by the following claims and their equivalents. APPENDIX © APPLE COMPUTER, INC. 1 993 37 C.F.R. § 1 .96(a) COMPUTER PROGRAM LISTINGS TABLE OF CONTENTS Section Page I. ENCODER MODULE 33 II. DECODER MODULE 43 III. BLENDING MODULE 55 IV. INTONATION ADJUSTMENT MODULE 59 I. ENCODER MODULE #include <stdio.h> #include <math.h> #include <Stdϋb.h> #include <types.h> ^include <fcntl.h> #include < string. h> #include <types.h> •^include <files.h> #include < resources. h> #include < memory. h> #include "vqcoder.h" #define LAST_FRAME_FLAG 128 #define PBUF_SIZE 440 static float oc_state[2], nsf_state[NSF_ORDER + 1]; static short pstatelPORDER + 1 ], dstatefPORDER + 1 ]; static short AnaPbuf[PBUF_SIZE]; static short vsize, cbook_size, bs size; #pragma segment vqlib /* Read Code Books */ float *EncodeBook[MAX_CBOOK_SIZE]; short * DecodeBookf MAX_CBOOK_SIZE] ; get_cbook(short ratio) { short *p; short frame_size, i; static short last_ratio = 0; Handle h; int skip; h = GetResource('CBOK',1); HLock(h); p = (short *) *h; if (ratio = = last_ratio) return; last_ratio = ratio; if (ratio < 3) return; if (NOMINAL PITCH < 165) frame_size = 96; else frame_size = 160; get_compr_pars(ratio, frame size, &vsize, &cbook_size, &bs_size); skip = 0; while (p[skip + 1] != vsize) { short t1, t2; t2 = plskip]; t1 = plskip +1]; skip + = sizeof(float) * (2 * t2-1) * (t1 +1) / sizeof(short) + (2 * t2 * t1 + 2); } /*Skip Binary search tree */ skip + = sizeof (float) * (cbook_size-1) * (vsize+1) / sizeof(short) + (cbook_size * vsize + 2); /* Get pointers to Full search code books */ for (i = 0; i < cbook size; i+ +) { EncodeBook ' i] = (float *) &p[skip]; skip + = (vsize+1) * sizeof (float) / sizeof (short); } for (i = 0; i < cbook_size; i+ +) { DecodeBookfi] = p + skip; skip + = vsize; } } char *getcbook(long *len, short ratio) { get_cbook(ratio); *len = sizeof(short) * vsize * cbook size; /* plus one is to make space at the end for the array of pointers */ return (char*) DecodeBooklO]; } /* A Routine for Pitch filter parameter Estimation */ GetPitchFilterPars (x, Ien, pbuf, min pitch, max_pitch, pitch, beta) float *beta; short *x, *pbuf; short min_pitch, max pitch; short Ien; unsigned int * pitch; { /* Estimate long-term predictor */ int best_pitch, i, j; float syy, sxy, best sxy = 0.0, best_syy = 1 .0; short *ptr; best_pitch = min_pitch; ptr = pbuf + PBUF_SIZE - min_pitch; syy = 1 .0; for (i = 0; i < Ien; i + + ) { syy + = ( *ptr) * (*ptr); ptr + + ; } for (j = min_pitch; j < max_pitch; j + + ) { sxy = 0.0; ptr = pbuf + PBUF_SIZE - j; for (i = 0; i < Ien; i + + ) sxy + = x[i] * (*ptr + + ); if (sxy > 0 && (sxy * sxy * best_syy > best_sxy * best_sxy * syy)) { best syy = syy; best sxy = sxy; best_pitch = j; } syy = syy - pbuf [PBUF_SIZE - j + Ien - 1 ] * pbuf [PBUF_SIZE - j + ien - 1 ; + pbuf[PBUF_SIZE - j - 1 ] * pbuffPBUF SIZE - j - 1 ]; } * pitch = best_pitch; *beta = best sxy / best syy; } /* Quantization of LTP gain parameter */ CodePitchFilterGain(beta, bcode) float beta; unsigned int * bcode; { int i; for (i = 0; i < DLB TAB SIZE; i + + ) { if (beta < = dlb_tab[i]) break; } * bcode = i; } /* Pitch filter */ PitchFilter(data, Ien, pbuf, pitch, ibeta) float *data; short ibeta; short *pbuf; short Ien; unsigned int pitch; { long pn; int i, j; j = PBUF SIZE - pitch; for (i = 0; i < Ien; i+ +) { pn - ((ibeta * pbuf[j++]) >> 4); data[i] -= pn; } } /* Forward Noise Shaping filter */ FNSFilter(float *inp, float *state, short Ien, float *out) { short i, j; for (j = 0; j < Ien; j+ +) { float tmp = inp[j]; for (i = 1; i < = NSF_ORDER; i+ +) tmp + = stateti] * nsf[i]; out[j] = state[0] = tmp; for (i = NSF_ORDER; i > 0; i~) state[i] = state[i-1]; } } /* Update Noise shaping Filter states */ UpdateNSFState(float *inp, float *state, short Ien) { short i, j; float temp_state[NSF_ORDER + 1 ]; for (i = 0; i < = NSF_ORDER; i+ +) temp_state[i] = 0; for (j = 0; j < ien; j+ +) { float tmp = inp[jl; f or (i = 1 ; i < = NSF_ORDER; i + + ) tmp + = temp_state[i] * nsf[i]; temp_state[0] = tmp; for (i = NSF ORDER; i > 0; i~) temp_state[il = temp_state[i-1]; } for (i = 0; i < = NSF_ORDER; i + + ) statefi] = state[i] - temp_state[i]; } /* Quantization of Segment Power */ CodeBlockGain(power, gcode) float power; unsigned int *gcode; { int i; for (i = 0; i < DLG_TAB_SIZE; i + + ) { if (power < = dlg_tab[i]) break; } *gcode = i; } /* Full search Coder */ VQCoder(float *x, float *nsf_state, short Ien, struct frame *bs) { float max x, tmp; int i, j, k, index, lshift_count; unsigned int gcode; float min err = 0; max x = x[01; for (i = 1 ; i < Ien; i + + ) if ( fabs(x[i]) > max_x) max_x = fabs(x[i]); CodeBlockGain(max_x, &gcode); max_x = qlg_tab[gcode]; lshift_count = 7 - gcode; /* To scale 14-bit Code book output to the 1 6-bit actual value */ bs-> gcode = gcode; for (i = 0; i < Ien; i + = vsize) { /* Filter the data vector */ FNSFilter(&x[i), nsf_state, vsize, &x[i]); /* Scale data */ for (j = i; j < i + vsize; j + + ) x[j] = x[j] * 1024 / max x; index = 0; for (j = 0; j < cbook_size; j + + ) { tmp = EncodeBook[j][vsize] * 1024.0; for (k = 0; k < vsize; k+ +) tmp -= x[i + k] * EncodeBook[j][k]; if (tmp < min_err j | j = = 0) { index = j; min_err = tmp; } } bs->vqcode[i/vsize] = index; /* Rescaie data: Decoded data is 14-bits, convert to 16 bits */ if (lshift_count) { for (k = 0; k < vsize; k+ +) x[i + k] = ((4 * DecodeBook[index][k]) >> lshift_count); } else { for (k = 0; k < vsize; k+ +) x[j + k] = 4 * DecodeBookfindexHk]; } /* Update noise shaping filter state */ UpdateNSFState(&x[i), nsf_state, vsize); } } init compressO { int i; oc_state[0] = 0;; oc_state[11 = 0;; for (i = 0; i < = PORDER; i+ +) pstate[i] = dstate[i] = 0; for (i = 0; i < PBUF_SIZE; i+ +) AnaPbuf[i] = 0; for (i=0; i < = NSF ORDER; i+ +) nsf_state[i] = 0; } Encoder(xn, frame_size, min pitch, max pitch, bs) short xn[]; struct frame *bs; short frame_size, min_pitch, max_pitch; { unsigned int pitch, bcode; float preemp_xn[PBUF_SIZE], beta; short xn copytPBUF SIZE]; short ibeta; float ace; int i, j; /* Offset Compensation */ for (i = 0; i < frame_size; i+ +) { float inp = xn[i]; xn[i] = inp - oc_state[0] + ALPHA * oc_state[1]; oc_state[1] = xn[i]; oc_state[0] = inp; } /* Linear Prediction Filtering */ for (i = 0; i < frame_size; i+ +) { ace = pstatefO] = xn[i]; for (j = 1; j <= PORDER; j++) acc-= pstatelj] * pfiltlj]; xn_copy[i] = preemp_xn[i] = ace; for (j = PORDER; j > 0; j--) pstate[j] = pstate[j-1]; } • GetPitchFilterPars (xn copy, frame_size, AnaPbuf, min pitch, max_pitch, &pitch, &beta); CodePitchFilterGain(beta, &bcode); ibeta = qlb_tab[bcode]; bs-> bcode = bcode; bs-> pitch = pitch - min_pitch + 1; PitchFilter(preemp_xn, frame_size, AnaPbuf, pitch, ibeta); VQCoder(preemp_xn, nsf state, frame_size, bs); /* Inverse Filtering */ j = PBUF_SIZE - pitch; for (i = 0; i < frame_size; i+ +) { xn_copy[i] = preemp_xn[i]; xn_copy[i] + = ((ibeta * AnaPbuf [j+ +]) >> 4); } /* Update Pitch Buffer */ j = 0; for (i = frame_size; i < PBUF SIZE; i + + ) AnaPbuf [j++] = • AnaPbuf [i]; for (i = 0; i < frame size; i+ +) AnaPbuf[j++] = xn_copy[i]; /* Inverse LP filtering */ for (i = 0; i < frame_size; i+ +) { ace = xn_copy[i]; for (j = 1; j < = PORDER; j++) ace = ace + dstatef] * pfilt[j]; dstatelO] = ace; for (j = PORDER; j > 0; j--) dstatefj] = dstate[j-1]; } for (j = 0; j < = PORDER; j+ +) pstate[j] = dstate[j]; } compress (short *input, short ilen, unsigned char *output, long *olen, long docomp) { int i, j, vcount; unsigned char temp; short frame_size, min_pitch, max_pitch; if (docomp > 2) { init_compress(); if (NOMINAL PITCH < 165) { min_pitch = 96; frame size = 96; max pitch = 350; } else { min pitch = 160; frame_size = 160; max_pitch = 414; } bs_size = frame_size / vsize + 2; /* TEMPORARY: Storing State information */ pstate[1] = * (input - 1); if (pstate[1] > 0) pstatem = (pstatem + 128) / 256 + 128; else pstate[1] = (pstatem - 128) / 256 + 128; if (pstatem < 0) pstate[1] = 0; if (pstatem > 255) pstateM] = 255; * output = pstate[1]; j = 1; pstate[1] = pstate[1] - 128; pstate[1] = 256 * pstateM]; dstate[1] = pstateM]; /* End of Hack */ for (i = 0; i < ilen; i + = frame_size) { Encoder(input + i, frame_size, min_pitch, max pitch, output + j); j + = bs_size; } j -= bs size; /* Number of vectors in last frame */ vcount = (ilen + frame_size - i + vsize - 1 ) / vsize; temp = output "' ]; output ' j] = vcount + LAST_FRAME_FLAG; output[j + vcount + 2] = temp; *olen = j + vcount + 3; } else { static long SampCount = 0; copy(input, output, 2*ilen); SampCount + = ilen; *olen = ilen; } } copy(a, b, Ien) short *a, *b; short Ien; { int i; for (i = 0; i < Ien; i+ +) *b+ + = (*a+ +); } II. DECODER MODULE #include <Types.h> #include < Memory. h> #include <Quickdraw.h> #include <ToolUtils.h> #include < errors. h> #include < files. h> #include "vtcint.h" #include <stdlib.h> -^include <math.h> #include <sysequ.h> #include < string. h> #define MAX_CBOOK_SIZE 256 #define LAST FRAME FLAG 128 #define PORDER 1 #define IPCONS 7 /* 7/8 */ #define LARGE NUM 100000000 #define VOICED 1 #define LEFT 0 #define RIGHT 1 #define UNVOICED 0 #define PFILT ORDER 8 struct frame { unsigned gcode : 4; unsigned bcode : 4; unsigned pitch : 8; unsigned char vqcode[]; }; void expand(short **DecodeBook, short frame_size, short vsize, short min_pitch, struct frame *bs, short *output, short smpnum); get_compr_pars(short ratio, short frame size, short *vsize, short *cbook_size, short *bs_size) { switch (ratio) { case 4: *vsize = 2; *cbook_size = 256; *bs_size = frame_size/2 + 2; break; case 7: *vsize = 4; *cbook_size = 256; *bs_size = frame_size/4 + 2; break; case 14: * vsize = 8; *cbook_size = 256; *bs_size = fra me_size/8 + 2; break; case 24: *vsize — 16; *cbook_size = 256; *bs_size = frame_size/16 + 2; break; default: *vsize = 2; *cbook_size = 256; *bs_size = frame_size/2 + 2; break; } } short *Snlnit(short comp_ ratio) { short * state, *ptr ; int i; state = ptr • = (short *)NewPtr((PFILT_ORDER+ 1 + PFILT ORDER/2 + 2) sizeof(short)); if ( state = = nil ) { return nil; } for (i = 0;i<PFILT_ORDER + 1;i++) *ptr++ = 0; /* if (comp_ratio = = 24) { *ptr+ + = 0.036953 * 32768 + 0.5; *ptr+ + = -0.132232 * 32768 - 0.5; *ptr++ = 0.047798 * 32768 + 0.5 *ptr++ = 0.403220 * 32768 + 0.5 *ptr+ + = 0.290033 * 32768 + 0.5 } else { *ptr+ + = 0.074539 * 32768 + 0.5; *ptr+ + = -0.174290 * 32768 - 0.5; *ptr++ = 0.013704 * 32768 + 0.5; *ptr+ + = 0.426815 * 32768 + 0.5; *ptr+ + = 0.320707 * 32768 + 0.5; } */ if (comp ratio = = 24) { *ptr+ + = 1211; *ptr+ + = -4333; * ptr + + = 1566; * ptr + + = 13213; *ptr+ + = 9504; } else { *ptr + + = 2442; * ptr + + • *** - -5711; * ptr + + = 449; * ptr + + = 13986; *ptr+ + = 10509; } *ptr = 0; /* DC value */ return state; } SnDone(char *state) { if ( state ! = r ul ) { DisposPtr(state); } } short **SnDelnit(p, ratio, frame size) short *p, ratio, frame_size; { int i; short cbook size = 256, vsize = 16, bs size; short ** DecodeBook; get_compr_pars(ratio, frame size, &vsize, &cbook_size, &bs_size); DecodeBook = (short* *)NewPtr(cbook_size * sizeof(short*)); if (DecodeBook) { for (i = 0; i < cbook_size; i+ +) { DecodeBook[i] = p; p + = vsize; } } return DecodeBook; } SnDeDone(char *DecodeBook) { if ( DecodeBook ! = nil ) { DisposPtr(DecodeBook); } } void expand(short * 'DecodeBook, short frame size, short vsize, short min_pitch, struct frame *bs, short * output, short smpnum) { short count; short *bptr, *sptr1, *sptr2; unsigned short pitch, bcode; /* short qlb_tab[] = { 1, 2,3,4, 5, 6,7,8, 9, 10, 11, 12, 13, 14, 15, 16 }; */ bcode = bs-> bcode; pitch = bs-> pitch + min_pitch - 1; /* Decode VQ vectors */ { unsigned char *cptr; short k, vsize_by_2; short rshift_count - ***■ 7 - bs-> gcode; /* We want the output to be 14-bit number */ sptrl = output + smpnum; cptr = bs->vqcode; vsize_by_2 = (vsize > > 1) + 1; /* +1 since we do a while (~i) instead of while (i— ) */ if (rshift_count) { for (k = 0; k < frame size; k + = vsize) { bptr = DecodeBook! *cptr + +]; count = vsize_by_2; while (-count) { *sptr1 + + = ((*bptr++) >> rshift_count); *sptr1 + + = ((*bptr++) >> rshift_count); } } } else { for (k = 0; k < frame_size; k + = vsize) { bptr = DecodeBook! *cptr + +]; count = vsize_by_2; while (--count) { *sptr1 + + = *bptr+ +; *sptr1 + + = *bptr+ +; } } } /* Inverse Filtering */ if (smpnum < pitch) { sptrl = output + pitch; count = smpnum + frame_size + 1 - pitch; /* + 1 since we do a while (~i) instead of while (i~) */ sptr2 = sptrl - pitch; switch (bcode) { case 0: while (-count) *sptr1 + + + = ((*sptr2+ +) > > 4); break; case 1 : while (-count) *sptr1 + + += ((*sptr2++) >> 3); break; case 2: while (-count) *sptr1 + + + = ((3 * (*sptr2+ +)) > > 4); break; case 3: while (-count) *sptr1 + + += ((*sptr2++) >> 2); break; case 4: while (-count) *sptr1 + + + = ((5 * (*sptr2+ +)) > > 4); break; case 5: while (-count) *sptr1 + + + = ((3 * (*sptr2+ +)) > > 3); break; case 6: while (-count) 'sptrl + + + = ((7 * (*sρtr2+ +)) > > 4); break; case 7: while (-count) *sptr1 + + + = ((*sptr2++) >> 1); break; case 8: while (-count) { long tmp; tmp = *sptr2+ +; *sptr1 + + + = (((tmp < < 3) + tmp) > > 4); } break; case 9: while (-count) *sptr1 + + + = ((5 * (*sptr2+ +)) > > 3); break; case 10: while (-count) { long tmp; tmp = *sptr2 + +; *sptr1 + + + = (((tmp < < 3) + 3 * tmp) > > 4); } break; case 11 : while (—count) *sptr1 + + + = ((3 * (*sptr2+ +)) > > 2); break; case 12: while (-count) { long tmp; tmp = *sptr2+ +; *sptr1 + + + = (((tmp < < 4) - 3 * tmp) > > 4); } break; case 13: while (-count) *sptr1 + + + = ((7 * (*sptr2+ +)) > > 3); break; case 14: while (-count) { long tmp; tmp = *sptr2+ +; *sptr1 + + + = (((tmp < < 4) - tmp) > > 4); } break; case 15: while (-count) *sptr1 + + + = f sptr2+ +; break; } } else { sptrl = output + smpnum; sptr2 = sptrl - pitch; count -= (frame_size / 4) + switch (bcode) { case 0: while (-count) { *sptr1 + + + ((*sptr2++) >> 4) *sptr1 + + + ((*sptr2++) >> 4) *sptr1 + + + ((*sptr2++) >> 4) *sptr1 + + + ((*sptr2++) >> 4) } break; case 1 : while (-count) { *sptr1 + + + ((*sptr2++) >> 3) *sptr1 + + + ((*sptr2++) >> 3) *sptr1 + + + ((*sptr2++) >> 3) *sptr1 + + + ((*sptr2++) >> 3) } break; case 2: while (-count) { *sptr1 + + + ((3 * (*sptr2++)) >> 4) *sptr1 + + + ((3 * (*sptr2++)) >> 4) *sptr1 + + + ((3 * (*sptr2++)) >> 4) *sptr1 + + + ((3 * (*sptr2++)) >> 4) } break; case 3: while (-count) { *sptr1 + + + ((*sptr2++) >> 2) *sptr1 + + + ((*sptr2++) >> 2) *sptr1 + + + ((*sptr2++) >> 2) *sptr1 + + + <(*sptr2++) >> 2) } break; case 4: while (-count) { *sptr1 + + + ((5 * (*sptr2++)) >> 4) *sptr1 + + + ((5 * (*sptr2++)) > > 4) *sptr1 + + + ((5 * (*sptr2++)) > > 4) *sptr1 + + + ((5 * (*sptr2++)) >> 4) } break; case 5: while (-count) { *sptr1 + + + ((3 * (*sptr2++)) >> 3) *sptr1 + + + ((3 * (*sptr2++)) >> 3) *sptr1 + + + ((3 * (*sptr2++)) >> 3) *sptr1 + + + ((3 * (*sptr2++)) >> 3) } break; case 6: while (-count) { *sptr1 + + + ((7 * (*sptr2++)) >> 4) *sptr1 + + + ((7 * (*sptr2++)) >> 4) *sptr1 + + + ((7 * (*sptr2++)) >> 4) *sptr1 + + + ((7 * (*sptr2++)) >> 4) } break; case 7: while (-count) { *sptr1 + + + ((*sptr2++) >> 1) *sptr1 + + + ((*sptr2 + +) >> 1) *sptr1 + + + ((*sptr2+ +) > > 1) *sptr1 + + + ((*sptr2+ +) > > 1) } break; case 8: while (-count) { long tmp; tmp = *sptr2 :++; *sptr1 + + + = ((8 * tmp + tmp) > > 4) tmp = *sptr2. + . , ; *sptr1 + + + = ((8 * tmp + tmp) > > 4) tmp = *sptr2+ +; *sptr1 + + + = ((8 * tmp + tmp) > > 4) tmp = *sptr2 :++; *sptr1 + + + = ((8 * tmp + tmp) > > 4) } break; case 9: while (-count) { *sptr1 + + + ((5 * (*sptr2++)) >> 3) *sptr1 + + + ((5 * (*sptr2++)) >> 3) *sptr1 + + + ((5 * (*sptr2++)) >> 3) 'sptrl + + + ((5 * (*sptr2++)) >> 3) } break; case 10: while (-count) { long tmp; tmp = *sptr2 + +; *sptr1 + + + = (((tmp < < 3) + 3 * tmp) > > 4); tmp = *sptr2 + + ; *sptr1 + + + = (((tmp < < 3) + 3 * tmp) > > 4); tmp = *sptr2 + + ; *sptr1 + + + = (((tmp < < 3) + 3 * tmp) > > 4); tmp = *sptr2 + + , * *sptr1 + + + = (((tmp < < 3) + 3 * tmp) > > 4); } break; case 11 : while (-count) { *sptr1 + + + = ((3 * (*sptr2++)) >> 2) *sptr1 + + + = ((3 * (*sptr2++)) >> 2) *sptr1 + + + = ((3 * (*sptr2++)) >> 2) *sptr1 + + + = ((3 * (*sptr2++)) >> 2) } break; case 12: while (-count) { long tmp; tmp = *sptr2 + + ; *sptr1 + + + = (((tmp < < 4) - 3 * tmp) > > 4) tmp = *sptr2 + + ; *sptr1 + + + = (((tmp < < 4) - 3 * tmp) > > 4) tmp = *sptr2 + + ; *sptr1 + + + = (((tmp < < 4) - 3 * tmp) > > 4) tmp = *sptr2 + + ; *sptr1 + + + = (((tmp < < 4) - 3 * tmp) > > 4) } break; case 13: while (-count) { *sptr1 + + + = ((7 * (*sptr2++)) >> 3) *sptr1 + + + = ((7 * (*sptr2++)) >> 3) *sptr1 + + + = ((7 * (*sptr2++)) >> 3) *sptr1 + + + = ((7 * (*sptr2++)) >> 3) } break; case 14: while (-count) { long tmp; tmp = *sptr2 + + ; *sptr1 + + + = (((tmp < < 4) - tmp) > > 4) tmp = *sptr2 + + ; *sptr1 + + + = (((tmp < < 4) - tmp) > > 4) tmp = *sptr2 + + ; *sptr1 + + + = (((tmp < < 4) - tmp) > > 4) tmp = *sptr2 + + ; *sptr1 + + + = (((tmp < < 4) - tmp) > > 4) break; case 15: while (-count) { *sptr1 + + + = *sptr2++; *sptr1 + + + = *sptr2++; *sptr1 + + + = *sptr2++; *sptr1 + + + = *sptr2++; } break; } } } short SnDecompress(DecodeBook, ratio, frame_size, min pitch, bstream, output) short ** DecodeBook, ratio; unsigned char * bstream; short *output, frame_size, min pitch; { short count, SampCount; register short dstate; short vcount; short vsize, cbook size, bs_size; get_compr_pars(ratio, frame size, &vsize, &cbook_size, &bs_size); dstate = *bstream++; dstate = (dstate - 128) < < 6; SampCount = 0; while((* bstream & LAST_FRAME_FLAG) = = 0) { expand(DecodeBook, frame_size, vsize, min_pitch, (struct frame *)bstream, output, SampCount); bstream + = bs_size; SampCount + = frame size; } vcount = * bstream - LAST FRAME FLAG; * bstream = * (bstream + 2 + vcount); expand(DecodeBook, frame size, vsize, min_pitch, (struct frame *)bstream, output, SampCount); * bstream = vcount + LAST FRAME FLAG; SampCount + = vcount * vsize; count = (SampCount >> 1) + 1; while (-count) { *output++ = dstate = ((IPCONS * dstate) > > 3) + *output; *output++ = dstate = ((IPCONS * dstate) > > 3) + *output; } output -= SampCount; return SampCount; } #define FILTER state + PFILT ORDER + 1 #define DC_VAL state + PFILT_ORDER + PFILT ORDER/2 + 2 void SnSampExpandFilt(short *src, short off, short Ien, char *dest, short *state) { short input, temp; long ace; register short dc = *(DC_VAL); register short *sptr1, *sptr2; src + = off; len+ +; sptrl = state; sptr2 = state + PFILT ORDER; while (-Ien) { input = *src + + - dc; dc + = input > > 5; temp = input + *sptr1 + +; /* (statelOJ + state[8]) * filterfOl */ ace = temp * '(FILTER); temp = *-sptr2 + *sptr1 + +; /* (stated] + state[7]) * filter[1] */ ace + = temp * '(FILTER +1); temp = *-sptr2 + *sptr1 + +; /* (state[2] + state[6]) * filter[2] */ ace + = temp * '(FILTER + 2); temp = *-sptr2 + *sptr1 + +; /* (state[3] + state[5]) * filter[3] */ ace + = temp * '(FILTER + 3); ace + = *sptr1 * '(FILTER + 4); /* state[4] » filter[4] */ if (ace > 0) { temp = (ace + (257 << 20)) >> 21; if (temp > 255) temp = 255; } else { temp = (ace + (255 << 20)) >> 21; if (temp < 0) temp = 0; } *dest+ + * = temp; sptrl -= 4; sptr2 -= 4; 'sptrl + + = *sptr2+ +; / * state[0] = state! 1] */ *sptr1 + + = *sptr2+ +; /* state! 1] = state[2] */ 'sptrl + + = *sptr2+ +; /* state[2] = state[3] */ *sptr1 + + = *sptr2+ + ; /* state[3] = state[4] */ *sptr1 + + = *sptr2+ +; /* state[4] = state[5] */ 'sptrl + + = *sptr2+ +; /* state[5] = state[6] */ *sptr1 + + = *sptr2+ +; /* state[6] = state[7] */ *sptr1 = input; /* state[7] = in iput */ sptrl -= 7; } f (DC v * AL) = dc; III. BLENDING MODULE /* A module for blending two diphones */ typedef struct { short Iptr, pitch; short weight, weightjnc; } bstate; void SnBlend(pitchp Ip, pitchp rp, short cur_tot, short tot, short type, bstate *bs) { #pragma unused (tot) short count; short *ptr1, *ptr2; if (type = = VOICED) { if (cur_tot) return; { short weight; long min_amdf; short bestjag = 0, lag; short window size; short weightjnc; /* First replicate the left pitch period */ ptrl = lp->bufp; ptr2 = ptrl + lp->olen; count = lp->olen + 1; while (-count) *ptr2+ + = *ptr1 + +; /* Smooth the discontinuity */ { register short en, e2; en = lp->bufp[2] + 3 * dp->bufp[0] - lp->bufp[1]) - lp->bufp[lp->olen - 1]; e2 = lp->bufp[0] - lp->bufp[lp->olen - 1]; if (en * en > e2 * e2) en = e2; ptr2 = lp->bufp + lp->olen; count = (lp->olen >> 1) + 1; while (-count) { *-ptr2 + = en; en = (((en < < 4) - en) > > 4); } } min amdf = LARGEjMUM; windowjsize = rp->olen; if (lp->olen < rp->olen) windowjsize = lp->olen; lag = rp->olen; while (-lag) { long amdf = 0; ptrl = rp- > buf p; ptr2 = lp->bufp + lag; count = ((windowjsize + 3) >> 2) + 1; while (-count) { short tmp; tmp = ('ptrl - *ptr2); if (tmp > 0) amdf + = tmp; else amdf -= tmp; ptrl + = 4; ptr2 + = 4; } if (amdf < min amdf) { bestjag = lag; min amdf = amdf; } } bs-> pitch = lp->olen; /* Update left buffer */ if (bestjag < (lp->olen >> 1)) { /* Add bestjag samples to the length of left pulse*/ lp->olen + = bestjag; } else { /* Delete a few samples from the left pulse */ lp->olen = bestjag; } bs->lptr = bestjag; weightjnc = 32767/ windowjsize; weight = 32767 - weightjnc; ptrl = rp->bufp; ptr2 = lp->bufp + bs->lptr; count = windowjsize + 1 ; while (-count) { *ptr1 + + + = (((short) (*ptr2+ + - *ptr1) * weight) > > 15); weight -= weightjnc; } ■ } } else { register short delta; /* Just blend 15 samples */ ptr2 = lp->bufp + lp->olen - 15; ptrl = rp->bufp; / * for (i = 1; i < 16; i+ +) { *ptr1 = *ptr2 + (i * (*ptr1 - *ptr2)) > > 4; ptrl + +; ptr2 + + ; } */ delta = *ptr1 - *ptr2; *ptr1 + + = *ptr2+ + + (delta > > 4); delta = *ptr1 - *ptr2; *ptr1 + + = *ptr2++ + ((delta) >> 3); delta = *ptr1 - *ptr2; *ptr1 + + = *ptr2+ + + ((3 * delta) > > 4); delta = *ptr1 - *ptr2; *ptr1 + + = *ptr2++ + (delta >> 2); delta = *ptr1 - *ptr2; *ptr1 + + = *ptr2+ + + ((5 * delta) > > 4); delta = *ptr1 - *ptr2; *ptr1 + + = *ptr2+ + + ((3 * delta) > > 8); delta = *ptr1 - *ptr2; *ptr1 + + = *ptr2+ + + ((7 * delta) > > 4); delta = *ptr1 - *ptr2; *ptr1 + + = *ptr2++ + (delta >> 1); delta = *ptr1 - *ptr2; • ptrl + + = *ptr2+ + + (((delta < < 3) + delta) > > 4); delta = *ptr1 - *ptr2; • ptrl + + = *ptr2+ + + ((5 * delta) > > 3); delta = *ptr1 - *ptr2; *ptr1 + + = *ptr2+ + + (((delta < < 3) + 3 * delta) > > 4); delta = *ptr1 - *ptr2; *ptr1 + + = *ptr2+ + + ((3 * delta) > > 2); delta = *ptr1 - *ptr2; *ptr1 + + = *ptr2+ + + (((delta < < 4) - 3 * delta) > > 4); delta = *ptr1 - *ptr2; *ptr1 + + = *ptr2+ + + ((7 * delta) > > 3); delta = *ptr1 - *ptr2; • ptrl = *ptr2 + (((delta < < 4) - delta) > > 4); lp->oien -= 15; IV. INTONATION ADJUSTMENT MODULE /* A module for deleting a pitch period */ /* Pointer src1 points to Left Pitch period Pointer src2 points to Right Pitch period Pointer dst points to Resulting Pitch period Ien = length of the pitch periods */ skipjDulses(short *srd , short *src2, short *dst, short Ien) { short i; register short weight, cweight; i = len + 1 ; weight = cweight = 32767/i; while (~i) { *dst + + = *src1 + + + (((short) ( *src2 + + - *src1 ) ' cweight) > > 1 5); cweight + = weight; } } /* A module for Inserting a pitch period */ /* Locn buffer ' curbeg] points to Left Pitch period Locn bufferlcurbeg + curlen] points to Right Pitch period Pointer dst points to Resulting Pitch period curlen = length of the pitch periods */ insert j ulse(short ' buffer, short *dst, short curlen, short curbeg) { short weight, cweight, count; short *src1 , *src2; srd = buffer + curbeg; src2 = buffer + curbeg + curlen; weight = 32767 / curlen; cweight = weight; count = curlen + 1 ; while (-count) { *dst + + = *src1 + + = *src2 + + + (((short) ( *src 1 - *src2) * cweight) > > 1 5); cweight + = weight; } } /* This module is used to change pitch information in the concatenated speech */ // This routine depends on the desired length (deslen) being at least half // and no more than twice the actual length (ien). void SnChangePitch(short *buf, short 'next, short Ien, short deslen, short Ivoe, short rvocshort dosmooth) { #pragma unused(rvoc, dosmooth) short delta; short count; short *bptr, *aptr; short weight, weightjnc; if (llvoc j j (deslen = = Ien)) return; if (deslen > Ien) { • /* Increase Pitch period */ delta = deslen - Ien; bptr = buf + Ien; aptr = buf + deslen; count = delta + 1 ; while (-count) '-aptr = '-bptr; count = Ien - delta + 1 ; weight = weightjnc — 32767 / count; while (-count) { register short tmp2; tmp2 = ( '-aptr - *-bptr); 'aptr = 'bptr + ((tmp2 * weight) > > 1 5); weight + = weightjnc; } return; /* Shorten Pitch Period */ short wsize; delta = Ien - deslen; wsize = 2 * delta; if (wsize > deslen) wsize = deslen; weightjnc = 32767 / (wsize + 1 ); weight = weightjnc; aptr = buf + deslen; bptr = buf + Ien - wsize; count = wsize - delta + 1 ; while (-count) { *bptr++ += (((short) (*aptr++ - *bptr) * weight ) >> 15); weight + = weightjnc; } aptr = buf + deslen; bptr = next; count = delta + 1 ; weight = 32767 - weight; while (-count) { *bptr+ + + = (((short) (*aptr+ + - *bptr) * weight ) > > 15); weight -= weightjnc; }

Claims: CLAIMS What is claimed is: 1 . An apparatus for synthesizing speech in response to a sequence of sound segment codes representing speech, comprising: memory storing a set of noise compensated quantization vectors; means, responsive to sound segment codes in the sequence, for identifying strings of noise compensated quantization vectors in the set for respective sound segment codes in the sequence; means, coupled to the means for identifying and the- memory, for generating a speech data sequence in response to the strings of noise compensated quantization vectors; and an audio transducer, coupled to the means for generating, to generate sound in response to the speech data sequence. 2. The apparatus of claim 1 , wherein the sound segment codes comprise data encoded using a first set of quantization vectors, and the set of noise compensated quantization vectors is different from the first set of quantization vectors. 3. The apparatus of claim 1 , wherein the noise compensated quantization vectors represent quantization of filtered sound segment data, and the means for generating a speech data sequence includes: means for applying an inverse filter to the identified strings of noise compensated quantization vectors in generation of the speech data sequence, wherein the inverse filter includes parameters chosen so that any multiplies are replaced by shift and/or add operations in application of the inverse filter. 4. The apparatus of claim 1 , wherein the noise compensated quantization vectors represent quantization of filtered sound segment data, and the means for generating a speech data sequence includes: means for applying an inverse filter to the identified strings of noise compensated quantization vectors in generation of the speech data sequence. 5. The apparatus of claim 1 , wherein the noise compensated quantization vectors represent quantization of results of linear prediction filtering of sound segment data, and the means for generating a speech data sequence includes: means for applying an inverse linear prediction filter to the identified strings of noise compensated quantization vectors in generation of the speech data sequence. 6. The apparatus of claim 1 , wherein the noise compensated quantization vectors represent quantization of results of pitch filtering of sound segment data, and the means for generating a speech data sequence includes: means for applying an inverse pitch filter to the identified strings of noise compensated quantization vectors in generation of the speech data sequence. 7. The apparatus of claim 1 , wherein the quantization vectors represent quantization of results of pitch filtering and linear prediction filtering of sound segment data, and the means for generating a speech data sequence includes: means for applying an inverse pitch filter to the identified strings of quantization vectors in generation of the speech data sequence to produce a filtered data sequence; and means for applying an inverse linear prediction filter to the filtered data sequence in generation of the speech data sequence. 8. The apparatus of claim 1 , wherein the means for generating a speech data sequence includes: means for concatenating the identified strings of quantization vectors and supplying the concatenated strings for the speech data sequence. 9. The apparatus of claim 1 , wherein the identified strings of quantization vectors have beginnings and endings, and means for generating a speech data sequence includes: means for supplying the identified strings of quantization vectors for respective sound segment codes in sequence; and means for blending the ending of an identified string of quantization vectors of a particular sound segment code in the sequence with the beginning an identified string of quantization vectors of an adjacent sound segment code in the sequence to smooth discontinuities between the particular and adjacent sound segment codes in the speech data sequence. 10. The apparatus of claim 1 , wherein the means for generating a speech data sequence includes: means, responsive to the sound segment codes for adjusting pitch and duration of the identified strings of quantization vectors in the speech data sequence. 1 1 . The apparatus of claim 1 , wherein the identified strings of quantization vectors have beginnings and endings, and means for generating a speech data sequence includes: means for supplying the identified strings of quantization vectors for respective sound segment codes in sequence; means for blending the ending of an identified string of quantization vectors of a particular sound segment code in the sequence with the beginning an identified string of quantization vectors of an adjacent sound segment code in the sequence to smooth discontinuities between the particular and adjacent sound segment codes in the speech data sequence; and means, responsive to the sound segment codes for adjusting pitch and duration of the identified strings of quantization vectors in the speech data sequence. 1 2. The apparatus of claim 1 , further including an encoder including: a store for an encoding set of quantization vectors different from the set of noise compensated quantization vectors used in decoding; and means for generating the sound segment codes in response to the encoding set and sound segment data. 13. The apparatus of claim 1 2, wherein the encoder further includes a linear prediction filter. 14. The apparatus of claim 1 2, wherein the encoder further includes a pitch filter. 1 5. The apparatus of claim 1 2, wherein the encoder further includes a linear prediction filter and a pitch filter. 1 6. An apparatus for synthesizing speech in response to a text, comprising: means for translating text to a sequence of sound segment codes; memory storing a set of quantization vectors; means, responsive to sound segment codes in the sequence, for identifying strings of quantization vectors in the set for respective sound segment codes in the sequence; means, coupled to the means for identifying and the memory, for generating a speech data sequence in response to the strings of quantization vectors; and an audio transducer, coupled to the means for generating, to generate sound in response to the speech data sequence. 1 7. The apparatus of claim 1 6, wherein the sound segment codes comprise data encoded using a first set of quantization vectors, and the set of noise compensated quantization vectors is different from the first set of quantization vectors. 1 8. The apparatus of claim 1 6, wherein the noise compensated quantization vectors represent quantization of filtered sound segment data, and the means for generating a speech data sequence includes: means for applying an inverse filter to the identified strings of noise compensated quantization vectors in generation of the speech data sequence, wherein the inverse filter includes parameters chosen so that any multiplies are replaced by shift and/or add operations in application of the inverse filter. 1 9. The apparatus of claim 1 6, wherein means for translating includes an table of encoded diphones, having entries including data identifying a string of quantization vectors in the set for respective diphones, and the sequence of sound segment codes comprises a sequence of indices to the table of encoded diphones representing the text; and the means for identifying strings of quantization vectors includes means responsive to the sound segment codes for accessing the entries in the table of encoded diphones. 20. The apparatus of claim 1 6, wherein the quantization vectors represent quantization of filtered sound segment data, and the means for generating a speech data sequence includes: means for applying an inverse filter to the identified strings of quantization vectors in generation of the speech data sequence. 21 . The apparatus of claim 1 6, wherein the quantization vectors represent quantization of results of linear prediction filtering of sound segment data, and the means for generating a speech data sequence includes: means for applying a inverse linear prediction filter to the identified strings of quantization vectors in generation of the speech data sequence. 22. The apparatus of claim 1 6, wherein the quantization vectors represent quantization of results of pitch filtering of sound segment data, and the means for generating a speech data sequence includes: means for applying an inverse pitch filter to the identified strings of quantization vectors in generation of the speech data sequence. 23. The apparatus of claim 1 6, wherein the quantization vectors represent quantization of results of pitch filtering and linear prediction filtering of sound segment data, and the means for generating a speech data sequence includes: means for applying an inverse pitch filter to the identified strings of quantization vectors in generation of the speech data sequence to produce a filtered data sequence; and means for applying a inverse linear prediction filter to the filtered data sequence in generation of the speech data sequence. 24. The apparatus of claim 1 6, wherein the means for generating a speech data sequence includes: means for concatenating the identified strings of quantization vectors and supplying the concatenated strings for the speech data sequence. 25. The apparatus of claim 1 6, wherein the identified strings of quantization vectors have beginnings and endings, and means for generating a speech data sequence includes: means for supplying the identified strings of quantization vectors for respective sound segment codes in sequence; and means for blending the ending of an identified string of quantization vectors of a particular sound segment code in the sequence with the beginning an identified string of quantization vectors of an adjacent sound segment code in the sequence to smooth discontinuities between the particular and adjacent sound segment codes in the speech data sequence. 26. The apparatus of claim 1 6, wherein the means for generating a speech data sequence includes: means, responsive to the sound segment codes for adjusting pitch and duration of the identified strings of quantization vectors in the speech data sequence. 27. The apparatus of claim 1 6, wherein the identified strings of quantization vectors have beginnings and endings, and means for generating a speech data sequence includes: means for supplying the identified strings of quantization vectors for respective sound segment codes in sequence; means for blending the ending of an identified string of quantization vectors of a particular sound segment code in the sequence with the beginning an identified string of quantization vectors of an adjacent sound segment code in the sequence to smooth discontinuities between the particular and adjacent sound segment codes in the speech data sequence; and means, responsive to the sound segment codes for adjusting pitch and duration of the identified strings of quantization vectors in the speech data sequence. 28. The apparatus of claim 1 6, further including an encoder including: a store for an encoding set of quantization vectors different from the set of noise compensated quantization vectors used in decoding; and means for generating the sound segment codes in response to the encoding set and sound segment data. 29. The apparatus of claim 28, wherein the encoder further includes a linear prediction filter. 30. The apparatus of claim 28, wherein the encoder further includes a pitch filter. 31 . The apparatus of claim 28, wherein the encoder further includes a linear prediction filter and a pitch filter. 32. An apparatus for synthesizing speech in response to a text, comprising: a programmable processor to execute routines to produce a speech data sequence; an audio transducer, coupled to the processor, to generate sound in response to the speech data sequence; a table memory, coupled to the processor, storing a set of noise compensated quantization vectors, and a table of encoded diphones having entries including data identifying a string of noise compensated quantization vectors in the set for respective diphones; and an instruction memory, coupled to the processor, storing a translator routine for execution by the processor to translate text to a sequence of diphone indices, and a decoder routine for execution by the processor including means, responsive to diphone indices in the sequence, for accessing the table of encoded diphones to identify strings of quantization vectors in the set for diphones in the text; and means, coupled to the means for accessing and the memory, for retrieving the identified strings of quantization vectors; means, coupled with the means for retrieving, for producing diphone data strings in response to the identified strings of quantization vectors, wherein the diphone data strings have beginnings and endings; means, coupled to the means for retrieving, for blending the ending of a particular diphone data string in the sequence with the beginning of an adjacent diphone data string in the sequence to smooth discontinuities between the particular and adjacent diphone data strings to produce a smoothed string of quantized speech data; and means, responsive to the text and the smoothed string of quantized speech data, for adjusting pitch and duration of the identified strings of quantization vectors for the diphones in the sequence to produce the sound data sequence for supply to the audio transducer. 33. The apparatus of claim 32, wherein the sound segment codes comprise data encoded using a first set of quantization vectors, and the set of noise compensated quantization vectors is different from the first set of quantization vectors. 34. The apparatus of claim 32, wherein the noise compensated quantization vectors represent quantization of filtered sound segment data, and the means for generating a speech data sequence includes: means for applying an inverse filter to the identified strings of noise compensated quantization vectors in generation of the speech data sequence, wherein the inverse filter includes parameters chosen so that any multiplies are replaced by shift and/or add operations in application of the inverse filter. 35. The apparatus of claim 32, wherein the quantization vectors represent quantization of filtered sound segment data, and the means for producing diphone data strings includes: means for applying an inverse filter to the identified strings of quantization vectors. 36. The apparatus of claim 32, wherein the quantization vectors represent quantization of results of linear prediction filtering of sound segment data, and the means for producing diphone data strings includes: means for applying a inverse linear prediction filter to the identified strings of quantization vectors. 37. The apparatus of claim 32, wherein the quantization vectors represent quantization of results of pitch filtering of sound segment data, and the means for producing diphone data strings includes: means for applying an inverse pitch filter to the identified strings of quantization vectors. 38. The apparatus of claim 32, wherein the quantization vectors represent quantization of results of pitch filtering and linear prediction filtering of sound segment data, and the means for producing diphone data strings includes: means for applying an inverse pitch filter to the identified strings of quantization vectors to produce a filtered data sequence; and means for applying a inverse linear prediction filter to the filtered data sequence.

Inventors: NARAYAN SHANKAR, NARAYAN, SHANKAR
Applicants: APPLE COMPUTER, NARAYAN SHANKAR, APPLE COMPUTER, INC., NARAYAN, SHANKAR
Application year: 1994
Main classification: G10L5
IPC codes: G10L13, G10L19, H03H7