This is a part of the Kinetiszer project.
master.c@0:cb80470434eb, 2014-10-28 (annotated)
- Committer:
- Clemo
- Date:
- Tue Oct 28 12:19:42 2014 +0000
- Revision:
- 0:cb80470434eb
Error & warning free.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Clemo | 0:cb80470434eb | 1 | #include "atmegatron.h" |
Clemo | 0:cb80470434eb | 2 | //#include "chip.h" // For SystemCoreClock only. |
Clemo | 0:cb80470434eb | 3 | |
Clemo | 0:cb80470434eb | 4 | //#define F_CPU SystemCoreClock |
Clemo | 0:cb80470434eb | 5 | |
Clemo | 0:cb80470434eb | 6 | |
Clemo | 0:cb80470434eb | 7 | unsigned long master_tick; //current tick. used for all timing of lfos, arp and envs |
Clemo | 0:cb80470434eb | 8 | volatile uint16_t master_index = 0; //position in master_output wavetable |
Clemo | 0:cb80470434eb | 9 | unsigned char master_output[WAVE_LEN]; //output wavetable |
Clemo | 0:cb80470434eb | 10 | unsigned char master_output_ch2[WAVE_LEN]; //output wavetable |
Clemo | 0:cb80470434eb | 11 | unsigned long master_ocr1 = 10227; //interrupt frequency (sets pitch of synth) |
Clemo | 0:cb80470434eb | 12 | unsigned long master_sf = 7040; //sample frequency, ocr1 derived from this |
Clemo | 0:cb80470434eb | 13 | |
Clemo | 0:cb80470434eb | 14 | |
Clemo | 0:cb80470434eb | 15 | // Set the sample frequency (pitch) |
Clemo | 0:cb80470434eb | 16 | void Master_Let_SampleFreq(void) |
Clemo | 0:cb80470434eb | 17 | { |
Clemo | 0:cb80470434eb | 18 | // Has the pitch actually changed? |
Clemo | 0:cb80470434eb | 19 | if (Pitch_Get_PitchChanged()==true) |
Clemo | 0:cb80470434eb | 20 | { |
Clemo | 0:cb80470434eb | 21 | // Calculate new sample frequency. |
Clemo | 0:cb80470434eb | 22 | master_sf = Pitch_Get_FreqCalc()*WAVE_LEN; |
Clemo | 0:cb80470434eb | 23 | // Convert sample frequency to interrupt ticks. |
Clemo | 0:cb80470434eb | 24 | master_ocr1 = /*Chip_Clock_GetSystemClockRate() / */ master_sf; |
Clemo | 0:cb80470434eb | 25 | //master_ocr1 = F_CPU/master_sf; //convert to interrupt time |
Clemo | 0:cb80470434eb | 26 | if (master_ocr1>65535) |
Clemo | 0:cb80470434eb | 27 | { |
Clemo | 0:cb80470434eb | 28 | // Highest possible value for ocr1 (lowest freq) |
Clemo | 0:cb80470434eb | 29 | master_ocr1 = 65535; |
Clemo | 0:cb80470434eb | 30 | } |
Clemo | 0:cb80470434eb | 31 | if (master_ocr1<100) |
Clemo | 0:cb80470434eb | 32 | { |
Clemo | 0:cb80470434eb | 33 | // Lowest possible value for ocr1. Any lower and code in interrupt doesn't have time to complete. |
Clemo | 0:cb80470434eb | 34 | // Worked out by trial and error. |
Clemo | 0:cb80470434eb | 35 | master_ocr1 = 100; |
Clemo | 0:cb80470434eb | 36 | } |
Clemo | 0:cb80470434eb | 37 | //master_ocr1 >>= 2; // cpv |
Clemo | 0:cb80470434eb | 38 | } |
Clemo | 0:cb80470434eb | 39 | } |
Clemo | 0:cb80470434eb | 40 | |
Clemo | 0:cb80470434eb | 41 | |
Clemo | 0:cb80470434eb | 42 | unsigned long Master_Get_SampleFreq(void) |
Clemo | 0:cb80470434eb | 43 | { |
Clemo | 0:cb80470434eb | 44 | return master_sf; |
Clemo | 0:cb80470434eb | 45 | } |