Test the Synth sound functions of Pokitto
Dependencies: PokittoLib
SynthTest - Pokitto synth demo
To test this program, simply press "Import into Compiler" button on the right!
SynthTest.cpp@0:e0bd5da25882, 2018-01-01 (annotated)
- Committer:
- group-Pokitto-Community-Team
- Date:
- Mon Jan 01 18:52:16 2018 +0000
- Revision:
- 0:e0bd5da25882
- Child:
- 2:91c41852a646
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
group-Pokitto-Community-Team | 0:e0bd5da25882 | 1 | #include "Pokitto.h" |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 2 | #include "Synth.h" |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 3 | |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 4 | Pokitto::Core game; |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 5 | Pokitto::Display disp; |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 6 | Pokitto::Sound snd; |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 7 | Pokitto::Buttons btn; |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 8 | |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 9 | int tonefreq=33; |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 10 | uint8_t amplitude = 255;//127; |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 11 | uint8_t wavetype = 1, arpmode=0; |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 12 | uint32_t changed = 1; |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 13 | char notestr[6]; |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 14 | uint8_t sbindx=0,sbx=0,prevy=0; |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 15 | |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 16 | int main() |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 17 | { |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 18 | game.begin(); |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 19 | snd.setVolume(snd.getMaxVol()); // volume to max level depending on headset/speaker safety level |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 20 | disp.persistence = true; |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 21 | disp.color=wavetype+1; |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 22 | disp.bgcolor=0; |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 23 | uint8_t sbindx=0; |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 24 | int oldvol=0; |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 25 | int linecenter = (disp.height/4)-10; // center oscilloscope line vertically |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 26 | snd.ampEnable(1); |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 27 | snd.playTone(1,tonefreq,amplitude,wavetype,arpmode); |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 28 | // want to have 2 oscillators 1 octave apart ? |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 29 | // snd.playTone(2,tonefreq+12,amplitude,wavetype,arpmode); |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 30 | |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 31 | disp.clear(); |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 32 | disp.print("Frq:"); |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 33 | getNoteString(notestr,tonefreq); |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 34 | disp.println(notestr); |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 35 | disp.print("Vol:"); |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 36 | disp.println((int)amplitude); |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 37 | disp.print("Wav:"); |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 38 | disp.print((int)wavetype); |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 39 | switch (wavetype) { |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 40 | case 0: |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 41 | disp.println(" Off");break; |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 42 | case 1: |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 43 | disp.println(" Square");break; |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 44 | case 2: |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 45 | disp.println(" Saw");break; |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 46 | case 3: |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 47 | disp.println(" Triang");break; |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 48 | case 4: |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 49 | disp.println(" Noise");break; |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 50 | case 5: |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 51 | disp.println(" SqNois");break; |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 52 | } |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 53 | disp.print("HWvol:"); |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 54 | disp.println((int)snd.getVolume()); |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 55 | disp.lcdRefresh(disp.screenbuffer); |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 56 | |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 57 | while (game.isRunning()) { |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 58 | |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 59 | #ifdef POK_SIM |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 60 | #define DEBOU 2048*32 |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 61 | #else |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 62 | #define DEBOU 256 |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 63 | #endif |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 64 | |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 65 | if (changed == 0) { |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 66 | if(btn.upBtn()) { amplitude++; changed = DEBOU; } |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 67 | if(btn.downBtn()) { amplitude--; changed = DEBOU; } |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 68 | if(btn.leftBtn() && (tonefreq > 0)) { tonefreq --; changed = DEBOU; } |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 69 | if(btn.rightBtn() && (tonefreq < 88)) { tonefreq ++; changed = DEBOU; } |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 70 | if(btn.released(BTN_A) && wavetype > 0 ) { wavetype--; changed = DEBOU*10;} |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 71 | if(btn.released(BTN_B) && wavetype < 5 ) { wavetype++; changed = DEBOU*10;} |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 72 | if (snd.getVolume() != oldvol) changed=DEBOU; |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 73 | |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 74 | if (changed) { |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 75 | disp.clear(); |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 76 | disp.color=0;//owavetype+1; |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 77 | disp.fillRectangle(0,0,109,34); |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 78 | disp.color=wavetype+1; |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 79 | disp.bgcolor=0; |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 80 | disp.print("Frq:"); |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 81 | getNoteString(notestr,tonefreq); |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 82 | disp.println(notestr); |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 83 | disp.print("Vol:"); |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 84 | disp.println((int)amplitude); |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 85 | disp.print("Wav:"); |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 86 | disp.print((int)wavetype); |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 87 | switch (wavetype) { |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 88 | case 0: |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 89 | disp.println(" Off");break; |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 90 | case 1: |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 91 | disp.println(" Square");break; |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 92 | case 2: |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 93 | disp.println(" Saw");break; |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 94 | case 3: |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 95 | disp.println(" Triang");break; |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 96 | case 4: |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 97 | disp.println(" Noise");break; |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 98 | case 5: |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 99 | disp.println(" SqNois");break; |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 100 | } |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 101 | disp.print("HWvol:"); |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 102 | disp.println((int)snd.getVolume()); |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 103 | snd.playTone(1,tonefreq,amplitude,wavetype,arpmode); |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 104 | oldvol = (int) snd.getVolume(); |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 105 | // want to have 2 oscillators 1 octave apart ? |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 106 | // snd.playTone(2,tonefreq+12,amplitude,wavetype,arpmode); |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 107 | } |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 108 | } else changed--; |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 109 | disp.color=0; |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 110 | disp.drawColumn(sbx,38,disp.height); |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 111 | disp.color=wavetype+1; |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 112 | uint8_t tindex = sbindx*2; |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 113 | int16_t y = linecenter + (((int)128-(soundbuf[tindex]))>>1); |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 114 | disp.drawLine(sbx-1,prevy,sbx,y); |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 115 | game.update(); |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 116 | disp.color=0; |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 117 | prevy=y; |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 118 | sbx++;sbindx++; |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 119 | if (sbx>disp.width-1) {sbx=0;} |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 120 | } |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 121 | return 0; // good manners! |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 122 | } |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 123 | |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 124 | |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 125 | |
group-Pokitto-Community-Team | 0:e0bd5da25882 | 126 |