]> icculus.org git repositories - taylor/freespace2.git/blob - include/codec1.h
re-add PXO sources to project files
[taylor/freespace2.git] / include / codec1.h
1 //                              Codec1.h
2 //
3 // Contains interface definition of VoiCTech (Voice Communications Technology)
4 // voice encoder/decoder.
5 //
6 // Written by Matthew F. Storch, Ph.D., copyright (c) 1998 Volition Inc.
7
8
9 //////////////////////////////////////////////////////////////////////////////
10 //
11 // Introduction to the VoiCTech encoder
12 // ------------------------------------
13 // The VoiCTech (short for Voice Communication Technology, pronounced
14 // "voice-tech") audio codec uses two separate algorithm suites: Codec1
15 // and LPC-10.  Codec1 does compression without using traditional signal 
16 // processing algorithms (expcept for a simple FIR low-pass filter).  As
17 // a result, it is extremely fast, and yields moderate-quality voice at a
18 // compression ratio of between 3-to-1 and 10-to-1, assuming 11KHz sampled
19 // data.  LPC-10 does significantly more analysis and is therefore slower
20 // (approximately 3 times slower than Codec1), but achieves substantially
21 // better compression (25-1) at a comparable quality.  (However, the
22 // *character* of the loss in quality is quite different.)
23 //
24 // The externally-callable interface for both algorithm suites is through
25 // a simple, generic front-end that is prototyped in this file.    
26 //
27 // codec1.cpp contains the implementions of both the generic interface and
28 // Codec1. LPC-10 is implemented in a set of files in the LPC10 subdirectory.
29 //
30 //////////////////////////////////////////////////////////////////////////////
31
32
33 // VoiCTech is only intended to work with 8-bit samples recorded at 11KHz.
34 // 8KHz should also work.
35 typedef unsigned char t_Sample;
36
37 // Algorithm suites.
38 enum t_Code { e_cCodec1, e_cLPC10 };
39
40 // One of these is passed with every buffer that is transmitted; it contains
41 // data on how to decode the buffer.
42 struct t_CodeInfo { t_Code Code; double Gain; };
43
44
45 // WARNING ***** DANGER ***** WARNING ***** DANGER ***** WARNING ***** DANGER
46 // If LPC-10 is used, all buffers must be a multiple of LFRAME (Frame length
47 // for LPC-10 codec) in length
48 #define LFRAME 180
49 // WARNING ***** DANGER ***** WARNING ***** DANGER ***** WARNING ***** DANGER
50
51
52 //////////////////////////////////////////////////////////////////////////////
53 // InitDecoder must be called once to initialize the decoder.
54 // Input: 
55 //     QoS      - Quality of Service: 1..10, 1 = highest compression/lowest
56 //                quality, 10 = worst compression/best quality (currently
57 //                *not* used by decoder)
58 //     tempBuf  - Temporary buffer that must be available until Encode() will
59 //                no longer be called.  Must be at least as large as the 
60 //                largest sizeIn that will be passed to Encode().
61 // Output:
62 //     initializes global variables
63 //
64 void InitDecoder(int QoS, t_Sample* tempBuf); 
65 //
66 //////////////////////////////////////////////////////////////////////////////
67
68
69 //////////////////////////////////////////////////////////////////////////////
70 // Decode is the main decoder entry point.
71 // Input:
72 //     codeInfo   - Information about how the buffer was encoded
73 //     bufIn      - Encoded data to decode
74 //     bufOut     - Empty buffer in which to place decoded data (should be
75 //                  at least decodeSize in length)
76 //     encodeSize - Size in bytes of encoded data in bufIn
77 //     decodeSize - Size data should be after decoding
78 // Output:
79 //     bufOut     - Decoded data written here
80 //     returns    - Nothing
81 //
82 void Decode(t_CodeInfo* codeInfo, t_Sample* bufIn, t_Sample* bufOut, 
83             int encodeSize, int decodeSize);
84 //
85 //////////////////////////////////////////////////////////////////////////////
86
87
88 //////////////////////////////////////////////////////////////////////////////
89 // InitEncoder must be called once to initialize the encoder.  May safely be
90 // called again to change tuning parameters.
91 // Input: 
92 //     code     - The algorithm that will be used to encode the data in
93 //                subsequent calls to Encode() 
94 //     QoS      - Quality of Service: 1..10, 1 = highest compression/lowest
95 //                quality, 10 = worst compression/best quality
96 //     tempBuf1 - Temporary buffer that must be available until Encode() will
97 //                no longer be called.  Must be at least as large as the 
98 //                largest sizeIn that will be passed to Encode().
99 //     tempBuf2 - Another temporary buffer (cannot be the same buffer as
100 //                tempBuf1) with same lifetime and size as tempBuf1.
101 // Output:
102 //     initializes global variables
103 //
104 void InitEncoder(t_Code code, int QoS, t_Sample* tempBuf1, t_Sample* tempBuf2);
105 //
106 //////////////////////////////////////////////////////////////////////////////
107
108
109 //////////////////////////////////////////////////////////////////////////////
110 // Encode is the main Encoder entry point.
111 // Input: 
112 //     bufIn    - encoded data to decode
113 //     bufOut   - empty buffer in which to place decoded data
114 //     sizeIn   - size of bufIn in bytes
115 //     sizeOut  - size of bufOut in bytes
116 // Output:
117 //     bufOut   - encoded data written here
118 //     returns  - number of bytes written to bufOut
119 //
120 #if defined(CODEC_DEMO)
121 // Test program version
122 int Encode(t_Sample* bufIn, t_Sample* bufOut, int sizeIn, int sizeOut,
123                    t_CodeInfo* codeInfo,
124            t_Sample* levels, int* modes, int samples[9], int storage[9]);
125 #else
126 // Release version
127 int Encode(t_Sample* bufIn, t_Sample* bufOut, int sizeIn, int sizeOut,
128                    t_CodeInfo* codeInfo);
129 #endif
130 //
131 //////////////////////////////////////////////////////////////////////////////
132