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.
Dependencies: PokittoLib
SynthTest.cpp@2:91c41852a646, 2018-01-30 (annotated)
- Committer:
- Pokitto
- Date:
- Tue Jan 30 10:42:21 2018 +0000
- Revision:
- 2:91c41852a646
- Parent:
- 0:e0bd5da25882
- Child:
- 5:09131ded851b
Now with improved sound library
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" |
| Pokitto | 2:91c41852a646 | 3 | #include "dma_11u6x.h" |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 4 | |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 5 | Pokitto::Core game; |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 6 | Pokitto::Display disp; |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 7 | Pokitto::Sound snd; |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 8 | Pokitto::Buttons btn; |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 9 | |
| Pokitto | 2:91c41852a646 | 10 | uint8_t mysine[] = { |
| Pokitto | 2:91c41852a646 | 11 | 0x80,0x83,0x86,0x89,0x8c,0x8f,0x92,0x95, |
| Pokitto | 2:91c41852a646 | 12 | 0x98,0x9b,0x9e,0xa2,0xa5,0xa7,0xaa,0xad, |
| Pokitto | 2:91c41852a646 | 13 | 0xb0,0xb3,0xb6,0xb9,0xbc,0xbe,0xc1,0xc4, |
| Pokitto | 2:91c41852a646 | 14 | 0xc6,0xc9,0xcb,0xce,0xd0,0xd3,0xd5,0xd7, |
| Pokitto | 2:91c41852a646 | 15 | 0xda,0xdc,0xde,0xe0,0xe2,0xe4,0xe6,0xe8, |
| Pokitto | 2:91c41852a646 | 16 | 0xea,0xeb,0xed,0xee,0xf0,0xf1,0xf3,0xf4, |
| Pokitto | 2:91c41852a646 | 17 | 0xf5,0xf6,0xf8,0xf9,0xfa,0xfa,0xfb,0xfc, |
| Pokitto | 2:91c41852a646 | 18 | 0xfd,0xfd,0xfe,0xfe,0xfe,0xff,0xff,0xff, |
| Pokitto | 2:91c41852a646 | 19 | 0xff,0xff,0xff,0xff,0xfe,0xfe,0xfe,0xfd, |
| Pokitto | 2:91c41852a646 | 20 | 0xfd,0xfc,0xfb,0xfa,0xfa,0xf9,0xf8,0xf6, |
| Pokitto | 2:91c41852a646 | 21 | 0xf5,0xf4,0xf3,0xf1,0xf0,0xee,0xed,0xeb, |
| Pokitto | 2:91c41852a646 | 22 | 0xea,0xe8,0xe6,0xe4,0xe2,0xe0,0xde,0xdc, |
| Pokitto | 2:91c41852a646 | 23 | 0xda,0xd7,0xd5,0xd3,0xd0,0xce,0xcb,0xc9, |
| Pokitto | 2:91c41852a646 | 24 | 0xc6,0xc4,0xc1,0xbe,0xbc,0xb9,0xb6,0xb3, |
| Pokitto | 2:91c41852a646 | 25 | 0xb0,0xad,0xaa,0xa7,0xa5,0xa2,0x9e,0x9b, |
| Pokitto | 2:91c41852a646 | 26 | 0x98,0x95,0x92,0x8f,0x8c,0x89,0x86,0x83, |
| Pokitto | 2:91c41852a646 | 27 | 0x80,0x7c,0x79,0x76,0x73,0x70,0x6d,0x6a, |
| Pokitto | 2:91c41852a646 | 28 | 0x67,0x64,0x61,0x5d,0x5a,0x58,0x55,0x52, |
| Pokitto | 2:91c41852a646 | 29 | 0x4f,0x4c,0x49,0x46,0x43,0x41,0x3e,0x3b, |
| Pokitto | 2:91c41852a646 | 30 | 0x39,0x36,0x34,0x31,0x2f,0x2c,0x2a,0x28, |
| Pokitto | 2:91c41852a646 | 31 | 0x25,0x23,0x21,0x1f,0x1d,0x1b,0x19,0x17, |
| Pokitto | 2:91c41852a646 | 32 | 0x15,0x14,0x12,0x11,0xf,0xe,0xc,0xb, |
| Pokitto | 2:91c41852a646 | 33 | 0xa,0x9,0x7,0x6,0x5,0x5,0x4,0x3, |
| Pokitto | 2:91c41852a646 | 34 | 0x2,0x2,0x1,0x1,0x1,0x0,0x0,0x0, |
| Pokitto | 2:91c41852a646 | 35 | 0x0,0x0,0x0,0x0,0x1,0x1,0x1,0x2, |
| Pokitto | 2:91c41852a646 | 36 | 0x2,0x3,0x4,0x5,0x5,0x6,0x7,0x9, |
| Pokitto | 2:91c41852a646 | 37 | 0xa,0xb,0xc,0xe,0xf,0x11,0x12,0x14, |
| Pokitto | 2:91c41852a646 | 38 | 0x15,0x17,0x19,0x1b,0x1d,0x1f,0x21,0x23, |
| Pokitto | 2:91c41852a646 | 39 | 0x25,0x28,0x2a,0x2c,0x2f,0x31,0x34,0x36, |
| Pokitto | 2:91c41852a646 | 40 | 0x39,0x3b,0x3e,0x41,0x43,0x46,0x49,0x4c, |
| Pokitto | 2:91c41852a646 | 41 | 0x4f,0x52,0x55,0x58,0x5a,0x5d,0x61,0x64, |
| Pokitto | 2:91c41852a646 | 42 | 0x67,0x6a,0x6d,0x70,0x73,0x76,0x79,0x7c |
| Pokitto | 2:91c41852a646 | 43 | }; |
| Pokitto | 2:91c41852a646 | 44 | |
| Pokitto | 2:91c41852a646 | 45 | int tonefreq=46; |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 46 | uint8_t amplitude = 255;//127; |
| Pokitto | 2:91c41852a646 | 47 | uint8_t wavetype = 1, arpmode=1; |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 48 | uint32_t changed = 1; |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 49 | char notestr[6]; |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 50 | uint8_t sbindx=0,sbx=0,prevy=0; |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 51 | |
| Pokitto | 2:91c41852a646 | 52 | /* Size of the source and destination buffers in 32-bit words. |
| Pokitto | 2:91c41852a646 | 53 | Allowable values = 126, 256, 512, or 1024 */ |
| Pokitto | 2:91c41852a646 | 54 | #define SIZE_BUFFERS (256) |
| Pokitto | 2:91c41852a646 | 55 | |
| Pokitto | 2:91c41852a646 | 56 | /* Source and destination buffers */ |
| Pokitto | 2:91c41852a646 | 57 | //uint32_t src[SIZE_BUFFERS], dst[SIZE_BUFFERS]; |
| Pokitto | 2:91c41852a646 | 58 | uint8_t src[SIZE_BUFFERS], dst[SIZE_BUFFERS]; |
| Pokitto | 2:91c41852a646 | 59 | |
| Pokitto | 2:91c41852a646 | 60 | /* DMA completion flag */ |
| Pokitto | 2:91c41852a646 | 61 | static volatile bool dmaDone; |
| Pokitto | 2:91c41852a646 | 62 | |
| Pokitto | 2:91c41852a646 | 63 | // IRQ handlers have to be extern "C" in mbed!!!!!!! |
| Pokitto | 2:91c41852a646 | 64 | extern "C" void DMA_IRQHandler(void) |
| Pokitto | 2:91c41852a646 | 65 | { |
| Pokitto | 2:91c41852a646 | 66 | /* Rrror interrupt on channel 0? */ |
| Pokitto | 2:91c41852a646 | 67 | if ((Chip_DMA_GetIntStatus(LPC_DMA) & DMA_INTSTAT_ACTIVEERRINT) != 0) { |
| Pokitto | 2:91c41852a646 | 68 | /* This shouldn't happen for this simple DMA example, so set the LED |
| Pokitto | 2:91c41852a646 | 69 | to indicate an error occurred. This is the correct method to clear |
| Pokitto | 2:91c41852a646 | 70 | an abort. */ |
| Pokitto | 2:91c41852a646 | 71 | Chip_DMA_DisableChannel(LPC_DMA, DMA_CH0); |
| Pokitto | 2:91c41852a646 | 72 | while ((Chip_DMA_GetBusyChannels(LPC_DMA) & (1 << DMA_CH0)) != 0) {} |
| Pokitto | 2:91c41852a646 | 73 | Chip_DMA_AbortChannel(LPC_DMA, DMA_CH0); |
| Pokitto | 2:91c41852a646 | 74 | Chip_DMA_ClearErrorIntChannel(LPC_DMA, DMA_CH0); |
| Pokitto | 2:91c41852a646 | 75 | Chip_DMA_EnableChannel(LPC_DMA, DMA_CH0); |
| Pokitto | 2:91c41852a646 | 76 | //Board_LED_Set(0, true); |
| Pokitto | 2:91c41852a646 | 77 | } |
| Pokitto | 2:91c41852a646 | 78 | |
| Pokitto | 2:91c41852a646 | 79 | /* Clear DMA interrupt for the channel */ |
| Pokitto | 2:91c41852a646 | 80 | Chip_DMA_ClearActiveIntAChannel(LPC_DMA, DMA_CH0); |
| Pokitto | 2:91c41852a646 | 81 | |
| Pokitto | 2:91c41852a646 | 82 | dmaDone = true; |
| Pokitto | 2:91c41852a646 | 83 | } |
| Pokitto | 2:91c41852a646 | 84 | |
| Pokitto | 2:91c41852a646 | 85 | void modifysrc(int j) { |
| Pokitto | 2:91c41852a646 | 86 | for (uint32_t i=0; i<SIZE_BUFFERS;i++) { |
| Pokitto | 2:91c41852a646 | 87 | src[i] = random(0,255); |
| Pokitto | 2:91c41852a646 | 88 | } |
| Pokitto | 2:91c41852a646 | 89 | } |
| Pokitto | 2:91c41852a646 | 90 | |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 91 | int main() |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 92 | { |
| Pokitto | 2:91c41852a646 | 93 | modifysrc(0); |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 94 | game.begin(); |
| Pokitto | 2:91c41852a646 | 95 | /* DMA part */ |
| Pokitto | 2:91c41852a646 | 96 | DMA_CHDESC_T dmaDesc; |
| Pokitto | 2:91c41852a646 | 97 | int i; |
| Pokitto | 2:91c41852a646 | 98 | |
| Pokitto | 2:91c41852a646 | 99 | uint32_t startTime, ticks[3]; |
| Pokitto | 2:91c41852a646 | 100 | /* DMA initialization - enable DMA clocking and reset DMA if needed */ |
| Pokitto | 2:91c41852a646 | 101 | Chip_DMA_Init(LPC_DMA); |
| Pokitto | 2:91c41852a646 | 102 | /* Enable DMA controller and use driver provided DMA table for current descriptors */ |
| Pokitto | 2:91c41852a646 | 103 | Chip_DMA_Enable(LPC_DMA); |
| Pokitto | 2:91c41852a646 | 104 | Chip_DMA_SetSRAMBase(LPC_DMA, DMA_ADDR(Chip_DMA_Table)); |
| Pokitto | 2:91c41852a646 | 105 | /* Setup channel 0 for the following configuration: |
| Pokitto | 2:91c41852a646 | 106 | - High channel priority |
| Pokitto | 2:91c41852a646 | 107 | - Interrupt A fires on descriptor completion */ |
| Pokitto | 2:91c41852a646 | 108 | Chip_DMA_EnableChannel(LPC_DMA, DMA_CH0); |
| Pokitto | 2:91c41852a646 | 109 | Chip_DMA_EnableIntChannel(LPC_DMA, DMA_CH0); |
| Pokitto | 2:91c41852a646 | 110 | Chip_DMA_SetupChannelConfig(LPC_DMA, DMA_CH0, |
| Pokitto | 2:91c41852a646 | 111 | (DMA_CFG_HWTRIGEN | DMA_CFG_TRIGTYPE_EDGE | DMA_CFG_TRIGPOL_HIGH | |
| Pokitto | 2:91c41852a646 | 112 | DMA_CFG_BURSTPOWER_128 | DMA_CFG_CHPRIORITY(0))); |
| Pokitto | 2:91c41852a646 | 113 | |
| Pokitto | 2:91c41852a646 | 114 | /* DMA descriptor for memory to memory operation - note that addresses must |
| Pokitto | 2:91c41852a646 | 115 | be the END address for src and destination, not the starting address. |
| Pokitto | 2:91c41852a646 | 116 | DMA operations moves from end to start. */ |
| Pokitto | 2:91c41852a646 | 117 | //dmaDesc.source = DMA_ADDR(&src[SIZE_BUFFERS - 1]) + 3; |
| Pokitto | 2:91c41852a646 | 118 | //dmaDesc.dest = DMA_ADDR(&dst[SIZE_BUFFERS - 1]) + 3; |
| Pokitto | 2:91c41852a646 | 119 | dmaDesc.source = DMA_ADDR(&src[SIZE_BUFFERS - 1]); |
| Pokitto | 2:91c41852a646 | 120 | //dmaDesc.dest = DMA_ADDR(&dst[SIZE_BUFFERS - 1]); |
| Pokitto | 2:91c41852a646 | 121 | dmaDesc.dest = DMA_ADDR(&game.display.screenbuffer[SIZE_BUFFERS - 1]); |
| Pokitto | 2:91c41852a646 | 122 | dmaDesc.next = DMA_ADDR(0); |
| Pokitto | 2:91c41852a646 | 123 | |
| Pokitto | 2:91c41852a646 | 124 | /* Enable DMA interrupt */ |
| Pokitto | 2:91c41852a646 | 125 | uint32_t rtr = NVIC->ISER[0]; |
| Pokitto | 2:91c41852a646 | 126 | NVIC_EnableIRQ(DMA_IRQn); |
| Pokitto | 2:91c41852a646 | 127 | |
| Pokitto | 2:91c41852a646 | 128 | /* Reset timer and perform a bunch memory to memory moves with DMA */ |
| Pokitto | 2:91c41852a646 | 129 | |
| Pokitto | 2:91c41852a646 | 130 | for (i = 0; i < 100; i++) { |
| Pokitto | 2:91c41852a646 | 131 | dmaDone = false; |
| Pokitto | 2:91c41852a646 | 132 | |
| Pokitto | 2:91c41852a646 | 133 | //modifyData(src, dst, SIZE_BUFFERS); |
| Pokitto | 2:91c41852a646 | 134 | modifysrc(i); |
| Pokitto | 2:91c41852a646 | 135 | |
| Pokitto | 2:91c41852a646 | 136 | /* Setup transfer descriptor and validate it */ |
| Pokitto | 2:91c41852a646 | 137 | Chip_DMA_SetupTranChannel(LPC_DMA, DMA_CH0, &dmaDesc); |
| Pokitto | 2:91c41852a646 | 138 | Chip_DMA_SetValidChannel(LPC_DMA, DMA_CH0); |
| Pokitto | 2:91c41852a646 | 139 | |
| Pokitto | 2:91c41852a646 | 140 | /* Setup data transfer and software trigger in same call */ |
| Pokitto | 2:91c41852a646 | 141 | /*Chip_DMA_SetupChannelTransfer(LPC_DMA, DMA_CH0, |
| Pokitto | 2:91c41852a646 | 142 | (DMA_XFERCFG_CFGVALID | DMA_XFERCFG_SETINTA | DMA_XFERCFG_SWTRIG | |
| Pokitto | 2:91c41852a646 | 143 | DMA_XFERCFG_WIDTH_32 | DMA_XFERCFG_SRCINC_1 | DMA_XFERCFG_DSTINC_1 | |
| Pokitto | 2:91c41852a646 | 144 | DMA_XFERCFG_XFERCOUNT(SIZE_BUFFERS)));*/ |
| Pokitto | 2:91c41852a646 | 145 | Chip_DMA_SetupChannelTransfer(LPC_DMA, DMA_CH0, |
| Pokitto | 2:91c41852a646 | 146 | (DMA_XFERCFG_CFGVALID | DMA_XFERCFG_SETINTA | DMA_XFERCFG_SWTRIG | |
| Pokitto | 2:91c41852a646 | 147 | DMA_XFERCFG_WIDTH_8 | DMA_XFERCFG_SRCINC_1 | DMA_XFERCFG_DSTINC_0 | |
| Pokitto | 2:91c41852a646 | 148 | DMA_XFERCFG_XFERCOUNT(SIZE_BUFFERS))); |
| Pokitto | 2:91c41852a646 | 149 | /* Wait for DMA completion */ |
| Pokitto | 2:91c41852a646 | 150 | while (dmaDone == false) { |
| Pokitto | 2:91c41852a646 | 151 | if (game.update()) { |
| Pokitto | 2:91c41852a646 | 152 | game.display.color=3; |
| Pokitto | 2:91c41852a646 | 153 | game.display.print("Hello! "); |
| Pokitto | 2:91c41852a646 | 154 | } |
| Pokitto | 2:91c41852a646 | 155 | |
| Pokitto | 2:91c41852a646 | 156 | } |
| Pokitto | 2:91c41852a646 | 157 | |
| Pokitto | 2:91c41852a646 | 158 | } |
| Pokitto | 2:91c41852a646 | 159 | |
| Pokitto | 2:91c41852a646 | 160 | |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 161 | snd.setVolume(snd.getMaxVol()); // volume to max level depending on headset/speaker safety level |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 162 | disp.persistence = true; |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 163 | disp.color=wavetype+1; |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 164 | disp.bgcolor=0; |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 165 | uint8_t sbindx=0; |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 166 | int oldvol=0; |
| Pokitto | 2:91c41852a646 | 167 | int linecenter = (disp.height/4); // center oscilloscope line vertically |
| Pokitto | 2:91c41852a646 | 168 | linecenter *=2; |
| Pokitto | 2:91c41852a646 | 169 | linecenter += 0; |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 170 | snd.ampEnable(1); |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 171 | snd.playTone(1,tonefreq,amplitude,wavetype,arpmode); |
| Pokitto | 2:91c41852a646 | 172 | //snd.playTone(1,100,255,0); |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 173 | // want to have 2 oscillators 1 octave apart ? |
| Pokitto | 2:91c41852a646 | 174 | snd.playTone(2,tonefreq+12,amplitude,wavetype,arpmode); |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 175 | |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 176 | disp.clear(); |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 177 | disp.print("Frq:"); |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 178 | getNoteString(notestr,tonefreq); |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 179 | disp.println(notestr); |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 180 | disp.print("Vol:"); |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 181 | disp.println((int)amplitude); |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 182 | disp.print("Wav:"); |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 183 | disp.print((int)wavetype); |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 184 | switch (wavetype) { |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 185 | case 0: |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 186 | disp.println(" Off");break; |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 187 | case 1: |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 188 | disp.println(" Square");break; |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 189 | case 2: |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 190 | disp.println(" Saw");break; |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 191 | case 3: |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 192 | disp.println(" Triang");break; |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 193 | case 4: |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 194 | disp.println(" Noise");break; |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 195 | case 5: |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 196 | disp.println(" SqNois");break; |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 197 | } |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 198 | disp.print("HWvol:"); |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 199 | disp.println((int)snd.getVolume()); |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 200 | disp.lcdRefresh(disp.screenbuffer); |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 201 | |
| Pokitto | 2:91c41852a646 | 202 | |
| Pokitto | 2:91c41852a646 | 203 | |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 204 | while (game.isRunning()) { |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 205 | |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 206 | #ifdef POK_SIM |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 207 | #define DEBOU 2048*32 |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 208 | #else |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 209 | #define DEBOU 256 |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 210 | #endif |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 211 | |
| Pokitto | 2:91c41852a646 | 212 | /* |
| Pokitto | 2:91c41852a646 | 213 | uint32_t* j = (uint32_t*)0x5000e204; |
| Pokitto | 2:91c41852a646 | 214 | *j = 0xab;//(0x1F*(uint32_t)val++)>>8; |
| Pokitto | 2:91c41852a646 | 215 | |
| Pokitto | 2:91c41852a646 | 216 | Chip_DMA_SetupTranChannel(LPC_DMA, DMA_CH0, &dmaDesc); |
| Pokitto | 2:91c41852a646 | 217 | Chip_DMA_SetValidChannel(LPC_DMA, DMA_CH0); |
| Pokitto | 2:91c41852a646 | 218 | dmaDesc.source = DMA_ADDR(&mysine[255]); |
| Pokitto | 2:91c41852a646 | 219 | dmaDesc.dest = DMA_ADDR(j); |
| Pokitto | 2:91c41852a646 | 220 | dmaDesc.next = DMA_ADDR(0);*/ |
| Pokitto | 2:91c41852a646 | 221 | |
| Pokitto | 2:91c41852a646 | 222 | /*if (!val) { |
| Pokitto | 2:91c41852a646 | 223 | dmaDesc.source = DMA_ADDR(&mysine[255]); |
| Pokitto | 2:91c41852a646 | 224 | dmaDesc.dest = DMA_ADDR(&soundbuf[255]); |
| Pokitto | 2:91c41852a646 | 225 | dmaDesc.next = DMA_ADDR(0); |
| Pokitto | 2:91c41852a646 | 226 | } else { |
| Pokitto | 2:91c41852a646 | 227 | dmaDesc.source = DMA_ADDR(&src[255]); |
| Pokitto | 2:91c41852a646 | 228 | dmaDesc.dest = DMA_ADDR(&soundbuf[255]); |
| Pokitto | 2:91c41852a646 | 229 | dmaDesc.next = DMA_ADDR(0); |
| Pokitto | 2:91c41852a646 | 230 | }*/ |
| Pokitto | 2:91c41852a646 | 231 | /* |
| Pokitto | 2:91c41852a646 | 232 | Chip_DMA_SetupChannelTransfer(LPC_DMA, DMA_CH0, |
| Pokitto | 2:91c41852a646 | 233 | (DMA_XFERCFG_CFGVALID | DMA_XFERCFG_SETINTA | DMA_XFERCFG_SWTRIG | |
| Pokitto | 2:91c41852a646 | 234 | DMA_XFERCFG_WIDTH_8 | DMA_XFERCFG_SRCINC_1 | DMA_XFERCFG_DSTINC_0 | |
| Pokitto | 2:91c41852a646 | 235 | DMA_XFERCFG_XFERCOUNT(255)));*/ |
| Pokitto | 2:91c41852a646 | 236 | |
| Pokitto | 2:91c41852a646 | 237 | //0x1f* |
| Pokitto | 2:91c41852a646 | 238 | //val=1-val; |
| Pokitto | 2:91c41852a646 | 239 | //fill buffer |
| Pokitto | 2:91c41852a646 | 240 | |
| Pokitto | 2:91c41852a646 | 241 | |
| Pokitto | 2:91c41852a646 | 242 | |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 243 | if (changed == 0) { |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 244 | if(btn.upBtn()) { amplitude++; changed = DEBOU; } |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 245 | if(btn.downBtn()) { amplitude--; changed = DEBOU; } |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 246 | if(btn.leftBtn() && (tonefreq > 0)) { tonefreq --; changed = DEBOU; } |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 247 | if(btn.rightBtn() && (tonefreq < 88)) { tonefreq ++; changed = DEBOU; } |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 248 | if(btn.released(BTN_A) && wavetype > 0 ) { wavetype--; changed = DEBOU*10;} |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 249 | if(btn.released(BTN_B) && wavetype < 5 ) { wavetype++; changed = DEBOU*10;} |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 250 | if (snd.getVolume() != oldvol) changed=DEBOU; |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 251 | |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 252 | if (changed) { |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 253 | disp.clear(); |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 254 | disp.color=0;//owavetype+1; |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 255 | disp.fillRectangle(0,0,109,34); |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 256 | disp.color=wavetype+1; |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 257 | disp.bgcolor=0; |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 258 | disp.print("Frq:"); |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 259 | getNoteString(notestr,tonefreq); |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 260 | disp.println(notestr); |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 261 | disp.print("Vol:"); |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 262 | disp.println((int)amplitude); |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 263 | disp.print("Wav:"); |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 264 | disp.print((int)wavetype); |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 265 | switch (wavetype) { |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 266 | case 0: |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 267 | disp.println(" Off");break; |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 268 | case 1: |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 269 | disp.println(" Square");break; |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 270 | case 2: |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 271 | disp.println(" Saw");break; |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 272 | case 3: |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 273 | disp.println(" Triang");break; |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 274 | case 4: |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 275 | disp.println(" Noise");break; |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 276 | case 5: |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 277 | disp.println(" SqNois");break; |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 278 | } |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 279 | disp.print("HWvol:"); |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 280 | disp.println((int)snd.getVolume()); |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 281 | snd.playTone(1,tonefreq,amplitude,wavetype,arpmode); |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 282 | oldvol = (int) snd.getVolume(); |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 283 | // want to have 2 oscillators 1 octave apart ? |
| Pokitto | 2:91c41852a646 | 284 | snd.playTone(2,tonefreq+12,amplitude,wavetype,arpmode); |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 285 | } |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 286 | } else changed--; |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 287 | disp.color=0; |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 288 | disp.drawColumn(sbx,38,disp.height); |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 289 | disp.color=wavetype+1; |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 290 | uint8_t tindex = sbindx*2; |
| Pokitto | 2:91c41852a646 | 291 | int16_t y = linecenter + (((int)128-(soundbuf[tindex]))>>2); |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 292 | disp.drawLine(sbx-1,prevy,sbx,y); |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 293 | game.update(); |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 294 | disp.color=0; |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 295 | prevy=y; |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 296 | sbx++;sbindx++; |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 297 | if (sbx>disp.width-1) {sbx=0;} |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 298 | } |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 299 | return 0; // good manners! |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 300 | } |
| group-Pokitto-Community-Team | 0:e0bd5da25882 | 301 |