Luke Cartwright / Mbed 2 deprecated ELEC2645_Project_el18loc_nearlythere

Dependencies:   mbed

Committer:
lukeocarwright
Date:
Tue May 19 15:04:33 2020 +0000
Revision:
14:9cfe0041cc4e
Child:
15:1c67f064278e
Actually make proper sound atlast. Checked Concert A against piano. included more preprocessor debug (SLOW TIME) for Debug if output check required w. printf

Who changed what in which revision?

UserRevisionLine numberNew 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 14:9cfe0041cc4e 24 i=wavetable_itt(i,frequency);
lukeocarwright 14:9cfe0041cc4e 25 if (waveform==1) {
lukeocarwright 14:9cfe0041cc4e 26 #ifdef SLOW_TIME
lukeocarwright 14:9cfe0041cc4e 27 printf("SIN_wavtable[%u]=",i)
lukeocarwright 14:9cfe0041cc4e 28 #endif
lukeocarwright 14:9cfe0041cc4e 29 return (sin_wavtable[i]);
lukeocarwright 14:9cfe0041cc4e 30 }
lukeocarwright 14:9cfe0041cc4e 31 return(0);
lukeocarwright 14:9cfe0041cc4e 32 }
lukeocarwright 14:9cfe0041cc4e 33
lukeocarwright 14:9cfe0041cc4e 34 //PRIVATE:----------------------------------------------------------------------
lukeocarwright 14:9cfe0041cc4e 35 uint16_t Sound::wavetable_itt(uint16_t i, int frequency)
lukeocarwright 14:9cfe0041cc4e 36 {
lukeocarwright 14:9cfe0041cc4e 37 i_d = i + ((1024*frequency)/4000); //i+((samples*f)*Ts)
lukeocarwright 14:9cfe0041cc4e 38 i=ceil(i_d); //ROUND IN FUTURE*************
lukeocarwright 14:9cfe0041cc4e 39
lukeocarwright 14:9cfe0041cc4e 40 if (i>=1024) {
lukeocarwright 14:9cfe0041cc4e 41 i=i-1024;
lukeocarwright 14:9cfe0041cc4e 42 }
lukeocarwright 14:9cfe0041cc4e 43 return(i);
lukeocarwright 14:9cfe0041cc4e 44 }