00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef AUDIOCHANNEL_H_INCLUDED
00020 #define AUDIOCHANNEL_H_INCLUDED
00021
00022 namespace Pentagram {
00023
00024 class AudioSample;
00025
00026 class AudioChannel
00027 {
00028
00029
00030
00031 uint8 *playdata;
00032 uint32 playdata_size;
00033 uint32 decompressor_size;
00034 uint32 frame_size;
00035
00036 uint32 sample_rate;
00037 bool stereo;
00038
00039 sint32 loop;
00040 AudioSample *sample;
00041
00042
00043 uint32 frame_evenodd;
00044 uint32 frame0_size;
00045 uint32 frame1_size;
00046 uint32 position;
00047 int lvol, rvol;
00048 uint32 pitch_shift;
00049 int priority;
00050 bool paused;
00051
00052 public:
00053 AudioChannel(uint32 sample_rate, bool stereo);
00054 ~AudioChannel(void);
00055
00056 void stop() { sample = 0; }
00057
00058 void playSample(AudioSample *sample, int loop, int priority, bool paused, uint32 pitch_shift, int lvol, int rvol);
00059 void resampleAndMix(sint16 *stream, uint32 bytes);
00060
00061 bool isPlaying() { return sample != 0; }
00062
00063 void setPitchShift(int pitch_shift_) { pitch_shift = pitch_shift_; }
00064 uint32 getPitchShift() const { return pitch_shift; }
00065
00066 void setLoop(int loop_) { loop = loop_; }
00067 sint32 getLoop() const { return loop;}
00068
00069 void setVolume(int lvol_, int rvol_) { lvol = lvol_; rvol = rvol_; }
00070 void getVolume(int &lvol_, int &rvol_) const { lvol_ = lvol; rvol_ = rvol; }
00071
00072 void setPriority(int priority_) { priority = priority_; }
00073 int getPriority() const { return priority; }
00074
00075 void setPaused(bool paused_) { paused = paused_; }
00076 bool isPaused() const { return paused; }
00077 private:
00078
00079
00080 void DecompressNextFrame();
00081
00082
00083
00084
00085 class CubicInterpolator {
00086 protected:
00087 int x0, x1, x2, x3;
00088 int a, b, c, d;
00089
00090 public:
00091 CubicInterpolator() : x0(0), x1(0), x2(0), x3(0)
00092 {
00093 updateCoefficients();
00094 }
00095
00096 CubicInterpolator(int a0, int a1, int a2, int a3) : x0(a0), x1(a1), x2(a2), x3(a3)
00097 {
00098 updateCoefficients();
00099 }
00100
00101 CubicInterpolator(int a1, int a2, int a3) : x0(2*a1-a2), x1(a1), x2(a2), x3(a3)
00102 {
00103
00104 updateCoefficients();
00105 }
00106
00107 inline void init(int a0, int a1, int a2, int a3)
00108 {
00109 x0 = a0;
00110 x1 = a1;
00111 x2 = a2;
00112 x3 = a3;
00113 updateCoefficients();
00114 }
00115
00116 inline void init(int a1, int a2, int a3)
00117 {
00118
00119 x0 = 2*a1-a2;
00120 x1 = a1;
00121 x2 = a2;
00122 x3 = a3;
00123 updateCoefficients();
00124 }
00125
00126 inline void feedData()
00127 {
00128 x0 = x1;
00129 x1 = x2;
00130 x2 = x3;
00131 x3 = 2*x2-x1;
00132 updateCoefficients();
00133 }
00134
00135 inline void feedData(int xNew)
00136 {
00137 x0 = x1;
00138 x1 = x2;
00139 x2 = x3;
00140 x3 = xNew;
00141 updateCoefficients();
00142 }
00143
00144
00145 inline int interpolate(uint32 fp_pos)
00146 {
00147 int result = 0;
00148 int t = fp_pos >> 8;
00149 result = (a*t + b) >> 8;
00150 result = (result * t + c) >> 8;
00151 result = (result * t + d) >> 8;
00152 result = (result/3 + 1) >> 1;
00153
00154 return result;
00155 }
00156
00157 protected:
00158 inline void updateCoefficients()
00159 {
00160 a = ((-x0*2)+(x1*5)-(x2*4)+x3);
00161 b = ((x0+x2-(2*x1))*6) << 8;
00162 c = ((-4*x0)+x1+(x2*4)-x3) << 8;
00163 d = (x1*6) << 8;
00164 }
00165 };
00166
00167
00168 CubicInterpolator interp_l;
00169 CubicInterpolator interp_r;
00170 int fp_pos;
00171 int fp_speed;
00172
00173 void resampleFrameM8toS(sint16 *&samples, uint32 &bytes);
00174 void resampleFrameM8toM(sint16 *&samples, uint32 &bytes);
00175
00176
00177
00178 };
00179
00180 };
00181
00182 #endif