No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

800 líneas
19KB

  1. #include "AudioStream.h"
  2. #include "arm_math.h"
  3. // When changing multiple audio object settings that must update at
  4. // the same time, these functions allow the audio library interrupt
  5. // to be disabled. For example, you may wish to begin playing a note
  6. // in response to reading an analog sensor. If you have "velocity"
  7. // information, you might start the sample playing and also adjust
  8. // the gain of a mixer channel. Use AudioNoInterrupts() first, then
  9. // make both changes to the 2 separate objects. Then allow the audio
  10. // library to update with AudioInterrupts(). Both changes will happen
  11. // at the same time, because AudioNoInterrupts() prevents any updates
  12. // while you make changes.
  13. #define AudioNoInterrupts() (NVIC_DISABLE_IRQ(IRQ_SOFTWARE))
  14. #define AudioInterrupts() (NVIC_ENABLE_IRQ(IRQ_SOFTWARE))
  15. // waveforms.c
  16. extern "C" {
  17. extern const int16_t AudioWaveformSine[257];
  18. extern const int16_t AudioWaveformTriangle[257];
  19. extern const int16_t AudioWaveformSquare[257];
  20. extern const int16_t AudioWaveformSawtooth[257];
  21. }
  22. // windows.c
  23. extern "C" {
  24. extern const int16_t AudioWindowHanning256[];
  25. extern const int16_t AudioWindowBartlett256[];
  26. extern const int16_t AudioWindowBlackman256[];
  27. extern const int16_t AudioWindowFlattop256[];
  28. extern const int16_t AudioWindowBlackmanHarris256[];
  29. extern const int16_t AudioWindowNuttall256[];
  30. extern const int16_t AudioWindowBlackmanNuttall256[];
  31. extern const int16_t AudioWindowWelch256[];
  32. extern const int16_t AudioWindowHamming256[];
  33. extern const int16_t AudioWindowCosine256[];
  34. extern const int16_t AudioWindowTukey256[];
  35. }
  36. class AudioAnalyzeFFT256 : public AudioStream
  37. {
  38. public:
  39. AudioAnalyzeFFT256(uint8_t navg = 8, const int16_t *win = AudioWindowHanning256)
  40. : AudioStream(1, inputQueueArray), window(win),
  41. prevblock(NULL), count(0), naverage(navg), outputflag(false) { init(); }
  42. bool available() {
  43. if (outputflag == true) {
  44. outputflag = false;
  45. return true;
  46. }
  47. return false;
  48. }
  49. virtual void update(void);
  50. //uint32_t cycles;
  51. int32_t output[128] __attribute__ ((aligned (4)));
  52. private:
  53. void init(void);
  54. const int16_t *window;
  55. audio_block_t *prevblock;
  56. int16_t buffer[512] __attribute__ ((aligned (4)));
  57. uint8_t count;
  58. uint8_t naverage;
  59. bool outputflag;
  60. audio_block_t *inputQueueArray[1];
  61. };
  62. #ifdef ORIGINAL_AUDIOSYNTHWAVEFORM
  63. class AudioSynthWaveform : public AudioStream
  64. {
  65. public:
  66. AudioSynthWaveform(const int16_t *waveform)
  67. : AudioStream(0, NULL), wavetable(waveform), magnitude(0), phase(0)
  68. , ramp_down(0), ramp_up(0), ramp_mag(0), ramp_length(0)
  69. { }
  70. void frequency(float freq) {
  71. if (freq > AUDIO_SAMPLE_RATE_EXACT / 2 || freq < 0.0) return;
  72. phase_increment = (freq / AUDIO_SAMPLE_RATE_EXACT) * 4294967296.0f;
  73. }
  74. void amplitude(float n) { // 0 to 1.0
  75. if (n < 0) n = 0;
  76. else if (n > 1.0) n = 1.0;
  77. // Ramp code
  78. if(magnitude && (n == 0)) {
  79. ramp_down = ramp_length;
  80. ramp_up = 0;
  81. last_magnitude = magnitude;
  82. }
  83. else if((magnitude == 0) && n) {
  84. ramp_up = ramp_length;
  85. ramp_down = 0;
  86. }
  87. // set new magnitude
  88. magnitude = n * 32767.0;
  89. }
  90. virtual void update(void);
  91. void set_ramp_length(uint16_t r_length);
  92. private:
  93. const int16_t *wavetable;
  94. uint16_t magnitude;
  95. uint16_t last_magnitude;
  96. uint32_t phase;
  97. uint32_t phase_increment;
  98. uint32_t ramp_down;
  99. uint32_t ramp_up;
  100. uint32_t ramp_mag;
  101. uint16_t ramp_length;
  102. };
  103. #else
  104. #define AUDIO_SAMPLE_RATE_ROUNDED (44118)
  105. #define DELAY_PASSTHRU -1
  106. #define TONE_TYPE_SINE 0
  107. #define TONE_TYPE_SAWTOOTH 1
  108. #define TONE_TYPE_SQUARE 2
  109. #define TONE_TYPE_TRIANGLE 3
  110. class AudioSynthWaveform :
  111. public AudioStream
  112. {
  113. public:
  114. AudioSynthWaveform(void) :
  115. AudioStream(0,NULL),
  116. tone_freq(0), tone_phase(0), tone_incr(0), tone_type(0),
  117. ramp_down(0), ramp_up(0), ramp_length(0)
  118. {
  119. }
  120. // Change the frequency on-the-fly to permit a phase-continuous
  121. // change between two frequencies.
  122. void frequency(int t_hi)
  123. {
  124. tone_incr = (0x100000000LL*t_hi)/AUDIO_SAMPLE_RATE_EXACT;
  125. }
  126. // If ramp_length is non-zero this will set up
  127. // either a rmap up or a ramp down when a wave
  128. // first starts or when the amplitude is set
  129. // back to zero.
  130. // Note that if the ramp_length is N, the generated
  131. // wave will be N samples longer than when it is not
  132. // ramp
  133. void amplitude(float n) { // 0 to 1.0
  134. if (n < 0) n = 0;
  135. else if (n > 1.0) n = 1.0;
  136. // Ramp code
  137. if(tone_amp && (n == 0)) {
  138. ramp_down = ramp_length;
  139. ramp_up = 0;
  140. last_tone_amp = tone_amp;
  141. }
  142. else if((tone_amp == 0) && n) {
  143. ramp_up = ramp_length;
  144. ramp_down = 0;
  145. // reset the phase when the amplitude was zero
  146. // and has now been increased. Note that this
  147. // happens even if the wave is not ramped
  148. // so that the signal starts at zero
  149. tone_phase = 0;
  150. }
  151. // set new magnitude
  152. tone_amp = n * 32767.0;
  153. }
  154. boolean begin(float t_amp,int t_hi,short t_type);
  155. virtual void update(void);
  156. void set_ramp_length(uint16_t r_length);
  157. private:
  158. short tone_amp;
  159. short last_tone_amp;
  160. short tone_freq;
  161. uint32_t tone_phase;
  162. uint32_t tone_incr;
  163. short tone_type;
  164. uint32_t ramp_down;
  165. uint32_t ramp_up;
  166. uint16_t ramp_length;
  167. };
  168. #endif
  169. #if 0
  170. class AudioSineWaveMod : public AudioStream
  171. {
  172. public:
  173. AudioSineWaveMod() : AudioStream(1, inputQueueArray) {}
  174. void frequency(float freq);
  175. //void amplitude(q15 n);
  176. virtual void update(void);
  177. private:
  178. uint32_t phase;
  179. uint32_t phase_increment;
  180. uint32_t modulation_factor;
  181. audio_block_t *inputQueueArray[1];
  182. };
  183. #endif
  184. class AudioOutputPWM : public AudioStream
  185. {
  186. public:
  187. AudioOutputPWM(void) : AudioStream(1, inputQueueArray) { begin(); }
  188. virtual void update(void);
  189. void begin(void);
  190. friend void dma_ch3_isr(void);
  191. private:
  192. static audio_block_t *block_1st;
  193. static audio_block_t *block_2nd;
  194. static uint32_t block_offset;
  195. static bool update_responsibility;
  196. static uint8_t interrupt_count;
  197. audio_block_t *inputQueueArray[1];
  198. };
  199. class AudioOutputAnalog : public AudioStream
  200. {
  201. public:
  202. AudioOutputAnalog(void) : AudioStream(1, inputQueueArray) { begin(); }
  203. virtual void update(void);
  204. void begin(void);
  205. void analogReference(int ref);
  206. friend void dma_ch4_isr(void);
  207. private:
  208. static audio_block_t *block_left_1st;
  209. static audio_block_t *block_left_2nd;
  210. static bool update_responsibility;
  211. audio_block_t *inputQueueArray[1];
  212. };
  213. class AudioPrint : public AudioStream
  214. {
  215. public:
  216. AudioPrint(const char *str) : AudioStream(1, inputQueueArray), name(str) {}
  217. virtual void update(void);
  218. private:
  219. const char *name;
  220. audio_block_t *inputQueueArray[1];
  221. };
  222. class AudioInputI2S : public AudioStream
  223. {
  224. public:
  225. AudioInputI2S(void) : AudioStream(0, NULL) { begin(); }
  226. virtual void update(void);
  227. void begin(void);
  228. friend void dma_ch1_isr(void);
  229. protected:
  230. AudioInputI2S(int dummy): AudioStream(0, NULL) {} // to be used only inside AudioInputI2Sslave !!
  231. static bool update_responsibility;
  232. private:
  233. static audio_block_t *block_left;
  234. static audio_block_t *block_right;
  235. static uint16_t block_offset;
  236. };
  237. class AudioOutputI2S : public AudioStream
  238. {
  239. public:
  240. AudioOutputI2S(void) : AudioStream(2, inputQueueArray) { begin(); }
  241. virtual void update(void);
  242. void begin(void);
  243. friend void dma_ch0_isr(void);
  244. friend class AudioInputI2S;
  245. protected:
  246. AudioOutputI2S(int dummy): AudioStream(2, inputQueueArray) {} // to be used only inside AudioOutputI2Sslave !!
  247. static void config_i2s(void);
  248. static audio_block_t *block_left_1st;
  249. static audio_block_t *block_right_1st;
  250. static bool update_responsibility;
  251. private:
  252. static audio_block_t *block_left_2nd;
  253. static audio_block_t *block_right_2nd;
  254. static uint16_t block_left_offset;
  255. static uint16_t block_right_offset;
  256. audio_block_t *inputQueueArray[2];
  257. };
  258. class AudioInputI2Sslave : public AudioInputI2S
  259. {
  260. public:
  261. AudioInputI2Sslave(void) : AudioInputI2S(0) { begin(); }
  262. void begin(void);
  263. friend void dma_ch1_isr(void);
  264. };
  265. class AudioOutputI2Sslave : public AudioOutputI2S
  266. {
  267. public:
  268. AudioOutputI2Sslave(void) : AudioOutputI2S(0) { begin(); } ;
  269. void begin(void);
  270. friend class AudioInputI2Sslave;
  271. friend void dma_ch0_isr(void);
  272. protected:
  273. static void config_i2s(void);
  274. };
  275. class AudioInputAnalog : public AudioStream
  276. {
  277. public:
  278. AudioInputAnalog(unsigned int pin) : AudioStream(0, NULL) { begin(pin); }
  279. virtual void update(void);
  280. void begin(unsigned int pin);
  281. friend void dma_ch2_isr(void);
  282. private:
  283. static audio_block_t *block_left;
  284. static uint16_t block_offset;
  285. uint16_t dc_average;
  286. static bool update_responsibility;
  287. };
  288. #include "SD.h"
  289. class AudioPlaySDcardWAV : public AudioStream
  290. {
  291. public:
  292. AudioPlaySDcardWAV(void) : AudioStream(0, NULL) { begin(); }
  293. void begin(void);
  294. bool play(const char *filename);
  295. void stop(void);
  296. bool start(void);
  297. virtual void update(void);
  298. private:
  299. File wavfile;
  300. bool consume(void);
  301. bool parse_format(void);
  302. uint32_t header[5];
  303. uint32_t data_length; // number of bytes remaining in data section
  304. audio_block_t *block_left;
  305. audio_block_t *block_right;
  306. uint16_t block_offset;
  307. uint8_t buffer[512];
  308. uint16_t buffer_remaining;
  309. uint8_t state;
  310. uint8_t state_play;
  311. uint8_t leftover_bytes;
  312. };
  313. class AudioPlaySDcardRAW : public AudioStream
  314. {
  315. public:
  316. AudioPlaySDcardRAW(void) : AudioStream(0, NULL) { begin(); }
  317. void begin(void);
  318. bool play(const char *filename);
  319. void stop(void);
  320. virtual void update(void);
  321. private:
  322. File rawfile;
  323. audio_block_t *block;
  324. bool playing;
  325. bool paused;
  326. };
  327. class AudioPlayMemory : public AudioStream
  328. {
  329. public:
  330. AudioPlayMemory(void) : AudioStream(0, NULL), playing(0) { }
  331. void play(const unsigned int *data);
  332. void stop(void);
  333. virtual void update(void);
  334. private:
  335. const unsigned int *next;
  336. uint32_t length;
  337. int16_t prior;
  338. volatile uint8_t playing;
  339. };
  340. class AudioMixer4 : public AudioStream
  341. {
  342. public:
  343. AudioMixer4(void) : AudioStream(4, inputQueueArray) {
  344. for (int i=0; i<4; i++) multiplier[i] = 65536;
  345. }
  346. virtual void update(void);
  347. void gain(unsigned int channel, float gain) {
  348. if (channel >= 4) return;
  349. if (gain > 32767.0f) gain = 32767.0f;
  350. else if (gain < 0.0f) gain = 0.0f;
  351. multiplier[channel] = gain * 65536.0f; // TODO: proper roundoff?
  352. }
  353. private:
  354. int32_t multiplier[4];
  355. audio_block_t *inputQueueArray[4];
  356. };
  357. class AudioFilterBiquad : public AudioStream
  358. {
  359. public:
  360. AudioFilterBiquad(int *parameters)
  361. : AudioStream(1, inputQueueArray), definition(parameters) { }
  362. virtual void update(void);
  363. void updateCoefs(int *source, bool doReset);
  364. void updateCoefs(int *source);
  365. private:
  366. int *definition;
  367. audio_block_t *inputQueueArray[1];
  368. };
  369. class AudioEffectFade : public AudioStream
  370. {
  371. public:
  372. AudioEffectFade(void)
  373. : AudioStream(1, inputQueueArray), position(0xFFFFFFFF) {}
  374. void fadeIn(uint32_t milliseconds) {
  375. uint32_t samples = (uint32_t)(milliseconds * 441u + 5u) / 10u;
  376. //Serial.printf("fadeIn, %u samples\n", samples);
  377. fadeBegin(0xFFFFFFFFu / samples, 1);
  378. }
  379. void fadeOut(uint32_t milliseconds) {
  380. uint32_t samples = (uint32_t)(milliseconds * 441u + 5u) / 10u;
  381. //Serial.printf("fadeOut, %u samples\n", samples);
  382. fadeBegin(0xFFFFFFFFu / samples, 0);
  383. }
  384. virtual void update(void);
  385. private:
  386. void fadeBegin(uint32_t newrate, uint8_t dir);
  387. uint32_t position; // 0 = off, 0xFFFFFFFF = on
  388. uint32_t rate;
  389. uint8_t direction; // 0 = fading out, 1 = fading in
  390. audio_block_t *inputQueueArray[1];
  391. };
  392. class AudioAnalyzeToneDetect : public AudioStream
  393. {
  394. public:
  395. AudioAnalyzeToneDetect(void)
  396. : AudioStream(1, inputQueueArray), thresh(6554), enabled(false) { }
  397. void frequency(float freq, uint16_t cycles=10) {
  398. set_params((int32_t)(cos((double)freq
  399. * (2.0 * 3.14159265358979323846 / AUDIO_SAMPLE_RATE_EXACT))
  400. * (double)2147483647.999), cycles,
  401. (float)AUDIO_SAMPLE_RATE_EXACT / freq * (float)cycles + 0.5f);
  402. }
  403. void set_params(int32_t coef, uint16_t cycles, uint16_t len);
  404. bool available(void) {
  405. __disable_irq();
  406. bool flag = new_output;
  407. if (flag) new_output = false;
  408. __enable_irq();
  409. return flag;
  410. }
  411. float read(void);
  412. void threshold(float level) {
  413. if (level < 0.01f) thresh = 655;
  414. else if (level > 0.99f) thresh = 64881;
  415. else thresh = level * 65536.0f + 0.5f;
  416. }
  417. operator bool(); // true if at or above threshold, false if below
  418. virtual void update(void);
  419. private:
  420. int32_t coefficient; // Goertzel algorithm coefficient
  421. int32_t s1, s2; // Goertzel algorithm state
  422. int32_t out1, out2; // Goertzel algorithm state output
  423. uint16_t length; // number of samples to analyze
  424. uint16_t count; // how many left to analyze
  425. uint16_t ncycles; // number of waveform cycles to seek
  426. uint16_t thresh; // threshold, 655 to 64881 (1% to 99%)
  427. bool enabled;
  428. volatile bool new_output;
  429. audio_block_t *inputQueueArray[1];
  430. };
  431. // TODO: more audio processing objects....
  432. // sine wave with frequency modulation (phase)
  433. // waveforms with bandwidth limited tables for synth
  434. // envelope: attack-decay-sustain-release, maybe other more complex?
  435. // MP3 decoding - it is possible with optimized code?
  436. // other decompression, ADPCM, Vorbis, Speex, etc?
  437. // A base class for all Codecs, DACs and ADCs, so at least the
  438. // most basic functionality is consistent.
  439. #define AUDIO_INPUT_LINEIN 0
  440. #define AUDIO_INPUT_MIC 1
  441. class AudioControl
  442. {
  443. public:
  444. virtual bool enable(void) = 0;
  445. virtual bool disable(void) = 0;
  446. virtual bool volume(float volume) = 0; // volume 0.0 to 100.0
  447. virtual bool inputLevel(float volume) = 0; // volume 0.0 to 100.0
  448. virtual bool inputSelect(int n) = 0;
  449. };
  450. class AudioControlWM8731 : public AudioControl
  451. {
  452. public:
  453. bool enable(void);
  454. bool disable(void) { return false; }
  455. bool volume(float n) { return volumeInteger(n * 0.8 + 47.499); }
  456. bool inputLevel(float n) { return false; }
  457. bool inputSelect(int n) { return false; }
  458. protected:
  459. bool write(unsigned int reg, unsigned int val);
  460. bool volumeInteger(unsigned int n); // range: 0x2F to 0x7F
  461. };
  462. class AudioControlWM8731master : public AudioControlWM8731
  463. {
  464. public:
  465. bool enable(void);
  466. };
  467. class AudioControlSGTL5000 : public AudioControl
  468. {
  469. public:
  470. bool enable(void);
  471. bool disable(void) { return false; }
  472. bool volume(float n) { return volumeInteger(n * 1.29 + 0.499); }
  473. bool inputLevel(float n) {return false;}
  474. bool muteHeadphone(void) { return write(0x0024, ana_ctrl | (1<<4)); }
  475. bool unmuteHeadphone(void) { return write(0x0024, ana_ctrl & ~(1<<4)); }
  476. bool muteLineout(void) { return write(0x0024, ana_ctrl | (1<<8)); }
  477. bool unmuteLineout(void) { return write(0x0024, ana_ctrl & ~(1<<8)); }
  478. bool inputSelect(int n) {
  479. if (n == AUDIO_INPUT_LINEIN) {
  480. return write(0x0024, ana_ctrl | (1<<2));
  481. } else if (n == AUDIO_INPUT_MIC) {
  482. //return write(0x002A, 0x0172) && write(0x0024, ana_ctrl & ~(1<<2));
  483. return write(0x002A, 0x0173) && write(0x0024, ana_ctrl & ~(1<<2)); // +40dB
  484. } else {
  485. return false;
  486. }
  487. }
  488. //bool inputLinein(void) { return write(0x0024, ana_ctrl | (1<<2)); }
  489. //bool inputMic(void) { return write(0x002A, 0x0172) && write(0x0024, ana_ctrl & ~(1<<2)); }
  490. bool volume(float left, float right);
  491. unsigned short micGain(unsigned int n) { return modify(0x002A, n&3, 3); }
  492. unsigned short lo_lvl(uint8_t n);
  493. unsigned short lo_lvl(uint8_t left, uint8_t right);
  494. unsigned short dac_vol(float n);
  495. unsigned short dac_vol(float left, float right);
  496. unsigned short dap_mix_enable(uint8_t n);
  497. unsigned short dap_enable(uint8_t n);
  498. unsigned short dap_enable(void);
  499. unsigned short dap_peqs(uint8_t n);
  500. unsigned short dap_audio_eq(uint8_t n);
  501. unsigned short dap_audio_eq_band(uint8_t bandNum, float n);
  502. void dap_audio_eq_geq(float bass, float mid_bass, float midrange, float mid_treble, float treble);
  503. void dap_audio_eq_tone(float bass, float treble);
  504. void load_peq(uint8_t filterNum, int *filterParameters);
  505. protected:
  506. bool muted;
  507. bool volumeInteger(unsigned int n); // range: 0x00 to 0x80
  508. uint16_t ana_ctrl;
  509. unsigned char calcVol(float n, unsigned char range);
  510. unsigned int read(unsigned int reg);
  511. bool write(unsigned int reg, unsigned int val);
  512. unsigned int modify(unsigned int reg, unsigned int val, unsigned int iMask);
  513. };
  514. //For Filter Type: 0 = LPF, 1 = HPF, 2 = BPF, 3 = NOTCH, 4 = PeakingEQ, 5 = LowShelf, 6 = HighShelf
  515. #define FILTER_LOPASS 0
  516. #define FILTER_HIPASS 1
  517. #define FILTER_BANDPASS 2
  518. #define FILTER_NOTCH 3
  519. #define FILTER_PARAEQ 4
  520. #define FILTER_LOSHELF 5
  521. #define FILTER_HISHELF 6
  522. void calcBiquad(uint8_t filtertype, float fC, float dB_Gain, float Q, uint32_t quantization_unit, uint32_t fS, int *coef);
  523. /******************************************************************/
  524. // Maximum number of coefficients in a FIR filter
  525. // The audio breaks up with 128 coefficients so a
  526. // maximum of 150 is more than sufficient
  527. #define MAX_COEFFS 150
  528. // Indicates that the code should just pass through the audio
  529. // without any filtering (as opposed to doing nothing at all)
  530. #define FIR_PASSTHRU ((short *) 1)
  531. class AudioFilterFIR :
  532. public AudioStream
  533. {
  534. public:
  535. AudioFilterFIR(void):
  536. AudioStream(2,inputQueueArray), coeff_p(NULL)
  537. {
  538. }
  539. void begin(short *coeff_p,int f_pin);
  540. virtual void update(void);
  541. void stop(void);
  542. private:
  543. audio_block_t *inputQueueArray[2];
  544. // arm state arrays and FIR instances for left and right channels
  545. // the state arrays are defined to handle a maximum of MAX_COEFFS
  546. // coefficients in a filter
  547. q15_t l_StateQ15[AUDIO_BLOCK_SAMPLES + MAX_COEFFS];
  548. q15_t r_StateQ15[AUDIO_BLOCK_SAMPLES + MAX_COEFFS];
  549. arm_fir_instance_q15 l_fir_inst;
  550. arm_fir_instance_q15 r_fir_inst;
  551. // pointer to current coefficients or NULL or FIR_PASSTHRU
  552. short *coeff_p;
  553. };
  554. /******************************************************************/
  555. // A u d i o E f f e c t F l a n g e
  556. // Written by Pete (El Supremo) Jan 2014
  557. #define DELAY_PASSTHRU 0
  558. class AudioEffectFlange :
  559. public AudioStream
  560. {
  561. public:
  562. AudioEffectFlange(void):
  563. AudioStream(2,inputQueueArray) {
  564. }
  565. boolean begin(short *delayline,int d_length,int delay_offset,int d_depth,float delay_rate);
  566. boolean modify(int delay_offset,int d_depth,float delay_rate);
  567. virtual void update(void);
  568. void stop(void);
  569. private:
  570. audio_block_t *inputQueueArray[2];
  571. static short *l_delayline;
  572. static short *r_delayline;
  573. static int delay_length;
  574. static short l_circ_idx;
  575. static short r_circ_idx;
  576. static int delay_depth;
  577. static int delay_offset_idx;
  578. static int delay_rate_incr;
  579. static unsigned int l_delay_rate_index;
  580. static unsigned int r_delay_rate_index;
  581. };
  582. /******************************************************************/
  583. // A u d i o E f f e c t C h o r u s
  584. // Written by Pete (El Supremo) Jan 2014
  585. class AudioEffectChorus :
  586. public AudioStream
  587. {
  588. public:
  589. AudioEffectChorus(void):
  590. AudioStream(2,inputQueueArray) {
  591. }
  592. boolean begin(short *delayline,int delay_length,int n_chorus);
  593. virtual void update(void);
  594. void stop(void);
  595. void modify(int n_chorus);
  596. private:
  597. audio_block_t *inputQueueArray[2];
  598. static short *l_delayline;
  599. static short *r_delayline;
  600. static short l_circ_idx;
  601. static short r_circ_idx;
  602. static int num_chorus;
  603. static int delay_length;
  604. };
  605. /******************************************************************/
  606. // A u d i o T o n e S w e e p
  607. // Written by Pete (El Supremo) Feb 2014
  608. class AudioToneSweep : public AudioStream
  609. {
  610. public:
  611. AudioToneSweep(void) :
  612. AudioStream(0,NULL), sweep_busy(0)
  613. { }
  614. boolean begin(short t_amp,int t_lo,int t_hi,float t_time);
  615. virtual void update(void);
  616. unsigned char busy(void);
  617. private:
  618. short tone_amp;
  619. int tone_lo;
  620. int tone_hi;
  621. uint64_t tone_freq;
  622. uint64_t tone_phase;
  623. uint64_t tone_incr;
  624. int tone_sign;
  625. unsigned char sweep_busy;
  626. };