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@15:1c67f064278e, 2020-05-19 (annotated)
- Committer:
- lukeocarwright
- Date:
- Tue May 19 18:38:33 2020 +0000
- Revision:
- 15:1c67f064278e
- Parent:
- 14:9cfe0041cc4e
- Child:
- 18:204cd747b54a
Fixed Tri wavetable issue to get tri wave out. Added more slow debug elements.
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 | 15:1c67f064278e | 29 | printf("SIN_wavtable[%u]=",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 | 15:1c67f064278e | 35 | printf("TRI_wavtable[%u]=",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 | 15:1c67f064278e | 41 | printf("SQR_wavtable[%u]=",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 | 15:1c67f064278e | 51 | i_d = i + ((1024*frequency)/ 16000); //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 | } |