#include "myWin.h" //*以下3行は再生用 #include "windows.h" //*再生用宣言 #include "MMSystem.h" //*再生用宣言 #pragma comment(lib,"winmm.lib")//*再生用宣言 #include "stdio.h" #include "stdlib.h" #include "math.h" #include "string.h" #define swap(type, X,Y) do{type T; T=X; X=Y; Y=T;}while(0) #define LB_1 1001 #define LB_2 1002 #define LB_3 1003 #define ED_FRQ 2000 #define ED_COF 2100 #define ED_DLY 2201 #define ED_POW 2202 #define ED_FR1 2203 #define ED_FR2 2204 #define BT_GEN 3001 #define BT_PLY 3002 #define BT_NO1 3003 #define BT_NO2 3004 #define PI 3.14159265358979 #define LS_1 4001 #define NUMFRQ 5 int size; char *buf; static HWND edFrq[NUMFRQ], edCof[NUMFRQ], edDelay, edPow, edFr1, edFr2; static HWND btGen, btPlay,btNoise1, btNoise2, label,list; static double freq[NUMFRQ], coff[NUMFRQ],sumCoff; // 44100Hz, 8bit, 1ch のWAVデータ #define SAMPLFRQ 44100 #define BIT 8 void intToByte(char BT[], int DT){//32ビット整数格納 BT[0] = DT & 0xff; BT[1] = DT >> 8 & 0xff; BT[2] = DT >> 16 & 0xff; BT[3] = DT >> 24 & 0xff; } void shortToByte(char BT[], int DT){//16整数ビット格納 BT[0] = DT & 0xff; BT[1] = DT >> 8 & 0xff; } int wav_write(const char *filename, char *buf, int size){ int filesize = 44 + size; char *tmp; tmp = (char *) malloc(filesize);//領域確保 if(tmp==NULL) return 1; //■出力データ設定------------------------------------------------------------------------- memcpy(tmp, "RIFF", 4); // ■RIFFヘッダ intToByte(tmp+4,filesize - 8); // これ以降のファイルサイズ (ファイルサイズ - 8) memcpy(tmp+8, "WAVE", 4); // ■WAVEヘッダ memcpy(tmp+12, "fmt ", 4); // ■fmtチャンク intToByte(tmp+16,16 ); // バイト数 fmt チャンクのバイト数(リニアPCM のとき 16(10 00 00 00)) shortToByte(tmp+20, 1); // フォーマットID (リニアPCM のとき 1(01 00)) shortToByte(tmp+22, 1); // チャンネル数 モノラル のとき 1(01 00) intToByte(tmp+24,SAMPLFRQ ); // サンプリングレート intToByte(tmp+28,SAMPLFRQ * (BIT/8)); // データ速度 (Byte/sec) shortToByte(tmp+32, BIT / 8); // ブロックサイズ shortToByte(tmp+34, BIT); // サンプルあたりのビット数 memcpy(tmp+36, "data", 4); // ■data チャンク intToByte(tmp+40,size); // バイト数 memcpy(tmp + 44, buf, size); // 音声複写 //■ファイル出力---------------------------------------------------------------------------- FILE *fp = fopen(filename, "wb"); if (fp == NULL) return 2; fwrite(tmp, filesize, 1, fp); // ファイルへの出力 fclose(fp); // ファイルクローズ free(tmp); // 領域返却 return 0; } void createLabel(HWND *label,HWND hw, TCHAR name[],int X, int Y, int W,int H, int No){ *label=CreateWindow(TEXT("STATIC"),name, WS_CHILD|WS_VISIBLE|SS_LEFT, X,Y, W, H,hw,(HMENU)No,hInstance,NULL); } void createEdit(HWND *edit,HWND hw, TCHAR name[],int X, int Y, int W,int H, int No){ *edit=CreateWindow(TEXT("EDIT"),name, WS_CHILD|WS_VISIBLE|WS_BORDER|ES_RIGHT, X,Y, W, H,hw,(HMENU)No,hInstance,NULL); } void createList(HWND *list,HWND hw, int X, int Y, int W,int H, int No){ *list=CreateWindow(TEXT("LISTBOX"),NULL, WS_CHILD|WS_VISIBLE|WS_BORDER, X,Y, W, H,hw,(HMENU)No,hInstance,NULL); } void createButton(HWND *edit,HWND hw, TCHAR name[],int X, int Y, int W,int H, int No){ *edit=CreateWindow(TEXT("BUTTON"),name, WS_CHILD|WS_VISIBLE|WS_BORDER|BS_PUSHBUTTON, X,Y, W, H,hw,(HMENU)No,hInstance,NULL); } int bufSize(int sec){return (SAMPLFRQ*(BIT/8)) * sec;} void procCreate(HWND hw, WPARAM wp,LPARAM lp){ int X0=20; TCHAR *frStr[]={TEXT("500"),TEXT("625"),TEXT("750"),TEXT("1000"),TEXT("1500")}; TCHAR *lstStr[]={TEXT("Linear"), TEXT("Exp(X)"), TEXT("Exp(-X)*X^S")}; createLabel(&label,hw,TEXT("周波数"), X0, 5, 50,30, LB_1); createLabel(&label,hw,TEXT("構成比"), X0, 35,50,30, LB_2); createLabel(&label,hw,TEXT("減衰率"), X0, 65,50,30, LB_2); createLabel(&label,hw,TEXT("べき乗"), X0, 95,50,30, LB_2); createLabel(&label,hw,TEXT("エンベローブパターン"), X0, 125,200,30, LB_2); createLabel(&label,hw,TEXT("周波数1"), X0+215, 125,200,30, LB_2); createLabel(&label,hw,TEXT("周波数2"), X0+215, 155,200,30, LB_2); int X=X0+60; for(int i=0;i0) B =exp(1.0)-0.5; E=getEdit(edDelay); X=(double)E/SAMPLFRQ; sumCoff=getFreqCof(freq, coff); for(int i=0; iFED) swap(double,FST,FED); int jst=(int)((double)SAMPLFRQ/(FED));if(jst<1)jst=1; int jed=(int)((double)SAMPLFRQ/(FST));if(jed>SAMPLFRQ)jed=SAMPLFRQ; double w, X=(double)1/SAMPLFRQ; double JD=(double)(jed-jst); for(int i=0; iFED) swap(double,FST,FED); int jst=(int)((double)SAMPLFRQ/(FED));if(jst<1)jst=1; int jed=(int)((double)SAMPLFRQ/(FST));if(jed>SAMPLFRQ)jed=SAMPLFRQ; double B=1, S=getEdit(edPow); if(S>0) B =exp(1.0)-0.5; double E=getEdit(edDelay); double X=(double)E/SAMPLFRQ; sumCoff=getFreqCof(freq, coff); double JD=(double)(jed-jst); for(int i=0; iFED) swap(double,FST,FED); int jst=(int)((double)SAMPLFRQ/(FED));if(jst<1)jst=1; int jed=(int)((double)SAMPLFRQ/(FST));if(jed>SAMPLFRQ)jed=SAMPLFRQ; double E=getEdit(edDelay); double X=(double)E/SAMPLFRQ; sumCoff=getFreqCof(freq, coff); double JD=(double)(jed-jst); for(int i=0; i