Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Sound/Sound.cpp@24:c3bb1b0b2207, 2020-05-24 (annotated)
- Committer:
- lukeocarwright
- Date:
- Sun May 24 15:20:31 2020 +0000
- Revision:
- 24:c3bb1b0b2207
- Parent:
- 18:204cd747b54a
- Child:
- 30:08cc4ec58d07
Basic Filtering Implemented & sample rate dropped to account for additional CPU usage
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
lukeocarwright | 14:9cfe0041cc4e | 1 | #include "Sound.h" |
lukeocarwright | 14:9cfe0041cc4e | 2 | |
lukeocarwright | 14:9cfe0041cc4e | 3 | //Global Variables |
lukeocarwright | 14:9cfe0041cc4e | 4 | volatile extern uint16_t sin_wavtable[1024]; |
lukeocarwright | 14:9cfe0041cc4e | 5 | volatile extern uint16_t tri_wavtable[1024]; |
lukeocarwright | 14:9cfe0041cc4e | 6 | volatile extern uint16_t pulse_wavtable[1024]; |
lukeocarwright | 14:9cfe0041cc4e | 7 | |
lukeocarwright | 14:9cfe0041cc4e | 8 | //Constructor/Destructor |
lukeocarwright | 14:9cfe0041cc4e | 9 | Sound::Sound() |
lukeocarwright | 14:9cfe0041cc4e | 10 | { |
lukeocarwright | 14:9cfe0041cc4e | 11 | } |
lukeocarwright | 14:9cfe0041cc4e | 12 | Sound::~Sound() |
lukeocarwright | 14:9cfe0041cc4e | 13 | { |
lukeocarwright | 14:9cfe0041cc4e | 14 | } |
lukeocarwright | 14:9cfe0041cc4e | 15 | |
lukeocarwright | 14:9cfe0041cc4e | 16 | //PUBLIC:----------------------------------------------------------------------- |
lukeocarwright | 14:9cfe0041cc4e | 17 | |
lukeocarwright | 14:9cfe0041cc4e | 18 | uint16_t Sound::sound_main(bool initial, int waveform, int frequency) |
lukeocarwright | 14:9cfe0041cc4e | 19 | { |
lukeocarwright | 14:9cfe0041cc4e | 20 | if (initial==true) { |
lukeocarwright | 14:9cfe0041cc4e | 21 | i=0; |
lukeocarwright | 14:9cfe0041cc4e | 22 | return(i); |
lukeocarwright | 14:9cfe0041cc4e | 23 | } |
lukeocarwright | 15:1c67f064278e | 24 | |
lukeocarwright | 14:9cfe0041cc4e | 25 | i=wavetable_itt(i,frequency); |
lukeocarwright | 15:1c67f064278e | 26 | |
lukeocarwright | 14:9cfe0041cc4e | 27 | if (waveform==1) { |
lukeocarwright | 14:9cfe0041cc4e | 28 | #ifdef SLOW_TIME |
lukeocarwright | 18:204cd747b54a | 29 | printf("SIN_wavtable[%u]\n",i); |
lukeocarwright | 14:9cfe0041cc4e | 30 | #endif |
lukeocarwright | 14:9cfe0041cc4e | 31 | return (sin_wavtable[i]); |
lukeocarwright | 14:9cfe0041cc4e | 32 | } |
lukeocarwright | 15:1c67f064278e | 33 | if (waveform==2) { |
lukeocarwright | 15:1c67f064278e | 34 | #ifdef SLOW_TIME |
lukeocarwright | 18:204cd747b54a | 35 | printf("TRI_wavtable[%u]\n",i); |
lukeocarwright | 15:1c67f064278e | 36 | #endif |
lukeocarwright | 15:1c67f064278e | 37 | return (tri_wavtable[i]); |
lukeocarwright | 15:1c67f064278e | 38 | } |
lukeocarwright | 15:1c67f064278e | 39 | if (waveform==3) { |
lukeocarwright | 15:1c67f064278e | 40 | #ifdef SLOW_TIME |
lukeocarwright | 18:204cd747b54a | 41 | printf("SQR_wavtable[%u]\n",i); |
lukeocarwright | 15:1c67f064278e | 42 | #endif |
lukeocarwright | 15:1c67f064278e | 43 | return (pulse_wavtable[i]); |
lukeocarwright | 15:1c67f064278e | 44 | } |
lukeocarwright | 14:9cfe0041cc4e | 45 | return(0); |
lukeocarwright | 14:9cfe0041cc4e | 46 | } |
lukeocarwright | 14:9cfe0041cc4e | 47 | |
lukeocarwright | 14:9cfe0041cc4e | 48 | //PRIVATE:---------------------------------------------------------------------- |
lukeocarwright | 14:9cfe0041cc4e | 49 | uint16_t Sound::wavetable_itt(uint16_t i, int frequency) |
lukeocarwright | 14:9cfe0041cc4e | 50 | { |
lukeocarwright | 24:c3bb1b0b2207 | 51 | i_d = i + ((1024*frequency)/ 10000); //i+((samples*f)*Ts) |
lukeocarwright | 14:9cfe0041cc4e | 52 | i=ceil(i_d); //ROUND IN FUTURE************* |
lukeocarwright | 14:9cfe0041cc4e | 53 | |
lukeocarwright | 14:9cfe0041cc4e | 54 | if (i>=1024) { |
lukeocarwright | 14:9cfe0041cc4e | 55 | i=i-1024; |
lukeocarwright | 14:9cfe0041cc4e | 56 | } |
lukeocarwright | 14:9cfe0041cc4e | 57 | return(i); |
lukeocarwright | 14:9cfe0041cc4e | 58 | } |