91 #include <propeller.h>
95 #define INLINE__ static inline
96 #define Yield__() __asm__ volatile( "" ::: "memory" )
97 #define PostEffect__(X, Y) __extension__({ int32_t tmp__ = (X); (X) = (Y); tmp__; })
99 #define INLINE__ static
100 static int32_t tmp__;
101 #define PostEffect__(X, Y) (tmp__ = (X), (X) = (Y), tmp__)
103 #define waitcnt(n) _waitcnt(n)
104 #define coginit(id, code, par) _coginit((unsigned)(par)>>2, (unsigned)(code)>>2, id)
105 #define cognew(code, par) coginit(0x8, (code), (par))
106 #define cogstop(i) _cogstop(i)
109 INLINE__ int32_t Min__(int32_t a, int32_t b) {
return a < b ? a : b; }
110 INLINE__ int32_t Max__(int32_t a, int32_t b) {
return a > b ? a : b; }
111 INLINE__ int32_t Shr__(uint32_t a, uint32_t b) {
return (a>>b); }
113 static uint8_t dat[] = {
114 0x00, 0x1a, 0xfe, 0xa0, 0x0a, 0x01, 0xbc, 0x80, 0x00, 0x18, 0xfe, 0xe4, 0x1e, 0x48, 0xfe, 0xa0,
115 0xd4, 0x9a, 0xbe, 0xa0, 0x0b, 0x09, 0xbc, 0x80, 0x01, 0x48, 0x7e, 0x61, 0x02, 0x08, 0xf0, 0x84,
116 0x04, 0x48, 0xfe, 0xe4, 0xc6, 0xd6, 0xbe, 0xa0, 0x0d, 0x48, 0xfe, 0xa0, 0x08, 0x4a, 0xfe, 0xa0,
117 0xe9, 0xd8, 0xbe, 0xa0, 0x0b, 0x19, 0xbc, 0x80, 0x0c, 0x4a, 0xfe, 0xe4, 0x08, 0x18, 0xfc, 0x84,
118 0x01, 0xd6, 0xfd, 0x80, 0x01, 0xda, 0xfd, 0x80, 0x01, 0xe0, 0xfd, 0x80, 0x0b, 0x48, 0xfe, 0xe4,
119 0xc6, 0xa6, 0xbf, 0xa0, 0xf0, 0x49, 0xbe, 0xa0, 0x08, 0x48, 0xfe, 0x80, 0x04, 0x4a, 0xfe, 0xa0,
120 0x24, 0xed, 0xbf, 0x08, 0x04, 0x48, 0xfe, 0x80, 0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a0,
143 0x24, 0x41, 0xbe, 0xa4, 0xf2, 0x48, 0xbe, 0xa0, 0x03, 0x48, 0xfe, 0x38, 0x24, 0x2f, 0xbe, 0x80,
144 0x01, 0x48, 0xfe, 0x38, 0x24, 0x2f, 0xbe, 0x80, 0x32, 0x49, 0xbe, 0xa0, 0x01, 0x48, 0xfe, 0x28,
145 0x24, 0x2f, 0xbe, 0x80, 0x31, 0x49, 0xbe, 0xa0, 0x17, 0x4b, 0xbe, 0xa0, 0xc7, 0xd6, 0xfe, 0x5c,
146 0x24, 0x45, 0xbe, 0x80, 0x82, 0x00, 0x3c, 0x5c, 0x83, 0x00, 0x00, 0x00, 0x21, 0x04, 0xfd, 0x5c,
147 0xf0, 0x23, 0xbe, 0xa0, 0x20, 0x22, 0xfe, 0x80, 0x10, 0x23, 0xbe, 0x80, 0x11, 0x27, 0xbe, 0x08,
148 0x03, 0x27, 0xbe, 0x62, 0x91, 0x00, 0x54, 0x5c, 0xbc, 0x1a, 0xbd, 0xa0, 0x0d, 0x24, 0xfe, 0xa0,
149 0x21, 0x04, 0xfd, 0x5c, 0x33, 0x4d, 0xbe, 0xa0, 0x0b, 0x1b, 0xbd, 0x80, 0x8c, 0x24, 0xfe, 0xe4,
150 0x83, 0x00, 0x7c, 0x5c, 0x01, 0x26, 0xfe, 0x80, 0x13, 0x29, 0xbe, 0xa0, 0x33, 0x39, 0xfd, 0x50,
151 0x26, 0x3b, 0xfd, 0x54, 0x33, 0x3d, 0xfd, 0x54, 0x40, 0x4d, 0xfd, 0x54, 0x03, 0x22, 0xfe, 0x80,
152 0x0d, 0x24, 0xfe, 0xa0, 0x21, 0x04, 0xfd, 0x5c, 0x11, 0x49, 0xbe, 0x00, 0x18, 0x48, 0xfe, 0x2c,
153 0x33, 0x4b, 0xbe, 0xa0, 0x25, 0x4d, 0xbe, 0xa0, 0x24, 0x67, 0xbe, 0xa0, 0x25, 0x49, 0xbe, 0x85,
154 0x24, 0x49, 0xbe, 0xb0, 0x01, 0xfe, 0x7f, 0x36, 0x08, 0x4a, 0xfe, 0xa0, 0x01, 0x48, 0xfe, 0x2d,
155 0x13, 0x49, 0xb2, 0x80, 0xa3, 0x4a, 0xfe, 0xe4, 0x24, 0x81, 0xbe, 0xbc, 0x01, 0x38, 0xfd, 0x80,
156 0x0a, 0x3b, 0xbd, 0x80, 0x0a, 0x3d, 0xbd, 0x80, 0x0a, 0x4d, 0xbd, 0x80, 0x01, 0x22, 0xfe, 0x80,
157 0x99, 0x24, 0xfe, 0xe4, 0x21, 0x04, 0xfd, 0x5c, 0xbd, 0x62, 0xbd, 0xa0, 0x0d, 0x24, 0xfe, 0xa0,
158 0x21, 0x04, 0xfd, 0x5c, 0x40, 0x4d, 0xbe, 0x80, 0x0b, 0x63, 0xbd, 0x80, 0xb0, 0x24, 0xfe, 0xe4,
159 0x13, 0x29, 0xbe, 0x80, 0x02, 0x29, 0x3e, 0x61, 0xad, 0x00, 0x4c, 0x5c, 0x10, 0x22, 0xfe, 0x84,
160 0x11, 0xff, 0x3f, 0x08, 0x10, 0x20, 0xfe, 0x80, 0x7f, 0x20, 0xfe, 0x60, 0x83, 0x00, 0x7c, 0x5c,
161 0x33, 0x4d, 0xbe, 0xa0, 0x40, 0x4d, 0xbe, 0x80, 0x24, 0x4b, 0xbe, 0xa0, 0x10, 0x4a, 0xfe, 0x28,
162 0x1c, 0x48, 0xfe, 0x28, 0x08, 0x4b, 0xbe, 0x60, 0x05, 0x4b, 0xbe, 0x68, 0x25, 0x4b, 0xbe, 0x04,
163 0x04, 0x4b, 0xbe, 0x68, 0x24, 0x4b, 0xbe, 0x2c, 0x00, 0x00, 0x7c, 0x5c, 0x13, 0x4a, 0xfe, 0x28,
164 0x07, 0x4b, 0x3e, 0x62, 0x09, 0x4b, 0x3e, 0x61, 0x25, 0x4b, 0xbe, 0xb0, 0x06, 0x4b, 0xbe, 0x68,
165 0x01, 0x4a, 0xfe, 0x2c, 0x25, 0x4b, 0xbe, 0x04, 0x25, 0x4b, 0xbe, 0xbc, 0x0f, 0x4a, 0xfe, 0x2c,
166 0x11, 0x48, 0xfe, 0x28, 0x0f, 0x4a, 0xfe, 0x38, 0x0e, 0x4a, 0xfe, 0x2c, 0x4d, 0x01, 0x7c, 0x5c,
167 0x01, 0x48, 0xfe, 0x39, 0x25, 0x49, 0xb2, 0x80, 0x01, 0x44, 0xfe, 0x38, 0x22, 0x49, 0xbe, 0xa0,
168 0x03, 0x48, 0xfe, 0x38, 0x24, 0x45, 0xbe, 0x80, 0x22, 0x49, 0xbe, 0xa0, 0x04, 0x48, 0xfe, 0x38,
169 0x24, 0x45, 0xbe, 0x80, 0x01, 0x46, 0xfe, 0x38, 0x23, 0x49, 0xbe, 0xa0, 0x03, 0x48, 0xfe, 0x38,
170 0x24, 0x47, 0xbe, 0x80, 0x23, 0x49, 0xbe, 0xa0, 0x04, 0x48, 0xfe, 0x38, 0x24, 0x47, 0xbe, 0x80,
171 0x22, 0x49, 0xbe, 0xa0, 0x23, 0x45, 0xbe, 0x84, 0x24, 0x47, 0xbe, 0x80, 0x00, 0x43, 0xbe, 0x85,
172 0x6d, 0x01, 0x7c, 0x5c, 0x21, 0x43, 0xbe, 0xa1, 0x23, 0x49, 0xbe, 0xa0, 0x01, 0x48, 0xfe, 0x38,
173 0x22, 0x4b, 0xbe, 0xa0, 0x01, 0x4a, 0xfe, 0x38, 0x24, 0x45, 0xbe, 0x94, 0x25, 0x47, 0xbe, 0x90,
174 0xf4, 0x42, 0xbe, 0x94, 0x00, 0x00, 0x92, 0x66, 0x01, 0x00, 0x00, 0x00, 0x00, 0x10, 0x06, 0x80,
175 0x76, 0x14, 0x90, 0x4b, 0x6d, 0xe1, 0xec, 0x27, 0x50, 0x47, 0x44, 0x14, 0x0c, 0x35, 0x2c, 0x0a,
176 0x85, 0x5f, 0x17, 0x05, 0x79, 0xd8, 0x8b, 0x02, 0x54, 0xf1, 0x45, 0x01, 0x4d, 0xf9, 0xa2, 0x00,
177 0xbb, 0x7c, 0x51, 0x00, 0x60, 0xbe, 0x28, 0x00, 0x30, 0x5f, 0x14, 0x00, 0x98, 0x2f, 0x0a, 0x00,
178 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0xff, 0x00,
179 0x00, 0x00, 0x01, 0x00, 0x00, 0xd0, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00,
180 0xfe, 0x0f, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x01, 0x02, 0x00, 0x00,
181 0xe3, 0x00, 0x00, 0x00,
183 int32_t VocalTract_start(
VocalTract *
self, int32_t tract_ptr, int32_t pos_pin, int32_t neg_pin, int32_t fm_offset)
193 VocalTract_stop(
self);
195 self->tract = tract_ptr;
200 if( (pos_pin < 0) && (neg_pin > -1) )
205 if( pos_pin == neg_pin)
211 if (pos_pin > (-1)) {
212 (&
self->dira_)[((Shr__(pos_pin, 5)) & 0x1)] = (&self->dira_)[((Shr__(pos_pin, 5)) & 0x1)] | ((1<<pos_pin));
213 self->ctrb_ = 402653184 + (pos_pin & 0x3f);
214 if (neg_pin > (-1)) {
215 (&
self->dira_)[((Shr__(neg_pin, 5)) & 0x1)] = (&
self->dira_)[((Shr__(neg_pin, 5)) & 0x1)] | ((1<<neg_pin));
216 self->ctrb_ =
self->ctrb_ + (67108864 + ((neg_pin & 0x3f) << 9));
220 if (fm_offset > (-1)) {
221 self->ctra_ = 92274688;
226 for(_idx__0001 = 0; _idx__0001 < 33; _idx__0001++) {
227 self->frqa_ =
self->frqa_ << 1;
229 fm_offset = fm_offset -
CLKFREQ;
232 fm_offset = fm_offset << 1;
238 return (self->cog =
cognew((int32_t)(&(*(int32_t *)&dat[0])), (int32_t)(&
self->attenuation)) + 1);
246 cogstop((PostEffect__(self->cog, 0) - 1));
248 memset( (
void *)&self->index, 0,
sizeof(int32_t)*0x29);
252 int32_t VocalTract_set_attenuation(
VocalTract *
self, int32_t level)
255 self->attenuation = level;
259 int32_t VocalTract_set_pace(
VocalTract *
self, int32_t percentage)
262 self->pace = percentage;
266 int32_t VocalTract_go(
VocalTract *
self, int32_t time)
272 while (self->frames[self->index]) {
276 memcpy( (
void *)(
void *)(((int32_t)(&self->frames[self->index]) + 3)), (
void *)self->tract, 1*(13));
278 self->frames[
self->index] =
self->frames[
self->index] | (16777216 / (Max__(((time * 100) / self->pace), 2)));
279 self->index = (
self->index + frame_longs) & 0x1f;
287 return self->frames[
self->index];
296 for(i = 0; i <= 0x7; i++) {
297 if (self->frames[(i * frame_longs)]) {
305 int32_t VocalTract_sample_ptr(
VocalTract *
self)
309 return (int32_t)(&
self->sample);
316 return (self->cog - 1);