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.
main.cpp
00001 /*****************************************************/ 00002 /* MBED MULTI EFFECTOR */ 00003 /* */ 00004 /* */ 00005 /*****************************************************/ 00006 00007 #include "mbed.h" 00008 #include "EffectParam.h" 00009 #include "TextLCD.h" 00010 #include "R_Sw_Check.h" 00011 #include "Distotion_Unit.h" 00012 #include "Delay_Unit.h" 00013 00014 //Serial debug(USBTX, USBRX); // tx, rx 00015 00016 LocalFileSystem local("local"); 00017 Ticker sampling; 00018 00019 AnalogIn Ain(p17); // Audio Input 00020 AnalogOut Aout(p18); // Audio Output 00021 TextLCD lcd(p24, p25, p26, p27, p28, p29, p30); // rs, rw, e, d0, d1, d2, d3) 00022 DigitalIn Rsw0A(p5); // Rotary SW 0 00023 DigitalIn Rsw0B(p6); 00024 DigitalIn Rsw1A(p7); // Rotary SW 1 00025 DigitalIn Rsw1B(p8); 00026 DigitalIn Rsw2A(p9); // Rotary SW 2 00027 DigitalIn Rsw2B(p10); 00028 DigitalIn Rsw3A(p11); // Rotary SW 3 00029 DigitalIn Rsw3B(p12); 00030 DigitalOut busyFlag(p13); // Effect Proc Busy Flag 00031 00032 /*******************************/ 00033 /* For Test Signal */ 00034 /*******************************/ 00035 #define TEST_SIGNAL_ENABLE (0) // 1 : Internal SinWave for Debug 00036 #define TEST_SIGNAL_FREQ (1000.0) // Frequency [Hz] 00037 #define TEST_SIGNAL_AMP (30000.0) // Amplitude 00038 #define PAI (3.14159) 00039 00040 /*******************************/ 00041 /* For ADC & DAC Setting */ 00042 /*******************************/ 00043 #define SAMPLING_TIME (25.0) // ADC Sampling Rate [us] 00044 volatile unsigned int *g_usiAd0cr, *g_usiAd0dr2; // ADC Reg 00045 unsigned int *g_usiDacr; // DAC Reg 00046 00047 /*******************************/ 00048 /* Gloval Valinat */ 00049 /*******************************/ 00050 unsigned int g_usiFinalOut; // DAC Out Final Data 00051 int g_ssBuff[10]; // Audio Data Buff 00052 float g_fTestWaveT; // Test Sin Wave Phase 00053 int g_iBankNo = 0; // Parameter Patch Bank No 00054 int g_iProgNo = 0; // Parameter Patch Program No 00055 int g_iFlag = 0; // Pacth Write Flag 00056 int g_iProgPatch[BANK_MAX_NUM][PROGNO_MAX_NUM][PP_MAX_NUM]; // Parameter Data 00057 00058 00059 /*******************************/ 00060 /* Function */ 00061 /*******************************/ 00062 int main(void); 00063 void effectProcess(void); // Effect Process Function 00064 void paramCheck(int*, int*); // Paramter Range Check 00065 void param1Change(int*, int*, int*, int*); // Process for Changed Rotary SW1 00066 void param2Change(int*, int*, int*, int*); // Process for Changed Rotary SW2 00067 void param3Change(int*, int*, int*, int*); // Process for Changed Rotary SW3 00068 void param4Change(int*, int*, int*, int*); // Process for Changed Rotary SW4 00069 00070 void progWrite(int*); // 00071 void distParamChange(int*, int*); // Change Parameter for Ditotion 00072 void delayParamChange(int*, int*); // Change PArameter for Delay 00073 00074 void progPatchWite(int); // Paramter Write for Flash ROM 00075 void ProgramPatchChange(int, int); // 00076 00077 /*******************************/ 00078 /* Effect Process */ 00079 /*******************************/ 00080 void effectProcess() { 00081 busyFlag = 1; 00082 // Line Out 00083 *g_usiDacr = g_usiFinalOut; 00084 // ADC Start 00085 *g_usiAd0cr = 0x01200204; 00086 00087 #if (TEST_SIGNAL_ENABLE == 1) // Test Signal Sin Wave 00088 g_ssBuff[0] = TEST_SIGNAL_AMP * sin(g_fTestWaveT); 00089 g_fTestWaveT = g_fTestWaveT + 2.0 * PAI * SAMPLING_TIME * TEST_SIGNAL_FREQ / 1e6; 00090 if (g_fTestWaveT >= (2.0 * PAI))g_fTestWaveT = 0; 00091 #endif 00092 00093 // 00094 // Effect Func 00095 // 00096 00097 g_ssBuff[1] = distotion(g_ssBuff[0]); // Call Distotion Function 00098 g_ssBuff[2] = delay(g_ssBuff[1]); // CAll Delay Function 00099 00100 // 00101 // Effect Func 00102 // 00103 00104 #if (TEST_SIGNAL_ENABLE == 0) 00105 while (1) { 00106 if ((*g_usiAd0dr2 & 0x80000000) != 0)break; // ADC Done ? 00107 } 00108 g_ssBuff[0] = (int)(*g_usiAd0dr2 & 0x0000FFF0) - 32768; 00109 #endif 00110 00111 g_usiFinalOut = 0x00010000 | (g_ssBuff[2] + 32768); 00112 00113 busyFlag = 0; 00114 } 00115 00116 00117 00118 00119 /*******************************/ 00120 /* MAIN */ 00121 /*******************************/ 00122 int main() { 00123 00124 int i ,j ,k; 00125 int iTemp1, iTemp2; 00126 int iParamSwPol[4]; 00127 int iRsw1Num, iRsw2Num, iRsw3Num, iRsw4Num; 00128 char str1[256], str2[256]; 00129 00130 iRsw1Num = iRsw2Num = iRsw3Num = iRsw4Num = 0; 00131 00132 // LCD INIT 00133 lcd.cls(); 00134 lcd.locate(0,0); 00135 lcd.printf("Multi Effector"); 00136 lcd.locate(1,1); 00137 lcd.printf("Mode:"); 00138 param1Change(&iRsw1Num, &iRsw2Num, &iRsw3Num, &iRsw4Num); 00139 00140 // Program Patch File Open 00141 FILE *fp = fopen("/local/prm.txt", "r"); 00142 if(!fp) { 00143 progPatchWite(1); // No File 00144 }else{ 00145 // Read Patch from File 00146 fgets(str1, 256, fp); 00147 fgets(str2, 256, fp); 00148 for(i=0;i<BANK_MAX_NUM;i++){ 00149 for(j=0;j<PROGNO_MAX_NUM;j++){ 00150 fscanf(fp, "%5d%5d", &iTemp1, &iTemp2); 00151 for(k=0;k<PP_MAX_NUM;k++){ 00152 fscanf(fp, "%5d", &g_iProgPatch[i][j][k]); 00153 } 00154 } 00155 } 00156 fclose(fp); 00157 } 00158 00159 // ADC & DAC SETTING 00160 g_usiAd0cr = (unsigned int*)0x40034000; 00161 g_usiAd0dr2 = (unsigned int*)0x40034018; 00162 g_usiDacr = (unsigned int*)0x4008C000; 00163 00164 // SAMPLING TIMER START 00165 sampling.attach_us(&effectProcess, SAMPLING_TIME); 00166 00167 // Rotary SW State Check 00168 while (1) { 00169 switch (ucRotarySwPol(Rsw0A, Rsw0B, Rsw1A, Rsw1B, Rsw2A, Rsw2B, Rsw3A, Rsw3B, iParamSwPol)) { 00170 case 0: 00171 iRsw1Num += iParamSwPol[0]; 00172 param1Change(&iRsw1Num, &iRsw2Num, &iRsw3Num, &iRsw4Num); 00173 break; 00174 case 1: 00175 iRsw2Num += iParamSwPol[1]; 00176 param2Change(&iRsw1Num, &iRsw2Num, &iRsw3Num, &iRsw4Num); 00177 break; 00178 case 2: 00179 iRsw3Num += iParamSwPol[2]; 00180 param3Change(&iRsw1Num, &iRsw2Num, &iRsw3Num, &iRsw4Num); 00181 break; 00182 case 3: 00183 iRsw4Num += iParamSwPol[3]; 00184 param4Change(&iRsw1Num, &iRsw2Num, &iRsw3Num, &iRsw4Num); 00185 break; 00186 default: 00187 break; 00188 } 00189 } 00190 } 00191 00192 00193 /*******************************/ 00194 /* Param Check */ 00195 /*******************************/ 00196 void paramCheck(int* iParam, int iMaxValue) { 00197 00198 if(*iParam >= iMaxValue)*iParam = 0; 00199 if(*iParam < 0)*iParam = iMaxValue - 1; 00200 00201 } 00202 00203 00204 /*******************************/ 00205 /* Param1 Change */ 00206 /*******************************/ 00207 void param1Change(int* iParam1, int* iParam2, int* iParam3, int* iParam4) { 00208 00209 paramCheck(iParam1, MODE_MAX_NUM); 00210 00211 lcd.locate(6,1); 00212 lcd.printf(" "); 00213 lcd.locate(0,2); 00214 lcd.printf(" "); 00215 lcd.locate(0,3); 00216 lcd.printf(" "); 00217 00218 switch (*iParam1) { 00219 case MODE_PLAY: 00220 lcd.locate(6,1); 00221 lcd.printf("PLAY"); 00222 lcd.locate(2,2); 00223 lcd.printf(" Bank PrgNo"); 00224 *iParam2 = g_iBankNo; 00225 *iParam3 = g_iProgNo; 00226 break; 00227 case MODE_EDIT: 00228 lcd.locate(6,1); 00229 lcd.printf("EDIT"); 00230 lcd.locate(2,2); 00231 lcd.printf("Effct Param Value"); 00232 *iParam2 = *iParam3 = 0; 00233 break; 00234 case MODE_PROGWRITE: 00235 lcd.locate(6,1); 00236 lcd.printf("Prog Write"); 00237 lcd.locate(2,2); 00238 lcd.printf(" Bank PrgNo Write"); 00239 *iParam2 = g_iBankNo; 00240 *iParam3 = g_iProgNo; 00241 break; 00242 default: 00243 break; 00244 } 00245 00246 param2Change(iParam1, iParam2, iParam3, iParam4); 00247 00248 } 00249 00250 00251 /*******************************/ 00252 /* Param2 Change */ 00253 /*******************************/ 00254 void param2Change(int* iParam1, int* iParam2, int* iParam3, int* iParam4) { 00255 00256 lcd.locate(0,3); 00257 lcd.printf(" "); 00258 00259 switch (*iParam1) { 00260 case MODE_PLAY: 00261 paramCheck(iParam2, BANK_MAX_NUM); 00262 g_iBankNo = *iParam2; 00263 *iParam3 = g_iProgNo; 00264 break; 00265 case MODE_EDIT: 00266 paramCheck(iParam2, EFFECT_MAX_NUM); 00267 *iParam3 = 0; 00268 break; 00269 case MODE_PROGWRITE: 00270 paramCheck(iParam2, BANK_MAX_NUM); 00271 g_iBankNo = *iParam2; 00272 *iParam3 = g_iProgNo; 00273 *iParam4 = 0; 00274 g_iFlag = 0; 00275 default: 00276 break; 00277 } 00278 00279 if ((*iParam1 == MODE_PLAY) || (*iParam1 == MODE_PROGWRITE)) { 00280 lcd.locate(6,3); 00281 lcd.printf("%d",*iParam2); 00282 } 00283 00284 if (*iParam1 == MODE_EDIT) { 00285 switch (*iParam2) { 00286 case EFFECT_DIST: 00287 lcd.locate(2,3); 00288 lcd.printf(" DIST"); 00289 break; 00290 case EFFECT_DELAY: 00291 lcd.locate(2,3); 00292 lcd.printf("DELAY"); 00293 break; 00294 default: 00295 break; 00296 } 00297 } 00298 00299 param3Change(iParam1, iParam2, iParam3, iParam4); 00300 00301 } 00302 00303 00304 /*******************************/ 00305 /* Param3 Change */ 00306 /*******************************/ 00307 void param3Change(int* iParam1, int* iParam2, int* iParam3, int* iParam4) { 00308 00309 lcd.locate(8,3); 00310 lcd.printf(" "); 00311 00312 switch (*iParam1) { 00313 case MODE_PLAY: 00314 paramCheck(iParam3, PROGNO_MAX_NUM); 00315 g_iProgNo = *iParam3; 00316 break; 00317 case MODE_EDIT: 00318 switch (*iParam2) { 00319 case EFFECT_DIST: 00320 paramCheck(iParam3, DIST_PARAM_MAX_NUM); 00321 switch (*iParam3) { 00322 case DIST_PARAM_BYPASS: *iParam4 = g_iProgPatch[g_iBankNo][g_iProgNo][PP_DIST_PARAM_BYPASS]; 00323 break; 00324 case DIST_PARAM_MODE: *iParam4 = g_iProgPatch[g_iBankNo][g_iProgNo][PP_DIST_PARAM_MODE]; 00325 break; 00326 case DIST_PARAM_INPUTGAIN: *iParam4 = g_iProgPatch[g_iBankNo][g_iProgNo][PP_DIST_PARAM_INPUTGAIN]; 00327 break; 00328 case DIST_PARAM_CLIPLEVEL: *iParam4 = g_iProgPatch[g_iBankNo][g_iProgNo][PP_DIST_PARAM_CLIPLEVEL]; 00329 break; 00330 case DIST_PARAM_OUTPUTGAIN: *iParam4 = g_iProgPatch[g_iBankNo][g_iProgNo][PP_DIST_PARAM_OUTPUTGAIN]; 00331 break; 00332 default: break; 00333 } 00334 distParamChange(iParam3, iParam4); 00335 break; 00336 case EFFECT_DELAY: 00337 paramCheck(iParam3, DLY_PARAM_MAX_NUM); 00338 switch (*iParam3) { 00339 case DLY_PARAM_BYPASS: *iParam4 = g_iProgPatch[g_iBankNo][g_iProgNo][PP_DLY_PARAM_BYPASS]; 00340 break; 00341 case DLY_PARAM_DELAYTIME: *iParam4 = g_iProgPatch[g_iBankNo][g_iProgNo][PP_DLY_PARAM_DELAYTIME]; 00342 break; 00343 case DLY_PARAM_FBGAIN: *iParam4 = g_iProgPatch[g_iBankNo][g_iProgNo][PP_DLY_PARAM_FBGAIN]; 00344 break; 00345 default: break; 00346 } 00347 delayParamChange(iParam3, iParam4); 00348 break; 00349 default: 00350 break; 00351 } 00352 break; 00353 case MODE_PROGWRITE: 00354 paramCheck(iParam3, PROGNO_MAX_NUM); 00355 g_iProgNo = *iParam3; 00356 *iParam4 = 0; 00357 g_iFlag = 0; 00358 progWrite(iParam4); 00359 break; 00360 default: 00361 break; 00362 } 00363 00364 if ((*iParam1 == MODE_PLAY) || (*iParam1 == MODE_PROGWRITE)) { 00365 lcd.locate(12,3); 00366 lcd.printf("%d",*iParam3); 00367 } 00368 00369 } 00370 00371 00372 /*******************************/ 00373 /* Param4 Change */ 00374 /*******************************/ 00375 void param4Change(int* iParam1, int* iParam2, int* iParam3, int* iParam4) { 00376 00377 lcd.locate(14,3); 00378 lcd.printf(" "); 00379 00380 switch (*iParam1) { 00381 case MODE_EDIT: 00382 switch (*iParam2) { 00383 case EFFECT_DIST: 00384 distParamChange(iParam3, iParam4); 00385 break; 00386 case EFFECT_DELAY: 00387 delayParamChange(iParam3, iParam4); 00388 break; 00389 default: 00390 break; 00391 } 00392 break; 00393 case MODE_PROGWRITE: 00394 progWrite(iParam4); 00395 break; 00396 default: 00397 break; 00398 } 00399 00400 } 00401 00402 00403 /*******************************/ 00404 /* Distotion Param Change */ 00405 /*******************************/ 00406 void distParamChange(int* iParam3, int* iParam4) { 00407 00408 lcd.locate(8,3); 00409 lcd.printf(" "); 00410 lcd.locate(8,3); 00411 00412 switch (*iParam3) { 00413 case DIST_PARAM_BYPASS: 00414 paramCheck(iParam4, DIST_VALUE_BYPASS_MAX); 00415 g_iDistBypass = *iParam4; 00416 //g_iProgPatch[g_iBankNo][g_iProgNo][PP_DIST_PARAM_BYPASS] = *iParam4; 00417 if(g_iDistBypass == 0){ 00418 lcd.printf("BYPSS OFF"); 00419 }else{ 00420 lcd.printf("BYPSS ON"); 00421 } 00422 break; 00423 case DIST_PARAM_MODE: 00424 paramCheck(iParam4, DIST_VALUE_MODE_MAX); 00425 g_iDistMode = *iParam4; 00426 //g_iProgPatch[g_iBankNo][g_iProgNo][PP_DIST_PARAM_MODE] = *iParam4; 00427 lcd.printf(" MODE %d", *iParam4); 00428 break; 00429 case DIST_PARAM_INPUTGAIN: 00430 paramCheck(iParam4, DIST_VALUE_INPUTGAIN_MAX); 00431 g_iDistInputGain = *iParam4; 00432 //g_iProgPatch[g_iBankNo][g_iProgNo][PP_DIST_PARAM_INPUTGAIN] = *iParam4; 00433 lcd.printf("INP.G %d", *iParam4); 00434 break; 00435 case DIST_PARAM_CLIPLEVEL: 00436 paramCheck(iParam4, DIST_VALUE_CLIPLEVEL_MAX); 00437 g_iDistClipLevel = *iParam4; 00438 //g_iProgPatch[g_iBankNo][g_iProgNo][PP_DIST_PARAM_CLIPLEVEL] = *iParam4; 00439 lcd.printf("CLP.L %d", *iParam4); 00440 break; 00441 case DIST_PARAM_OUTPUTGAIN: 00442 paramCheck(iParam4, DIST_VALUE_OUTPUTGAIN_MAX); 00443 g_iDistOutputGain = *iParam4; 00444 //g_iProgPatch[g_iBankNo][g_iProgNo][PP_DIST_PARAM_OUTPUTGAIN] = *iParam4; 00445 lcd.printf("OUT.G %d", *iParam4); 00446 break; 00447 default: 00448 break; 00449 00450 } 00451 } 00452 00453 /*******************************/ 00454 /* Delay Param Change */ 00455 /*******************************/ 00456 void delayParamChange(int* iParam3, int* iParam4) { 00457 00458 lcd.locate(8,3); 00459 lcd.printf(" "); 00460 lcd.locate(8,3); 00461 00462 switch (*iParam3) { 00463 case DLY_PARAM_BYPASS: 00464 paramCheck(iParam4, DLY_VALUE_BYPASS_MAX); 00465 g_iDelayBypass = *iParam4; 00466 //g_iProgPatch[g_iBankNo][g_iProgNo][PP_DLY_PARAM_BYPASS] = *iParam4; 00467 if(g_iDelayBypass == 0){ 00468 lcd.printf("BYPSS OFF"); 00469 }else{ 00470 lcd.printf("BYPSS ON"); 00471 } 00472 break; 00473 case DLY_PARAM_DELAYTIME: 00474 paramCheck(iParam4, DLY_VALUE_DELAYTIME_MAX); 00475 g_iDelayTime = *iParam4; 00476 //g_iProgPatch[g_iBankNo][g_iProgNo][PP_DLY_PARAM_DELAYTIME] = *iParam4; 00477 lcd.printf("DLY.T %d", *iParam4); 00478 break; 00479 case DLY_PARAM_FBGAIN: 00480 paramCheck(iParam4, DLY_VALUE_FBGAIN_MAX); 00481 g_iDelayFeedBackLevel = *iParam4; 00482 //g_iProgPatch[g_iBankNo][g_iProgNo][PP_DLY_PARAM_FBGAIN] = *iParam4; 00483 lcd.printf(" FB.G %d", *iParam4); 00484 break; 00485 default: 00486 break; 00487 00488 } 00489 } 00490 00491 /*******************************/ 00492 /* Program Patch Write */ 00493 /*******************************/ 00494 void progWrite(int* param){ 00495 00496 if(g_iFlag == 0){ 00497 if((*param > 24) || (*param < -24)){ 00498 lcd.locate(14,3); 00499 lcd.printf(" Done"); 00500 ProgramPatchChange(g_iBankNo, g_iProgNo); 00501 progPatchWite(0); 00502 g_iFlag = 1; 00503 }else{ 00504 lcd.locate(14,3); 00505 lcd.printf("Unexe"); 00506 } 00507 }else{ 00508 lcd.locate(14,3); 00509 lcd.printf(" Done"); 00510 } 00511 } 00512 00513 00514 /*******************************/ 00515 /* Program Patch Wite */ 00516 /*******************************/ 00517 void progPatchWite(int iFlag){ 00518 00519 int i, j, k; 00520 00521 FILE *fp = fopen("/local/prm.txt", "w"); 00522 if(!fp) { 00523 while(1){ 00524 lcd.cls(); 00525 wait(0.5); 00526 lcd.locate(1,1); 00527 lcd.printf("SYSTEM ERROR #2000"); 00528 wait(0.5); 00529 } 00530 } 00531 00532 fprintf(fp, " BANK PROG ---- DISTOTION --- ----- DELAY ------\n"); 00533 fprintf(fp, " BYP MODE ING C.Lv OUTG BYP TIME FB\n"); 00534 for(i=0;i<BANK_MAX_NUM;i++){ 00535 for(j=0;j<PROGNO_MAX_NUM;j++){ 00536 if(iFlag == 1)ProgramPatchChange(i, j); 00537 fprintf(fp, "%5d%5d", i, j); 00538 for(k=0;k<PP_MAX_NUM;k++){ 00539 fprintf(fp, "%5d\0", g_iProgPatch[i][j][k]); 00540 } 00541 fprintf(fp, "\n"); 00542 } 00543 } 00544 00545 fclose(fp); 00546 } 00547 00548 00549 /*******************************/ 00550 /* Program Patch Chanege */ 00551 /*******************************/ 00552 void ProgramPatchChange(int iBank, int iProg){ 00553 00554 // Distotion Param 00555 g_iProgPatch[iBank][iProg][PP_DIST_PARAM_BYPASS] = g_iDistBypass; 00556 g_iProgPatch[iBank][iProg][PP_DIST_PARAM_MODE] = g_iDistMode; 00557 g_iProgPatch[iBank][iProg][PP_DIST_PARAM_INPUTGAIN] = g_iDistInputGain; 00558 g_iProgPatch[iBank][iProg][PP_DIST_PARAM_CLIPLEVEL] = g_iDistClipLevel; 00559 g_iProgPatch[iBank][iProg][PP_DIST_PARAM_OUTPUTGAIN] = g_iDistOutputGain; 00560 00561 // Delay Param 00562 g_iProgPatch[iBank][iProg][PP_DLY_PARAM_BYPASS] = g_iDelayBypass; 00563 g_iProgPatch[iBank][iProg][PP_DLY_PARAM_DELAYTIME] = g_iDelayTime; 00564 g_iProgPatch[iBank][iProg][PP_DLY_PARAM_FBGAIN] = g_iDelayFeedBackLevel; 00565 00566 }
Generated on Sat Jul 16 2022 21:12:01 by
