Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*****************************************************************/
- /* */
- /* CASIO fx-9860G SDK Library */
- /* */
- /* File name : [ProjectName].c */
- /* */
- /* Copyright (c) 2006 CASIO COMPUTER CO., LTD. */
- /* */
- /*****************************************************************/
- #include "fxlib.h"
- #include "serial.h"
- #include "MonochromeLib.h" // FICHIER DEFINISSANT LES FONCTIONS GRAPHIQUES
- #include "stdio.h"
- #include "stdlib.h"
- #include "string.h"
- #include "SH4comp.c"
- //#include "math.h"
- //****************************************************************************
- // AddIn_main (Sample program main function)
- //
- // param : isAppli : 1 = This application is launched by MAIN MENU.
- // : 0 = This application is launched by a strip in eACT application.
- //
- // OptionNum : Strip number (0~3)
- // (This parameter is only used when isAppli parameter is 0.)
- //
- // retval : 1 = No error / 0 = Error
- //
- //****************************************************************************
- // une fonction qui affiche la fequence=>son (faite) et autre qui fait note =>frequence (faite)
- // *(array+octave*12+demi_ton)
- //#define NB_DEMI_TON 12
- #define r 1.059463094
- char *notes[12]=
- {
- "do",
- "do#",
- "re",
- "re#",
- "mi",
- "fa",
- "fa#",
- "sol",
- "sol#",
- "la",
- "la#",
- "si"
- };
- float power(float x, int y)
- {
- float temp;
- if( y == 0)
- return 1;
- temp = power(x, y/2);
- if (y%2 == 0)
- return temp*temp;
- else
- {
- if(y > 0)
- return x*temp*temp;
- else
- return (temp*temp)/x;
- }
- }
- short note=9; //correspond au la 3
- short octave=3;
- double tempo=60.0;
- double calcul_frequence()
- {
- double frequence;
- //short nb_de_demi_ton=0;
- char buffer[50];
- unsigned int key;
- while(1)
- {
- Bdisp_AllClr_DDVRAM();
- sprintf(buffer,"note : %s",notes[note]);
- PrintMini(10,30,buffer,0);
- sprintf(buffer,"%d",octave);
- PrintMini(37+5*strlen(notes[note]),32,buffer,0);
- sprintf(buffer,"freq : %.2f",440*power(r,12*octave+note-45));
- PrintMini(10,20,buffer,0);
- sprintf(buffer,"tempo : %.0f",tempo);
- PrintMini(10,40,buffer,0);
- GetKey(&key);
- switch(key)
- {
- case KEY_CTRL_UP :
- {
- if (note<11)
- {
- note++;
- }
- else
- {
- note=0;
- octave=(octave<5 ? octave+1 : 0);
- }
- break;
- }
- case KEY_CTRL_DOWN :
- {
- if(note>0)
- {
- note--;
- }
- else
- {
- note=11;
- octave=(octave>0 ? octave-1 : 5);
- }
- break;
- }
- case KEY_CHAR_PLUS : tempo+=10; break;
- case KEY_CHAR_MINUS : tempo-=10; break;
- case KEY_CTRL_EXE : return 440*power(r,12*octave+note-45);
- }
- }
- }
- void play(double frequence , double length)
- {
- int i;
- double j;
- unsigned char config[] = {0, 5, 0, 0, 0, 0};
- Serial_Open(config);
- for(i=0;i<(int)(frequence*length);i++)
- {
- Serial_WriteByte(255);
- for (j=0;j<17.5;j+=0.211892619*frequence/440); // 0.211892619 => 2*((12)/square(2))
- }
- Serial_Close(1);
- }
- int AddIn_main(int isAppli, unsigned short OptionNum)
- {
- double length=1.0; // a 60 batt/minute
- double freq=440;
- while(1)
- {
- freq=calcul_frequence();
- play(freq, 60/tempo);
- }
- }
- //****************************************************************************
- //************** ****************
- //************** Notice! ****************
- //************** ****************
- //************** Please do not change the following source. ****************
- //************** ****************
- //****************************************************************************
- #pragma section _BR_Size
- unsigned long BR_Size;
- #pragma section
- #pragma section _TOP
- //****************************************************************************
- // InitializeSystem
- //
- // param : isAppli : 1 = Application / 0 = eActivity
- // OptionNum : Option Number (only eActivity)
- //
- // retval : 1 = No error / 0 = Error
- //
- //****************************************************************************
- int InitializeSystem(int isAppli, unsigned short OptionNum)
- {
- return INIT_ADDIN_APPLICATION(isAppli, OptionNum);
- }
- #pragma section
Advertisement
Add Comment
Please, Sign In to add comment