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.
Revision 0:ad6637c36dc7, committed 2016-09-02
- Comitter:
- p_igmon
- Date:
- Fri Sep 02 13:24:16 2016 +0000
- Commit message:
- for Micro Gen4 Synthesizer
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LCD.lib Fri Sep 02 13:24:16 2016 +0000 @@ -0,0 +1,1 @@ +https://developer.mbed.org/users/p_igmon/code/LCD/#105c1b8f0c0e
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Synthsizer.cpp Fri Sep 02 13:24:16 2016 +0000
@@ -0,0 +1,575 @@
+/**********************************************************************
+
+
+***********************************************************************/
+
+#include "synthesizer.h"
+
+#ifdef DCF
+__asm S16 dcf64(S32 *param ,S32 *signal){
+
+ PUSH {R4-R7}
+ LDR r2,[r0 , #0]; param a0
+ LDR r3,[r1 , #0]; signal 0
+ SMULL r4,r5,r2,r3
+
+ LDR r6,[r0 , #4]; a1
+ LDR r7,[r1 , #4]; x1
+ SMLAL r4,r5,r6,r7; Top r5 Bottom r4
+ LDR r2,[r0 , #8]; b0
+ LDR r3,[r1 , #8]; x2
+ SMLAL r4,r5,r2,r3
+ LDR r6,[r0 , #12]; b1
+ LDR r7,[r1 , #12]; y1
+ SMLAL r4,r5,r6,r7
+ LDR r2,[r0 , #16]; b2
+ LDR r3,[r1 , #16]; y2
+ SMLAL r4,r5,r2,r3
+
+ MOV r0,r1; r0 = r1 signal
+ ADDS r4 ,r4, r4 ; add the least significant words
+ ADCS r5 ,r5, r5 ; add the most significant words with carry
+ ADDS r4, r4, r4 ; add the least significant words
+ ADCS r5, r5, r5 ; add the most significant words with carry
+
+ LDR r6,[r1, #12]; dcf_y1
+ LDR r3,[r0, #4]; dcf_x1
+ STR r6,[r1, #16]; dcf_y2 = dcf_y1
+ STR r3,[r0, #8]; dcf_x2 = dcf_x1
+ LDR r4,[r1, #0]; sample
+ STR r5,[r0, #12]; dcf_y1 = result
+ STR r4,[r1 ,#4]; dcf_x1 = sample
+
+ ASR r0,r5,#16; r0 = r5 >>16
+ POP {R4-R7}
+ BX LR
+; ENDP
+
+ ALIGN
+; END
+}
+#endif
+
+__asm S16 satAdd16(S16 val1 ,S16 val2){
+ QADD16 r0,r0,r1
+
+ BX LR
+; ENDP
+
+ ALIGN
+; END
+}
+
+__asm S32 satAdd32(S32 val1 ,S32 val2){
+ QADD r0,r0,r1
+
+ BX LR
+ ENDP
+
+ ALIGN
+ END
+}
+
+int gen_encount;
+
+extern DigitalOut generating;
+#define GENERATE_ON generating=1;
+#define GENERATE_OFF generating=0;
+
+S16 limit;
+
+/* DMA WAVE BUFFER */
+extern S16 DMA_Buffer[];
+extern __IO BUFFER_StateTypeDef BufferOffset;
+
+extern U8 midi_base_ch ;
+volatile U8 midi_note_ch ;
+volatile U8 midi_prog_ch ;
+
+volatile U8 samplecount = 0;
+extern S8 MasterTune;// -128 - +127
+volatile int portament;
+S16 MasterVolume = 127<<8;// max 127<<8
+volatile S16 mvoldiv = 0;
+
+extern STR_VOICE voice[];
+
+//static _UWORD df_table[] ={24883,26363,27930,29591,31351,33215,35190,37282,39499,41848,44336,46973};// 44.1k 440Hz@A4 1404029
+static U16 df_table[] ={24996,26482,28057,29725,31493,33366,35350,37452,39679,42038,44538,47186};// 44.1k 442Hz@A4
+
+static U16 k[16] ={65535,61439,57343,53247,49151,45055,40959,36863,32767,28671,24575,20479,16383,12287,8191,4095};// 121009
+
+#ifdef REVERVE16BIT
+S16 reverve_buf[22000];
+S16 *reverve_wtemp;
+#else
+S8 reverve_buf[44000];
+S8 *reverve_wtemp;
+#endif
+
+extern volatile int TimerCount10mS ;
+extern volatile int KeyValDiv;
+
+extern GENERATOR sgen[];
+extern GENERATOR dgen[];
+extern GENERATOR_TEMP dgen_temp[];
+extern GENERATOR *gen ;// = &sgen[(PresetVoiceNum - 1)*PRGGENMAX] set by Menu PresetVoice
+extern GENERATOR *pgen;// = &dgen[0];
+extern GENERATOR_TEMP *pgen_temp;// = &dgen_temp[0];
+extern WaveDef Wave[];
+
+extern U8 PresetVoiceNum;
+extern U8 MidiChannel;;
+extern S8 MasterTune;;
+extern int rch_pol;
+
+void init_voice(void){
+#ifdef DCF
+ int i;
+ GENERATOR *gena;
+ GENERATOR_TEMP *gena_temp;
+ STR_VOICE *voicea;
+ gena = pgen;
+ gena_temp = pgen_temp;
+ voicea = &voice[0];
+ for (i=0;i<VOICEMAX;i++){
+ voicea->enable = 0;
+ voicea->signal[0] = voicea->signal[1] = voicea->signal[2] = voicea->signal[3] = voicea->signal[4] = voicea->signal[5] = 0;
+ voicea->gen = gena;
+ voicea->gen_temp = gena_temp;
+ gena += PRGGENMAX;
+ gena_temp += PRGGENMAX;
+ voicea++;
+ }
+#endif
+}
+
+void gen_attack(GENERATOR *gena,GENERATOR_TEMP *gena_temp){
+ /* Generator Start */
+ gena_temp->lfo1value = 0;
+ gena_temp->lfo1count = 0;
+ gena_temp->lfo2count = 0;
+ gena_temp->lfo1delaycount = gena->lfo1delaytime;
+ gena_temp->lfo2delaycount = gena->lfo2delaytime;
+ gena_temp->x = 0;
+ gena_temp->startadr = (U8 *)Wave[gena->wave_num - 1].startaddr;
+ gena_temp->p1 = (U8 *)Wave[gena->wave_num - 1].p1;
+ gena_temp->p2 = (U8 *)Wave[gena->wave_num - 1].p2;
+ gena_temp->cycle = (U8 *)Wave[gena->wave_num - 1].cycle;
+ gena_temp->samplecountp1p2 = (U8 *)((uint8_t *)gena_temp->p2 - (uint8_t *)gena_temp->p1);
+ gena_temp->voltemp = 0;
+ gena_temp->voltemp1 = (gena->volume<<16) / gena->attacktime;
+ gena_temp->voltemp2 = ((gena->volume * gena->sustainlevel) /100) <<16;
+
+ gena_temp->status = GEN_NOTEON;
+ gena_temp->eg_status = EG_IDLE;
+}
+
+void init_sgen(void){
+ GENERATOR gena ={
+ 1,// U8 sw;// 0,1
+ 1,// U8 wave_num;// 1-128
+ 0,// S8 notebias;// -128 - +127
+ 31,// U8 pan;// 0-31
+ 0,// S16 detune;// -512 - +511
+ 32512,// U16 volume;// 0-127<<8
+ 1,// U16 attacktime;//
+ 100,// U16 decaytime;//
+ 80,// U8 sustainlevel;//
+ 0,// U16 releasetime;// 0-21
+ 0,// U16 lfo1depth;
+ 0,// U8 lfo1speed;
+ 0,// U8 lfo1type;
+ 0,// U16 lfo1delaytime;// 0-3000
+ 0,// U16 lfo2depth;
+ 0,// U8 lfo2speed;
+ 0,// U8 lfo2type;
+ 0,// U16 lfo2delaytime;// 0-3000
+ };
+
+// for(int i=0;i<PRGGENMAX*128;i++){
+ for(int i=0;i<PRGGENMAX*64;i++){
+ memcpy (&sgen[i],&gena,sizeof(GENERATOR));
+ }
+}
+
+
+void notenum2df(GENERATOR *gen ,GENERATOR_TEMP *gen_temp){
+ U32 temp;
+ U8 octave ,notenum;
+ notenum = gen_temp->notenum + gen->notebias;
+ octave = notenum / 12;
+ /* Pitch Adjuster */
+
+ if (gen_temp->cycle == 0){
+ temp = df_table[(notenum % 12)] * (U32)((U8 *)gen_temp->samplecountp1p2);// 2^16 * 2^(7-8)
+ }else{
+ temp = df_table[(notenum % 12)] * (U32)((U8 *)gen_temp->cycle);
+ }
+// temp += ((S32)(temp * MasterTune))>>12;// +32 縺ァ +1% ・・128 縺ァ +4%
+// temp += ((S32)(temp * MasterTune))>>4;// +32 縺ァ +1% ・・128 縺ァ +4%
+ gen_temp->df = (temp << (1 + octave));
+// gen_temp->df += (S32)((S32)((gen_temp->df>>19) * MasterTune)>>8);// 140617
+ gen_temp->df += (S32)((S32)((gen_temp->df>>8) * MasterTune)>>4);// 140618
+}
+
+void noteon(U8 notenum ,U8 velocity){
+ U8 i;
+ U8 gencount ,sgencount;
+ STR_VOICE *voicea;
+ GENERATOR *sgen;
+ GENERATOR *gena;
+ GENERATOR_TEMP *gena_temp;
+ voicea = &voice[0];
+ sgen = gen;// source
+ gena = pgen;// 螳滉ス薙・縺サ縺・〒
+ gena_temp = pgen_temp;// 螳滉ス薙・縺サ縺・〒
+ gencount = sgencount = 0;
+
+
+ if (portament){
+ while(sgencount < PRGGENMAX){// 騾壼クク・・
+ if(sgen->sw){ // 130302
+ while(gencount < GENMAX){
+ if(gena_temp->status == GEN_POROFF){
+ gena_temp->status = GEN_PORON;
+ gena_temp->notenum = notenum;
+ notenum2df(gena,gena_temp);
+// gena->velocity = velocity;
+ gena++;
+ gena_temp++;
+ gencount++;
+ break;// exit while
+ }
+ gena++;
+ gena_temp++;
+ gencount++;
+ }
+ }
+ sgen++;
+ sgencount++;
+ } // while loop
+ }else{
+#ifdef DCF
+ if(gen_encount > (GENMAX - 1))return;// 140707 Gen count limit
+ for (i=0;i<VOICEMAX;i++){
+ if(voicea->enable == 0) break;// 遨コ縺・※縺・kvoice
+ voicea++;
+ }
+ if(i>(VOICEMAX - 1))return;// All Voice is Working
+// voicea->enable = 0;
+ gena = voicea->gen;
+ gena_temp = voicea->gen_temp;
+ sgen = gen;// source
+
+ for (i=0;i<PRGGENMAX;i++){
+ if(sgen->sw){
+ memcpy(gena ,sgen ,sizeof(GENERATOR));// sgen1 ->> gena1
+ gena_temp->notenum = notenum;
+ gena_temp->velocity = velocity;
+ gen_attack(gena ,gena_temp);
+ notenum2df(gena ,gena_temp);
+ gen_encount++;// 140707
+ voicea->enable |= 1<<i;
+ }else{
+ gena_temp->status = GEN_IDLE;
+ gena->sw = 0;
+ gena_temp->voltemp = 0;
+ }
+ gena++;
+ gena_temp++;
+ sgen++;
+ }
+
+ }
+#else
+ if(gen_encount > (GENMAX - 1))return;// 140707 Gen count limit
+ while(sgencount < PRGGENMAX){// 騾壼クク・・
+ if(sgen->sw){ // 130302
+ while(gencount < GENMAX){
+ if(gena_temp->status == GEN_IDLE){
+ memcpy(gena ,sgen ,sizeof(GENERATOR));// sgen ->> gena
+ gena_temp->notenum = notenum;
+ gena_temp->velocity = velocity;
+ gen_attack(gena ,gena_temp);
+ notenum2df(gena ,gena_temp);
+ gena++;
+ gena_temp++;
+ gencount++;
+ gen_encount++;// 140707
+ break;// exit while
+ }
+ gena++;
+ gena_temp++;
+ gencount++;
+ }
+ }
+ sgen++;
+ sgencount++;
+ }
+ }
+#endif
+}
+
+void noteoff(U8 notenum ,U8 velocity){
+ U8 i;
+ GENERATOR *gena;
+ GENERATOR_TEMP *gena_temp;
+ gena = pgen;// 螳滉ス薙・縺サ縺・〒
+ gena_temp = pgen_temp;// 螳滉ス薙・縺サ縺・〒
+ for(i=0;i<GENMAX;i++){
+ if(((gena_temp->status == GEN_NOTEON)||(gena_temp->status == GEN_PORON)) && (gena_temp->notenum == notenum)){ // 130302
+
+/* 111025 Velocity active untill release time
+ gena->velocity = 0;
+*/
+ if (portament){
+ gena_temp->status = GEN_POROFF;
+ }else{
+ /* Generator Start Release */
+ gena_temp->status = GEN_NOTEOFF;
+ gena_temp->eg_status = EG_RELEASE;
+ }
+ }
+ gena++;
+ gena_temp++;
+ }
+}
+
+void pgmchg(U8 number){
+ if (number >63) return;
+ PresetVoiceNum = number + 1;
+ presetvoice();
+}
+
+
+/*
+ Interpolaton value
+ x - 逵溘・豕「蠖「縺ョ蠎ァ讓・
+ y - 陬憺俣險育ョ励↓繧医▲縺ヲ蠕励ky(x)
+
+ 謖・焚驛ィ・主ー乗焚驛ィ
+ 20 12 bit
+*/
+
+ uint32_t temp32a;
+/* DMA Wave繝舌ャ繝輔ぃ縺ォ豕「蠖「繧呈嶌縺崎セシ繧 */
+void wave_generate(void){
+ U8 i;
+ U16 count;
+ S32 rch,lch;
+ S16 rchout,lchout;
+ S16 temps16;
+ S32 sample;
+ S16 interpovalue;
+ S32 interpovalue32;
+ GENERATOR *gena;
+ GENERATOR_TEMP *gena_temp;
+ STR_VOICE *voicea;
+
+ volatile S16 *ptr;
+ U16 temp;
+ S32 y;
+ U32 expo_x; // 謖・焚驛ィ 20bit
+ U16 fract_x;// 蟆乗焚驛ィ 12bit
+
+ volatile S16 *ptr0;
+ GENERATE_ON
+ if (--TimerCount10mS < 0) TimerCount10mS = 0;
+
+ if (BufferOffset == DMA_FullComplete){
+ ptr0 = (S16 *)&DMA_Buffer[DMA_BUFFERSIZE>>1];// From Half
+ }else{
+ ptr0 = (S16 *)&DMA_Buffer[0];// From Top
+ }
+ BufferOffset = DMA_Idle;
+
+ count = DMA_BUFFERSIZE/4;// DMA 繝舌ャ繝輔ぃ縺ョ繧オ繧、繧コ
+ while(count-- > 0){
+ if(samplecount++ > 43){
+ samplecount = 0;
+ envelope_work();
+ }
+ voicea = &voice[0];
+ sample = 0;
+ gena = pgen;// 螳滉ス薙・縺サ縺・〒
+ gena_temp = pgen_temp;// 螳滉ス薙・縺サ縺・〒
+ for(i=0;i<GENMAX;i++){
+ if(gena_temp->eg_status != EG_IDLE){
+ // if(gena_temp->status !=GEN_IDLE){
+
+/*
+#ifdef BEND
+ gena->x += (((U32)gena_temp->df>>16) + (S16)gena->detune + gena->lfo1value + gena->bendvalue);
+#else
+// gena_temp->x += (((U32)gena_temp->df>>16) + (S16)gena->detune + gena_temp->lfo1value);
+ gena_temp->x += (((U32)gena_temp->df>>16) + (S32)gena->detune + gena_temp->lfo1value);
+#endif
+*/
+ gena_temp->x += gena_temp->xx;
+
+ if (gena_temp->x <= (U32)gena_temp->p2<<12){
+ goto generate1;
+ }else if(gena_temp->p1 == 0){// No Loop
+ goto nothing;
+ }else{
+ gena_temp->x -= ((U32)gena_temp->samplecountp1p2 <<12);// Loop p1 - p2
+ }
+
+generate1: expo_x = gena_temp->x>>12;
+#ifdef INTERPO2
+ temp = (gena_temp->x) & 0xfff;
+ ptr = (S16*)gena_temp->startadr +((U32)expo_x);
+ y = (*ptr * (4096 - temp));
+ ptr++;
+ y += *ptr * temp;
+ interpovalue32 = (S32)((S16)(y>>12) * limit)>>3;
+#else
+ fract_x = (gena_temp->x>>8) & 0x0f;
+ ptr = (S16*)gena_temp->startadr +((U32)expo_x);
+
+ temp = k[fract_x];
+ y = *ptr * temp;
+ ptr++;
+ y += (*ptr * (65535 - temp));
+ interpovalue32 = (S16)(y>>16) * limit;
+
+#endif
+
+#ifdef DIST
+// if (gena_temp->eg_status < EG_RELEASE){
+ if (interpovalue32 > 120<<8){
+ interpovalue32 = 120<<8;
+ }else if(interpovalue32 < (120<<8) * -1){
+ interpovalue32 = (120<<8) * -1;
+ }
+// }
+#endif
+
+#ifdef 0
+ if (gena_temp->eg_status < EG_RELEASE){
+ if (interpovalue > limit<<8){
+ interpovalue = limit<<8;
+ }else if(interpovalue < (limit<<8) * -1){
+ interpovalue = (limit<<8) * -1;
+ }
+ }
+#endif
+
+// sample += ((S16)interpovalue * ((gena_temp->voltempL)>>1));// 譛牙柑譯∵焚32繝薙ャ繝・
+ sample = satAdd32(sample ,((S16)interpovalue32 * ((gena_temp->voltempL)>>1)));
+nothing:
+
+ }
+#ifdef DCF
+ if ((i & (PRGGENMAX - 1))== (PRGGENMAX - 1)){
+ voicea->signal[0] = (S32)(sample);// 譛牙柑譯∵焚32繝薙ャ繝・
+ voicea++;
+ sample = 0;
+ }
+#endif
+ gena++;
+ gena_temp++;
+ }
+#ifdef DCF
+ voicea =&voice[0];
+ lch = 0;
+ i = VOICEMAX;
+ while(i--){
+// lch += (S16)(dcf64(voicea->dcf_param ,&voicea->signal[0]));
+ lch = satAdd16(lch ,(S16)(dcf64(voicea->dcf_param ,&voicea->signal[0])));
+// lch += (S16)((S32)voicea->signal[0]>>16);// NoneLPF
+ voicea++;
+ }
+#else
+ lch = sample >> 16;
+#endif
+
+// temps16 = (((S32)lch) * (((S16)MasterVolume)<<1))>>16;
+
+#ifdef 0
+ if (lch > limit<<8){
+ lch = limit<<8;
+ }else if(lch < (limit<<8) * -1){
+ lch = (limit<<8) * -1;
+ }
+#endif
+
+#if 0
+ /* Reverve */
+#ifdef REVERVE16BIT
+ if (count & 1){
+ if(++reverve_wtemp == (reverve_buf + 22000)) reverve_wtemp = reverve_buf;
+ *reverve_wtemp = temps16;
+ rchout = lchout = 0;
+ for(i=0;i<90;i += 3){
+ S16 *temp_ptr = reverve_wtemp - reverve_tap[i];
+ if(temp_ptr < reverve_buf){
+ lchout += ((S16)(*(temp_ptr + 22000)) * (U16)reverve_tap[i+1])>>18;
+ rchout += ((S16)(*(temp_ptr + 22000)) * (U16)reverve_tap[i+2])>>18;
+ }else{
+ lchout += ((S16)(*temp_ptr) * (U16)reverve_tap[i+1])>>18;
+ rchout += ((S16)(*temp_ptr) * (U16)reverve_tap[i+2])>>18;
+ }
+ }
+ }
+#else
+ /* Reverve */
+ rchout = lchout = 0;
+ if(++reverve_wtemp == (reverve_buf + 44000)) reverve_wtemp = reverve_buf;
+ *reverve_wtemp = S8(temps16>>8);
+ for(i=0;i<90;i += 3){
+ S8 *temp_ptr = reverve_wtemp - reverve_tap[i];
+ if(temp_ptr < reverve_buf){
+ lchout += ((S8)(*(temp_ptr + 44000)) * (U16)reverve_tap[i+1])>>10;
+ rchout += ((S8)(*(temp_ptr + 44000)) * (U16)reverve_tap[i+2])>>10;
+ }else{
+ lchout += ((S8)(*temp_ptr) * (U16)reverve_tap[i+1])>>10;
+ rchout += ((S8)(*temp_ptr) * (U16)reverve_tap[i+2])>>10;
+ }
+
+ }
+
+#endif
+// *bufptr++ = ((rch + (rchout & 0xffff))<<16)|(((lch & 0xffff) + (lchout & 0xffff)) & 0xffff);
+
+ *ptr0++ = temps16 + rchout;
+ *ptr0++ = temps16 + lchout;
+#endif
+
+ temps16 = (((S32)lch) * (((S16)MasterVolume)<<1))>>16;
+ *ptr0++ = temps16;
+ *ptr0++ = rch_pol * temps16;
+
+ }
+ GENERATE_OFF
+}
+
+
+void uGen4_init(void)
+{
+ GENERATOR *gena;
+ GENERATOR_TEMP *gena_temp;
+
+ mvoldiv = 0;
+ portament = 0;// 130213
+
+ gena = pgen;
+ gena_temp = pgen_temp;
+ for(int i=0;i<GENMAX;i++){
+ gena_temp->status = GEN_IDLE;
+ gena->sw = 0;
+ gena_temp->voltemp = 0;
+ gena++;
+ gena_temp++;
+ }
+
+ init_voice();
+
+ midi_note_ch = midi_base_ch;
+ midi_prog_ch = midi_base_ch;
+
+// init_midi();
+
+}
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/dcf_table.h Fri Sep 02 13:24:16 2016 +0000
@@ -0,0 +1,349 @@
+/*
+ LPF Parameter Table
+ a0,a1,b0,b1,b2
+
+*/
+
+static signed long dcf_table[][5]={
+{13562,27124,13562,2137910446,-1064222872},
+{13574,27148,13574,2139807431,-1066119905},
+{13598,27196,13598,2143611519,-1069924090},
+{13606,27213,13606,2144882556,-1071195159},
+{13610,27221,13610,2145518640,-1071831259},
+{13612,27225,13612,2145900471,-1072213100},
+{13614,27229,13614,2146155101,-1072467736},
+{13615,27231,13615,2146337016,-1072649656},
+{13616,27233,13616,2146473473,-1072786117},
+{13617,27234,13617,2146579618,-1072892264},
+{13617,27235,13617,2146664542,-1072977190},
+{19163,38327,19163,2136096511,-1062431344},
+{19184,38368,19184,2138348985,-1064683899},
+{19224,38449,19224,2142868214,-1069203290},
+{19238,38476,19238,2144378872,-1070714002},
+{19244,38489,19244,2145135000,-1071470157},
+{19249,38498,19249,2145588933,-1071924106},
+{19251,38503,19251,2145891661,-1072226845},
+{19253,38507,19253,2146107948,-1072443140},
+{19255,38510,19255,2146270192,-1072605390},
+{19256,38512,19256,2146396399,-1072731601},
+{19257,38514,19257,2146497375,-1072832580},
+{27074,54149,27074,2133938300,-1060304777},
+{27108,54217,27108,2136612105,-1062978717},
+{27176,54353,27176,2141979867,-1068346751},
+{27199,54399,27199,2143775119,-1070142094},
+{27210,54421,27210,2144673874,-1071040895},
+{27217,54435,27217,2145213489,-1071580537},
+{27222,54444,27222,2145573383,-1071940450},
+{27225,54451,27225,2145830524,-1072197604},
+{27228,54456,27228,2146023420,-1072390510},
+{27230,54460,27230,2146173475,-1072540572},
+{27231,54463,27231,2146293534,-1072660637},
+{38244,76488,38244,2131370245,-1057781399},
+{38301,76602,38301,2134543095,-1060954476},
+{38415,76830,38415,2140917219,-1067329058},
+{38453,76907,38453,2143050395,-1069462387},
+{38472,76945,38472,2144118578,-1070530647},
+{38484,76968,38484,2144759999,-1071172114},
+{38492,76984,38492,2145187826,-1071599972},
+{38497,76995,38497,2145493522,-1071905689},
+{38501,77003,38501,2145722851,-1072135034},
+{38504,77009,38504,2145901251,-1072313448},
+{38507,77014,38507,2146043993,-1072456200},
+{54009,108018,54009,2128314199,-1054788412},
+{54104,108209,54104,2132077687,-1058552283},
+{54296,108593,54296,2139644735,-1066120099},
+{54360,108721,54360,2142179035,-1068654656},
+{54393,108786,54393,2143448437,-1069924187},
+{54412,108825,54412,2144210801,-1070686628},
+{54425,108850,54425,2144719345,-1071195224},
+{54434,108869,54434,2145082738,-1071558654},
+{54441,108883,54441,2145355364,-1071831307},
+{54446,108893,54446,2145567455,-1072043419},
+{54451,108902,54451,2145737157,-1072213139},
+{76252,152505,76252,2124676993,-1051240181},
+{76412,152825,76412,2129138878,-1055702706},
+{76734,153469,76734,2138119106,-1064684223},
+{76843,153686,76843,2141129373,-1067694922},
+{76897,153794,76897,2142637687,-1069203453},
+{76929,153859,76929,2143543696,-1070109592},
+{76951,153902,76951,2144148128,-1070714110},
+{76966,153933,76966,2144580074,-1071146118},
+{76978,153956,76978,2144904147,-1071470238},
+{76987,153975,76987,2145156272,-1071722399},
+{76994,153989,76994,2145358015,-1071924171},
+{107622,215245,107622,2120347510,-1047036179},
+{107891,215782,107891,2125634296,-1052324038},
+{108432,216864,108432,2136287356,-1062979262},
+{108613,217226,108613,2139862145,-1066554776},
+{108704,217408,108704,2141654030,-1068347024},
+{108759,217518,108759,2142730602,-1069423815},
+{108795,217591,108795,2143448918,-1070142277},
+{108821,217643,108821,2143962296,-1070655759},
+{108841,217682,108841,2144347490,-1071041032},
+{108856,217712,108856,2144647182,-1071340785},
+{108868,217737,108868,2144886996,-1071580647},
+{151842,303685,151842,2115193160,-1042058707},
+{152291,304583,152291,2121452974,-1048320319},
+{153198,306397,153198,2134084418,-1060955390},
+{153503,307006,153503,2138328392,-1065200583},
+{153656,307312,153656,2140456716,-1067329517},
+{153747,307495,153747,2141735745,-1068608913},
+{153809,307618,153809,2142589280,-1069462694},
+{153852,307705,153852,2143199365,-1070072954},
+{153885,307771,153885,2143657157,-1070530877},
+{153911,307822,153911,2144013352,-1070887175},
+{153931,307863,153931,2144298394,-1071172298},
+{214135,428271,214135,2109055663,-1036170384},
+{214887,429775,214887,2116461401,-1043579129},
+{216407,432815,216407,2131430007,-1058553814},
+{216918,433837,216918,2136466705,-1063592558},
+{217175,434351,217175,2138993991,-1066120870},
+{217329,434659,217329,2140513234,-1067640731},
+{217432,434865,217432,2141527263,-1068655171},
+{217506,435012,217506,2142252157,-1069380360},
+{217561,435123,217561,2142796150,-1069924574},
+{217604,435209,217604,2143219447,-1070348043},
+{217638,435277,217638,2143558205,-1070686938},
+{301826,603653,301826,2101745977,-1029211461},
+{303083,606167,303083,2110498666,-1037969177},
+{305629,611258,305629,2128224581,-1055705275},
+{306487,612974,306487,2134199574,-1061683700},
+{306918,613836,306918,2137199669,-1064685518},
+{307177,614354,307177,2139003778,-1066490663},
+{307350,614700,307350,2140208211,-1067695788},
+{307473,614947,307473,2141069350,-1068557422},
+{307566,615133,307566,2141715660,-1069204103},
+{307638,615277,307638,2142218615,-1069707347},
+{307696,615393,307696,2142621149,-1070110113},
+{425163,850326,425163,2093038202,-1020997031},
+{427261,854523,427261,2103370466,-1031337691},
+{431522,863044,431522,2124344076,-1052328343},
+{432961,865922,432961,2131428539,-1059418562},
+{433684,867369,433684,2134988520,-1062981435},
+{434119,868239,434119,2137130222,-1065124878},
+{434410,868820,434410,2138560412,-1066556230},
+{434617,869235,434617,2139583149,-1067579798},
+{434773,869547,434773,2140350844,-1068348117},
+{434895,869790,434895,2140948321,-1068946079},
+{434992,869984,434992,2141426543,-1069424690},
+{598458,1196917,598458,2082662270,-1011314281},
+{601958,1203916,601958,2094841718,-1023507728},
+{609082,1218164,609082,2119633024,-1048327530},
+{611494,1222988,611494,2128027705,-1056731860},
+{612707,1225415,612707,2132250030,-1060959038},
+{613438,1226876,613438,2134791478,-1063503407},
+{613925,1227851,613925,2136489144,-1065203025},
+{614274,1228549,614274,2137703417,-1066418694},
+{614536,1229073,614536,2138615028,-1067331352},
+{614740,1229481,614740,2139324597,-1068041737},
+{614903,1229807,614903,2139892591,-1068610383},
+{841656,1683312,841656,2070295152,-999919954},
+{847483,1694966,847483,2084627377,-1014275486},
+{859381,1718763,859381,2113895498,-1043591202},
+{863422,1726844,863422,2123835031,-1053546897},
+{865457,1730914,865457,2128839931,-1058559937},
+{866682,1733365,866682,2131854210,-1061579117},
+{867501,1735002,867501,2133868476,-1063596658},
+{868087,1736174,868087,2135309569,-1065040095},
+{868527,1737054,868527,2136391667,-1066123953},
+{868869,1737739,868869,2137234057,-1066967713},
+{869143,1738287,869143,2137908448,-1067643200},
+{1182468,2364936,1182468,2055550357,-986538407},
+{1192150,2384300,1192150,2072381098,-1003407877},
+{1211997,2423995,1211997,2106883204,-1037989372},
+{1218761,2437522,1218761,2118640623,-1049773846},
+{1222171,2444342,1222171,2124568680,-1055715543},
+{1224226,2448453,1224226,2128141464,-1059296548},
+{1225600,2451201,1225600,2130530003,-1061690583},
+{1226584,2453168,1226584,2132239388,-1063403901},
+{1227322,2454645,1227322,2133523228,-1064690695},
+{1227897,2455795,1227897,2134522839,-1065692607},
+{1228358,2456716,1228358,2135323203,-1066494812},
+{1659274,3318549,1659274,2037965389,-970860664},
+{1675326,3350653,1675326,2057681174,-990640658},
+{1708381,3416762,1708381,2098279735,-1031371438},
+{1719691,3439382,1719691,2112170955,-1045307897},
+{1725402,3450805,1725402,2119185766,-1052345554},
+{1728847,3457695,1728847,2123417063,-1056590631},
+{1731152,3462304,1731152,2126247328,-1059430113},
+{1732801,3465603,1732801,2128273569,-1061462953},
+{1734041,3468082,1734041,2129795786,-1062990128},
+{1735006,3470012,1735006,2130981238,-1064179441},
+{1735779,3471558,1735779,2131930551,-1065131846},
+{2325026,4650053,2325026,2016986907,-952545190},
+{2351569,4703139,2351569,2040013181,-975677636},
+{2406515,4813031,2406515,2087679813,-1023564054},
+{2425406,4850812,2425406,2104067586,-1040027389},
+{2434963,4869926,2434963,2112358332,-1048356363},
+{2440733,4881467,2440733,2117364216,-1053385328},
+{2444595,4889191,2444595,2120714674,-1056751235},
+{2447362,4894724,2447362,2123114357,-1059161983},
+{2449440,4898881,2449440,2124917687,-1060973627},
+{2451060,4902120,2451060,2126322395,-1062384813},
+{2452357,4904714,2452357,2127447500,-1063515106},
+{3252449,6504899,3252449,1991953192,-931221167},
+{3296200,6592401,3296200,2018748588,-958191568},
+{3387332,6774664,3387332,2074561854,-1014369361},
+{3418839,6837679,3418839,2093858475,-1033792012},
+{3434814,6869628,3434814,2103642031,-1043639466},
+{3444471,6888942,3444471,2109556173,-1049592234},
+{3450938,6901877,3450938,2113517444,-1053579376},
+{3455573,6911147,3455573,2116356043,-1056436515},
+{3459058,6918116,3459058,2118490001,-1058584411},
+{3461773,6923546,3461773,2120152724,-1060257993},
+{3463947,6927895,3463947,2121484783,-1061598752},
+{4540897,9081794,4540897,1962073844,-906495609},
+{4612745,9225490,4612745,1993118696,-937827854},
+{4763485,9526970,4763485,2058251950,-1003564069},
+{4815945,9631891,4815945,2080919450,-1026441409},
+{4842611,9685222,4842611,2092441464,-1038070087},
+{4858753,9717506,4858753,2099416122,-1045109312},
+{4869574,9739148,4869574,2104091783,-1049828257},
+{4877333,9754666,4877333,2107444312,-1053211822},
+{4883168,9766337,4883168,2109965729,-1055756580},
+{4887716,9775433,4887716,2111931005,-1057740050},
+{4891361,9782723,4891361,2113505865,-1059329488},
+{6325263,12650527,6325263,1926406511,-877965744},
+{6442734,12885469,6442734,1962183130,-914212246},
+{6691271,13382542,6691271,2037876749,-990900011},
+{6778433,13556866,6778433,2064422627,-1017794537},
+{6822871,13645742,6822871,2077956611,-1031506274},
+{6849815,13699630,6849815,2086162515,-1039819952},
+{6867896,13735792,6867896,2091669218,-1045398980},
+{6880869,13761739,6880869,2095620410,-1049402066},
+{6890632,13781264,6890632,2098593615,-1052414320},
+{6898244,13796488,6898244,2100911946,-1054763100},
+{6904346,13808692,6904346,2102770303,-1056645864},
+{8787386,17574772,8787386,1883830915,-845238637},
+{8978456,17956913,8978456,1924792457,-886964462},
+{9386659,18773318,9386659,2012302447,-976107261},
+{9531101,19062203,9531101,2043267925,-1007650509},
+{9605003,19210006,9605003,2059110809,-1023788999},
+{9649896,19299793,9649896,2068735018,-1033592782},
+{9680059,19360119,9680059,2075201295,-1040179710},
+{9701720,19403440,9701720,2079844869,-1044909926},
+{9718029,19436058,9718029,2083341210,-1048471504},
+{9730752,19461504,9730752,2086068724,-1051249910},
+{9740954,19481908,9740954,2088255883,-1053477877},
+{12170368,24340736,12170368,1833020484,-807960134},
+{12479265,24958531,12479265,1879544567,-855719806},
+{13146616,26293233,13146616,1980056610,-958901255},
+{13385216,26770433,13385216,2015992898,-995791941},
+{13507793,27015587,13507793,2034454680,-1014744033},
+{13582423,27164847,13582423,2045694951,-1026282823},
+{13632636,27265273,13632636,2053257722,-1034046447},
+{13668731,27337462,13668731,2058694027,-1039627130},
+{13695927,27391855,13695927,2062790185,-1043832074},
+{13717155,27434311,13717155,2065987372,-1047114172},
+{13734185,27468370,13734185,2068552267,-1049747185},
+{16796193,33592387,16796193,1772412863,-765855815},
+{17292027,34584055,17292027,1824735547,-820161834},
+{18377029,36754058,18377029,1939229999,-938996293},
+{18769600,37539200,18769600,1980655931,-981992509},
+{18972243,37944486,18972243,2002039770,-1004186920},
+{19095943,38191886,19095943,2015093151,-1017735100},
+{19179309,38358619,19179309,2023890383,-1026865799},
+{19239304,38478608,19239304,2030221295,-1033436689},
+{19284547,38569094,19284547,2034995532,-1038391898},
+{19319883,38639766,19319883,2038724380,-1042262090},
+{19348245,38696491,19348245,2041717311,-1045368472},
+{23086903,46173807,23086903,1700180433,-718786226},
+{23876198,47752397,23876198,1758306196,-780069169},
+{25628578,51257156,25628578,1887356040,-916128531},
+{26271300,52542601,26271300,1934687796,-966031176},
+{26604904,53209808,26604904,1959255230,-991933024},
+{26809164,53618328,26809164,1974297478,-1007792312},
+{26947088,53894177,26947088,1984454623,-1018501156},
+{27046478,54092957,27046478,1991773949,-1026218041},
+{27121503,54243007,27121503,1997298974,-1032043165},
+{27180144,54360289,27180144,2001617453,-1036596208},
+{27227240,54454480,27227240,2005085705,-1040252843},
+{31589485,63178970,31589485,1614202708,-666818827},
+{32833809,65667619,32833809,1677786901,-735380318},
+{35641695,71283391,35641695,1821268090,-890093051},
+{36687511,73375023,36687511,1874708612,-947716835},
+{37233777,74467554,37233777,1902622442,-977815728},
+{37569415,75138830,37569415,1919773340,-996309178},
+{37796556,75593112,37796556,1931380092,-1008824494},
+{37960488,75920977,37960488,1939756929,-1017857060},
+{38084374,76168748,38084374,1946087399,-1024683072},
+{38181289,76362579,38181289,1951039736,-1030023073},
+{38259178,76518356,38259178,1955019791,-1034314681},
+{43004703,86009407,43004703,1512041128,-610318119},
+{44944494,89888988,44944494,1580243977,-686280132},
+{49401114,98802229,49401114,1736938316,-860800953},
+{51089773,102179547,51089773,1796311389,-926928661},
+{51978147,103956295,51978147,1827546539,-961717307},
+{52526158,105052316,52526158,1846814532,-983177343},
+{52897963,105795927,52897963,1859887175,-997737207},
+{53166778,106333556,53166778,1869338660,-1008263950},
+{53370188,106740377,53370188,1876490555,-1016229486},
+{53529476,107058952,53529476,1882091087,-1022467168},
+{53657592,107315184,53657592,1886595640,-1027484186},
+{58220519,116441038,58220519,1390915479,-550055733},
+{61205645,122411290,61205645,1462231534,-633312292},
+{68199161,136398323,68199161,1629309921,-828364745},
+{70899550,141799101,70899550,1693823483,-903679864},
+{72331557,144663115,72331557,1728034801,-943619210},
+{73218869,146437738,73218869,1749233080,-968366733},
+{73822603,147645207,73822603,1763656587,-985205179},
+{74259974,148519949,74259974,1774105584,-997403661},
+{74591419,149182838,74591419,1782023947,-1006647801},
+{74851262,149702524,74851262,1788231712,-1013894937},
+{75060443,150120886,75060443,1793229151,-1019729101},
+{78352429,156704859,78352429,1247674584,-487342479},
+{82878656,165757312,82878656,1319749670,-577522472},
+{93704853,187409706,93704853,1492144716,-793222306},
+{97970730,195941460,97970730,1560074021,-878215118},
+{100252712,200505425,100252712,1596412038,-923681066},
+{101673652,203347305,101673652,1619038912,-951991699},
+{102643536,205287073,102643536,1634483231,-971315555},
+{103347717,206695435,103347717,1645696525,-985345573},
+{103882227,207764454,103882227,1654207985,-995995071},
+{104301794,208603589,104301794,1660889125,-1004354480},
+{104639896,209279793,104639896,1666273020,-1011090783},
+{104796818,209593636,104796818,1078744319,-424189770},
+{111544626,223089253,111544626,1148204062,-520640746},
+{128032510,256065020,128032510,1317924963,-756313180},
+{134667781,269335563,134667781,1386226287,-851155591},
+{138250182,276500364,138250182,1423102353,-902361259},
+{140492592,280985185,140492592,1446184997,-934413545},
+{142028388,284056776,142028388,1461993973,-956365702},
+{143146103,286292207,143146103,1473499375,-972341968},
+{143996004,287992008,143996004,1482247971,-984490164},
+{144664047,289328094,144664047,1489124590,-994038956},
+{145202961,290405922,145202961,1494671996,-1001742019},
+{139311738,278623476,139311738,880016370,-363521500},
+{149179103,298358207,149179103,942347393,-465321986},
+{173799301,347598602,173799301,1097870374,-719325757},
+{183917059,367834119,183917059,1161783100,-823709515},
+{189430938,378861876,189430938,1196613641,-880595570},
+{192900867,385801734,192900867,1218532788,-916394433},
+{195285649,390571299,195285649,1233597186,-940997961},
+{197025488,394050976,197025488,1244587548,-958947678},
+{198350848,396701696,198350848,1252959698,-972621269},
+{199394076,398788153,199394076,1259549652,-983384135},
+{200236593,400473187,200236593,1264871736,-992076288},
+{184155418,368310836,184155418,646614121,-309493971},
+{198267318,396534636,198267318,696164408,-415491858},
+{234153927,468307855,234153927,822170956,-685044845},
+{249188388,498376776,249188388,874960576,-797972306},
+{257453627,514907254,257453627,903981825,-860054512},
+{262681295,525362591,262681295,922337430,-899320790},
+{266285969,532571939,266285969,934994311,-926396368},
+{268921906,537843813,268921906,944249722,-946195527},
+{270933362,541866725,270933362,951312429,-961304057},
+{272518753,545037506,272518753,956879117,-973212307},
+{273800487,547600974,273800487,961379595,-982839722},
+{242344825,484689650,242344825,372426117,-268063595},
+{262004215,524008430,262004215,402637904,-376912942},
+{312744927,625489854,312744927,480614260,-657852145},
+{334327282,668654564,334327282,513781186,-777348493},
+{346275420,692550841,346275420,532142621,-843502481},
+{353863206,707726413,353863206,543803236,-885514240},
+{359109211,718218423,359109211,551865093,-914560117},
+{362952608,725905216,362952608,557771475,-935840084},
+{365889580,731779161,365889580,562284901,-952101402},
+{368206962,736413925,368206962,565846163,-964932190},
+{370082110,740164221,370082110,568727818,-975314437}
+};
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/device.cpp Fri Sep 02 13:24:16 2016 +0000
@@ -0,0 +1,164 @@
+/**
+ * COPYRIGHT(c) 2014 STMicroelectronics
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of STMicroelectronics nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ ******************************************************************************
+ */
+
+#include "synthesizer.h"
+
+/* Private variables ---------------------------------------------------------*/
+I2S_HandleTypeDef hi2s2;
+DMA_HandleTypeDef hdma_i2s2_ext_tx;
+
+
+/* Private function prototypes -----------------------------------------------*/
+static void SystemClock_Config(void);
+static void MX_DMA_Init(void);
+static void MX_I2S2_Init(void);
+
+
+void uGen4_device_init(void)
+{
+ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
+ HAL_Init();
+
+ /* Configure the system clock */
+ SystemClock_Config();// Set RCC I2S Clock
+
+ /* Initialize all configured peripherals */
+ MX_GPIO_Init();// GPIO CLOCK Enable
+ MX_DMA_Init();
+ MX_I2S2_Init();
+}
+
+
+/** System Clock Configuration
+*/
+static void SystemClock_Config(void)
+{
+
+ RCC_ClkInitTypeDef RCC_ClkInitStruct;
+ RCC_PeriphCLKInitTypeDef PeriphClkInitStruct;
+ RCC_OscInitTypeDef RCC_OscInitStruct;
+
+ __PWR_CLK_ENABLE();
+
+ __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE2);
+
+ RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
+ RCC_OscInitStruct.HSIState = RCC_HSI_ON;
+ RCC_OscInitStruct.HSICalibrationValue = 6;
+ RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
+ RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
+ RCC_OscInitStruct.PLL.PLLM = 16;
+ RCC_OscInitStruct.PLL.PLLN = 336;
+ RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4;
+ RCC_OscInitStruct.PLL.PLLQ = 4;
+ HAL_RCC_OscConfig(&RCC_OscInitStruct);
+
+ RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK|RCC_CLOCKTYPE_PCLK1;
+ RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
+ RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
+ RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
+ RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
+ HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2);
+
+ PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_I2S;
+ PeriphClkInitStruct.PLLI2S.PLLI2SN = 290;
+ PeriphClkInitStruct.PLLI2S.PLLI2SR = 2;
+ HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct);
+
+}
+
+/* I2S2 init function */
+void MX_I2S2_Init(void)
+{
+
+ hi2s2.Instance = SPI2;
+ hi2s2.Init.Mode = I2S_MODE_MASTER_TX;
+ hi2s2.Init.Standard = I2S_STANDARD_PHILLIPS;
+ hi2s2.Init.DataFormat = I2S_DATAFORMAT_16B;
+ hi2s2.Init.MCLKOutput = I2S_MCLKOUTPUT_ENABLE;
+ hi2s2.Init.AudioFreq = I2S_AUDIOFREQ_44K;
+ hi2s2.Init.CPOL = I2S_CPOL_LOW;
+ hi2s2.Init.ClockSource = I2S_CLOCK_PLL;
+ hi2s2.Init.FullDuplexMode = I2S_FULLDUPLEXMODE_DISABLE;
+ HAL_I2S_Init(&hi2s2);
+
+}
+
+
+/**
+ * Enable DMA controller clock
+ */
+void MX_DMA_Init(void)
+{
+ /* DMA controller clock enable */
+ __DMA1_CLK_ENABLE();
+
+ /* DMA interrupt init */
+ NVIC_SetVector(DMA1_Stream4_IRQn, (uint32_t )&DMA1_Stream4_IRQHandler);
+ /* Sets the priority grouping field */
+ HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_0);
+ HAL_NVIC_SetPriority(DMA1_Stream4_IRQn, 0, 0);
+ HAL_NVIC_EnableIRQ(DMA1_Stream4_IRQn);
+}
+
+/** Pinout Configuration
+*/
+void MX_GPIO_Init(void)
+{
+
+ /* GPIO Ports Clock Enable */
+ __GPIOC_CLK_ENABLE();
+ __GPIOB_CLK_ENABLE();
+ __GPIOA_CLK_ENABLE();
+
+}
+
+
+#ifdef USE_FULL_ASSERT
+
+/**
+ * @brief Reports the name of the source file and the source line number
+ * where the assert_param error has occurred.
+ * @param file: pointer to the source file name
+ * @param line: assert_param error line source number
+ * @retval None
+ */
+void assert_failed(uint8_t* file, uint32_t line)
+{
+ /* User can add his own implementation to report the file name and line number,
+ ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
+
+}
+
+#endif
+
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
+
+
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/envelope_work.cpp Fri Sep 02 13:24:16 2016 +0000
@@ -0,0 +1,188 @@
+#include "synthesizer.h"
+
+extern GENERATOR sgen[];
+extern GENERATOR dgen[];
+extern GENERATOR_TEMP dgen_temp[];
+extern GENERATOR *gen ;// = &sgen[PresetVoiceNum - 1] set by Menu PresetVoice
+extern GENERATOR *pgen;// = &dgen[0];
+extern GENERATOR_TEMP *pgen_temp;// = &dgen_temp[0];
+extern PresetVoiceDef PresetVoice[];
+extern STR_VOICE voice[];
+
+extern int gen_encount;
+extern U8 PresetVoiceNum;
+extern U8 MidiChannel;
+
+extern S16 MasterVolume;
+extern volatile S16 mvoldiv;
+
+void envelope_work(void)
+{
+ U8 i;
+ U16 temp;
+ U8 temp1,temp2;
+ S16 *lfo1wave;
+ GENERATOR *gena;
+ GENERATOR_TEMP *gena_temp;
+ STR_VOICE *voicea;
+ gena = pgen;// 螳滉ス薙・縺サ縺・〒
+ gena_temp = pgen_temp;// 螳滉ス薙・縺サ縺・〒
+ voicea = &voice[0];
+ PresetVoiceDef *voice_ptr = (PresetVoiceDef *)&PresetVoice[PresetVoiceNum- 1];
+ MasterVolume += mvoldiv;
+ if(MasterVolume >(127<<8)){
+ MasterVolume = 127<<8;
+ mvoldiv = 0;
+ }else if(MasterVolume < 0){
+ MasterVolume = 0;
+ mvoldiv = 0;
+ }
+
+ for (i =0;i<GENMAX;i++){
+ if(gena_temp->status == GEN_IDLE){
+// gena_temp->voltemp = 0;
+ gena_temp->lfo1delaycount = gena->lfo1delaytime;
+ gena_temp->lfo2delaycount = gena->lfo2delaytime;
+#ifdef DCF
+ voicea->enable &= ~(1<<(i & (PRGGENMAX - 1)));// 1,2,4,8
+#endif
+ }else{
+ if(gena_temp->status == GEN_NOTEOFF){
+ /* Function Release */
+ gena_temp->voltemp = (gena_temp->voltemp>>16) * releasetime_table[gena->releasetime];
+ if(gena_temp->voltemp == 0){
+ gena_temp->zerocount++;
+ }else{
+ gena_temp->zerocount = 0;
+ }
+ if(gena_temp->zerocount > 10){
+ gena_temp->status = GEN_IDLE;
+ gena_temp->eg_status = EG_IDLE;
+#ifdef DCF
+ voicea->enable &= ~(1<<(i & (PRGGENMAX - 1)));// 1,2,4,8
+#endif
+ gen_encount--;
+ //ledgreen_off();
+ }else{
+ gena_temp->eg_status = EG_RELEASE;
+ //ledred_off();
+ }
+
+ }else{ // NOTE ON
+ if(gena_temp->eg_status == EG_IDLE){
+ gena_temp->voltemp += gena_temp->voltemp1;
+ //ledred_on();
+ if(gena_temp->voltemp > gena->volume <<16){
+ gena_temp->voltemp = gena->volume <<16;
+ gena_temp->voltemp1 = ((gena->volume<<16) /100 * (100 - gena->sustainlevel))/(gena->decaytime);
+ gena_temp->eg_status = EG_DECAY;
+ }else{
+ gena_temp->eg_status = EG_ATTACK;
+ }
+ }else if(gena_temp->eg_status == EG_ATTACK){
+ gena_temp->voltemp += gena_temp->voltemp1;
+ //ledred_on();
+ if(gena_temp->voltemp > gena->volume <<16){
+ gena_temp->voltemp = gena->volume <<16;
+ gena_temp->voltemp1 = ((gena->volume<<16) /100 * (100 - gena->sustainlevel))/(gena->decaytime);
+ gena_temp->eg_status = EG_DECAY;
+ }
+ }else if(gena_temp->eg_status == EG_DECAY){
+ gena_temp->voltemp -= gena_temp->voltemp1;
+ if(gena_temp->voltemp < gena_temp->voltemp2){
+ gena_temp->voltemp = gena_temp->voltemp2;
+ gena_temp->eg_status = EG_SUSTAIN;
+
+ //ledgreen_on();
+ }
+
+ }
+
+ }
+ /* Note On/Off蜈ア騾壹・蜃ヲ逅・*/
+ if (gena_temp->dpf != 0){ // 110812
+ gena_temp->df += (S32)gena_temp->dpf;//
+ }
+
+ /* PitchBend 120617 */
+// gena->bendvalue = ((((ADC.ADDRA.WORD>>6) - adc0bias) * gena->benddepth) >>10);// ADDR 縺ョ繝薙ャ繝・5・・縺後ョ繝シ繧ソ
+// gena->bendvalue = ((gena->df>>26) * gena->bendvalue )>>2;
+
+#ifdef BEND
+ gena_temp->xx = (((U32)gena_temp->df>>16) + (S16)gena->detune + gena->lfo1value + gena->bendvalue);
+#else
+ gena_temp->xx = (((U32)gena_temp->df>>16) + (S32)gena->detune + gena_temp->lfo1value);
+#endif
+
+#if 1
+ /* Function LFO1 */
+ if(gena_temp->lfo1delaycount > 0){
+ gena_temp->lfo1delaycount--;
+ }else{
+ /* lof1speed 3e.5f */
+ gena_temp->lfo1count += (U8)gena->lfo1speed ;
+ if (gena_temp->lfo1count >= (256<<5)) gena_temp->lfo1count -=(256<<5);
+// gena_temp->lfo1value = ((S16)sin_table[(gena_temp->lfo1count>>5)] * (U16)gena->lfo1depth) >>20;
+ switch(gena->lfo1type){
+ case 0:
+ lfo1wave = sin_table;
+ break;
+ case 1:
+ lfo1wave = saw1_table;
+ break;
+ case 2:
+ lfo1wave = saw2_table;
+ break;
+ case 3:
+ lfo1wave = tri_table;
+ break;
+ case 4:
+ lfo1wave = square_table;
+ break;
+ }
+
+// gena_temp->lfo1value = ((S16)lfo1wave[(gena_temp->lfo1count>>5)] * (U16)gena->lfo1depth) >>20;
+// gena_temp->lfo1value = ((gena_temp->df>>26) * gena_temp->lfo1value)<<4;// 140614
+ gena_temp->lfo1value = ((S16)lfo1wave[(gena_temp->lfo1count>>5)] * (U16)gena->lfo1depth) >>10;//140617
+ gena_temp->lfo1value = ((gena_temp->df>>16) * (gena_temp->lfo1value>>4))>>12;// 140617
+ }
+#endif
+ gena_temp->voltempL = (((U32)gena_temp->voltemp>>7) * (U8)gena_temp->velocity) >>16;
+#if 1
+ /* Function LFO2 */
+ if(gena_temp->lfo2delaycount > 0){
+ gena_temp->lfo2delaycount--;
+ }else{
+ /* lof2speed 3e.5f */
+ gena_temp->lfo2count += (U8)gena->lfo2speed ;
+ if (gena_temp->lfo2count >= (256<<5)) gena_temp->lfo2count -=(256<<5);
+// temp = (U16)(( (U16)sin_table2[((U16)gena_temp->lfo2count>>5)] * (U16)gena->lfo2depth) >>16);
+// gena_temp->voltempL += (gena_temp->voltempL * temp) >>15;
+ temp = (U16)(( (U16)sin_table2[((U16)gena_temp->lfo2count>>5)] * (U16)gena->lfo2depth) >>10);// 140618
+ gena_temp->voltempL += (gena_temp->voltempL * temp) >>11;// 140618
+
+ }
+#endif
+ /* GEN_NOTEONOFF END */
+ }
+#ifdef DCF
+ /* Voice Process */
+ if ((i & (PRGGENMAX - 1)) == 0){
+
+ temp1 = voice_ptr->dcf_freq +((30 - voice_ptr->dcf_freq)*((S16)gena_temp->voltempL * (voice_ptr->dcf_freqsence))>>16);
+ if (temp1 > 30) temp1 = 30;
+ temp2 = voice_ptr->dcf_q +((10 - voice_ptr->dcf_q)*((S16)gena_temp->voltempL * (voice_ptr->dcf_qsence))>>16);
+ if (temp2 > 10) temp2 = 10;
+
+ voicea->dcf_param = (S32 *)&dcf_table[temp1 * 11 + temp2][0];
+
+ }
+#endif
+ gena++;
+ gena_temp++;
+#ifdef DCF
+ if ((i & (PRGGENMAX - 1))== (PRGGENMAX - 1)) voicea++;
+#endif
+ }
+}
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/from_save.cpp Fri Sep 02 13:24:16 2016 +0000
@@ -0,0 +1,181 @@
+#include "synthesizer.h"
+
+/*
+Sector 0 0x0800 0000 - 0x0800 3FFF 16 Kbytes
+Sector 1 0x0800 4000 - 0x0800 7FFF 16 Kbytes
+Sector 2 0x0800 8000 - 0x0800 BFFF 16 Kbytes
+Sector 3 0x0800 C000 - 0x0800 FFFF 16 Kbytes
+Sector 4 0x0801 0000 - 0x0801 FFFF 64 Kbytes
+Sector 5 0x0802 0000 - 0x0803 FFFF 128 Kbytes
+Sector 6 0x0804 0000 - 0x0805 FFFF 128 Kbytes
+Sector 7 0x0806 0000 - 0x0807 FFFF 128 Kbytes
+*/
+extern Serial pc;
+//extern RawSerial pc;
+
+extern U32 PresetVoiceAmount;
+extern U32 SGenAmount;
+
+extern U8 PresetVoiceNum;
+extern U8 MidiChannel;
+extern U16 MasterVolume;
+extern S8 MasterTune;
+extern U8 midi_base_ch;
+extern int rch_pol;
+
+extern WaveDef Wave[];
+extern PresetVoiceDef PresetVoice[];
+extern GENERATOR sgen[];
+
+void FROM_WriteBlock(uint32_t MemAddress , uint32_t FromAddress ,uint32_t datalength){
+ uint32_t *SrcAddress = (uint32_t *)MemAddress;
+ uint32_t *DstAddress = (uint32_t *)FromAddress;
+ HAL_FLASH_Unlock();
+ HAL_FLASH_OB_Unlock();
+ datalength >>= 2;
+ while(datalength--){
+ HAL_StatusTypeDef status = HAL_FLASH_Program(TYPEPROGRAM_WORD, (uint32_t)DstAddress++, *SrcAddress++);
+ if (status != HAL_OK){
+ pc.printf("FLASH->CR = 0x%4x \n\r",FLASH->CR);
+ pc.printf("FLASH->SR = 0x%4x \n\r",FLASH->SR);// PGPERR: Programming parallelism error
+ pc.printf("FLASH->OPTCR = 0x%4x \n\r",FLASH->OPTCR);
+ return ;
+ }
+ }
+ HAL_FLASH_Lock();
+}
+
+
+void save2from(void){
+ U32 temp;
+ HAL_StatusTypeDef status;
+
+ HAL_FLASH_Unlock();// for Erase
+ HAL_FLASH_OB_Unlock();// for Erase
+ FLASH_Erase_Sector(FLASH_SECTOR_3, VOLTAGE_RANGE_3);// FLASH_SECTOR_0-7
+ FROM_WriteBlock((uint32_t) &Wave[0] , (uint32_t)Flash_Wave_Address ,(uint32_t)Flash_Wave_Len);
+ FROM_WriteBlock((uint32_t) &PresetVoice[0] , (uint32_t)Flash_PresetVoice_Address ,(uint32_t)Flash_PresetVoice_Len);
+ FROM_WriteBlock((uint32_t) &sgen[0] , (uint32_t)Flash_Generator_Address ,(uint32_t)Flash_Generator_Len);
+
+ temp = (PresetVoiceNum<<24) |(MasterTune<<16) |(MasterVolume & 0x7f00) | (MidiChannel & 0x0f);
+ HAL_FLASH_Unlock();
+ HAL_FLASH_OB_Unlock();
+ status = HAL_FLASH_Program(TYPEPROGRAM_WORD, (uint32_t)Flash_System_Address , temp);
+ if (status != HAL_OK){
+ pc.printf("System Write FLASH->SR = 0x%4x \n\r",FLASH->SR);// PGPERR: Programming parallelism error
+ }
+ temp = rch_pol;// & 0xffff;
+ status = HAL_FLASH_Program(TYPEPROGRAM_WORD, (uint32_t)((uint32_t *)Flash_System_Address + 1) , temp);
+ if (status != HAL_OK){
+ pc.printf("System Write2 FLASH->SR = 0x%4x \n\r",FLASH->SR);// PGPERR: Programming parallelism error
+ }
+
+ HAL_FLASH_Lock();
+
+}
+
+void FROM_ReadBlock(uint32_t *MemAddress , uint32_t *FromAddress ,int datalength){
+ memcpy (MemAddress ,FromAddress ,datalength);
+}
+
+void load2from(void){
+// FROM_ReadBlock((uint32_t *) &Wave[0] , (uint32_t *)Flash_Wave_Address ,(U32)&Wave[99]-(U32)&Wave[0]+sizeof(WaveDef));
+/*
+ FROM_ReadBlock((uint32_t *) &PresetVoice[0] , (uint32_t *)Flash_PresetVoice_Address ,(U32)&PresetVoice[63]-(U32)&PresetVoice[0]+sizeof(PresetVoiceDef));
+ FROM_ReadBlock((uint32_t *) &sgen[0] , (uint32_t *)Flash_Generator_Address ,(U32)&sgen[PRGGENMAX * 64-1]-(U32)&sgen[0]+sizeof(GENERATOR));
+*/
+ FROM_ReadBlock((uint32_t *) &PresetVoice[0] , (uint32_t *)Flash_PresetVoice_Address, PresetVoiceAmount);
+ FROM_ReadBlock((uint32_t *) &sgen[0] , (uint32_t *)Flash_Generator_Address , SGenAmount);
+
+ U32 temp = *Flash_System_Address;
+ PresetVoiceNum = (U8)((temp>>24) & 0x7f);
+ MasterTune = (S8)((temp>>16)& 0xff);
+ MasterVolume = (U16)(temp & 0x7f00);
+ MidiChannel = (U8)(temp & 0x0f);
+ midi_base_ch = MidiChannel - 1;
+
+ temp = *(Flash_System_Address + 1);
+ rch_pol = (int)temp;
+}
+
+
+int get_wave_addr (WaveDef *wave){
+ WaveDef *wavea = wave;
+ uint8_t *ptr = (uint8_t *)Flash_WaveData_Address;
+ uint8_t *next_ptr;
+ GEN4_CHUNK *Gen4Chunk;
+ int n;
+ int num = 0;
+
+ while(1){
+ /* RIFF ? */
+ if(! ((*ptr == 'R') && (*(ptr+1) =='I') && (*(ptr+2) =='F') && (*(ptr+3) =='F')) ) return -1;
+ ptr += 4;
+ /* get next waveaddress */
+ next_ptr = (uint8_t *)((*(ptr+3)<<24)|(*(ptr+2)<<16)|(*(ptr+1)<<8)|(*ptr));
+ ptr += 4;
+ next_ptr += (uint32_t )ptr;
+
+ /* WAVE ? */
+ if(! ((*ptr == 'W') && (*(ptr+1) =='A') && (*(ptr+2) =='V') && (*(ptr+3) =='E')) ) return -2;
+
+ /* Search gen4 */
+ ptr += 4;
+ n = 64;
+ while (n-- > 0){
+ if ((*ptr == 'g') && (*(ptr+1) =='e') && (*(ptr+2) =='n') && (*(ptr+3) =='4')) break;
+ ptr++;
+ }
+ if (n == 0)return -4;
+
+// printf("0x%x 0x%x\r\n",ptr,*ptr);
+
+ ptr += 4;// volume
+ ptr += 4;// name
+ memcpy(&wave[num].name[0] ,ptr ,16);
+
+ Gen4Chunk = (GEN4_CHUNK *)ptr;
+ wave[num].name[16] = 0;
+ num++;
+ wavea->p1 = Gen4Chunk->p1;
+ wavea->p2 = Gen4Chunk->p2;
+ wavea->cycle = Gen4Chunk->cycle;
+// printf("p1 = %d\r\n",Gen4Chunk->p1);
+
+ /* Search data */
+ ptr += 16+4+4+4;
+ n = 200;
+ while (n-- > 0){
+ if ((*ptr == 'd') && (*(ptr+1) =='a') && (*(ptr+2) =='t') && (*(ptr+3) =='a')) break;
+ ptr++;
+ }
+ if (n == 0)return -3;
+
+ /* get startaddr */
+ ptr += 8;
+ wavea->startaddr = (U32)ptr;
+// pc.printf("wavea->startaddr = 0x%4x \r\n",wavea->startaddr);
+ wavea++;
+
+ ptr = next_ptr;
+ if ((*ptr == 0x00)||(*ptr == 0xff)) return 0;
+ }
+}
+
+void dump2serial(void){
+ uint32_t *ptr = Flash_Sector3_Address;
+ uint8_t c;
+// uint32_t len = ALIGNMENT4_INC(sizeof(PresetVoiceDef));
+ U32 len = 16384>>2;
+ while (len--){
+ for (int i =0;i<4;i++){
+ c = (*ptr >>(i*8))& 0xff;
+ pc.putc(c);
+ }
+ ptr++;
+ }
+}
+
+
+
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/from_save.h Fri Sep 02 13:24:16 2016 +0000 @@ -0,0 +1,41 @@ +/* +Sector 0 0x0800 0000 - 0x0800 3FFF 16 Kbytes +Sector 1 0x0800 4000 - 0x0800 7FFF 16 Kbytes +Sector 2 0x0800 8000 - 0x0800 BFFF 16 Kbytes +Sector 3 0x0800 C000 - 0x0800 FFFF 16 Kbytes +Sector 4 0x0801 0000 - 0x0801 FFFF 64 Kbytes +Sector 5 0x0802 0000 - 0x0803 FFFF 128 Kbytes +Sector 6 0x0804 0000 - 0x0805 FFFF 128 Kbytes +Sector 7 0x0806 0000 - 0x0807 FFFF 128 Kbytes +*/ +#define Flash_Sector0_Address (uint32_t *)0x08000000 +#define Flash_Sector1_Address (uint32_t *)0x08004000 +#define Flash_Sector2_Address (uint32_t *)0x08008000 +#define Flash_Sector3_Address (uint32_t *)0x0800C000 +#define Flash_Sector4_Address (uint32_t *)0x08010000 +#define Flash_Sector5_Address (uint32_t *)0x08020000 +#define Flash_Sector6_Address (uint32_t *)0x08040000 +#define Flash_Sector7_Address (uint32_t *)0x08060000 + +#define ALIGNMENT4_INC(_X_) (((_X_)+3)&~3) + +#define Flash_Wave_Address Flash_Sector3_Address +#define Flash_Wave_Len 3600 +#define Flash_System_Address (uint32_t *)0x0800ce10 + +#define Flash_PresetVoice_Address (uint32_t *)0x0800d000 +#define Flash_PresetVoice_Len 4096 +#define Flash_Generator_Address (uint32_t *)0x0800e000 +#define Flash_Generator_Len 8192 + +#define Flash_WaveData_Address Flash_Sector4_Address + + +void FROM_WriteBlock(uint32_t MemAddress , uint32_t FromAddress ,uint32_t datalength); +void save2from(void); +void FROM_ReadBlock(uint32_t *MemAddress , uint32_t *FromAddress ,int datalength); +void load2from(void); +void dump2serial(void); + + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/i2s_dma.cpp Fri Sep 02 13:24:16 2016 +0000
@@ -0,0 +1,107 @@
+#include "synthesizer.h"
+
+extern Serial pc;
+//extern RawSerial PC;
+extern DigitalOut myled;
+
+extern GENERATOR *pgen;// = &dgen[0];
+extern GENERATOR_TEMP *pgen_temp;// = &dgen_temp[0];
+
+extern I2S_HandleTypeDef hi2s2;
+extern DMA_HandleTypeDef hdma_i2s2_ext_tx;
+
+
+S16 DMA_Buffer[DMA_BUFFERSIZE];
+//S16 * DMA_Buffer = (S16 *)0x20008000;
+__IO BUFFER_StateTypeDef BufferOffset = DMA_Idle;
+
+
+static const PinMap PinMap_I2S_MCK[] = {
+ {PC_6, SPI_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI2)},
+// {PC_7, SPI_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF6_SPI3)},
+ {NC, NC, 0}
+};
+
+static const PinMap PinMap_I2S_CK[] = {
+ {PB_10, SPI_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI2)},
+ {PB_13, SPI_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI2)},
+// {PD_3, SPI_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI2)},
+// {PC_10, SPI_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF6_SPI3)},
+ {NC, NC, 0}
+};
+
+static const PinMap PinMap_I2S_WS[] = {
+ {PB_12, SPI_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI2)},
+ {PB_9, SPI_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI2)},
+// {PA_15, SPI_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF6_SPI3)},
+ {NC, NC, 0}
+};
+
+static const PinMap PinMap_I2S_SD[] = {
+ {PC_3, SPI_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI2)},
+ {PB_15, SPI_2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI2)},
+// {PC_12, SPI_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF6_SPI3)},
+// {PD_6, SPI_3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI3)},
+ {NC, NC, 0}
+};
+
+
+
+void HAL_I2S_TxCpltCallback(I2S_HandleTypeDef *hi2s)
+{
+ if(hi2s->Instance == I2S2)
+ {
+ BufferOffset = DMA_FullComplete;
+ HAL_I2S_Transmit_DMA(&hi2s2, (uint16_t*)&DMA_Buffer[0], DMA_BUFFERSIZE);
+ }
+}
+
+void HAL_I2S_TxHalfCpltCallback(I2S_HandleTypeDef *hi2s)
+{
+ if(hi2s->Instance == I2S2) BufferOffset = DMA_HalfComplete;
+}
+
+
+
+void init_dmabuffer(void){
+ int16_t *ptr0 = (int16_t*)&DMA_Buffer[0];
+ for (int i =0;i < DMA_BUFFERSIZE/2 ;i++){
+ *ptr0++ = 0;// Lch
+ *ptr0++ = 0;// Rch
+ }
+}
+
+
+void i2s_dma_init(void) {
+ pinmap_pinout(PC_6, PinMap_I2S_MCK);
+ pinmap_pinout(PB_13, PinMap_I2S_CK);
+ pinmap_pinout(PB_12, PinMap_I2S_WS);
+ pinmap_pinout(PB_15, PinMap_I2S_SD);
+
+ pin_mode(PC_6, PullUp);
+ pin_mode(PB_13, PullUp);
+ pin_mode(PB_12, PullUp);
+ pin_mode(PB_15, PullUp);
+
+ init_dmabuffer();
+
+ HAL_I2S_Transmit_DMA(&hi2s2, (uint16_t *)&DMA_Buffer[0],DMA_BUFFERSIZE / 2);
+/*
+ pc.printf("DMA CR =%4x \n\r" ,DMA1_Stream4->CR);
+ pc.printf("DMA FCR =%4x \n\r" ,DMA1_Stream4->FCR);
+
+ pc.printf("DMA M0AR =%4x M1AR =%4x PAR = %4x \n\r" ,DMA1_Stream4->M0AR ,DMA1_Stream4->M1AR ,DMA1_Stream4->PAR);
+ pc.printf("I2S CR2 = %4x \n\r" ,SPI2->CR2);
+ pc.printf("I2S SR = %4x \n\r" ,SPI2->SR);
+ pc.printf("I2S I2SCFGR = %4x \n\r" ,SPI2->I2SCFGR);
+ pc.printf("I2S I2SPR = %4x \n\r" ,SPI2->I2SPR);
+ pc.printf("RCC->PLLI2SCFGR = %4x \n\r" ,RCC->PLLI2SCFGR);
+*/
+
+// HAL_RCC_MCOConfig(uint32_t RCC_MCO2, RCC_MCO2SOURCE_PLLI2SCLK, RCC_MCODIV_5);
+}
+
+
+
+
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/lcd_sw.cpp Fri Sep 02 13:24:16 2016 +0000
@@ -0,0 +1,619 @@
+#include "synthesizer.h"
+
+U8 PresetVoiceNum;
+U8 MidiChannel;
+S8 MasterTune;
+int rch_pol;
+
+extern S16 limit;
+
+extern S16 MasterVolume;
+U8 midi_base_ch;
+extern volatile int KeyValDiv;
+
+char lcd_string[20];
+U8 selectsw = 0;
+extern int menu_index;
+char str[5];
+char wave_type[5][5]={"Sine","Saw1","Saw2","Tri ","Squr"};
+
+extern volatile U8 key;
+extern KeyState_TypeDef keystate;
+
+extern GENERATOR sgen[];
+extern GENERATOR dgen[];
+extern GENERATOR_TEMP dgen_temp[];
+extern GENERATOR *gen ;// = &sgen[(PresetVoiceNum - 1)*PRGGENMAX] set by Menu PresetVoice
+extern GENERATOR *pgen;// = &dgen[0];
+extern GENERATOR_TEMP *pgen_temp;// = &dgen_temp[0];
+
+extern PresetVoiceDef PresetVoice[];
+extern WaveDef Wave[];
+
+MenuListDef MenuList[] ={
+ {"Parameter" ,param ,0 ,0}, // index 0
+ {"RchOut Polarity" ,rch_polarity ,-1 ,1},
+ {"Voice " ,presetvoice ,1 ,64},
+ {"Midi Channel" ,midichannel ,1 ,16},
+ {"MasterTune " ,mastertune ,-128 ,127},
+// {"DCFF Q FE QE" ,dcfcontrol ,0 ,0},
+ {"Generator Switch" ,gen_sw ,0 ,0},
+ {"Gen WaveNumber" ,gen_wave ,1 ,100},
+ {"Gen NoteShift" ,gen_notebias ,-128 ,127},
+ {"Gen OutputLevel" ,gen_outlevel ,0 ,127},
+ {"Gen Detune" ,gen_detune ,-512 ,511},
+ {"Gen AttackTime" ,gen_attacktime ,1 ,9999},
+ {"Gen DecayTime" ,gen_decaytime ,1 ,9999},
+ {"Gen SustainLevel" ,gen_sustainlevel ,0 ,100},
+ {"Gen ReleaseTime" ,gen_relesetime ,0 ,21}, // 13
+
+ {"Gen LFO1 WavForm" ,gen_lfo1_wavetype ,0 ,4}, // 14 Sine Saw1 Saw2 Tri Rect
+ {"Gen LFO1 Speed" ,gen_lfo1_speed ,0 ,127},
+ {"Gen LFO1 Depth" ,gen_lfo1_depth ,0 ,999},
+ {"Gen LFO1 Delay" ,gen_lfo1_delaytime ,0 ,3000},
+
+ {"Gen LFO2 Speed" ,gen_lfo2_speed ,0 ,127},
+ {"Gen LFO2 Depth" ,gen_lfo2_depth ,0 ,127}, // 19
+ {"Gen LFO2 Delay" ,gen_lfo2_delaytime ,0 ,3000}, // 20
+ {"Gen Limit" ,gen_limit ,0 ,127} // 21
+};
+
+void lcd_print(char *str){
+ lcd.printf(str);
+}
+
+void lcd_print1(char *str){
+ lcd.cls();
+ lcd.printf(str);
+}
+
+void lcd_print2(char *str){
+ lcd.locate(0,1);
+ lcd.printf(str);
+}
+
+/* Title "μGen4" */
+void lcd_print_title(void){
+ lcd.setCGRAM(1<<3,&cgfont[0]);
+ lcd_string[0] = 1;// 'μ'
+ lcd_string[1] = 0;// NULL
+ strcat ((char *)lcd_string,"Gen4 ");
+
+// strcpy ((char *)lcd_string,"uGen4 ");
+ strcat ((char *)lcd_string,FWVERSION);
+ lcd_print1((char *)lcd_string);
+ strcpy((char *)lcd_string," Synthesizer");
+ lcd_print2((char *)lcd_string);
+
+}
+
+void gen_limit(void){
+ int value = limit;
+ if(key & 0x10){
+ value -= KeyValDiv;
+ if(value < MenuList[menu_index].min) value = MenuList[menu_index].min;
+ }else if(key & 0x20){
+ value += KeyValDiv;
+ if(value > MenuList[menu_index].max) value = MenuList[menu_index].max;
+
+ }
+ limit = value;
+ val2str4(limit);
+ lcd_print(&str[0]);
+}
+
+void presetvoice(void){
+ int value = PresetVoiceNum;
+ if(key & 0x10){
+ value -= KeyValDiv;
+ if(value < MenuList[menu_index].min) value = MenuList[menu_index].min;
+ }else if(key & 0x20){
+ value += KeyValDiv;
+ if(value > MenuList[menu_index].max) value = MenuList[menu_index].max;
+
+ }
+ lcd_print1("Voice ");
+ PresetVoiceNum = value;
+ gen = (GENERATOR *)&sgen[(PresetVoiceNum - 1)*PRGGENMAX];
+ val2str4(PresetVoiceNum);
+ lcd_print(&str[0]);
+ lcd_print2(PresetVoice[PresetVoiceNum-1].name);
+}
+
+void param(void){
+ lcd_print2("SaveLoad PC");
+ if(SELECTSW1){
+ save2from();
+ lcd_print2("Saved Parameter ");
+ }else if(SELECTSW2){
+ load2from();
+ lcd_print2("Loaded Parameter");
+ }else if(SELECTSW3){
+ lcd_print2("DumppingToSerial");
+ dump2serial();
+ lcd_print2("Complete ");
+ }
+}
+
+void mastertune(void){
+ int value = MasterTune;
+ if(key & 0x10){
+ value -= KeyValDiv;
+ if(value < MenuList[menu_index].min) value = MenuList[menu_index].min;
+ }else if(key & 0x20){
+ value += KeyValDiv;
+ if(value > MenuList[menu_index].max) value = MenuList[menu_index].max;
+
+ }
+ MasterTune = value;
+ val2str4(MasterTune);
+ lcd_print(&str[0]);
+}
+
+void rch_polarity(void){
+ int value = rch_pol;
+ if(key & 0x10){
+ value = -1;
+ }else if(key & 0x20){
+ value = 1;
+ }
+ rch_pol = value;
+
+ if (rch_pol > 0){
+ strcpy(lcd_string,"Same as LchOut");
+ }else{
+ strcpy(lcd_string,"Invert");
+ }
+ lcd_print1("RchOut Polarity");
+ lcd_print2(lcd_string);
+}
+
+void dcfcontrol(void){
+ /* DCFF Q FE QE */
+ int value = PresetVoice[PresetVoiceNum - 1].dcf_freq;
+ if (selectsw & 1){
+ if(key & 0x20){
+ value += KeyValDiv;
+ if(value > 30) value = 30;
+ }else if(key & 0x10){
+ value -= KeyValDiv;
+ if(value < 0) value = 0;
+ }
+ PresetVoice[PresetVoiceNum - 1].dcf_freq = value;
+ }
+ val2str4(value);
+ strcat(lcd_string, &str[0]);
+
+ value = PresetVoice[PresetVoiceNum - 1].dcf_q;
+ if (selectsw & 2){
+ if(key & 0x20){
+ value += KeyValDiv;
+ if(value > 10) value = 10;
+ }else if(key & 0x10){
+ value -= KeyValDiv;
+ if(value < 0) value = 0;
+ }
+ PresetVoice[PresetVoiceNum - 1].dcf_q = value;
+ }
+ val2str4(value);
+ strcat(lcd_string, &str[0]);
+
+ value = PresetVoice[PresetVoiceNum - 1].dcf_freqsence;
+ if (selectsw & 4){
+ if(key & 0x20){
+ value += KeyValDiv;
+ if(value > 10) value = 10;
+ }else if(key & 0x10){
+ value -= KeyValDiv;
+ if(value < 0) value = 0;
+ }
+ PresetVoice[PresetVoiceNum - 1].dcf_freqsence = value;
+ }
+ val2str4(value);
+ strcat(lcd_string, &str[0]);
+
+
+ value = PresetVoice[PresetVoiceNum - 1].dcf_qsence;
+ if (selectsw & 8){
+ if(key & 0x20){
+ value += KeyValDiv;
+ if(value > 10) value = 10;
+ }else if(key & 0x10){
+ value -= KeyValDiv;
+ if(value < 0) value = 0;
+ }
+ PresetVoice[PresetVoiceNum - 1].dcf_qsence = value;
+ }
+ val2str4(value);
+ strcat(lcd_string, &str[0]);
+
+ lcd_print2(lcd_string);
+}
+
+void gen_sw(void){
+ GENERATOR *gena = &sgen[(PresetVoiceNum-1) * PRGGENMAX];
+ U8 bitsw = 1;
+ int n = PRGGENMAX;
+ while(n--){
+ if(key & bitsw){
+ gena->sw ^= 1;
+ gena->sw &= 1;
+ }
+ if(gena->sw){
+ strcat(lcd_string," On ");
+ }else{
+ strcat(lcd_string," Off");
+ }
+ bitsw <<= 1;
+ gena++;
+ }
+ lcd_print2(lcd_string);
+}
+
+void midichannel(void){
+ int value = MidiChannel;
+ if(key & 0x10){
+ value -= KeyValDiv;
+ if(value < MenuList[menu_index].min) value = MenuList[menu_index].min;
+ }else if(key & 0x20){
+ value += KeyValDiv;
+ if(value > MenuList[menu_index].max) value = MenuList[menu_index].max;
+
+ }
+ MidiChannel = value;
+ midi_base_ch = value -1;
+ val2str4(MidiChannel);
+ lcd_print(&str[0]);
+ }
+
+void gen_outlevel(void){
+ GENERATOR *gena = &sgen[(PresetVoiceNum-1) * PRGGENMAX];
+ int n = PRGGENMAX;
+ U8 bitsw = 1;
+ while(n--){
+ int value = (gena->volume>>8);
+ if (gena->sw){
+ if(selectsw & bitsw){
+ if(key & 0x20){
+ value += KeyValDiv;
+ if(value > MenuList[menu_index].max) value = MenuList[menu_index].max;
+ }else if(key & 0x10){
+ value -= KeyValDiv;
+ if(value < MenuList[menu_index].min) value = MenuList[menu_index].min;
+ }
+ gena->volume = (value<<8);
+ }
+ val2str4((gena->volume)>>8);
+ strcat(lcd_string, &str[0]);
+ }else{
+ strcat(lcd_string," Off");
+ }
+ bitsw <<= 1;
+ gena++;
+ }
+
+ lcd_print2(lcd_string);
+}
+
+void gen_lfo1_wavetype(void){
+ GENERATOR *gena = &sgen[(PresetVoiceNum-1) * PRGGENMAX];
+ int n = PRGGENMAX;
+ U8 bitsw = 1;
+ while(n--){
+ int value = gena->lfo1type;
+ if (gena->sw){
+ if(selectsw & bitsw){
+ if(key & 0x10){
+ value -= KeyValDiv;
+ if(value < MenuList[menu_index].min) value = MenuList[menu_index].min;
+ }else if(key & 0x20){
+ value += KeyValDiv;
+ if(value > MenuList[menu_index].max) value = MenuList[menu_index].max;
+ }
+ }
+ gena->lfo1type = value;
+ strcat(lcd_string, &wave_type[value][0]);
+ }else{
+ strcat(lcd_string," Off");
+ }
+ gena++;
+ bitsw <<= 1;
+ }
+ lcd_print2(lcd_string);
+}
+
+
+U8 gen_function_type_byte(GENERATOR *gena_value){
+ int value ,value1;
+ GENERATOR *gena = &sgen[(PresetVoiceNum-1) * PRGGENMAX];
+ U32 temp = (U32)gena_value - (U32)gena;
+ int n = PRGGENMAX;
+ U8 bitsw = 1;
+ while(n--){
+ value = *(U8 *)( (U32)gena + temp );
+ if(gena->sw){
+ if (selectsw & bitsw){
+ if(key & 0x20){
+ value += KeyValDiv;
+ if(value > MenuList[menu_index].max) value = MenuList[menu_index].max;
+ }else if(key & 0x10){
+ value -= KeyValDiv;
+ if(value < MenuList[menu_index].min) value = MenuList[menu_index].min;
+ }
+ *(U8 *)( (U32)gena + temp )= value;
+ value1 = value;
+ }
+ val2str4(value);
+ strcat(lcd_string, &str[0]);
+ }else{
+ strcat(lcd_string," Off");
+ }
+ gena++;
+ gena_value++;
+ bitsw <<= 1;
+ }
+
+ lcd_print2(lcd_string);
+ return (U8)value1;
+}
+
+void gen_function_type_word(GENERATOR *gena_value){
+ GENERATOR *gena = &sgen[(PresetVoiceNum-1) * PRGGENMAX];
+ U32 temp = (U32)gena_value - (U32)gena;
+ int n = PRGGENMAX;
+ U8 bitsw = 1;
+ while(n--){
+ int value = *(U16 *)( (U32)gena + temp );
+ if(gena->sw){
+ if (selectsw & bitsw){
+ if(key & 0x20){
+ value += KeyValDiv;
+ if(value > MenuList[menu_index].max) value = MenuList[menu_index].max;
+ }else if(key & 0x10){
+ value -= KeyValDiv;
+ if(value < MenuList[menu_index].min) value = MenuList[menu_index].min;
+ }
+ *(U16 *)( (U32)gena + temp )= value;
+ }
+ val2str4(value);
+ strcat(lcd_string, &str[0]);
+ }else{
+ strcat(lcd_string," Off");
+ }
+ gena++;
+ gena_value++;
+ bitsw <<= 1;
+ }
+
+ lcd_print2(lcd_string);
+}
+
+void gen_function_type_sbyte(GENERATOR *gena_value){
+ GENERATOR *gena = &sgen[(PresetVoiceNum-1) * PRGGENMAX];
+ U32 temp = (U32)gena_value - (U32)gena;
+ int n = PRGGENMAX;
+ U8 bitsw = 1;
+ while(n--){
+ int value = *(S8 *)( (U32)gena + temp );
+ if(gena->sw){
+ if (selectsw & bitsw){
+ if(key & 0x20){
+ value += KeyValDiv;
+ if(value > MenuList[menu_index].max) value = MenuList[menu_index].max;
+ }else if(key & 0x10){
+ value -= KeyValDiv;
+ if(value < MenuList[menu_index].min) value = MenuList[menu_index].min;
+ }
+ *(S8 *)( (U32)gena + temp )= value;
+
+ }
+ val2str4(value);
+ strcat(lcd_string, &str[0]);
+ }else{
+ strcat(lcd_string," Off");
+ }
+ gena++;
+ gena_value++;
+ bitsw <<= 1;
+ }
+
+ lcd_print2(lcd_string);
+
+}
+void gen_function_type_sword(GENERATOR *gena_value){
+ GENERATOR *gena = &sgen[(PresetVoiceNum-1) * PRGGENMAX];
+ U32 temp = (U32)gena_value - (U32)gena;
+ int n = PRGGENMAX;
+ U8 bitsw = 1;
+ while(n--){
+ int value = *(S16 *)( (U32)gena + temp );
+ if(gena->sw){
+ if (selectsw & bitsw){
+ if(key & 0x20){
+ value += KeyValDiv;
+ if(value > MenuList[menu_index].max) value = MenuList[menu_index].max;
+ }else if(key & 0x10){
+ value -= KeyValDiv;
+ if(value < MenuList[menu_index].min) value = MenuList[menu_index].min;
+ }
+ *(S16 *)( (U32)gena + temp )= value;
+
+ }
+ val2str4(value);
+ strcat(lcd_string, &str[0]);
+ }else{
+ strcat(lcd_string," Off");
+ }
+ gena++;
+ gena_value++;
+ bitsw <<= 1;
+ }
+
+ lcd_print2(lcd_string);
+
+}
+
+
+void gen_attacktime(void){
+ GENERATOR *gena = &sgen[(PresetVoiceNum-1) * PRGGENMAX];
+ GENERATOR *gena_value = (GENERATOR *)&gena->attacktime;
+ gen_function_type_word(gena_value);
+}
+
+void gen_wave (void){
+// pc.printf("PresetVoiceNum = %d\r\n",PresetVoiceNum);
+ GENERATOR *gena = &sgen[(PresetVoiceNum-1) * PRGGENMAX];
+ GENERATOR *gena_value = (GENERATOR *)&gena->wave_num;
+ U8 value = gen_function_type_byte(gena_value);
+ if(key & 0x30){// when push Value+- key
+ lcd_print2(" ");
+ lcd_print2(Wave[value - 1].name);
+// keystate = KEY_GEN_WAVE1;
+// TimerCount10mS= 100;// 1000mS Wait
+ }
+}
+
+void gen_notebias(void){
+ GENERATOR *gena = &sgen[(PresetVoiceNum-1) * PRGGENMAX];
+ GENERATOR *gena_value = (GENERATOR *)&gena->notebias;
+ gen_function_type_sbyte(gena_value);
+}
+
+void gen_detune(void){
+ GENERATOR *gena = &sgen[(PresetVoiceNum-1) * PRGGENMAX];
+ GENERATOR *gena_value = (GENERATOR *)&gena->detune;
+ gen_function_type_sword(gena_value);
+}
+
+void gen_decaytime(void){
+ GENERATOR *gena = &sgen[(PresetVoiceNum-1) * PRGGENMAX];
+ GENERATOR *gena_value = (GENERATOR *)&gena->decaytime;
+ gen_function_type_word(gena_value);
+}
+void gen_sustainlevel(void){
+ GENERATOR *gena = &sgen[(PresetVoiceNum-1) * PRGGENMAX];
+ GENERATOR *gena_value = (GENERATOR *)&gena->sustainlevel;
+ gen_function_type_byte(gena_value);
+}
+void gen_relesetime(void){
+ GENERATOR *gena = &sgen[(PresetVoiceNum-1) * PRGGENMAX];
+ GENERATOR *gena_value = (GENERATOR *)&gena->releasetime;
+ gen_function_type_word(gena_value);
+}
+
+void gen_lfo1_speed (void){
+ GENERATOR *gena = &sgen[(PresetVoiceNum-1) * PRGGENMAX];
+ GENERATOR *gena_value = (GENERATOR *)&gena->lfo1speed;
+ gen_function_type_byte(gena_value);
+}
+
+
+void gen_lfo1_depth(void){
+ GENERATOR *gena = &sgen[(PresetVoiceNum-1) * PRGGENMAX];
+ GENERATOR *gena_value = (GENERATOR *)&gena->lfo1depth;
+ gen_function_type_word(gena_value);
+}
+
+void gen_lfo1_delaytime(void){
+ GENERATOR *gena = &sgen[(PresetVoiceNum-1) * PRGGENMAX];
+ GENERATOR *gena_value = (GENERATOR *)&gena->lfo1delaytime;
+ gen_function_type_word(gena_value);
+}
+
+void gen_lfo2_delaytime(void){
+ GENERATOR *gena = &sgen[(PresetVoiceNum-1) * PRGGENMAX];
+ GENERATOR *gena_value = (GENERATOR *)&gena->lfo2delaytime;
+ gen_function_type_word(gena_value);
+}
+
+void gen_lfo2_speed (void){
+ GENERATOR *gena = &sgen[(PresetVoiceNum-1) * PRGGENMAX];
+ GENERATOR *gena_value = (GENERATOR *)&gena->lfo2speed;
+ gen_function_type_byte(gena_value);
+}
+
+void gen_lfo2_depth(void){
+ GENERATOR *gena = &sgen[(PresetVoiceNum-1) * PRGGENMAX];
+ GENERATOR *gena_value = (GENERATOR *)&gena->lfo2depth;
+ gen_function_type_word(gena_value);
+}
+
+char *val2str4(int value){
+ uint8_t n;
+ char *c;
+ int value_temp = value;
+ if (value < 0){
+ str[0] = '-';
+ value_temp *= -1;
+
+ n = 0;
+ while(value_temp >= 100){
+ value_temp -= 100;
+ n++;
+ }
+ str[1] = 0x30 + n;
+ n = 0;
+ while(value_temp >= 10){
+ value_temp -= 10;
+ n++;
+ }
+ str[2] = 0x30 + n;
+ str[3] = 0x30 + value_temp;
+/*
+ if (value_temp >99){
+ str[1] = '1';
+ value_temp -= 100;
+ }else{
+ str[1] = '0';
+ }
+ n = 0;
+ while(value_temp >= 10){
+ value_temp -= 10;
+ n++;
+ }
+ str[2] = 0x30 + n;
+ str[3] = 0x30 + value_temp;
+*/
+ }else{
+ n = 0;
+ while(value_temp >= 1000){
+ value_temp -= 1000;
+ n++;
+ }
+ str[0] = 0x30 + n;
+ n = 0;
+ while(value_temp >= 100){
+ value_temp -= 100;
+ n++;
+ }
+ str[1] = 0x30 + n;
+ n = 0;
+ while(value_temp >= 10){
+ value_temp -= 10;
+ n++;
+ }
+ str[2] = 0x30 + n;
+ str[3] = 0x30 + value_temp;
+ }
+
+ n = 3;
+ c = &str[0];
+ while(n-- >0){
+ if ((*c != '0')&&(*c != '-')) break;
+ if (*c != '-') *c = ' ';
+ c++;
+ }
+ if (str[0] == '-'){
+ if (str[2] == ' '){// - n -> -n
+ str[0] = str[1] = ' ';
+ str[2] = '-';
+ }else if (str[1] == ' '){// - mn -> -mn
+ str[0] = ' ';
+ str[1] = '-';
+ }
+ }
+ str[4] = 0;
+ return &str[4];
+}
+
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/lcd_sw.h Fri Sep 02 13:24:16 2016 +0000
@@ -0,0 +1,31 @@
+#define SELECTSW1 (~(SW1)&1)
+#define SELECTSW2 ((~(SW2)&1)<<1)
+#define SELECTSW3 ((~(SW3)&1)<<2)
+#define SELECTSW4 ((~(SW4)&1)<<3)
+#define MENUSW_PLUS ((~(SW5)&1)<<7)
+#define MENUSW_MINUS ((~(SW6)&1)<<6)
+#define VALUESW_PLUS ((~(SW7)&1)<<5)
+#define VALUESW_MINUS ((~(SW8)&1)<<4)
+#define ANYKEYON (SELECTSW1|SELECTSW2|SELECTSW3|SELECTSW4|MENUSW_PLUS|MENUSW_MINUS|VALUESW_PLUS|VALUESW_MINUS)
+
+#define MENU_INDEXMAX 21
+extern DigitalIn SW1;
+extern DigitalIn SW2;
+extern DigitalIn SW3;
+extern DigitalIn SW4;
+extern DigitalIn SW5;
+extern DigitalIn SW6;
+extern DigitalIn SW7;
+extern DigitalIn SW8;
+
+extern LCD lcd;
+//extern Serial pc;
+extern RawSerial PC;
+extern DigitalOut myled;
+void rch_polarity(void);
+
+static char cgfont[]={0x00,0x11,0x11,0x11,0x13,0x1d,0x10,0x10};
+
+
+
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/lfo_table.h Fri Sep 02 13:24:16 2016 +0000
@@ -0,0 +1,1819 @@
+/* LFO Wave Form */
+static S16 square_table[]={
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+32767 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768 ,
+-32768
+};
+
+
+static S16 sin_table[]={
+0 ,
+804 ,
+1608 ,
+2410 ,
+3212 ,
+4011 ,
+4808 ,
+5602 ,
+6393 ,
+7179 ,
+7962 ,
+8739 ,
+9512 ,
+10278 ,
+11039 ,
+11793 ,
+12539 ,
+13279 ,
+14010 ,
+14732 ,
+15446 ,
+16151 ,
+16846 ,
+17530 ,
+18204 ,
+18868 ,
+19519 ,
+20159 ,
+20787 ,
+21403 ,
+22005 ,
+22594 ,
+23170 ,
+23731 ,
+24279 ,
+24812 ,
+25329 ,
+25832 ,
+26319 ,
+26790 ,
+27245 ,
+27683 ,
+28105 ,
+28510 ,
+28898 ,
+29268 ,
+29621 ,
+29956 ,
+30273 ,
+30571 ,
+30852 ,
+31113 ,
+31356 ,
+31580 ,
+31785 ,
+31971 ,
+32137 ,
+32285 ,
+32412 ,
+32521 ,
+32609 ,
+32678 ,
+32728 ,
+32757 ,
+32767 ,
+32757 ,
+32728 ,
+32678 ,
+32609 ,
+32521 ,
+32412 ,
+32285 ,
+32137 ,
+31971 ,
+31785 ,
+31580 ,
+31356 ,
+31113 ,
+30852 ,
+30571 ,
+30273 ,
+29956 ,
+29621 ,
+29268 ,
+28898 ,
+28510 ,
+28105 ,
+27683 ,
+27245 ,
+26790 ,
+26319 ,
+25832 ,
+25329 ,
+24812 ,
+24279 ,
+23731 ,
+23170 ,
+22594 ,
+22005 ,
+21403 ,
+20787 ,
+20159 ,
+19519 ,
+18868 ,
+18204 ,
+17530 ,
+16846 ,
+16151 ,
+15446 ,
+14732 ,
+14010 ,
+13279 ,
+12539 ,
+11793 ,
+11039 ,
+10278 ,
+9512 ,
+8739 ,
+7962 ,
+7179 ,
+6393 ,
+5602 ,
+4808 ,
+4011 ,
+3212 ,
+2410 ,
+1608 ,
+804 ,
+0 ,
+-804 ,
+-1608 ,
+-2410 ,
+-3212 ,
+-4011 ,
+-4808 ,
+-5602 ,
+-6393 ,
+-7179 ,
+-7962 ,
+-8739 ,
+-9512 ,
+-10278 ,
+-11039 ,
+-11793 ,
+-12539 ,
+-13279 ,
+-14010 ,
+-14732 ,
+-15446 ,
+-16151 ,
+-16846 ,
+-17530 ,
+-18204 ,
+-18868 ,
+-19519 ,
+-20159 ,
+-20787 ,
+-21403 ,
+-22005 ,
+-22594 ,
+-23170 ,
+-23731 ,
+-24279 ,
+-24812 ,
+-25329 ,
+-25832 ,
+-26319 ,
+-26790 ,
+-27245 ,
+-27683 ,
+-28105 ,
+-28510 ,
+-28898 ,
+-29268 ,
+-29621 ,
+-29956 ,
+-30273 ,
+-30571 ,
+-30852 ,
+-31113 ,
+-31356 ,
+-31580 ,
+-31785 ,
+-31971 ,
+-32137 ,
+-32285 ,
+-32412 ,
+-32521 ,
+-32609 ,
+-32678 ,
+-32728 ,
+-32757 ,
+-32767 ,
+-32757 ,
+-32728 ,
+-32678 ,
+-32609 ,
+-32521 ,
+-32412 ,
+-32285 ,
+-32137 ,
+-31971 ,
+-31785 ,
+-31580 ,
+-31356 ,
+-31113 ,
+-30852 ,
+-30571 ,
+-30273 ,
+-29956 ,
+-29621 ,
+-29268 ,
+-28898 ,
+-28510 ,
+-28105 ,
+-27683 ,
+-27245 ,
+-26790 ,
+-26319 ,
+-25832 ,
+-25329 ,
+-24812 ,
+-24279 ,
+-23731 ,
+-23170 ,
+-22594 ,
+-22005 ,
+-21403 ,
+-20787 ,
+-20159 ,
+-19519 ,
+-18868 ,
+-18204 ,
+-17530 ,
+-16846 ,
+-16151 ,
+-15446 ,
+-14732 ,
+-14010 ,
+-13279 ,
+-12539 ,
+-11793 ,
+-11039 ,
+-10278 ,
+-9512 ,
+-8739 ,
+-7962 ,
+-7179 ,
+-6393 ,
+-5602 ,
+-4808 ,
+-4011 ,
+-3212 ,
+-2410 ,
+-1608 ,
+-804
+};
+
+static S16 sin_table2[]={
+0 ,
+804 ,
+1608 ,
+2410 ,
+3212 ,
+4011 ,
+4808 ,
+5602 ,
+6393 ,
+7179 ,
+7962 ,
+8739 ,
+9512 ,
+10278 ,
+11039 ,
+11793 ,
+12539 ,
+13279 ,
+14010 ,
+14732 ,
+15446 ,
+16151 ,
+16846 ,
+17530 ,
+18204 ,
+18868 ,
+19519 ,
+20159 ,
+20787 ,
+21403 ,
+22005 ,
+22594 ,
+23170 ,
+23731 ,
+24279 ,
+24812 ,
+25329 ,
+25832 ,
+26319 ,
+26790 ,
+27245 ,
+27683 ,
+28105 ,
+28510 ,
+28898 ,
+29268 ,
+29621 ,
+29956 ,
+30273 ,
+30571 ,
+30852 ,
+31113 ,
+31356 ,
+31580 ,
+31785 ,
+31971 ,
+32137 ,
+32285 ,
+32412 ,
+32521 ,
+32609 ,
+32678 ,
+32728 ,
+32757 ,
+32767 ,
+32757 ,
+32728 ,
+32678 ,
+32609 ,
+32521 ,
+32412 ,
+32285 ,
+32137 ,
+31971 ,
+31785 ,
+31580 ,
+31356 ,
+31113 ,
+30852 ,
+30571 ,
+30273 ,
+29956 ,
+29621 ,
+29268 ,
+28898 ,
+28510 ,
+28105 ,
+27683 ,
+27245 ,
+26790 ,
+26319 ,
+25832 ,
+25329 ,
+24812 ,
+24279 ,
+23731 ,
+23170 ,
+22594 ,
+22005 ,
+21403 ,
+20787 ,
+20159 ,
+19519 ,
+18868 ,
+18204 ,
+17530 ,
+16846 ,
+16151 ,
+15446 ,
+14732 ,
+14010 ,
+13279 ,
+12539 ,
+11793 ,
+11039 ,
+10278 ,
+9512 ,
+8739 ,
+7962 ,
+7179 ,
+6393 ,
+5602 ,
+4808 ,
+4011 ,
+3212 ,
+2410 ,
+1608 ,
+804 ,
+0 ,
+804 ,
+1608 ,
+2410 ,
+3212 ,
+4011 ,
+4808 ,
+5602 ,
+6393 ,
+7179 ,
+7962 ,
+8739 ,
+9512 ,
+10278 ,
+11039 ,
+11793 ,
+12539 ,
+13279 ,
+14010 ,
+14732 ,
+15446 ,
+16151 ,
+16846 ,
+17530 ,
+18204 ,
+18868 ,
+19519 ,
+20159 ,
+20787 ,
+21403 ,
+22005 ,
+22594 ,
+23170 ,
+23731 ,
+24279 ,
+24812 ,
+25329 ,
+25832 ,
+26319 ,
+26790 ,
+27245 ,
+27683 ,
+28105 ,
+28510 ,
+28898 ,
+29268 ,
+29621 ,
+29956 ,
+30273 ,
+30571 ,
+30852 ,
+31113 ,
+31356 ,
+31580 ,
+31785 ,
+31971 ,
+32137 ,
+32285 ,
+32412 ,
+32521 ,
+32609 ,
+32678 ,
+32728 ,
+32757 ,
+32767 ,
+32757 ,
+32728 ,
+32678 ,
+32609 ,
+32521 ,
+32412 ,
+32285 ,
+32137 ,
+31971 ,
+31785 ,
+31580 ,
+31356 ,
+31113 ,
+30852 ,
+30571 ,
+30273 ,
+29956 ,
+29621 ,
+29268 ,
+28898 ,
+28510 ,
+28105 ,
+27683 ,
+27245 ,
+26790 ,
+26319 ,
+25832 ,
+25329 ,
+24812 ,
+24279 ,
+23731 ,
+23170 ,
+22594 ,
+22005 ,
+21403 ,
+20787 ,
+20159 ,
+19519 ,
+18868 ,
+18204 ,
+17530 ,
+16846 ,
+16151 ,
+15446 ,
+14732 ,
+14010 ,
+13279 ,
+12539 ,
+11793 ,
+11039 ,
+10278 ,
+9512 ,
+8739 ,
+7962 ,
+7179 ,
+6393 ,
+5602 ,
+4808 ,
+4011 ,
+3212 ,
+2410 ,
+1608 ,
+804
+};
+
+
+
+
+static S16 saw1_table[]={
+0 ,
+256 ,
+512 ,
+768 ,
+1024 ,
+1280 ,
+1536 ,
+1792 ,
+2048 ,
+2304 ,
+2560 ,
+2816 ,
+3072 ,
+3328 ,
+3584 ,
+3840 ,
+4096 ,
+4352 ,
+4608 ,
+4864 ,
+5120 ,
+5376 ,
+5632 ,
+5888 ,
+6144 ,
+6400 ,
+6656 ,
+6912 ,
+7168 ,
+7424 ,
+7680 ,
+7936 ,
+8192 ,
+8448 ,
+8704 ,
+8960 ,
+9216 ,
+9472 ,
+9728 ,
+9984 ,
+10240 ,
+10496 ,
+10752 ,
+11008 ,
+11264 ,
+11520 ,
+11776 ,
+12032 ,
+12288 ,
+12544 ,
+12800 ,
+13056 ,
+13312 ,
+13568 ,
+13824 ,
+14080 ,
+14336 ,
+14592 ,
+14848 ,
+15104 ,
+15360 ,
+15616 ,
+15872 ,
+16128 ,
+16384 ,
+16640 ,
+16896 ,
+17152 ,
+17408 ,
+17664 ,
+17920 ,
+18176 ,
+18432 ,
+18688 ,
+18944 ,
+19200 ,
+19456 ,
+19712 ,
+19968 ,
+20224 ,
+20480 ,
+20736 ,
+20992 ,
+21248 ,
+21504 ,
+21760 ,
+22016 ,
+22272 ,
+22528 ,
+22784 ,
+23040 ,
+23296 ,
+23552 ,
+23808 ,
+24064 ,
+24320 ,
+24576 ,
+24832 ,
+25088 ,
+25344 ,
+25600 ,
+25856 ,
+26112 ,
+26368 ,
+26624 ,
+26880 ,
+27136 ,
+27392 ,
+27648 ,
+27904 ,
+28160 ,
+28416 ,
+28672 ,
+28928 ,
+29184 ,
+29440 ,
+29696 ,
+29952 ,
+30208 ,
+30464 ,
+30720 ,
+30976 ,
+31232 ,
+31488 ,
+31744 ,
+32000 ,
+32256 ,
+32512 ,
+-32768 ,
+-32512 ,
+-32256 ,
+-32000 ,
+-31744 ,
+-31488 ,
+-31232 ,
+-30976 ,
+-30720 ,
+-30464 ,
+-30208 ,
+-29952 ,
+-29696 ,
+-29440 ,
+-29184 ,
+-28928 ,
+-28672 ,
+-28416 ,
+-28160 ,
+-27904 ,
+-27648 ,
+-27392 ,
+-27136 ,
+-26880 ,
+-26624 ,
+-26368 ,
+-26112 ,
+-25856 ,
+-25600 ,
+-25344 ,
+-25088 ,
+-24832 ,
+-24576 ,
+-24320 ,
+-24064 ,
+-23808 ,
+-23552 ,
+-23296 ,
+-23040 ,
+-22784 ,
+-22528 ,
+-22272 ,
+-22016 ,
+-21760 ,
+-21504 ,
+-21248 ,
+-20992 ,
+-20736 ,
+-20480 ,
+-20224 ,
+-19968 ,
+-19712 ,
+-19456 ,
+-19200 ,
+-18944 ,
+-18688 ,
+-18432 ,
+-18176 ,
+-17920 ,
+-17664 ,
+-17408 ,
+-17152 ,
+-16896 ,
+-16640 ,
+-16384 ,
+-16128 ,
+-15872 ,
+-15616 ,
+-15360 ,
+-15104 ,
+-14848 ,
+-14592 ,
+-14336 ,
+-14080 ,
+-13824 ,
+-13568 ,
+-13312 ,
+-13056 ,
+-12800 ,
+-12544 ,
+-12288 ,
+-12032 ,
+-11776 ,
+-11520 ,
+-11264 ,
+-11008 ,
+-10752 ,
+-10496 ,
+-10240 ,
+-9984 ,
+-9728 ,
+-9472 ,
+-9216 ,
+-8960 ,
+-8704 ,
+-8448 ,
+-8192 ,
+-7936 ,
+-7680 ,
+-7424 ,
+-7168 ,
+-6912 ,
+-6656 ,
+-6400 ,
+-6144 ,
+-5888 ,
+-5632 ,
+-5376 ,
+-5120 ,
+-4864 ,
+-4608 ,
+-4352 ,
+-4096 ,
+-3840 ,
+-3584 ,
+-3328 ,
+-3072 ,
+-2816 ,
+-2560 ,
+-2304 ,
+-2048 ,
+-1792 ,
+-1536 ,
+-1280 ,
+-1024 ,
+-768 ,
+-512 ,
+-256
+};
+
+static S16 saw2_table[]={
+0 ,
+-256 ,
+-512 ,
+-768 ,
+-1024 ,
+-1280 ,
+-1536 ,
+-1792 ,
+-2048 ,
+-2304 ,
+-2560 ,
+-2816 ,
+-3072 ,
+-3328 ,
+-3584 ,
+-3840 ,
+-4096 ,
+-4352 ,
+-4608 ,
+-4864 ,
+-5120 ,
+-5376 ,
+-5632 ,
+-5888 ,
+-6144 ,
+-6400 ,
+-6656 ,
+-6912 ,
+-7168 ,
+-7424 ,
+-7680 ,
+-7936 ,
+-8192 ,
+-8448 ,
+-8704 ,
+-8960 ,
+-9216 ,
+-9472 ,
+-9728 ,
+-9984 ,
+-10240 ,
+-10496 ,
+-10752 ,
+-11008 ,
+-11264 ,
+-11520 ,
+-11776 ,
+-12032 ,
+-12288 ,
+-12544 ,
+-12800 ,
+-13056 ,
+-13312 ,
+-13568 ,
+-13824 ,
+-14080 ,
+-14336 ,
+-14592 ,
+-14848 ,
+-15104 ,
+-15360 ,
+-15616 ,
+-15872 ,
+-16128 ,
+-16384 ,
+-16640 ,
+-16896 ,
+-17152 ,
+-17408 ,
+-17664 ,
+-17920 ,
+-18176 ,
+-18432 ,
+-18688 ,
+-18944 ,
+-19200 ,
+-19456 ,
+-19712 ,
+-19968 ,
+-20224 ,
+-20480 ,
+-20736 ,
+-20992 ,
+-21248 ,
+-21504 ,
+-21760 ,
+-22016 ,
+-22272 ,
+-22528 ,
+-22784 ,
+-23040 ,
+-23296 ,
+-23552 ,
+-23808 ,
+-24064 ,
+-24320 ,
+-24576 ,
+-24832 ,
+-25088 ,
+-25344 ,
+-25600 ,
+-25856 ,
+-26112 ,
+-26368 ,
+-26624 ,
+-26880 ,
+-27136 ,
+-27392 ,
+-27648 ,
+-27904 ,
+-28160 ,
+-28416 ,
+-28672 ,
+-28928 ,
+-29184 ,
+-29440 ,
+-29696 ,
+-29952 ,
+-30208 ,
+-30464 ,
+-30720 ,
+-30976 ,
+-31232 ,
+-31488 ,
+-31744 ,
+-32000 ,
+-32256 ,
+-32512 ,
+-32768 ,
+32511 ,
+32255 ,
+31999 ,
+31743 ,
+31487 ,
+31231 ,
+30975 ,
+30719 ,
+30463 ,
+30207 ,
+29951 ,
+29695 ,
+29439 ,
+29183 ,
+28927 ,
+28671 ,
+28415 ,
+28159 ,
+27903 ,
+27647 ,
+27391 ,
+27135 ,
+26879 ,
+26623 ,
+26367 ,
+26111 ,
+25855 ,
+25599 ,
+25343 ,
+25087 ,
+24831 ,
+24575 ,
+24319 ,
+24063 ,
+23807 ,
+23551 ,
+23295 ,
+23039 ,
+22783 ,
+22527 ,
+22271 ,
+22015 ,
+21759 ,
+21503 ,
+21247 ,
+20991 ,
+20735 ,
+20479 ,
+20223 ,
+19967 ,
+19711 ,
+19455 ,
+19199 ,
+18943 ,
+18687 ,
+18431 ,
+18175 ,
+17919 ,
+17663 ,
+17407 ,
+17151 ,
+16895 ,
+16639 ,
+16383 ,
+16127 ,
+15871 ,
+15615 ,
+15359 ,
+15103 ,
+14847 ,
+14591 ,
+14335 ,
+14079 ,
+13823 ,
+13567 ,
+13311 ,
+13055 ,
+12799 ,
+12543 ,
+12287 ,
+12031 ,
+11775 ,
+11519 ,
+11263 ,
+11007 ,
+10751 ,
+10495 ,
+10239 ,
+9983 ,
+9727 ,
+9471 ,
+9215 ,
+8959 ,
+8703 ,
+8447 ,
+8191 ,
+7935 ,
+7679 ,
+7423 ,
+7167 ,
+6911 ,
+6655 ,
+6399 ,
+6143 ,
+5887 ,
+5631 ,
+5375 ,
+5119 ,
+4863 ,
+4607 ,
+4351 ,
+4095 ,
+3839 ,
+3583 ,
+3327 ,
+3071 ,
+2815 ,
+2559 ,
+2303 ,
+2047 ,
+1791 ,
+1535 ,
+1279 ,
+1023 ,
+767 ,
+511 ,
+255
+};
+
+static S16 tri_table[]={
+0 ,
+512 ,
+1024 ,
+1536 ,
+2048 ,
+2560 ,
+3072 ,
+3584 ,
+4096 ,
+4608 ,
+5120 ,
+5632 ,
+6144 ,
+6656 ,
+7168 ,
+7680 ,
+8192 ,
+8704 ,
+9216 ,
+9728 ,
+10240 ,
+10752 ,
+11264 ,
+11776 ,
+12288 ,
+12800 ,
+13312 ,
+13824 ,
+14336 ,
+14848 ,
+15360 ,
+15872 ,
+16384 ,
+16896 ,
+17408 ,
+17920 ,
+18432 ,
+18944 ,
+19456 ,
+19968 ,
+20480 ,
+20992 ,
+21504 ,
+22016 ,
+22528 ,
+23040 ,
+23552 ,
+24064 ,
+24576 ,
+25088 ,
+25600 ,
+26112 ,
+26624 ,
+27136 ,
+27648 ,
+28160 ,
+28672 ,
+29184 ,
+29696 ,
+30208 ,
+30720 ,
+31232 ,
+31744 ,
+32256 ,
+32767 ,
+32255 ,
+31743 ,
+31231 ,
+30719 ,
+30207 ,
+29695 ,
+29183 ,
+28671 ,
+28159 ,
+27647 ,
+27135 ,
+26623 ,
+26111 ,
+25599 ,
+25087 ,
+24575 ,
+24063 ,
+23551 ,
+23039 ,
+22527 ,
+22015 ,
+21503 ,
+20991 ,
+20479 ,
+19967 ,
+19455 ,
+18943 ,
+18431 ,
+17919 ,
+17407 ,
+16895 ,
+16383 ,
+15871 ,
+15359 ,
+14847 ,
+14335 ,
+13823 ,
+13311 ,
+12799 ,
+12287 ,
+11775 ,
+11263 ,
+10751 ,
+10239 ,
+9727 ,
+9215 ,
+8703 ,
+8191 ,
+7679 ,
+7167 ,
+6655 ,
+6143 ,
+5631 ,
+5119 ,
+4607 ,
+4095 ,
+3583 ,
+3071 ,
+2559 ,
+2047 ,
+1535 ,
+1023 ,
+511 ,
+-1 ,
+-513 ,
+-1025 ,
+-1537 ,
+-2049 ,
+-2561 ,
+-3073 ,
+-3585 ,
+-4097 ,
+-4609 ,
+-5121 ,
+-5633 ,
+-6145 ,
+-6657 ,
+-7169 ,
+-7681 ,
+-8193 ,
+-8705 ,
+-9217 ,
+-9729 ,
+-10241 ,
+-10753 ,
+-11265 ,
+-11777 ,
+-12289 ,
+-12801 ,
+-13313 ,
+-13825 ,
+-14337 ,
+-14849 ,
+-15361 ,
+-15873 ,
+-16385 ,
+-16897 ,
+-17409 ,
+-17921 ,
+-18433 ,
+-18945 ,
+-19457 ,
+-19969 ,
+-20481 ,
+-20993 ,
+-21505 ,
+-22017 ,
+-22529 ,
+-23041 ,
+-23553 ,
+-24065 ,
+-24577 ,
+-25089 ,
+-25601 ,
+-26113 ,
+-26625 ,
+-27137 ,
+-27649 ,
+-28161 ,
+-28673 ,
+-29185 ,
+-29697 ,
+-30209 ,
+-30721 ,
+-31233 ,
+-31745 ,
+-32257 ,
+-32768 ,
+-32256 ,
+-31744 ,
+-31232 ,
+-30720 ,
+-30208 ,
+-29696 ,
+-29184 ,
+-28672 ,
+-28160 ,
+-27648 ,
+-27136 ,
+-26624 ,
+-26112 ,
+-25600 ,
+-25088 ,
+-24576 ,
+-24064 ,
+-23552 ,
+-23040 ,
+-22528 ,
+-22016 ,
+-21504 ,
+-20992 ,
+-20480 ,
+-19968 ,
+-19456 ,
+-18944 ,
+-18432 ,
+-17920 ,
+-17408 ,
+-16896 ,
+-16384 ,
+-15872 ,
+-15360 ,
+-14848 ,
+-14336 ,
+-13824 ,
+-13312 ,
+-12800 ,
+-12288 ,
+-11776 ,
+-11264 ,
+-10752 ,
+-10240 ,
+-9728 ,
+-9216 ,
+-8704 ,
+-8192 ,
+-7680 ,
+-7168 ,
+-6656 ,
+-6144 ,
+-5632 ,
+-5120 ,
+-4608 ,
+-4096 ,
+-3584 ,
+-3072 ,
+-2560 ,
+-2048 ,
+-1536 ,
+-1024 ,
+-512
+};
+
+/*
+static S16 rand_table[]={
+-4702 ,
+-5937 ,
+1759 ,
+5872 ,
+-12112 ,
+3206 ,
+-1264 ,
+-15611 ,
+-14364 ,
+2695 ,
+14181 ,
+-7401 ,
+3850 ,
+-11648 ,
+10868 ,
+3708 ,
+-10377 ,
+9014 ,
+8700 ,
+-14739 ,
+6456 ,
+16098 ,
+4686 ,
+6799 ,
+-975 ,
+16232 ,
+9697 ,
+13385 ,
+751 ,
+7436 ,
+-6095 ,
+13099 ,
+11876 ,
+-13041 ,
+-3477 ,
+6435 ,
+-6829 ,
+-12507 ,
+-5812 ,
+12803 ,
+10729 ,
+-7479 ,
+7376 ,
+-5443 ,
+-10950 ,
+10022 ,
+-2564 ,
+-15874 ,
+4668 ,
+4713 ,
+9395 ,
+-10234 ,
+3657 ,
+-5513 ,
+5354 ,
+-12489 ,
+-15931 ,
+-5721 ,
+14209 ,
+-4347 ,
+13988 ,
+-7041 ,
+-2546 ,
+-11584 ,
+-8644 ,
+-228 ,
+-16181 ,
+-8151 ,
+11335 ,
+14388 ,
+14949 ,
+-8035 ,
+-13892 ,
+15135 ,
+-3969 ,
+6648 ,
+15148 ,
+8950 ,
+574 ,
+-9073 ,
+15669 ,
+11775 ,
+763 ,
+3151 ,
+-12135 ,
+-12169 ,
+9605 ,
+-6657 ,
+-15719 ,
+13266 ,
+-3722 ,
+-15255 ,
+5692 ,
+-10309 ,
+13124 ,
+-9366 ,
+-7765 ,
+6999 ,
+8386 ,
+15420 ,
+-4968 ,
+-202 ,
+8628 ,
+-4212 ,
+-11400 ,
+8105 ,
+-11109 ,
+-5194 ,
+-3745 ,
+-7401 ,
+6659 ,
+8305 ,
+2596 ,
+14753 ,
+2982 ,
+-7625 ,
+2982 ,
+13759 ,
+8370 ,
+15031 ,
+960 ,
+7657 ,
+-12315 ,
+3118 ,
+3594 ,
+1096 ,
+-8170 ,
+15216 ,
+8214 ,
+10686 ,
+-5097 ,
+-2757 ,
+16009 ,
+15692 ,
+-6785 ,
+6745 ,
+-3329 ,
+15549 ,
+13942 ,
+-2251 ,
+5121 ,
+6668 ,
+4485 ,
+7399 ,
+-1296 ,
+-13123 ,
+15626 ,
+8179 ,
+-15663 ,
+-3525 ,
+-11335 ,
+-3789 ,
+-15464 ,
+5378 ,
+11846 ,
+-3336 ,
+-6615 ,
+5632 ,
+-1580 ,
+-7516 ,
+14305 ,
+-3498 ,
+11659 ,
+4070 ,
+-15716 ,
+-1538 ,
+-15156 ,
+-14056 ,
+-11466 ,
+-3617 ,
+-7872 ,
+5279 ,
+957 ,
+-11435 ,
+-12116 ,
+-2382 ,
+10603 ,
+-8960 ,
+2788 ,
+-14564 ,
+15417 ,
+-14205 ,
+1446 ,
+-38 ,
+14555 ,
+3048 ,
+-15186 ,
+8049 ,
+13701 ,
+15978 ,
+-8635 ,
+5345 ,
+5956 ,
+-959 ,
+-1412 ,
+-8778 ,
+6102 ,
+-9267 ,
+-5359 ,
+-9307 ,
+-4823 ,
+262 ,
+15678 ,
+-2597 ,
+2381 ,
+2733 ,
+1589 ,
+14095 ,
+-4438 ,
+3132 ,
+-8347 ,
+-15531 ,
+-14455 ,
+9221 ,
+-16371 ,
+-3805 ,
+6240 ,
+-83 ,
+-2819 ,
+-7996 ,
+13221 ,
+581 ,
+-2605 ,
+9129 ,
+-16278 ,
+-4914 ,
+9007 ,
+-3943 ,
+11643 ,
+-2273 ,
+5094 ,
+11570 ,
+-16142 ,
+-15706 ,
+-13944 ,
+-359 ,
+-5528 ,
+-5262 ,
+-15017 ,
+-10309 ,
+2162 ,
+-6804 ,
+-11014 ,
+14903 ,
+-6135 ,
+-3560 ,
+-3194 ,
+-8291 ,
+-11162 ,
+-5989 ,
+5102 ,
+3235 ,
+1329 ,
+1232 ,
+9652 ,
+-12759
+};
+*/
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Fri Sep 02 13:24:16 2016 +0000
@@ -0,0 +1,344 @@
+#include "synthesizer.h"
+
+Serial pc(SERIAL_TX, SERIAL_RX);
+//RawSerial pc(SERIAL_TX, SERIAL_RX);
+RawSerial midi(PB_6, PB_7); // tx, rx USART1 when use I2C_LCD
+
+LCD lcd(PB_9,PB_8);
+DigitalOut myled(LED1);
+DigitalOut generating(PC_10);
+
+DigitalIn SW1(PC_0,PullUp);
+DigitalIn SW2(PC_1,PullUp);
+DigitalIn SW3(PC_2,PullUp);
+DigitalIn SW4(PC_3,PullUp);
+DigitalIn SW5(PA_0,PullUp);
+DigitalIn SW6(PA_1,PullUp);
+DigitalIn SW7(PB_0,PullUp);
+DigitalIn SW8(PC_12,PullUp);
+
+
+STR_VOICE voice[VOICEMAX];
+GENERATOR sgen[PRGGENMAX * 64];
+GENERATOR dgen[PRGGENMAX * VOICEMAX];
+GENERATOR_TEMP dgen_temp[PRGGENMAX * VOICEMAX];
+
+STR_VOICE *voice_ptr = &voice[0];
+GENERATOR *gen ;// = &sgen[PresetVoiceNum - 1] set by Menu PresetVoice
+GENERATOR *pgen = &dgen[0];
+GENERATOR_TEMP *pgen_temp = &dgen_temp[0];
+
+KeyState_TypeDef keystate;
+
+#ifdef REVERVE16BIT
+extern S16 reverve_buf[22000];
+extern S16 *reverve_wtemp;
+#else
+extern S8 reverve_buf[44000];
+extern S8 *reverve_wtemp;
+#endif
+
+
+extern uint8_t com[16];
+extern uint8_t *com_ptr;
+
+volatile int TimerCount10mS;
+volatile int KeyValDiv;
+
+U32 PresetVoiceAmount;
+U32 SGenAmount;
+
+int menu_index;
+volatile U8 key;
+
+extern int gen_encount;
+extern U8 PresetVoiceNum;
+extern U8 MidiChannel;
+extern U16 MasterVolume;
+extern S8 MasterTune;
+extern U8 midi_base_ch;
+extern char lcd_string[];
+extern char str[];
+
+extern U8 selectsw;
+extern MenuListDef MenuList[];
+extern int rch_pol;
+
+extern volatile U8 *midi_rdptr;
+extern volatile U8 *midi_wrptr;
+extern volatile U8 midi_receivebuf[];
+
+extern volatile U8 *param_wrptr;
+extern volatile U8 param_receivebuf[PARAM_BUFSIZE];
+
+extern S16 * DMA_Buffer;
+extern __IO BUFFER_StateTypeDef BufferOffset;
+
+WaveDef Wave[100];// ={
+#if 0
+/*Name[16] ,startadr ,p1 ,p2 ,cycle */
+{"SineWave" ,0 ,50 ,150 ,0},
+{"SawWave" ,0 ,100 ,200 ,0},
+{"Saw1kWave" ,0 ,1 ,101 ,0},
+{"SquareWave" ,0 ,50 ,150 ,0},
+{"Square4QWave" ,0 ,1 ,101 ,0},
+{"Square8QWave" ,0 ,1 ,101 ,0},
+{"Sin124Wave" ,0 ,1 ,101 ,0},
+{"Sin13Wave" ,0 ,1 ,43 ,0},
+{"fluto" ,0 ,1 ,68 ,0},
+{"EnglishHorn" ,0 ,3030 ,3142 ,0},
+{"FrenchHorn" ,0 ,3033 ,3132 ,0},
+{"1278_trumpet" ,0 ,9089 ,9200 ,0},
+{"1507_trumpet" ,0 ,6612 ,6718 ,0},
+{"BrassP-C6" ,0 ,2965 ,3133 ,0},
+{"Trombone" ,0 ,6852 ,6991 ,0},
+{"Tuba_Loud" ,0 ,12686 ,13088 ,0},
+{"2524_cello" ,0 ,8683 ,9157 ,0},
+{"Contrabassoon" ,0 ,5004 ,5759 ,0},
+{"Base-Elec" ,0 ,17400 ,17934 ,0},
+{"EFEKTOharp" ,0 ,9423 ,9522 ,0},
+{"Harpsicord" ,0 ,21595 ,21764 ,0},
+{"Glockenspie" ,0 ,3886 ,3911 ,0},
+{"Xylofon" ,0 ,1126 ,1150 ,0},
+{"Acoustic Guitar" ,0 ,11422 ,11622 ,0},
+{"Piano" ,0 ,6699 ,6783 ,0},
+{"Piano 5" ,0 ,13937 ,14335 ,0},
+{"Piano 10" ,0 ,11837 ,12005 ,0},
+{"VIOLIN1" ,0 ,1 ,56 ,0},
+{"Strings" ,0 ,3606 ,37992 ,84},
+};
+#endif
+
+PresetVoiceDef PresetVoice[65];//={
+#if 0
+/*Name[16] ,DCF Freq ,Q ,FreqEnv ,QEnv */
+{"Piano " ,30 ,0 ,0 ,0},// 1
+{"Piano 5" ,30 ,0 ,0 ,0},//
+{"Piano 10" ,30 ,0 ,0 ,0},//
+{"Electo Piano" ,30 ,0 ,0 ,0},//
+{"Organ 1" ,30 ,0 ,0 ,0},
+{"Organ 2" ,30 ,0 ,0 ,0},
+{"Organ 2B" ,30 ,0 ,0 ,0},
+{"Synth Strings 1" ,30 ,0 ,0 ,0},
+{"Strings 1" ,30 ,0 ,0 ,0},
+{"Synthe Brass" ,30 ,0 ,0 ,0},
+{"Brass 1" ,30 ,0 ,0 ,0},
+{"Brass 2" ,30 ,0 ,0 ,0},
+{"EnglishHorn" ,30 ,0 ,0 ,0},
+{"Trb" ,30 ,0 ,0 ,0},
+{"Tuba" ,30 ,0 ,0 ,0},
+{"Harp" ,30 ,0 ,0 ,0},
+{"Harpsicord" ,30 ,0 ,0 ,0},
+{"Gloccken" ,30 ,0 ,0 ,0},
+{"Xylofon" ,30 ,0 ,0 ,0},
+{"Fluto" ,30 ,0 ,0 ,0},
+{"ContraBass" ,30 ,0 ,0 ,0},
+{"Chello&ContBass" ,30 ,0 ,0 ,0},
+{"Acoustic Guitar" ,30 ,0 ,0 ,0},
+{"Bass" ,30 ,0 ,0 ,0},
+{"Bass 2" ,30 ,0 ,0 ,0},
+{"User 1" ,30 ,0 ,0 ,0},
+{"User 2" ,30 ,0 ,0 ,0},
+{"User 3" ,30 ,0 ,0 ,0},
+{"User 4" ,30 ,0 ,0 ,0},
+{"User 5" ,30 ,0 ,0 ,0},
+{"User 6" ,30 ,0 ,0 ,0},
+{"User 7" ,30 ,0 ,0 ,0},
+{"User 8" ,30 ,0 ,0 ,0},
+{"User 9" ,30 ,0 ,0 ,0},
+{"User 10" ,30 ,0 ,0 ,0}
+};
+#endif
+
+void my_inthandler(void){
+ while (USART1->SR & (1<<5)){ // RXNE 1: Received data is ready to be read.
+ *midi_wrptr = (uint8_t)(USART1->DR & 0xFF);
+ if (++midi_wrptr >&midi_receivebuf[255]) midi_wrptr = &midi_receivebuf[0];//
+ }
+}
+
+void my_inthandler2(void){
+
+ while (USART2->SR & (1<<5)){ // RXNE 1: Received data is ready to be read.
+ *param_wrptr = (uint8_t)(USART2->DR & 0xFF);
+ if (++param_wrptr >¶m_receivebuf[255]) param_wrptr = ¶m_receivebuf[0];//
+ }
+}
+
+void anykeyon(U8 inkey){
+ U8 temp = inkey & 0x0f;
+ /* Select OneGenSw of them */
+ if (temp > 7){selectsw = 8;}
+ else if(temp > 3){selectsw = 4;}
+ else if(temp > 1){selectsw = 2;}
+ else if(temp > 0){selectsw = 1;}
+
+ if (inkey == 0x80){
+ if (++menu_index > MENU_INDEXMAX) menu_index = MENU_INDEXMAX;
+ }else if(inkey == 0x40){
+ if(--menu_index < 0) menu_index = 0;
+ }
+ lcd_print1((char *)&MenuList[menu_index].menu);
+ lcd_string[0] = 0;
+ (*MenuList[menu_index].function)();
+}
+
+
+int main(){
+ int temp2;
+ uint8_t *test;
+ uGen4_device_init();
+ pc.baud(115200);
+ pc.attach(my_inthandler2, Serial::RxIrq);
+// pc.format(8,RawSerial::None,1);
+ pc.printf("CPU SystemCoreClock is %d Hz\r\n", SystemCoreClock);
+ PresetVoiceAmount = (U32)&PresetVoice[63]-(U32)&PresetVoice[0]+sizeof(PresetVoiceDef);
+ SGenAmount = (U32)&sgen[PRGGENMAX * 64-1]-(U32)&sgen[0]+sizeof(GENERATOR);
+
+// pc.printf("%d\r\n",PresetVoiceAmount);
+// pc.printf("%d\r\n",SGenAmount);
+
+ lcd_print_title();
+
+ PresetVoiceNum = 1;
+ MasterVolume = 127<<8;
+ MidiChannel = 1;
+ midi_base_ch = MidiChannel - 1;
+ menu_index = 2;
+ selectsw = 1;
+ keystate = KEY_FIRST_WAIT;
+ MasterTune = 0;
+ rch_pol = 1;
+ limit = 8;
+
+ TimerCount10mS= 0;
+ KeyValDiv = 1;
+ int KeyAutoLoopCount = 0;
+
+ reverve_wtemp = reverve_buf;
+
+ if (temp2 = get_wave_addr(&Wave[0])){
+ pc.printf("Wave Format Eror No %d\r\n",temp2);
+ lcd_print2("WaveFormatEror");
+ val2str4(temp2);
+ lcd_print(&str[0]);
+ while(1){}
+ }
+
+ init_sgen();
+
+ voice_ptr = &voice[0];
+ gen = &sgen[PresetVoiceNum - 1];
+ pgen = &dgen[0];
+ pgen_temp = &dgen_temp[0];
+ gen_encount = 0;
+
+ init_midi();
+ midi.attach(my_inthandler, Serial::RxIrq);
+ midi.format(8,RawSerial::None,1);
+ midi.baud(31250);
+
+ load2from();
+
+ uGen4_init();
+ i2s_dma_init();
+
+ init_param();
+/*
+ test = (uint8_t *)malloc(60000);
+ if (test == 0) myled =1;
+*/
+
+ while(1) {
+ if(BufferOffset != DMA_Idle) wave_generate();
+ midi_work();
+ param_work();
+
+ switch(keystate){
+ case KEY_FIRST_WAIT:
+ if (ANYKEYON){
+ keystate = KEY_AFTER_ON;
+ anykeyon(0);
+ }
+ break;
+
+ case KEY_GEN_WAVE1:
+ if (TimerCount10mS== 0){
+ keystate = KEY_WAIT_OFF;
+ TimerCount10mS= 100;// 1000mS Wait
+ }
+ break;
+
+ case KEY_WAIT_ON:
+ if(key = ANYKEYON){
+ anykeyon(key);/* call function */
+ if(keystate == KEY_GEN_WAVE1){
+ }else{
+ keystate = KEY_AFTER_ON;
+ TimerCount10mS= 4;// 40mS wait for key stable
+ }
+ }
+ break;
+
+ case KEY_AFTER_ON:
+ if (TimerCount10mS== 0){
+ keystate = KEY_WAIT_OFF;
+ TimerCount10mS= 100;// 1000mS Wait
+ }
+ break;
+
+ case KEY_AUTO_PRESS:
+ anykeyon(key);/* call function */
+ keystate = KEY_AFTER_AUTO_PRESS;
+ TimerCount10mS = 20;// 200mS Wait
+ break;
+
+ case KEY_AFTER_AUTO_PRESS:
+ if(key = ANYKEYON){
+ if (TimerCount10mS== 0){
+ if(++KeyAutoLoopCount > 40){
+ KeyAutoLoopCount = 0;
+ KeyValDiv *= 10;
+ if(KeyValDiv >500) KeyValDiv = 500;
+ }
+ keystate = KEY_AUTO_PRESS;
+ }
+ }else{
+ KeyValDiv = 1;
+ keystate = KEY_AFTER_OFF;
+ TimerCount10mS= 4;// 40mS wait for key stable
+
+ }
+ break;
+
+ case KEY_WAIT_OFF:
+ if (TimerCount10mS== 0){
+ KeyValDiv <<= 2;
+ if(KeyValDiv >500) KeyValDiv = 500;
+ keystate = KEY_AUTO_PRESS;
+ }else if(ANYKEYON == 0){
+ KeyValDiv = 1;
+ keystate = KEY_AFTER_OFF;
+ TimerCount10mS= 7;// 70mS wait for key stable
+ }
+ break;
+
+ case KEY_AFTER_OFF:
+ if (TimerCount10mS== 0){
+ keystate = KEY_WAIT_ON;
+ }
+ break;
+ }
+ }
+}
+
+
+
+
+
+
+
+
+
+
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Fri Sep 02 13:24:16 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/024bf7f99721 \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/midi_work.cpp Fri Sep 02 13:24:16 2016 +0000
@@ -0,0 +1,322 @@
+#include "synthesizer.h"
+
+#define MIDI_IDLE 0
+#define MIDI_NOTEON 1
+#define MIDI_NOTEOFF 2
+#define MIDI_VELOCITY 3
+#define MIDI_VELOCITY0 4
+#define MIDI_PGMCHG 5
+#define MIDI_CONTCHG 6
+#define MIDI_VOLH 7
+#define MIDI_VOLL 8
+#define MIDI_PORH 9
+#define MIDI_PORL 10
+#define MIDI_PORD 24
+#define MIDI_LFO1H 11
+#define MIDI_LFO1L 12
+#define MIDI_NOTECHG 13
+#define MIDI_OTHER 14
+#define MIDI_PORSW 15
+#define MIDI_SETMVOL 16
+#define MIDI_INCMVOL 17
+#define MIDI_DECMVOL 18
+#define MIDI_INCMVOL2 19
+#define MIDI_DECMVOL2 20
+#define MIDI_ATTACKTIME 21
+#define MIDI_RELEASETIME 22
+#define MIDI_DECAYTIME 23
+#define MIDI_BUFSIZE 256
+
+extern DigitalOut myled;
+
+volatile U8 midi_com;
+volatile U8 midi_ch;
+volatile U8 notenum;
+volatile U8 *midi_rdptr;
+volatile U8 *midi_wrptr;
+volatile U16 md_voltemp;
+volatile U16 md_lfo1depth;
+volatile S16 md_portemp;
+volatile U8 midi_receivebuf[MIDI_BUFSIZE];
+
+extern int portament;
+extern GENERATOR *pgen;
+extern GENERATOR *gen;// ProgramChangeによるテンポラリに変更する。
+extern GENERATOR_TEMP *pgen_temp;// = &dgen_temp[0];
+
+extern volatile U8 midi_base_ch;
+extern volatile U8 midi_note_ch;
+extern volatile U8 midi_prog_ch;
+extern volatile S16 interpovalue;
+extern volatile S16 MasterVolume;
+extern volatile S16 mvoldiv;
+
+void init_midi(void){
+ midi_com = MIDI_IDLE;
+ midi_wrptr = midi_rdptr = &midi_receivebuf[0];
+}
+
+void midi_work(void){
+ GENERATOR *gena;// 110824
+ GENERATOR_TEMP *gena_temp;// 110824
+ U8 i ,data;
+ U16 temp16;
+
+ while(midi_rdptr != midi_wrptr){
+ /* レシーブバッファが空なら、リターン */
+ data = *midi_rdptr;
+ if (++midi_rdptr >&midi_receivebuf[255]) midi_rdptr = &midi_receivebuf[0];//
+ if (data > 0xf7){
+ /* リアルタイムメッセージ */
+ if (data == 0xff){// 110824 システムリセット
+ //prog_enable = 0;
+ MasterVolume = 127 <<8 ;// s7e8f
+ mvoldiv = 0;
+ portament = 0;
+ // gena = pgen;
+ gena_temp = pgen_temp;
+ for(i=0;i<GENMAX;i++){
+ gena_temp->status = GEN_IDLE;
+ // ge_tempna->midich =255;
+ gena_temp->voltemp = 0;
+ // gena++;
+ gena_temp++;
+ }
+ }
+ }else if (data <0x80){
+ /* 何かしらの値 */
+ switch (midi_com){ // 有効になっているMIDIコマンドを適用する。
+ case MIDI_NOTEON:
+ notenum = data;
+ midi_com = MIDI_VELOCITY;
+ break;
+ case MIDI_VELOCITY:
+ midi_com = MIDI_NOTEON;
+ if (midi_ch == midi_base_ch) {
+ if(data >0){
+ /* ノートONの処理 */
+ noteon(notenum ,data);
+ }else{
+ /* ノートOFFの処理 */
+ noteoff(notenum ,0);
+ }
+ }
+ break;
+ case MIDI_NOTEOFF:
+ notenum = data;
+ midi_com = MIDI_VELOCITY0;
+ break;
+ case MIDI_VELOCITY0:
+ midi_com = MIDI_NOTEON;
+ if (midi_ch == midi_base_ch){
+ /* ノートOFFの処理 */
+ noteoff(notenum ,0);
+ }
+ break;
+ case MIDI_PGMCHG:
+ midi_com = MIDI_PGMCHG;
+ if (midi_ch == midi_base_ch){ //やはり 戻す 131230
+// if (midi_ch == midi_prog_ch){
+ /* 音色変更の処理 */
+ pgmchg(data);
+ }
+ break;
+ case MIDI_CONTCHG:
+ switch(data){
+ case 90:// 121125
+// if ((midi_ch == midi_base_ch)||(midi_ch == midi_base_ch2)) midi_com = MIDI_NOTECHG;
+ if (midi_ch == midi_base_ch) midi_com = MIDI_NOTECHG;
+ break;
+ case 1:
+ midi_com = MIDI_LFO1H;
+ break;
+ case 1+32:
+ midi_com = MIDI_LFO1L;
+ break;
+ case 5:
+ midi_com = MIDI_PORH;
+ break;
+ case 5+32:
+ midi_com = MIDI_PORL;
+ break;
+ case 38:
+ midi_com = MIDI_PORD;
+ break;
+ case 65:
+ if (midi_ch == midi_base_ch) midi_com = MIDI_PORSW;
+ break;
+ case 70:
+ if (midi_ch == midi_base_ch) midi_com = MIDI_SETMVOL;
+ break;
+ case 71:
+ if (midi_ch == midi_base_ch) midi_com = MIDI_INCMVOL;
+ break;
+ case 72:
+ if (midi_ch == midi_base_ch) midi_com = MIDI_DECMVOL;
+ break;
+ case 73:
+ if (midi_ch == midi_base_ch) midi_com = MIDI_INCMVOL2;
+ break;
+ case 74:
+ if (midi_ch == midi_base_ch) midi_com = MIDI_DECMVOL2;
+ break;
+ case 50:
+ if (midi_ch == midi_base_ch) midi_com = MIDI_ATTACKTIME;
+ break;
+ case 51:
+ if (midi_ch == midi_base_ch) midi_com = MIDI_RELEASETIME;
+ break;
+ case 52:
+ if (midi_ch == midi_base_ch) midi_com = MIDI_DECAYTIME;
+ break;
+
+ case 7:
+ midi_com = MIDI_VOLH;
+ break;
+ case 7+32:
+ midi_com = MIDI_VOLL;
+ break;
+ default:
+ midi_com = MIDI_OTHER;
+ break;
+ }
+ break;
+ case MIDI_NOTECHG:
+ midi_note_ch = data & 0x0f;
+ break;
+ case MIDI_LFO1H:
+ md_lfo1depth = data<<7;
+ break;
+ case MIDI_LFO1L:
+ md_lfo1depth |= data;
+ gena = gen;
+ for(i=0;i<PRGGENMAX;i++){
+ gena->lfo1depth = md_lfo1depth;
+ gena++;
+ }
+ break;
+ case MIDI_PORSW:
+ if(data < 64){
+ portament = 0;
+ }else{
+ portament = -1;
+ }
+ break;
+ case MIDI_SETMVOL:
+ mvoldiv = 0;
+ MasterVolume = data<<8;
+ break;
+ case MIDI_INCMVOL:
+ MasterVolume += (data<<16);
+ if(MasterVolume >(127<<8)) MasterVolume = (127<<8);
+ break;
+ case MIDI_DECMVOL:
+ MasterVolume -= (data<<16);
+ if(MasterVolume < 0) MasterVolume = 0;
+ break;
+ case MIDI_INCMVOL2:
+ mvoldiv = data;
+ break;
+ case MIDI_DECMVOL2:
+ mvoldiv = data * (-1);
+ break;
+
+ case MIDI_ATTACKTIME:
+// gena = pgen;// 実体のほうで
+// for(i=0;i<GENMAX;i++){
+ gena = gen;
+ for(i=0;i<PRGGENMAX;i++){
+ gena->attacktime = (1<<data);
+ gena++;
+ }
+ break;
+
+ case MIDI_RELEASETIME:
+ temp16 = (528 + data) * 100;
+// gena = pgen;// 実体のほうで
+// for(i=0;i<GENMAX;i++){
+ gena = gen;
+ for(i=0;i<PRGGENMAX;i++){
+ gena->releasetime = temp16;
+ gena++;
+ }
+ break;
+
+ case MIDI_DECAYTIME:
+// gena = pgen;// 実体のほうで
+// for(i=0;i<GENMAX;i++){
+ gena = gen;
+ for(i=0;i<PRGGENMAX;i++){
+ gena->decaytime = (1<<data);
+ gena++;
+ }
+ break;
+
+ case MIDI_PORH:
+ md_portemp = data<<9;
+ break;
+ case MIDI_PORL:
+// md_portemp |= data<<1;
+ gena = pgen;
+ // gena_temp = pgen_temp;
+ for(i=0;i<GENMAX;i++){
+ gena_temp->dpf = (gena_temp->df >>14)* data;
+// gena++;
+ gena_temp++;
+ }
+ break;
+ case MIDI_PORD:// Portament Down
+// gena = pgen;
+ gena_temp = pgen_temp;
+ for(i=0;i<GENMAX;i++){
+ gena_temp->dpf = (gena_temp->df >>14)* data;
+ gena_temp->dpf *= -1;
+// gena++;
+ gena_temp++;
+ }
+ break;
+ case MIDI_VOLH:
+ md_voltemp = data<<9;
+ break;
+ case MIDI_VOLL:
+ md_voltemp |= data<<1;
+ gena = gen;
+ for(i=0;i<PRGGENMAX;i++){
+ gena->lfo1depth = md_lfo1depth;
+ gena++;
+ }
+ break;
+ case MIDI_OTHER:
+ default:
+ break;
+ }
+ }else{
+ switch (data & 0xf0){
+ case 0x80:// NOTEOFF コマンド
+ midi_com = MIDI_NOTEOFF;
+ midi_ch = data & 0x0f;
+ break;
+ case 0x90:// NOTEON コマンド
+ midi_com = MIDI_NOTEON;
+ midi_ch = data & 0x0f;
+ break;
+ case 0xc0:// プログラムチェンジコマンド
+ midi_com = MIDI_PGMCHG;
+ midi_ch = data & 0x0f;
+ break;
+ case 0xb0:// コントロールチェンジコマンド
+ midi_com = MIDI_CONTCHG;
+ midi_ch = data & 0x0f;
+ break;
+ case 0xa0:// ポリフォニックキープレッシャーコマンド
+ case 0xd0:// チャンネルプレッシャーコマンド
+ case 0xe0:// ピッチベンドコマンド
+ default:// エクスクルーシブメッセージ
+ midi_com = MIDI_OTHER;
+ break;
+ }
+ }
+ }
+}
+
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/param_work.cpp Fri Sep 02 13:24:16 2016 +0000
@@ -0,0 +1,102 @@
+#include "synthesizer.h"
+
+extern Serial pc;
+//extern RawSerial pc;
+extern U32 PresetVoiceAmount;
+extern U32 SGenAmount;
+
+uint8_t com[16];
+uint8_t *com_ptr;
+
+volatile U8 *param_rdptr;
+volatile U8 *param_wrptr;
+volatile U8 param_receivebuf[PARAM_BUFSIZE];
+
+void init_param(void){
+ param_wrptr = param_rdptr = ¶m_receivebuf[0];
+ com_ptr = &com[0];
+
+}
+
+int strxcmp(uint8_t *str1 ,uint8_t *str2){
+ uint8_t *c1;
+ uint8_t *c2;
+ c1 = str1;
+ c2 = str2;
+ if ((*c1 == 0x0d)||(*c1 == 0x0a)) return 0;
+ while(*c1 != 0x0d){
+ if (*c1++ != *c2++) return 0;
+ }
+ return -1;
+}
+
+void name2pc(void){
+ uint8_t c;
+ uint8_t *ptr = (uint8_t *)&PresetVoice[0];
+ U32 len = PresetVoiceAmount;
+ while (len--){
+ c = *ptr++ & 0xff;
+ pc.putc(c);
+ }
+
+}
+
+void sgen2pc(void){
+ uint8_t c;
+ uint8_t *ptr = (uint8_t *)&sgen[0];
+ U32 len = SGenAmount;
+ while (len--){
+ c = *ptr++ & 0xff;
+ pc.putc(c);
+ }
+
+}
+
+void name2gen(void){
+ uint8_t *ptr = (uint8_t *)&PresetVoice[0];
+ U32 len = PresetVoiceAmount;
+ while (len){
+ if(param_rdptr != param_wrptr){
+ *ptr++ = *param_rdptr;
+ if (++param_rdptr >¶m_receivebuf[255]) param_rdptr = ¶m_receivebuf[0];//
+ len--;
+ }
+ }
+}
+
+void sgen2gen(void){
+ uint8_t *ptr = (uint8_t *)&sgen[0];
+ U32 len = SGenAmount;
+ while (len){
+ if(param_rdptr != param_wrptr){
+ *ptr++ = *param_rdptr;
+ if (++param_rdptr >¶m_receivebuf[255]) param_rdptr = ¶m_receivebuf[0];//
+ len--;
+ }
+ }
+}
+
+void param_work(void){
+ uint8_t c;
+ while(param_rdptr != param_wrptr){
+ /* レシーブバッファが空なら、リターン */
+ c = *param_rdptr;
+ if (++param_rdptr >¶m_receivebuf[255]) param_rdptr = ¶m_receivebuf[0];//
+ if (c == 0x0a){
+ /* compare command */
+ com_ptr = &com[0];
+ if(strxcmp(&com[0],(uint8_t *)"name2PC")){name2pc();}
+ else if(strxcmp(&com[0],(uint8_t *)"gen2PC")){sgen2pc();}
+ else if(strxcmp(&com[0],(uint8_t *)"name2GEN")){name2gen();}
+ else if(strxcmp(&com[0],(uint8_t *)"gen2GEN")){
+ sgen2gen();
+ save2from();
+ lcd_print2("Saved Parameter ");
+ }
+ }else{
+ *com_ptr++ = c;
+ }
+ }
+}
+
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/releasetime_table.h Fri Sep 02 13:24:16 2016 +0000
@@ -0,0 +1,25 @@
+static uint32_t releasetime_table[] ={
+55000 ,
+60000 ,
+62500 ,
+63700 ,
+64300 ,
+64560 ,
+64756 ,
+64885 ,
+64980 ,
+65052 ,
+65102 ,
+65149 ,
+65194 ,
+65237 ,
+65279 ,
+65318 ,
+65357 ,
+65393 ,
+65429 ,
+65463 ,
+65496 ,
+65528
+};
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/reverve_tap.h Fri Sep 02 13:24:16 2016 +0000
@@ -0,0 +1,135 @@
+static U16 reverve_tap[] = {
+1323, 42498, 42498,
+2425, 31189, 0,
+2866, 0, 27559,
+3528, 22890, 0,
+3748, 0, 21516,
+4189, 19012, 0,
+4630, 0, 16799,
+5071, 14843, 0,
+5292, 0, 13953,
+5733, 12329, 0,
+6174, 0, 10894,
+6615, 9625, 0,
+6835, 0, 9048,
+7276, 7995, 0,
+7717, 0, 7064,
+7938, 6640, 0,
+8379, 0, 5867,
+8599, 5515, 0,
+9040, 0, 4873,
+9481, 4306, 0,
+9702, 0, 4047,
+10363, 3362, 0,
+10804, 0, 2970,
+11025, 2792, 0,
+11466, 0, 2467,
+11686, 2319, 0,
+12348, 0, 1926,
+12789, 1702, 0,
+13009, 0, 1600,
+13230, 1504, 0
+};
+
+#if 0
+static U16 reverve_tap[] = {
+1323, 52714, 52714,
+3087, 39433, 0,
+4410, 0, 31718,
+5292, 27433, 0,
+5733, 0, 25512,
+7056, 20521, 0,
+7497, 0, 19084,
+8379, 16506, 0,
+9261, 0, 14276,
+10584, 11483, 0,
+11025, 0, 10679,
+11466, 9931, 0,
+12348, 0, 8590,
+13230, 7429, 0,
+13671, 0, 6909,
+14553, 5976, 0,
+15435, 0, 5168,
+17199, 3866, 0,
+17640, 0, 3595,
+18522, 3110, 0,
+18963, 0, 2892,
+20286, 2326, 0,
+20727, 0, 2163,
+21168, 2012, 0,
+22050, 0, 1740,
+23373, 1399, 0,
+24255, 0, 1210,
+24696, 1125, 0,
+25578, 0, 973,
+26901, 783, 0
+};
+#endif
+
+#if 0
+static U16 reverve_tap[] = {
+1323,57982,57982,
+3087,49246,0,
+4410,0,43570,
+5292,40154,0,
+5733,0,38548,
+7056,34105,0,
+7497,0,32740,
+8379,30174,0,
+9261,0,27808,
+10584,24603,0,
+11025,0,23618,
+11466,22674,0,
+12348,0,20896,
+13230,19258,0,
+13671,0,18487,
+14553,17038,0,
+15435,0,15702,
+17199,13336,0,
+17640,0,12803,
+18522,11799,0,
+18963,0,11327,
+20286,10022,0,
+20727,0,9621,
+21168,9236,0,
+22050,0,8512,
+23373,7531,0,
+24255,0,6940,
+24696,6662,0,
+25578,0,6140,
+26901,5432,0
+};
+#endif
+
+#if 0
+static U16 reverve_tap[] = {
+8820,47465,
+11907,42398,
+12789,41052,
+14553,38487,
+15876,36669,
+16758,35505,
+18522,33286,
+19404,32230,
+19845,31714,
+21168,30216,
+22491,28789,
+23373,27875,
+25137,26133,
+26460,24899,
+27342,24108,
+29106,22602,
+29988,21885,
+30429,21534,
+32193,20189,
+33957,18927,
+35280,18033,
+37485,16636,
+38808,15850,
+40572,14860,
+41013,14622,
+43218,13489,
+44100,13061
+};
+#endif
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/stm32f4xx_hal_conf.h Fri Sep 02 13:24:16 2016 +0000
@@ -0,0 +1,386 @@
+/**
+ ******************************************************************************
+ * @file stm32f4xx_hal_conf.h
+ * @brief HAL configuration file.
+ ******************************************************************************
+ * @attention
+ *
+ * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of STMicroelectronics nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ ******************************************************************************
+ */
+
+/* Define to prevent recursive inclusion -------------------------------------*/
+#ifndef __STM32F4xx_HAL_CONF_H
+#define __STM32F4xx_HAL_CONF_H
+
+#ifdef __cplusplus
+ extern "C" {
+#endif
+
+/* Exported types ------------------------------------------------------------*/
+/* Exported constants --------------------------------------------------------*/
+
+/* ########################## Module Selection ############################## */
+/**
+ * @brief This is the list of modules to be used in the HAL driver
+ */
+#define HAL_MODULE_ENABLED
+//#define HAL_ADC_MODULE_ENABLED
+//#define HAL_CAN_MODULE_ENABLED
+//#define HAL_CRC_MODULE_ENABLED
+//#define HAL_CRYP_MODULE_ENABLED
+//#define HAL_DAC_MODULE_ENABLED
+//#define HAL_DCMI_MODULE_ENABLED
+//#define HAL_DMA2D_MODULE_ENABLED
+//#define HAL_ETH_MODULE_ENABLED
+//#define HAL_NAND_MODULE_ENABLED
+//#define HAL_NOR_MODULE_ENABLED
+//#define HAL_PCCARD_MODULE_ENABLED
+//#define HAL_SRAM_MODULE_ENABLED
+//#define HAL_SDRAM_MODULE_ENABLED
+//#define HAL_HASH_MODULE_ENABLED
+#define HAL_I2C_MODULE_ENABLED
+#define HAL_I2S_MODULE_ENABLED
+//#define HAL_IWDG_MODULE_ENABLED
+//#define HAL_LTDC_MODULE_ENABLED
+//#define HAL_RNG_MODULE_ENABLED
+//#define HAL_RTC_MODULE_ENABLED
+//#define HAL_SAI_MODULE_ENABLED
+//#define HAL_SD_MODULE_ENABLED
+//#define HAL_SPI_MODULE_ENABLED
+//#define HAL_TIM_MODULE_ENABLED
+#define HAL_UART_MODULE_ENABLED
+//#define HAL_USART_MODULE_ENABLED
+//#define HAL_IRDA_MODULE_ENABLED
+//#define HAL_SMARTCARD_MODULE_ENABLED
+//#define HAL_WWDG_MODULE_ENABLED
+//#define HAL_PCD_MODULE_ENABLED
+//#define HAL_HCD_MODULE_ENABLED
+#define HAL_GPIO_MODULE_ENABLED
+#define HAL_DMA_MODULE_ENABLED
+#define HAL_RCC_MODULE_ENABLED
+#define HAL_FLASH_MODULE_ENABLED
+#define HAL_PWR_MODULE_ENABLED
+#define HAL_CORTEX_MODULE_ENABLED
+
+/* ########################## HSE/HSI Values adaptation ##################### */
+/**
+ * @brief Adjust the value of External High Speed oscillator (HSE) used in your application.
+ * This value is used by the RCC HAL module to compute the system frequency
+ * (when HSE is used as system clock source, directly or through the PLL).
+ */
+#if !defined (HSE_VALUE)
+ #define HSE_VALUE ((uint32_t)25000000) /*!< Value of the External oscillator in Hz */
+#endif /* HSE_VALUE */
+
+#if !defined (HSE_STARTUP_TIMEOUT)
+ #define HSE_STARTUP_TIMEOUT ((uint32_t)5000) /*!< Time out for HSE start up, in ms */
+#endif /* HSE_STARTUP_TIMEOUT */
+
+/**
+ * @brief Internal High Speed oscillator (HSI) value.
+ * This value is used by the RCC HAL module to compute the system frequency
+ * (when HSI is used as system clock source, directly or through the PLL).
+ */
+#if !defined (HSI_VALUE)
+ #define HSI_VALUE ((uint32_t)16000000) /*!< Value of the Internal oscillator in Hz*/
+#endif /* HSI_VALUE */
+
+/**
+ * @brief External clock source for I2S peripheral
+ * This value is used by the I2S HAL module to compute the I2S clock source
+ * frequency, this source is inserted directly through I2S_CKIN pad.
+ */
+#if !defined (EXTERNAL_CLOCK_VALUE)
+ #define EXTERNAL_CLOCK_VALUE ((uint32_t)12288000) /*!< Value of the External audio frequency in Hz*/
+#endif /* EXTERNAL_CLOCK_VALUE */
+
+/* Tip: To avoid modifying this file each time you need to use different HSE,
+ === you can define the HSE value in your toolchain compiler preprocessor. */
+
+/* ########################### System Configuration ######################### */
+/**
+ * @brief This is the HAL system configuration section
+ */
+
+#define VDD_VALUE ((uint32_t)3300) /*!< Value of VDD in mv */
+#define USE_RTOS 0
+#define PREFETCH_ENABLE 1
+#define INSTRUCTION_CACHE_ENABLE 1
+#define DATA_CACHE_ENABLE 1
+
+/* ########################## Assert Selection ############################## */
+/**
+ * @brief Uncomment the line below to expanse the "assert_param" macro in the
+ * HAL drivers code
+ */
+/* #define USE_FULL_ASSERT 1 */
+
+/* ################## Ethernet peripheral configuration ##################### */
+
+/* Section 1 : Ethernet peripheral configuration */
+
+/* MAC ADDRESS: MAC_ADDR0:MAC_ADDR1:MAC_ADDR2:MAC_ADDR3:MAC_ADDR4:MAC_ADDR5 */
+#define MAC_ADDR0 2
+#define MAC_ADDR1 0
+#define MAC_ADDR2 0
+#define MAC_ADDR3 0
+#define MAC_ADDR4 0
+#define MAC_ADDR5 0
+
+/* Definition of the Ethernet driver buffers size and count */
+#define ETH_RX_BUF_SIZE ETH_MAX_PACKET_SIZE /* buffer size for receive */
+#define ETH_TX_BUF_SIZE ETH_MAX_PACKET_SIZE /* buffer size for transmit */
+#define ETH_RXBUFNB ((uint32_t)4) /* 4 Rx buffers of size ETH_RX_BUF_SIZE */
+#define ETH_TXBUFNB ((uint32_t)4) /* 4 Tx buffers of size ETH_TX_BUF_SIZE */
+
+/* Section 2: PHY configuration section */
+
+/* DP83848 PHY Address*/
+#define DP83848_PHY_ADDRESS 0x01
+/* PHY Reset delay these values are based on a 1 ms Systick interrupt*/
+#define PHY_RESET_DELAY ((uint32_t)0x000000FF)
+/* PHY Configuration delay */
+#define PHY_CONFIG_DELAY ((uint32_t)0x00000FFF)
+
+#define PHY_READ_TO ((uint32_t)0x0000FFFF)
+#define PHY_WRITE_TO ((uint32_t)0x0000FFFF)
+
+/* Section 3: Common PHY Registers */
+
+#define PHY_BCR ((uint16_t)0x00) /*!< Transceiver Basic Control Register */
+#define PHY_BSR ((uint16_t)0x01) /*!< Transceiver Basic Status Register */
+
+#define PHY_RESET ((uint16_t)0x8000) /*!< PHY Reset */
+#define PHY_LOOPBACK ((uint16_t)0x4000) /*!< Select loop-back mode */
+#define PHY_FULLDUPLEX_100M ((uint16_t)0x2100) /*!< Set the full-duplex mode at 100 Mb/s */
+#define PHY_HALFDUPLEX_100M ((uint16_t)0x2000) /*!< Set the half-duplex mode at 100 Mb/s */
+#define PHY_FULLDUPLEX_10M ((uint16_t)0x0100) /*!< Set the full-duplex mode at 10 Mb/s */
+#define PHY_HALFDUPLEX_10M ((uint16_t)0x0000) /*!< Set the half-duplex mode at 10 Mb/s */
+#define PHY_AUTONEGOTIATION ((uint16_t)0x1000) /*!< Enable auto-negotiation function */
+#define PHY_RESTART_AUTONEGOTIATION ((uint16_t)0x0200) /*!< Restart auto-negotiation function */
+#define PHY_POWERDOWN ((uint16_t)0x0800) /*!< Select the power down mode */
+#define PHY_ISOLATE ((uint16_t)0x0400) /*!< Isolate PHY from MII */
+
+#define PHY_AUTONEGO_COMPLETE ((uint16_t)0x0020) /*!< Auto-Negotiation process completed */
+#define PHY_LINKED_STATUS ((uint16_t)0x0004) /*!< Valid link established */
+#define PHY_JABBER_DETECTION ((uint16_t)0x0002) /*!< Jabber condition detected */
+
+/* Section 4: Extended PHY Registers */
+
+#define PHY_SR ((uint16_t)0x10) /*!< PHY status register Offset */
+#define PHY_MICR ((uint16_t)0x11) /*!< MII Interrupt Control Register */
+#define PHY_MISR ((uint16_t)0x12) /*!< MII Interrupt Status and Misc. Control Register */
+
+#define PHY_LINK_STATUS ((uint16_t)0x0001) /*!< PHY Link mask */
+#define PHY_SPEED_STATUS ((uint16_t)0x0002) /*!< PHY Speed mask */
+#define PHY_DUPLEX_STATUS ((uint16_t)0x0004) /*!< PHY Duplex mask */
+
+#define PHY_MICR_INT_EN ((uint16_t)0x0002) /*!< PHY Enable interrupts */
+#define PHY_MICR_INT_OE ((uint16_t)0x0001) /*!< PHY Enable output interrupt events */
+
+#define PHY_MISR_LINK_INT_EN ((uint16_t)0x0020) /*!< Enable Interrupt on change of link status */
+#define PHY_LINK_INTERRUPT ((uint16_t)0x2000) /*!< PHY link status interrupt mask */
+
+/* Includes ------------------------------------------------------------------*/
+/**
+ * @brief Include module's header file
+ */
+
+#ifdef HAL_RCC_MODULE_ENABLED
+ #include "stm32f4xx_hal_rcc.h"
+#endif /* HAL_RCC_MODULE_ENABLED */
+
+#ifdef HAL_GPIO_MODULE_ENABLED
+ #include "stm32f4xx_hal_gpio.h"
+#endif /* HAL_GPIO_MODULE_ENABLED */
+
+#ifdef HAL_DMA_MODULE_ENABLED
+ #include "stm32f4xx_hal_dma.h"
+#endif /* HAL_DMA_MODULE_ENABLED */
+
+#ifdef HAL_CORTEX_MODULE_ENABLED
+ #include "stm32f4xx_hal_cortex.h"
+#endif /* HAL_CORTEX_MODULE_ENABLED */
+
+#ifdef HAL_ADC_MODULE_ENABLED
+ #include "stm32f4xx_hal_adc.h"
+#endif /* HAL_ADC_MODULE_ENABLED */
+
+#ifdef HAL_CAN_MODULE_ENABLED
+ #include "stm32f4xx_hal_can.h"
+#endif /* HAL_CAN_MODULE_ENABLED */
+
+#ifdef HAL_CRC_MODULE_ENABLED
+ #include "stm32f4xx_hal_crc.h"
+#endif /* HAL_CRC_MODULE_ENABLED */
+
+#ifdef HAL_CRYP_MODULE_ENABLED
+ #include "stm32f4xx_hal_cryp.h"
+#endif /* HAL_CRYP_MODULE_ENABLED */
+
+#ifdef HAL_DMA2D_MODULE_ENABLED
+ #include "stm32f4xx_hal_dma2d.h"
+#endif /* HAL_DMA2D_MODULE_ENABLED */
+
+#ifdef HAL_DAC_MODULE_ENABLED
+ #include "stm32f4xx_hal_dac.h"
+#endif /* HAL_DAC_MODULE_ENABLED */
+
+#ifdef HAL_DCMI_MODULE_ENABLED
+ #include "stm32f4xx_hal_dcmi.h"
+#endif /* HAL_DCMI_MODULE_ENABLED */
+
+#ifdef HAL_ETH_MODULE_ENABLED
+ #include "stm32f4xx_hal_eth.h"
+#endif /* HAL_ETH_MODULE_ENABLED */
+
+#ifdef HAL_FLASH_MODULE_ENABLED
+ #include "stm32f4xx_hal_flash.h"
+#endif /* HAL_FLASH_MODULE_ENABLED */
+
+#ifdef HAL_SRAM_MODULE_ENABLED
+ #include "stm32f4xx_hal_sram.h"
+#endif /* HAL_SRAM_MODULE_ENABLED */
+
+#ifdef HAL_NOR_MODULE_ENABLED
+ #include "stm32f4xx_hal_nor.h"
+#endif /* HAL_NOR_MODULE_ENABLED */
+
+#ifdef HAL_NAND_MODULE_ENABLED
+ #include "stm32f4xx_hal_nand.h"
+#endif /* HAL_NAND_MODULE_ENABLED */
+
+#ifdef HAL_PCCARD_MODULE_ENABLED
+ #include "stm32f4xx_hal_pccard.h"
+#endif /* HAL_PCCARD_MODULE_ENABLED */
+
+#ifdef HAL_SDRAM_MODULE_ENABLED
+ #include "stm32f4xx_hal_sdram.h"
+#endif /* HAL_SDRAM_MODULE_ENABLED */
+
+#ifdef HAL_HASH_MODULE_ENABLED
+ #include "stm32f4xx_hal_hash.h"
+#endif /* HAL_HASH_MODULE_ENABLED */
+
+#ifdef HAL_I2C_MODULE_ENABLED
+ #include "stm32f4xx_hal_i2c.h"
+#endif /* HAL_I2C_MODULE_ENABLED */
+
+#ifdef HAL_I2S_MODULE_ENABLED
+ #include "stm32f4xx_hal_i2s.h"
+#endif /* HAL_I2S_MODULE_ENABLED */
+
+#ifdef HAL_IWDG_MODULE_ENABLED
+ #include "stm32f4xx_hal_iwdg.h"
+#endif /* HAL_IWDG_MODULE_ENABLED */
+
+#ifdef HAL_LTDC_MODULE_ENABLED
+ #include "stm32f4xx_hal_ltdc.h"
+#endif /* HAL_LTDC_MODULE_ENABLED */
+
+#ifdef HAL_PWR_MODULE_ENABLED
+ #include "stm32f4xx_hal_pwr.h"
+#endif /* HAL_PWR_MODULE_ENABLED */
+
+#ifdef HAL_RNG_MODULE_ENABLED
+ #include "stm32f4xx_hal_rng.h"
+#endif /* HAL_RNG_MODULE_ENABLED */
+
+#ifdef HAL_RTC_MODULE_ENABLED
+ #include "stm32f4xx_hal_rtc.h"
+#endif /* HAL_RTC_MODULE_ENABLED */
+
+#ifdef HAL_SAI_MODULE_ENABLED
+ #include "stm32f4xx_hal_sai.h"
+#endif /* HAL_SAI_MODULE_ENABLED */
+
+#ifdef HAL_SD_MODULE_ENABLED
+ #include "stm32f4xx_hal_sd.h"
+#endif /* HAL_SD_MODULE_ENABLED */
+
+#ifdef HAL_SPI_MODULE_ENABLED
+ #include "stm32f4xx_hal_spi.h"
+#endif /* HAL_SPI_MODULE_ENABLED */
+
+#ifdef HAL_TIM_MODULE_ENABLED
+ #include "stm32f4xx_hal_tim.h"
+#endif /* HAL_TIM_MODULE_ENABLED */
+
+#ifdef HAL_UART_MODULE_ENABLED
+ #include "stm32f4xx_hal_uart.h"
+#endif /* HAL_UART_MODULE_ENABLED */
+
+#ifdef HAL_USART_MODULE_ENABLED
+ #include "stm32f4xx_hal_usart.h"
+#endif /* HAL_USART_MODULE_ENABLED */
+
+#ifdef HAL_IRDA_MODULE_ENABLED
+ #include "stm32f4xx_hal_irda.h"
+#endif /* HAL_IRDA_MODULE_ENABLED */
+
+#ifdef HAL_SMARTCARD_MODULE_ENABLED
+ #include "stm32f4xx_hal_smartcard.h"
+#endif /* HAL_SMARTCARD_MODULE_ENABLED */
+
+#ifdef HAL_WWDG_MODULE_ENABLED
+ #include "stm32f4xx_hal_wwdg.h"
+#endif /* HAL_WWDG_MODULE_ENABLED */
+
+#ifdef HAL_PCD_MODULE_ENABLED
+ #include "stm32f4xx_hal_pcd.h"
+#endif /* HAL_PCD_MODULE_ENABLED */
+
+#ifdef HAL_HCD_MODULE_ENABLED
+ #include "stm32f4xx_hal_hcd.h"
+#endif /* HAL_HCD_MODULE_ENABLED */
+
+/* Exported macro ------------------------------------------------------------*/
+#ifdef USE_FULL_ASSERT
+/**
+ * @brief The assert_param macro is used for function's parameters check.
+ * @param expr: If expr is false, it calls assert_failed function
+ * which reports the name of the source file and the source
+ * line number of the call that failed.
+ * If expr is true, it returns no value.
+ * @retval None
+ */
+ #define assert_param(expr) ((expr) ? (void)0 : assert_failed((uint8_t *)__FILE__, __LINE__))
+/* Exported functions ------------------------------------------------------- */
+ void assert_failed(uint8_t* file, uint32_t line);
+#else
+ #define assert_param(expr) ((void)0)
+#endif /* USE_FULL_ASSERT */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __STM32F4xx_HAL_CONF_H */
+
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/stm32f4xx_hal_msp.cpp Fri Sep 02 13:24:16 2016 +0000
@@ -0,0 +1,123 @@
+/**
+ ******************************************************************************
+ * File Name : stm32f4xx_hal_msp.c
+ * Date : 22/06/2014 09:00:07
+ * Description : This file provides code for the MSP Initialization
+ * and de-Initialization codes.
+ ******************************************************************************
+ *
+ * COPYRIGHT(c) 2014 STMicroelectronics
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of STMicroelectronics nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ ******************************************************************************
+ */
+
+#include "synthesizer.h"
+extern DigitalOut myled;
+
+extern DMA_HandleTypeDef hdma_i2s2_ext_tx;
+
+void HAL_I2S_MspInit(I2S_HandleTypeDef* hi2s)
+{
+
+// GPIO_InitTypeDef GPIO_InitStruct;
+ if(hi2s->Instance==SPI2)
+ {
+ /* Peripheral clock enable */
+ __SPI2_CLK_ENABLE();
+
+ /**I2S2 GPIO Configuration
+ PC3 ------> I2S2_SD
+ PB10 ------> I2S2_CK
+ PB12 ------> I2S2_WS
+ PC6 ------> I2S2_MCK
+ */
+/*
+ GPIO_InitStruct.Pin = GPIO_PIN_3|GPIO_PIN_6;
+ GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
+ GPIO_InitStruct.Pull = GPIO_NOPULL;
+ GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
+ GPIO_InitStruct.Alternate = GPIO_AF5_SPI2;
+ HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
+
+ GPIO_InitStruct.Pin = GPIO_PIN_10|GPIO_PIN_12;
+ GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
+ GPIO_InitStruct.Pull = GPIO_NOPULL;
+ GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
+ GPIO_InitStruct.Alternate = GPIO_AF5_SPI2;
+ HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
+*/
+ /* Peripheral DMA init*/
+
+ hdma_i2s2_ext_tx.Instance = DMA1_Stream4;
+ hdma_i2s2_ext_tx.Init.Channel = DMA_CHANNEL_0;
+ hdma_i2s2_ext_tx.Init.Direction = DMA_MEMORY_TO_PERIPH;
+ hdma_i2s2_ext_tx.Init.PeriphInc = DMA_PINC_DISABLE;
+ hdma_i2s2_ext_tx.Init.MemInc = DMA_MINC_ENABLE;
+ hdma_i2s2_ext_tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD;
+ hdma_i2s2_ext_tx.Init.MemDataAlignment = DMA_MDATAALIGN_WORD;
+ hdma_i2s2_ext_tx.Init.Mode = DMA_NORMAL;
+ hdma_i2s2_ext_tx.Init.Priority = DMA_PRIORITY_LOW;
+ hdma_i2s2_ext_tx.Init.FIFOMode = DMA_FIFOMODE_ENABLE;
+ hdma_i2s2_ext_tx.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_FULL;
+ hdma_i2s2_ext_tx.Init.MemBurst = DMA_MBURST_SINGLE;
+ hdma_i2s2_ext_tx.Init.PeriphBurst = DMA_PBURST_SINGLE;
+ HAL_DMA_Init(&hdma_i2s2_ext_tx);
+
+ __HAL_LINKDMA(hi2s,hdmatx,hdma_i2s2_ext_tx);
+// myled =1;
+ }
+
+}
+
+void HAL_I2S_MspDeInit(I2S_HandleTypeDef* hi2s)
+{
+
+ if(hi2s->Instance==SPI2)
+ {
+ /* Peripheral clock disable */
+ __SPI2_CLK_DISABLE();
+
+ /**I2S2 GPIO Configuration
+ PC3 ------> I2S2_SD
+ PB10 ------> I2S2_CK
+ PB12 ------> I2S2_WS
+ PC6 ------> I2S2_MCK
+ */
+// HAL_GPIO_DeInit(GPIOC, GPIO_PIN_3|GPIO_PIN_6);
+
+// HAL_GPIO_DeInit(GPIOB, GPIO_PIN_10|GPIO_PIN_12);
+
+ /* Peripheral DMA DeInit*/
+ HAL_DMA_DeInit(hi2s->hdmatx);
+ }
+
+}
+
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
+
+
+
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/stm32f4xx_it.cpp Fri Sep 02 13:24:16 2016 +0000
@@ -0,0 +1,64 @@
+/**
+ ******************************************************************************
+ * @file stm32f4xx_it.c
+ * @date 22/06/2014 09:00:07
+ * @brief Interrupt Service Routines.
+ ******************************************************************************
+ *
+ * COPYRIGHT(c) 2014 STMicroelectronics
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of STMicroelectronics nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ ******************************************************************************
+ */
+
+#include "synthesizer.h"
+extern DigitalOut myled;
+extern DMA_HandleTypeDef hdma_i2s2_ext_tx;
+
+/******************************************************************************/
+/* Cortex-M4 Processor Interruption and Exception Handlers */
+/******************************************************************************/
+
+/**
+* @brief This function handles System tick timer.
+*/
+/*
+void SysTick_Handler(void)
+{
+ HAL_IncTick();
+ HAL_SYSTICK_IRQHandler();
+}
+*/
+
+/**
+* @brief This function handles DMA1 Stream4 global interrupt.
+*/
+void DMA1_Stream4_IRQHandler(void)
+{
+ HAL_NVIC_ClearPendingIRQ(DMA1_Stream4_IRQn);
+ HAL_DMA_IRQHandler(&hdma_i2s2_ext_tx);
+// myled = ~myled;
+}
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/stm32f4xx_it.h Fri Sep 02 13:24:16 2016 +0000
@@ -0,0 +1,58 @@
+/**
+ ******************************************************************************
+ * @file stm32f4xx_it.h
+ * @date 19/06/2014 09:00:07
+ * @brief This file contains the headers of the interrupt handlers.
+ ******************************************************************************
+ *
+ * COPYRIGHT(c) 2014 STMicroelectronics
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. Neither the name of STMicroelectronics nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ ******************************************************************************
+ */
+
+/* Define to prevent recursive inclusion -------------------------------------*/
+#ifndef __STM32F4xx_IT_H
+#define __STM32F4xx_IT_H
+
+#ifdef __cplusplus
+ extern "C" {
+#endif
+
+/* Includes ------------------------------------------------------------------*/
+/* Exported types ------------------------------------------------------------*/
+/* Exported constants --------------------------------------------------------*/
+/* Exported macro ------------------------------------------------------------*/
+/* Exported functions ------------------------------------------------------- */
+
+//void SysTick_Handler(void);
+void DMA1_Stream4_IRQHandler(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __STM32F4xx_IT_H */
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/synthesizer.h Fri Sep 02 13:24:16 2016 +0000
@@ -0,0 +1,277 @@
+#ifndef SYNTHESIZER_H
+#define SYNTHESIZER_H
+
+typedef signed long S32;
+typedef signed short S16;
+typedef signed char S8;
+typedef unsigned long U32;
+typedef unsigned short U16;
+typedef unsigned char U8;
+
+#include "mbed.h"
+#include "cmsis.h"
+#include "stm32f401xe.h"
+#include "stm32f4xx.h"
+#include "stm32f4xx_hal.h"
+#include "stm32f4xx_hal_dma_ex.h"
+#include "stm32f4xx_hal_dma.h"
+#include "stm32f4xx_hal_i2s.h"
+#include "stm32f4xx_hal_flash.h"
+#include "stm32f4xx_hal_conf.h"
+#include "stm32f4xx_it.h"
+
+#include "error.h"
+#include "pinmap.h"
+#include "PinNames.h"
+#include "gpio_irq_api.h"
+
+#include "LCD.h"
+
+#include "reverve_tap.h"
+#include "from_save.h"
+#include "lcd_sw.h"
+#include "releasetime_table.h"
+
+#include "lfo_table.h"
+#include "dcf_table.h"
+
+#define FWVERSION " Ver 2.1"
+
+#define DIST
+//#define REVERVE16BIT
+//#define DCF
+#define INTERPO2
+
+#define VOICEMAX 8
+#define PRGGENMAX 4
+//#define VOICEMAX 12
+//#define PRGGENMAX 2
+//#define GENMAX (PRGGENMAX*VOICEMAX)
+#define GENMAX 24
+
+#define I2S2 SPI2
+#define DMA_BUFFERSIZE 2048
+
+#define PARAM_BUFSIZE 256
+
+#define GEN_IDLE 0
+#define GEN_NOTEON 1
+#define GEN_NOTEOFF 2
+#define GEN_PORON 3
+#define GEN_POROFF 4
+
+/* for main Request*/
+//#define REQUEST_NONE 0
+//#define REQUEST_BUFFERFULL 1
+//#define REQUEST_PARAM 2
+//#define REQUEST_MIDI 4
+
+/* EG Function */
+#define EG_IDLE 0
+#define EG_ATTACK 1
+#define EG_DECAY 2
+#define EG_SUSTAIN 3
+#define EG_RELEASE 4
+#define EG_BEFOREATTACK 5
+
+extern S16 limit;
+
+typedef struct {
+ U8 sw;// 0,1
+ U8 wave_num;// 1 - 100
+ S8 notebias;// -128 - +127
+ U8 pan;// 0-31
+ S16 detune;// -512 - +511
+ U16 volume;// 0-65535
+
+ U16 attacktime;//
+ U16 decaytime;//
+ U8 sustainlevel;//
+ U16 releasetime;// 0-21
+
+ U8 lfo1type;
+ U8 lfo1speed;
+ U16 lfo1depth;
+ U16 lfo1delaytime;// 0-3000
+
+ U8 lfo2type;
+ U8 lfo2speed;
+ U16 lfo2depth;
+ U16 lfo2delaytime;// 0-3000
+}GENERATOR ;
+
+typedef struct {
+ U8 status;// BUFFULL,PARAM,MIDI
+ U8 eg_status;// IDLE,ATTCK,DECAY,SUSTAIN,RELEASE
+ U8 *startadr;
+ U8 *p1;
+ U8 *p2;
+ U8 *samplecountp1p2;
+ U8 *cycle;
+ U32 df;// 4e28f
+ S32 dpf;// 4e28f portament data 110812
+ U8 notenum;// 0-127
+ volatile U32 voltemp;// 32bit
+ volatile U32 voltemp1;// 32bit
+ volatile U32 voltemp2;// 32bit
+ volatile U32 voltempL;// 32bit
+ volatile U32 voltempR;// 32bit
+ U8 velocity;// 0-127
+ U32 x;// 指数部20ビット 小数部12ビット
+ U32 xx;// 指数部20ビット 小数部12ビット
+ S16 lfo1value;
+ U16 lfo1count;
+ U16 lfo1delaycount;// 3000-0
+ S16 lfo2value;
+ U16 lfo2count;
+ U16 lfo2delaycount;// 3000-0
+ U16 zerocount;
+}GENERATOR_TEMP ;
+
+typedef struct {
+ U8 name[16];
+ U32 p1;
+ U32 p2;
+ U32 cycle;
+}GEN4_CHUNK;
+
+typedef struct {
+ char menu[20];
+ void (*function)(void);
+ int min;
+ int max;
+}MenuListDef;
+
+
+typedef struct {
+ int enable;
+ S32 signal[6];// sample,x1,x2,y1,y2,result
+ S32 *dcf_param;// pointer of dcf_table(b0a0 ,b1a0,... a2,a0)
+ GENERATOR *gen;// gen1_adr,gen2_adr...gen4_adr
+ GENERATOR_TEMP *gen_temp;// gen1_adr,gen2_adr...gen4_adr
+}STR_VOICE;
+
+
+typedef struct{
+ char name[20];
+ uint32_t startaddr;// Wave data Start Address
+ uint32_t p1;// Loop Point1
+ uint32_t p2;// Loop Point2
+ uint32_t cycle;// Loop Cycle :if (cycle == 0) cycle = P2-p1 ;
+}WaveDef;
+
+typedef struct{
+ char name[20];
+ uint8_t dcf_freq;
+ uint8_t dcf_q;
+ uint8_t dcf_freqsence;
+ uint8_t dcf_qsence;
+}PresetVoiceDef;
+
+typedef enum
+{
+ DMA_Idle = 0,
+ DMA_HalfComplete,
+ DMA_FullComplete,
+}BUFFER_StateTypeDef;
+
+typedef enum
+{
+ KEY_WAIT_ON = 0,
+ KEY_AFTER_ON,
+ KEY_WAIT_OFF,
+ KEY_AFTER_OFF,
+ KEY_AUTO_PRESS,
+ KEY_AFTER_AUTO_PRESS,
+ KEY_GEN_WAVE1,
+ KEY_GEN_WAVE2,
+ KEY_FIRST_WAIT
+}KeyState_TypeDef;
+
+void MX_GPIO_Init(void);
+void uGen4_device_init(void);
+void init_dmabuffer(void);
+void i2s_dma_init(void);
+void uGen4_init(void);
+
+void lcd_print_title(void);
+void gen_function(int *);
+
+S32 satAdd32(S32 val1 ,S32 val2);
+S16 satAdd16(S16 val1 ,S16 val2);
+S16 dcf64(S32 *param ,S32 *signal);
+char *val2str4(int value);
+void presetvoice(void);
+void param(void);
+void midichannel(void);
+void mastertune(void);
+void dcfcontrol(void);
+void gen_sw (void);
+void gen_wave (void);
+void gen_notebias(void);
+void gen_outlevel(void);
+void gen_detune(void);
+void gen_attacktime(void);
+void gen_decaytime(void);
+void gen_sustainlevel(void);
+void gen_relesetime(void);
+void gen_lfo1_wavetype(void);
+void gen_lfo1_speed (void);
+void gen_lfo1_depth(void);
+void gen_lfo2_speed (void);
+void gen_lfo2_depth(void);
+void gen_lfo1_delaytime(void);
+void gen_lfo2_delaytime(void);
+void gen_limit(void);
+
+void Erase_Sector2(void);
+
+HAL_StatusTypeDef WriteBlockFrom(uint32_t *src_address ,uint32_t *dst_address,uint32_t length);
+
+int strcmp(U8 *a ,U8 *b);
+
+void init_voice(void);
+void init_sgen(void);
+void noteon(U8 notenum ,U8 velocity);
+void noteoff(U8 notenum ,U8 velocity);
+void pgmchg(U8 number);
+void change_endian16(U16 *data);
+void wave_generate(void);
+
+void gen_attack(GENERATOR *gena,GENERATOR_TEMP *gena_temp);
+void notenum2df(GENERATOR *gen ,GENERATOR_TEMP *gen_temp);
+void envelope_work(void);
+void midi_work(void);
+void param_work(void);
+void init_midi(void);
+void init_param(void);
+
+int get_wave_addr (WaveDef *wave);
+void load2from(void);
+
+void lcd_print(char *str);
+void lcd_print1(char *str);
+void lcd_print2(char *str);
+
+void anykeyon(U8 inkey);
+
+U8 gen_function_type_byte(GENERATOR *gena_value);
+
+void test_loop(void);
+void test_loop2(void);
+
+extern WaveDef Wave[];
+extern PresetVoiceDef PresetVoice[];
+extern GENERATOR sgen[];
+
+
+#endif
+
+
+
+
+
+
+
+
+