#include <stdio.h> 
#include <windows.h>
#include <math.h>
#include <malloc.h>
#include "resource.h"
#include "virtualphone.h" 
#include <limits.h> 
#include <time.h>
#include <string.h>
#include "filename.h"
#include "Hrtf_nCycle.h"
#include "wav.h"				

#include <windowsx.h>
#include <commctrl.h>
#include <winnetwk.h>
#include <string.h>
#include <Shlobj.h>

#include <stdlib.h>	

 	long aifp = 0;		// adc読込値の積分reg
	long zifp = 0;		// adc読込値の初期値

char portName[5];

LPITEMIDLIST GetItemIDList( char *p_cFileStr );

//信号処理に使用する構造体の宣言
informationRMS infoRMS = {
	0.6,
	0.4,
	0.4,
	0.6,
	300.0,
	2000.0,
	12000.0,
	500.0,
	0.04110815261,
	0.00000000000,
	-0.04110815261,
	1.61615999868,
	-0.91778369477,
	0.93354168925,
	-1.22853475641,
	0.93354168925,
	1.22853475641,
	-0.86708337850,
	0.93354169092,
	0.39047966174,
	0.93354169092,
	-0.39047966174,
	-0.86708338184,
	1
};

/////////////////////////////////////////////////////////////////////
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
                    PSTR szCmdLine, int iCmdShow)

{
	g_hInstance = hInstance;

    if (-1 == DialogBox (hInstance, szAppName, NULL, DlgProc))
    {
        MessageBox (NULL, TEXT ("This program requires Windows NT!"),
                      szAppName, MB_ICONERROR) ;
    }
   
    return 0 ;
}

////////////////////////////////////////////////////////////////////////////////
VOID FillBuffer (short * pBuffer, int nExclude ) 
{
	int i, j;
	short *dummy = new short[ OUT_BUFFER_SIZE ];
		
	//ファイル読み込み
	fid  = freadPcmFile( fid, OUT_BUFFER_SIZE, dummy, nExclude );

	//現在のファイルの位置取得 
	lFileNowPos = ftell( fid );

	//音像処理時
	if( f_remaster_on ){
		for( i=0; i<FLENdev; i++){
			//L,R信号のインターリーブ形式からL,R信号を分離
			short *dummyLR		= new short[ FLEN * 2 ];
			short *dummyLRout	= new short[ FLEN * 2 ];

			for ( j=0; j<FLEN; j++){
				// buffer copy
				dummyLR[ 2 * j ] = dummy [ 2 * j + i * FLEN * 2];
				dummyLR[ 2*j+1 ] = dummy [ 2*j+1 + i * FLEN * 2];
			}

			//Rms処理////////////////////////////////////////////////////////////////////////////////////////
			Rms_nCycle_cal( dummyLR, dummyLRout, FLEN, &infoRMS);
			/////////////////////////////////////////////////////////////////////////////////////////////////

			//出力
			for ( j=0; j<FLEN; j++ ){
				pBuffer[ 2 * j     + i * FLEN * 2 ] = dummyLRout[ 2 * j ];
				pBuffer[ 2 * j + 1 + i * FLEN * 2 ] = dummyLRout[ 2*j+1 ];
			}

			delete [] dummyLR;
			delete [] dummyLRout;
		}
	// throughの時の処理
	}else {
	
		for( i=0; i<FLENdev; i++){
			//出力
			for ( j=0; j<FLEN; j++ ){		
				pBuffer[ 2 * j     + i * FLEN * 2 ] = (short)( g_ThroughGain * dummy[ 2 * j + i * FLEN * 2 ] );
				pBuffer[ 2 * j + 1 + i * FLEN * 2 ] = (short)( g_ThroughGain * dummy[ 2*j+1 + i * FLEN * 2 ] );
			}
		}
	}

	delete [] dummy;
}

///////////////////////////////////////////////////////////////////////////////////
BOOL CALLBACK DlgProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
     static BOOL         bShutOff, bClosing ;
     static HWAVEOUT     hWaveOut ;
	 static HWAVEIN      hWaveIn ;
     static int          iFreq;
	 static short        *pBuffer1, *pBuffer2 ;
	 static PWAVEHDR     pWaveHdr1, pWaveHdr2 ;
	 static PWAVEHDR     pWaveHdri1, pWaveHdri2 ; 
     static WAVEFORMATEX waveformat ;
     static OPENFILENAME ofn; 
     static unsigned short nChannel = 2; 
	 static char channel, bps;
	 static unsigned short bpss = 16;
     static unsigned char fs[5], size[5];
     static int fs1, fs2;
	 static char buffer[5];
	 static char cPassName[PATHLEN];
	 char cPassTempName[PATHLEN];
	 int allLen ;
	 int divLen ;
	 int objectlen ;
  	 DWORD dwLen;
	 char filename1[255];		// file読み込み
	 int flag;					// file読み込み
	 static char cTemp[ 256];
	 static char name1[ 256 ];
	 static char name2[ 256 ];
	 static char name3[ 256 ];
	 static char name4[ 256 ];
	 static char name5[ 256 ];
	 static char cCoefInit1[ 256 ];
	 static char cCoefInit2[ 256 ];
	 static char cCoefInit3[ 256 ];
	 static char cCoefInit4[ 256 ];
	 static char cCoefInit5[ 256 ];
	 static char cCoefDir1[ 256 ];
	 static char cCoefDir2[ 256 ];
	 static char cCoefDir3[ 256 ];
	 static char cCoefDir4[ 256 ];
	 static char cCoefDir5[ 256 ];
	 static HWND hSlider;
	 int po;
	 static int nParamPoint[ PARAM_NUM ];
	 static HWND hwndScroll[ PARAM_NUM ] ;
	 int iDummy ;
	 int nJuge;

	 //初期状態 
	 int nChannelInfo = 2;
	 int nBpsInfo = 16;
	 int nExcludeLen = 44;

	 static double DGain = 0.1;
	 static double DDelay = 100;

	 HANDLE hComm;	//通信ハンドル
	DCB myDCB;

	FILE *ffp;		// file read

     switch (message)
     {
     case WM_INITDIALOG:
		
		////////////////////////////////////////////////
		SAMPLE_RATE = 44100;  

		OUT_BUFFER_SIZE = 32768;
		FLEN = 64;
		FLENdev = OUT_BUFFER_SIZE / FLEN / 2;	//stereo
		/////////////////////////////////////////////////

		wvaWriteFlg = 0;	// 初期状態ではWavに出力結果を書き込まない
		CheckDlgButton( hwnd, IDC_WAVWRITE_OFF, BST_CHECKED );
		CheckDlgButton(hwnd,IDC_RMS_ON,BST_CHECKED);
		CheckDlgButton(hwnd,IDC_RADIO_GAIN1,BST_CHECKED);
		CheckDlgButton(hwnd,IDC_RADIO_DELAY3,BST_CHECKED);
		CheckDlgButton(hwnd,IDC_NOTCH_ON,BST_CHECKED);
		CheckDlgButton(hwnd,IDC_N1_Freq1,BST_CHECKED);
		CheckDlgButton(hwnd,IDC_N2_Freq6,BST_CHECKED);
		CheckDlgButton(hwnd,IDC_RADIO_AP30,BST_CHECKED);
		CheckDlgButton(hwnd,IDC_HEADTRACK_OFF,BST_CHECKED);

		displaySetGain( hwnd);

		//アプリのカレントディレクトリ取得 
		dwLen = GetModuleFileName( GetModuleHandle( APL_FILE_NAME ), cPassTempName, PATHLEN );
		allLen = strlen( cPassTempName );
		divLen = strlen( APL_FILE_NAME );
		objectlen = allLen - divLen;
		strncpy( cPassName , cPassTempName , objectlen);
		strcpy( g_cPassName, cPassName );

		//データ書き込み用ファイルのオープン
		memset( cFileNameWriteFile, 0, sizeof( char ) * PATHLEN );
		sprintf( cFileNameWriteFile , "%s%s%s", cPassName, "\\", OUTPUT_FILE_NAME );

		// wavファイル位置指定用スライダー
		hSlider = GetDlgItem( hwnd, IDC_SLIDER_PLAYFILE_POSITION );
		SendMessage( hSlider, TBM_SETRANGEMAX, (WPARAM)TRUE, lFileLengthPos );
		SendMessage( hSlider, TBM_SETRANGEMIN, (WPARAM)TRUE, 0 );
		SendMessage( hSlider, TBM_SETPOS, (WPARAM)TRUE, (LPARAM)0 );
		lFileNowPos = SendMessage( hSlider, TBM_GETPOS, (WPARAM)0L, (LPARAM)0L );

		memset(	cResampleFirFilePath, 0, sizeof( char ) * 256 );

		nParamPoint[ 1 ] = RESAMPLE_MIN; 
		hwndScroll[ 0 ] = GetDlgItem ( hwnd, IDC_SCROLLBAR_FIRMODE );//指定されたダイアログボックス内のコントロールのハンドルを取得
		SetScrollRange (reinterpret_cast<HWND>(hwndScroll[ 0 ]), SB_CTL, 0, RESAMPLE_MAX-1, FALSE) ;//バースクロールの移動範囲
        SetScrollPos   (reinterpret_cast<HWND>(hwndScroll[ 0 ]), SB_CTL, 0, TRUE) ;//バーの初期化
        SetDlgItemInt  (hwnd, IDC_TEXT, nResampleData[ RESAMPLE_MIN ], FALSE) ;//ダイアログの初期化

		return TRUE;
  
	 case WM_HSCROLL://ユーザーの操作を通知します
		 	
		  //スクロールバーの設定　
		  po = GetWindowLong( (HWND) lParam, GWL_ID );
		  if( IDC_SLIDER_PLAYFILE_POSITION == po ){
				scrollpoint = 0;		
		  }else if( IDC_SCROLLBAR_FIRMODE == po ){
				scrollpoint = 1;		
		  }else{

		  }

          switch (LOWORD (wParam))
          {
          case SB_LINELEFT: 
			  nParamPoint[ scrollpoint ] -= 1;
			  break;	//バー左移動
          case SB_LINERIGHT:
			  nParamPoint[ scrollpoint ] += 1;
			  break;	//バー右移動
          case SB_PAGELEFT:
			  nParamPoint[ scrollpoint ] /= 2;
			  break;	//バーの左途中移動
          case SB_PAGERIGHT:
			  nParamPoint[ scrollpoint ] *= 2;
			  break;	//バーの右途中移動
               
          case SB_THUMBTRACK://マウスによる位置の移動
               nParamPoint[ scrollpoint ] = HIWORD (wParam) ;
               break ;
               
          case SB_TOP://左                       //最小位置 最大位置 
               GetScrollRange (reinterpret_cast<HWND>(hwndScroll[ scrollpoint ]), SB_CTL, &nParamPoint[ scrollpoint ], &iDummy) ;
			   //指定したスクロールバーのスクロールボックスの最大位置と最小位置を取得
               break ;
               
          case SB_BOTTOM://右                    //最小位置 最大位置 
               GetScrollRange (reinterpret_cast<HWND>(hwndScroll[ scrollpoint ]), SB_CTL, &iDummy, &nParamPoint[ scrollpoint ]) ;
               break ;
          }

		  //バー位置情報
          nParamPoint[ 1 ] = max( RESAMPLE_MIN, min (RESAMPLE_MAX-1, nParamPoint[ 1 ] ) );
	      //スクロールボックスの位置の状況とそれの描写
          SetScrollPos (hwndScroll[ 0 ], SB_CTL, nParamPoint[ 1 ], TRUE );
		 
	
		  //ダイアログ内のバーの位置情報の値の表示
		  if( 1 == scrollpoint ){
			   SetDlgItemInt (hwnd, IDC_TEXT, nResampleData[ nParamPoint[ 1 ] ], TRUE );		//Azimuth
			
			   memset(	cResampleFirFilePath, 0, sizeof( char ) * 256 );
			   sprintf( cResampleFirFilePath, "%d", nResampleData[ nParamPoint[ scrollpoint ] ] );
			
			   FLEN = 64;
			   FLENdev = OUT_BUFFER_SIZE / FLEN / 2;	//stereo
	
			   memset( cCoefDirResample, 0, sizeof( char ) * 256 );
			   sprintf( cCoefDirResample, "%s", g_cPassName );
		  }
	
	
		  //wavファイルのファイルポインタを手で動作させたときの位置を取得しファイルポインタを移動する処理
		  if( scrollpoint == 0 && fid != NULL ){
			  lFileNowPos = SendMessage( hSlider, TBM_GETPOS, (WPARAM)0L, (LPARAM)0L );//(LPARAM)lFileLengthPos
					 		
			  //偶数だったよい 奇数にすると正しくwavデータのデータの並びを崩して読み取るため
			  nJuge = lFileNowPos % 4;
			  if( nJuge != 0 ){	//偶数じゃなかったら(奇数であれば)
				 lFileNowPos -= nJuge;
			  }

			  if( lFileNowPos == 0 ){	//スライダーを手で戻した時のノイズをならないように修正
			      lFileNowPos = nExcludeLen;	
			  }
			  fseek( fid, lFileNowPos, SEEK_SET );

			  SendMessage( hSlider, TBM_SETPOS, (WPARAM)1, (LPARAM)lFileNowPos );
		  }

		  return TRUE ;

     case WM_COMMAND:
        switch (LOWORD (wParam)){
		 	case IDC_FILE:
			   	ofn.lStructSize = sizeof(OPENFILENAME);
				ofn.hwndOwner = hwnd;
				ofn.lpstrFilter = "Windows wave (*.WAV)\0*.wav\0全ファイル(*.*)\0*.*\0";
				ofn.lpstrCustomFilter = NULL;
				ofn.nFilterIndex = 1; 
				filename1[0] = 0;
				ofn.lpstrFile = (LPSTR)filename1;
				ofn.nMaxFile = sizeof(filename1);
				ofn.lpstrInitialDir = NULL;
				ofn.lpstrTitle = "再生用にファイルを開く";
				ofn.lpstrDefExt = NULL;
				ofn.Flags = OFN_HIDEREADONLY | OFN_FILEMUSTEXIST ;
				flag = GetOpenFileName((LPOPENFILENAME)&ofn);

				fid	= setPcmFile (filename1, fid);
				if( fid == NULL ){
					break;
				}
				getWavInfo( filename1, &SAMPLE_RATE, &nChannelInfo, &nBpsInfo, &nExcludeLen, &lFileLengthPos );
				fseek( fid, nExcludeLen, SEEK_SET );
				
				//wav位置指定用処理追加
				hSlider = GetDlgItem( hwnd, IDC_SLIDER_PLAYFILE_POSITION );
 				SendMessage( hSlider, TBM_SETRANGEMAX, (WPARAM)TRUE, lFileLengthPos );
				SendMessage( hSlider, TBM_SETRANGEMIN, (WPARAM)TRUE, 0 );
				SendMessage( hSlider, TBM_SETPOS, (WPARAM)TRUE, (LPARAM)0 );
				lFileNowPos = SendMessage( hSlider, TBM_GETPOS, (WPARAM)0L, (LPARAM)0L );

				////////////////////////////////////////////////////////////////////////////////////////
				if((fidoutput = fopen( cFileNameWriteFile, "wb" ))==NULL) {
					MessageBox(NULL,"出力ファイルをオープンできません","ファイルエラー",MB_OK);	
				}
								
				CreateWavHeader(fidoutput, nChannelInfo, SAMPLE_RATE, nBpsInfo);
				
				FLEN = 64;
				FLENdev = OUT_BUFFER_SIZE / FLEN / 2;	//stereo

								
				/////////////////////////////////////////////////////////////////////////////////////////

				if( flag ){
					SetDlgItemText( hwnd, IDC_EDITFILE, filename1 );
				}
				if( flag == 0 ){
					break;
				}
				
				break;
     
			case IDC_WAVE:  
				wave_flg=1;
				EnableWindow(GetDlgItem(hwnd, IDC_EDITFILE), TRUE);
				EnableWindow(GetDlgItem(hwnd, IDC_FILE), TRUE);			   				

				break;

		 	case IDC_RMS_OFF:
			    f_remaster_on=0;
				break;

		 	case IDC_RMS_ON: 
				f_remaster_on=1;
				break;

		 	case IDC_NOTCH_OFF:
			    infoRMS.dNTFType = 0;
				break;

		 	case IDC_NOTCH_ON:
			    infoRMS.dNTFType = 1;
				break;

		 	case IDC_N1_Freq1:
			    infoRMS.dNotch1b10 = 0.93354168925;
			    infoRMS.dNotch1b11 = -1.22853475641;
			    infoRMS.dNotch1b12 = 0.93354168925;
			    infoRMS.dNotch1a11 = 1.22853475641;
			    infoRMS.dNotch1a12 = -0.86708337850;
				break;

		 	case IDC_N1_Freq2:
			    infoRMS.dNotch1b10 = 0.93354168947;
			    infoRMS.dNotch1b11 = -1.01555494695;
			    infoRMS.dNotch1b12 = 0.93354168947;
			    infoRMS.dNotch1a11 = 1.01555494695;
			    infoRMS.dNotch1a12 = -0.86708337894;
				break;

		 	case IDC_N1_Freq3:
			    infoRMS.dNotch1b10 = 0.93354168971;
			    infoRMS.dNotch1b11 = -0.78199486322;
			    infoRMS.dNotch1b12 = 0.93354168971;
			    infoRMS.dNotch1a11 = 0.78199486322;
			    infoRMS.dNotch1a12 = -0.86708337942;
				break;

		 	case IDC_N1_Freq4:
			    infoRMS.dNotch1b10 = 0.93354168997;
			    infoRMS.dNotch1b11 = -0.53258761298;
			    infoRMS.dNotch1b12 = 0.93354168997;
			    infoRMS.dNotch1a11 = 0.53258761298;
			    infoRMS.dNotch1a12 = -0.86708337994;
				break;

		 	case IDC_N1_Freq5:
			    infoRMS.dNotch1b10 = 0.93354169024;
			    infoRMS.dNotch1b11 = -0.27238744756;
			    infoRMS.dNotch1b12 = 0.93354169024;
			    infoRMS.dNotch1a11 = 0.27238744756;
			    infoRMS.dNotch1a12 = -0.86708338047;
				break;

		 	case IDC_N2_Freq1:
			    infoRMS.dNotch2b10 = 0.93354168947;
			    infoRMS.dNotch2b11 = -1.01555494695;
			    infoRMS.dNotch2b12 = 0.93354168947;
			    infoRMS.dNotch2a11 = 1.01555494695;
			    infoRMS.dNotch2a12 = -0.86708337894;
				break;

		 	case IDC_N2_Freq2:
			    infoRMS.dNotch2b10 = 0.93354168971;
			    infoRMS.dNotch2b11 = -0.78199486322;
			    infoRMS.dNotch2b12 = 0.93354168971;
			    infoRMS.dNotch2a11 = 0.78199486322;
			    infoRMS.dNotch2a12 = -0.86708337942;
				break;

		 	case IDC_N2_Freq3:
			    infoRMS.dNotch2b10 = 0.93354168997;
			    infoRMS.dNotch2b11 = -0.53258761298;
			    infoRMS.dNotch2b12 = 0.93354168997;
			    infoRMS.dNotch2a11 = 0.53258761298;
			    infoRMS.dNotch2a12 = -0.86708337994;
				break;

		 	case IDC_N2_Freq4:
			    infoRMS.dNotch2b10 = 0.93354169024;
			    infoRMS.dNotch2b11 = -0.27238744756;
			    infoRMS.dNotch2b12 = 0.93354169024;
			    infoRMS.dNotch2a11 = 0.27238744756;
			    infoRMS.dNotch2a12 = -0.86708338047;
				break;

		 	case IDC_N2_Freq5:
			    infoRMS.dNotch2b10 = 0.93354169051;
			    infoRMS.dNotch2b11 = -0.00666733716;
			    infoRMS.dNotch2b12 = 0.93354169051;
			    infoRMS.dNotch2a11 = 0.00666733716;
			    infoRMS.dNotch2a12 = -0.86708338102;
				break;

		 	case IDC_N2_Freq6:
			    infoRMS.dNotch2b10 = 0.93354169092;
			    infoRMS.dNotch2b11 = 0.39047966174;
			    infoRMS.dNotch2b12 = 0.93354169092;
			    infoRMS.dNotch2a11 = -0.39047966174;
			    infoRMS.dNotch2a12 = -0.86708338184;
				break;

			case IDC_RADIO_GAIN1:
				DGain = 0.1;
				break;

			case IDC_RADIO_GAIN2:
				DGain = 0.01;
				break;

			case IDC_RADIO_DELAY4:
				DDelay = 1000;
				break;

			case IDC_RADIO_DELAY3:
				DDelay = 100;
				break;

			case IDC_RADIO_DELAY2:
				DDelay = 10;
				break;

			case IDC_RADIO_DELAY1:
				DDelay = 1;
				break;

			case IDC_BUTTON_LLGAIN_UP:
				infoRMS.dLLGain += DGain;
		displaySetGain( hwnd);
				break;

			case IDC_BUTTON_LLGAIN_DOWN:
				infoRMS.dLLGain -= DGain;
		displaySetGain( hwnd);
				break;

			case IDC_BUTTON_LLDELAY_UP:
				infoRMS.dLLDelay += DDelay;
		displaySetGain( hwnd);
				break;

			case IDC_BUTTON_LLDELAY_DOWN:
				infoRMS.dLLDelay -= DDelay;
		displaySetGain( hwnd);
				break;

			case IDC_BUTTON_LRGAIN_UP:
				infoRMS.dLRGain += DGain;
		displaySetGain( hwnd);
				break;

			case IDC_BUTTON_LRGAIN_DOWN:
				infoRMS.dLRGain -= DGain;
		displaySetGain( hwnd);
				break;

			case IDC_BUTTON_LRDELAY_UP:
				infoRMS.dLRDelay += DDelay;
		displaySetGain( hwnd);
				break;

			case IDC_BUTTON_LRDELAY_DOWN:
				infoRMS.dLRDelay -= DDelay;
		displaySetGain( hwnd);
				break;

			case IDC_BUTTON_RLGAIN_UP:
				infoRMS.dRLGain += DGain;
		displaySetGain( hwnd);
				break;

			case IDC_BUTTON_RLGAIN_DOWN:
				infoRMS.dRLGain -= DGain;
		displaySetGain( hwnd);
				break;

			case IDC_BUTTON_RLDELAY_UP:
				infoRMS.dRLDelay += DDelay;
		displaySetGain( hwnd);
				break;

			case IDC_BUTTON_RLDELAY_DOWN:
				infoRMS.dRLDelay -= DDelay;
		displaySetGain( hwnd);
				break;

			case IDC_BUTTON_RRGAIN_UP:
				infoRMS.dRRGain += DGain;
		displaySetGain( hwnd);
				break;

			case IDC_BUTTON_RRGAIN_DOWN:
				infoRMS.dRRGain -= DGain;
		displaySetGain( hwnd);
				break;

			case IDC_BUTTON_RRDELAY_UP:
				infoRMS.dRRDelay += DDelay;
		displaySetGain( hwnd);
				break;

			case IDC_BUTTON_RRDELAY_DOWN:
				infoRMS.dRRDelay -= DDelay;
		displaySetGain( hwnd);
				break;

			case IDC_RADIO_AM50:
				infoRMS.dLLGain = 1.0;
				infoRMS.dLRGain = 0.7;
				infoRMS.dRLGain = 0.7;
				infoRMS.dRRGain = 1.0;
				infoRMS.dLLDelay = 700.0;
				infoRMS.dLRDelay = 800.0;
				infoRMS.dRLDelay = 2800.0;
				infoRMS.dRRDelay = 200.0;
				displaySetGain( hwnd);
				break;

			case IDC_RADIO_AM40:
				infoRMS.dLLGain = 1.0;
				infoRMS.dLRGain = 0.7;
				infoRMS.dRLGain = 0.7;
				infoRMS.dRRGain = 1.0;
				infoRMS.dLLDelay = 600.0;
				infoRMS.dLRDelay = 1000.0;
				infoRMS.dRLDelay = 2400.0;
				infoRMS.dRRDelay = 300.0;
				displaySetGain( hwnd);
				break;

			case IDC_RADIO_AM30:
				infoRMS.dLLGain = 1.0;
				infoRMS.dLRGain = 0.7;
				infoRMS.dRLGain = 0.7;
				infoRMS.dRRGain = 1.0;
				infoRMS.dLLDelay = 500.0;
				infoRMS.dLRDelay = 1200.0;
				infoRMS.dRLDelay = 2000.0;
				infoRMS.dRRDelay = 300.0;
				displaySetGain( hwnd);
				break;

			case IDC_RADIO_AM20:
				infoRMS.dLLGain = 1.0;
				infoRMS.dLRGain = 0.7;
				infoRMS.dRLGain = 0.7;
				infoRMS.dRRGain = 1.0;
				infoRMS.dLLDelay = 400.0;
				infoRMS.dLRDelay = 800.0;
				infoRMS.dRLDelay = 1600.0;
				infoRMS.dRRDelay = 200.0;
				displaySetGain( hwnd);
				break;

			case IDC_RADIO_AM10:
				infoRMS.dLLGain = 1.0;
				infoRMS.dLRGain = 0.7;
				infoRMS.dRLGain = 0.7;
				infoRMS.dRRGain = 1.0;
				infoRMS.dLLDelay = 300.0;
				infoRMS.dLRDelay = 500.0;
				infoRMS.dRLDelay = 1200.0;
				infoRMS.dRRDelay = 100.0;
				displaySetGain( hwnd);
				break;

			case IDC_RADIO_A0:
				infoRMS.dLLGain = 1.0;
				infoRMS.dLRGain = 0.7;
				infoRMS.dRLGain = 0.7;
				infoRMS.dRRGain = 1.0;
				infoRMS.dLLDelay = 100.0;
				infoRMS.dLRDelay = 500.0;
				infoRMS.dRLDelay = 500.0;
				infoRMS.dRRDelay = 100.0;
				displaySetGain( hwnd);
				break;

			case IDC_RADIO_AP10:
				infoRMS.dLLGain = 1.0;
				infoRMS.dLRGain = 0.7;
				infoRMS.dRLGain = 0.7;
				infoRMS.dRRGain = 1.0;
				infoRMS.dLLDelay = 100.0;
				infoRMS.dLRDelay = 200.0;
				infoRMS.dRLDelay = 500.0;
				infoRMS.dRRDelay = 300.0;
				displaySetGain( hwnd);
				break;

			case IDC_RADIO_AP20:
				infoRMS.dLLGain = 1.0;
				infoRMS.dLRGain = 0.7;
				infoRMS.dRLGain = 0.7;
				infoRMS.dRRGain = 1.0;
				infoRMS.dLLDelay = 200.0;
				infoRMS.dLRDelay = 1600.0;
				infoRMS.dRLDelay = 800.0;
				infoRMS.dRRDelay = 400.0;
				displaySetGain( hwnd);
				break;

			case IDC_RADIO_AP30:
				infoRMS.dLLGain = 1.0;
				infoRMS.dLRGain = 0.7;
				infoRMS.dRLGain = 0.7;
				infoRMS.dRRGain = 1.0;
				infoRMS.dLLDelay = 300.0;
				infoRMS.dLRDelay = 2000.0;
				infoRMS.dRLDelay = 1200.0;
				infoRMS.dRRDelay = 500.0;
				displaySetGain( hwnd);
				break;

			case IDC_RADIO_AP40:
				infoRMS.dLLGain = 1.0;
				infoRMS.dLRGain = 0.7;
				infoRMS.dRLGain = 0.7;
				infoRMS.dRRGain = 1.0;
				infoRMS.dLLDelay = 250.0;
				infoRMS.dLRDelay = 2400.0;
				infoRMS.dRLDelay = 1000.0;
				infoRMS.dRRDelay = 600.0;
				displaySetGain( hwnd);
				break;

			case IDC_RADIO_AP50:
				infoRMS.dLLGain = 1.0;
				infoRMS.dLRGain = 0.7;
				infoRMS.dRLGain = 0.7;
				infoRMS.dRRGain = 1.0;
				infoRMS.dLLDelay = 200.0;
				infoRMS.dLRDelay = 2800.0;
				infoRMS.dRLDelay = 800.0;
				infoRMS.dRRDelay = 700.0;
				displaySetGain( hwnd);
				break;

			case IDC_HEADTRACK_OFF:
				f_headtrack_on = 0;
				break;

			case IDC_HEADTRACK_ON:
				char cTempBuf[ 256 ];

				memset( cTempBuf, 0, sizeof( char ) * 256 );	
				sprintf( cTempBuf, "%s%s%s", cPassName, "\\", "Virtualphone.INI" );
				if((ffp = fopen(cTempBuf, "r")) == NULL) {
					fprintf(stderr, "ファイルVirtualphone.ini のオープンに失敗しました\n");
					exit(1);
				}
				while(fscanf(ffp, "%s", portName) == 1) {

				}

		  //----------ポートオープン
				hComm = CreateFile(portName, GENERIC_READ | GENERIC_WRITE,
				0, NULL, OPEN_EXISTING, 0, NULL );
				//----------DCB構造体を使って通信設定をする
				BuildCommDCB("9600,n,8,2",&myDCB);

				//----------DCB構造体セット
				SetCommState(hComm, &myDCB);

				//----------タイムアウト設定
				COMMTIMEOUTS CommTimeout;
				GetCommTimeouts(hComm,&CommTimeout);
				CommTimeout.ReadIntervalTimeout = 30000;
				CommTimeout.ReadTotalTimeoutMultiplier = 30000;
				CommTimeout.ReadTotalTimeoutConstant = 30000;
				CommTimeout.WriteTotalTimeoutMultiplier = 30000;
				CommTimeout.WriteTotalTimeoutConstant = 30000;
				SetCommTimeouts(hComm,&CommTimeout);

			//----------通信初期化
				char RecBuff[1];
				DWORD ReadLen;
				DWORD WriteLen;

				WriteFile(hComm,"c104080\r\n",9,&WriteLen,NULL);
				ReadFile(hComm,RecBuff,3,&ReadLen,NULL);
	memset( cTempBuf, 0, sizeof( char ) * 256 );	
	sprintf( cTempBuf, "%s    %s", portName, RecBuff );
			SetDlgItemText( hwnd, IDC_EDIT1, cTempBuf );

	CloseHandle( hComm );

				fclose(ffp);

				f_headtrack_on = 1;
				break;

			case IDC_BUTTON_UPDATE_GAIN1:
				displayGetGain(hwnd);
				break;

			case IDC_BUTTON_UPDATE_DELAY:
				displayGetDelay(hwnd);
				break;

			case IDC_WAVWRITE_OFF:
 
			 	wvaWriteFlg = 0;

			 	break;

			case IDC_WAVWRITE_ON:
  
				wvaWriteFlg = 1;

				break;

			 case IDC_ONOFF:
				if( fid == NULL ){
					MessageBox(NULL,"再生用ファイルを指定してください","ファイルエラー",MB_OK);	
					break;
				}
		 
				EnableWindow(GetDlgItem(hwnd, IDC_EDITFILE), FALSE);
				EnableWindow(GetDlgItem(hwnd, IDC_FILE), FALSE);
				
				if (hWaveOut == NULL ){	
					pWaveHdr1 = (struct wavehdr_tag *)malloc (sizeof (WAVEHDR)) ;
					pWaveHdr2 = (struct wavehdr_tag *)malloc (sizeof (WAVEHDR)) ;
					
					pBuffer1  = ( short *)malloc (OUT_BUFFER_SIZE*sizeof(short)) ;
					pBuffer2  = ( short *)malloc (OUT_BUFFER_SIZE*sizeof(short)) ;

					if (!pWaveHdr1 || !pWaveHdr2 || !pBuffer1 || !pBuffer2 ){
						if (!pWaveHdr1) free (pWaveHdr1) ;
						if (!pWaveHdr2) free (pWaveHdr2) ;
                   
						if (!pBuffer1)  free (pBuffer1) ;
						if (!pBuffer2)  free (pBuffer2) ;

						MessageBeep (MB_ICONEXCLAMATION) ;
						MessageBox (hwnd, TEXT ("Error allocating memory!"),
									 szAppName, MB_ICONEXCLAMATION | MB_OK) ;
						return TRUE ;
					}

					bShutOff = FALSE ;
                         
					// Open waveform audio for output
                    waveformat.wFormatTag      = WAVE_FORMAT_PCM ;
					waveformat.nChannels       = nChannel;						    //チャンネル数			//2
					waveformat.nSamplesPerSec  = SAMPLE_RATE ;						//サンプリングレート	//SAMPLE_RATE
					waveformat.nAvgBytesPerSec = SAMPLE_RATE * nChannel * bpss / 8;	//転送量/1秒			//SAMPLE_RATE*4 
					waveformat.nBlockAlign     = (unsigned short)( nChannel * bpss / 8 );		    //データ転送の最小単位  //4
					waveformat.wBitsPerSample  = bpss ;							    //量子化ビット数		//16
					waveformat.cbSize          = 0 ;								//エリ 
				
					if (waveOutOpen (&hWaveOut, WAVE_MAPPER, &waveformat,
								 (DWORD) hwnd, 0, CALLBACK_WINDOW)
							  != MMSYSERR_NOERROR){
						free (pWaveHdr1) ;
						free (pWaveHdr2) ;

						free (pBuffer1) ;
						free (pBuffer2) ;

						hWaveOut = NULL ;
						MessageBeep (MB_ICONEXCLAMATION) ;
						MessageBox (hwnd, 
							  TEXT ("Error opening waveform audio  output device!"),
							  szAppName, MB_ICONEXCLAMATION | MB_OK) ;
						return TRUE ;
					}

						 // Set up headers and prepare them

					pWaveHdr1->lpData          = (char *)pBuffer1 ;
					pWaveHdr1->dwBufferLength  = OUT_BUFFER_SIZE*2 ;
					pWaveHdr1->dwBytesRecorded = 0 ;
					pWaveHdr1->dwUser          = 0 ;
					pWaveHdr1->dwFlags         = 0 ;
					pWaveHdr1->dwLoops         = 1 ;  
					pWaveHdr1->lpNext          = NULL ;
					pWaveHdr1->reserved        = 0 ;
                    
					waveOutPrepareHeader (hWaveOut, pWaveHdr1, 
										  sizeof (WAVEHDR)) ;

					pWaveHdr2->lpData          = (char *)pBuffer2 ;
					pWaveHdr2->dwBufferLength  = OUT_BUFFER_SIZE*2 ;
					pWaveHdr2->dwBytesRecorded = 0 ;
					pWaveHdr2->dwUser          = 0 ;
					pWaveHdr2->dwFlags         = 0 ;
					pWaveHdr2->dwLoops         = 1 ;  
					pWaveHdr2->lpNext          = NULL ;
					pWaveHdr2->reserved        = 0 ;
                    
					waveOutPrepareHeader (hWaveOut, pWaveHdr2,
										  sizeof (WAVEHDR)) ;
				}
					
					// If turning off waveform, reset waveform audio
				else{
					bShutOff = TRUE ;
					waveOutReset (hWaveOut) ;
				}
				return TRUE ;
		   }	// end of switch (LOWORD (wParam)){


			break ;


			return TRUE ;

            // Message generated from waveOutOpen call
	            
     case MM_WOM_OPEN: 
          
		  SetDlgItemText (hwnd, IDC_ONOFF, TEXT ("STOP")) ;
	       
		  // Send two buffers to waveform output device

          FillBuffer (pBuffer1, nExcludeLen) ;
		  waveOutWrite (hWaveOut, pWaveHdr1, sizeof (WAVEHDR)) ;
		  if( wvaWriteFlg == 1 ){
			fwrite( pBuffer1, sizeof( short ), OUT_BUFFER_SIZE, fidoutput );
		  }
		  
          FillBuffer (pBuffer2, nExcludeLen) ;
	      waveOutWrite (hWaveOut, pWaveHdr2, sizeof (WAVEHDR)) ;
		  if( wvaWriteFlg == 1 ){
			fwrite( pBuffer2, sizeof( short ), OUT_BUFFER_SIZE, fidoutput );
		  }

				hComm = CreateFile(portName, GENERIC_READ | GENERIC_WRITE,
				0, NULL, OPEN_EXISTING, 0, NULL );
				//----------DCB構造体を使って通信設定をする
				BuildCommDCB("9600,n,8,2",&myDCB);

				//----------DCB構造体セット
				SetCommState(hComm, &myDCB);

				//----------タイムアウト設定
				COMMTIMEOUTS CommTimeout;
				GetCommTimeouts(hComm,&CommTimeout);
				CommTimeout.ReadIntervalTimeout = 30000;
				CommTimeout.ReadTotalTimeoutMultiplier = 30000;
				CommTimeout.ReadTotalTimeoutConstant = 30000;
				CommTimeout.WriteTotalTimeoutMultiplier = 30000;
				CommTimeout.WriteTotalTimeoutConstant = 30000;
				SetCommTimeouts(hComm,&CommTimeout);
			//----------受信
				char RecBuff[1];
				DWORD ReadLen;
				DWORD WriteLen;	
				WriteFile(hComm,"r1\r\n",4,&WriteLen,NULL);
				ReadFile(hComm,RecBuff,8,&ReadLen,NULL);
			//----------エディットボックスに表示
				sscanf(RecBuff, "%x", &zifp);
	char cTempBuf[ 256 ];
		memset( cTempBuf, 0, sizeof( char ) * 256 );	
		sprintf( cTempBuf, "%x", zifp );
		SetDlgItemText( hwnd, IDC_EDIT1, cTempBuf );

						CloseHandle(hComm);

			aifp = 0;

				return TRUE ;

          // Message generated when a buffer is finished
          
     case MM_WOM_DONE:
          if (bShutOff){
               waveOutClose (hWaveOut) ;
               return TRUE ;
          }

		  if( f_remaster_on ){
	float fp;
//				//----------ポートオープン
				hComm = CreateFile(portName, GENERIC_READ | GENERIC_WRITE,
				0, NULL, OPEN_EXISTING, 0, NULL );
				//----------DCB構造体を使って通信設定をする
				BuildCommDCB("9600,n,8,2",&myDCB);

				//----------DCB構造体セット
				SetCommState(hComm, &myDCB);

				//----------タイムアウト設定
				COMMTIMEOUTS CommTimeout;
				GetCommTimeouts(hComm,&CommTimeout);
				CommTimeout.ReadIntervalTimeout = 30000;
				CommTimeout.ReadTotalTimeoutMultiplier = 30000;
				CommTimeout.ReadTotalTimeoutConstant = 30000;
				CommTimeout.WriteTotalTimeoutMultiplier = 30000;
				CommTimeout.WriteTotalTimeoutConstant = 30000;
				SetCommTimeouts(hComm,&CommTimeout);

				//----------受信
				char RecBuff[1];
				DWORD ReadLen;
				DWORD WriteLen;
				long ifp;
				WriteFile(hComm,"r1\r\n",4,&WriteLen,NULL);
				ReadFile(hComm,RecBuff,8,&ReadLen,NULL);
			//----------エディットボックスに表示
				sscanf(RecBuff, "%x", &ifp);	// froat->hex changed
				aifp += ifp - zifp;
				fp = (float)(aifp >> 4) / (float)(524288 / 3.07);		// 524288=2~19

	char cTempBuf[ 256 ];
	memset( cTempBuf, 0, sizeof( char ) * 256 );	
//	sprintf( cTempBuf, "%x   %x   %x   %lf", ifp , zifp, aifp, -fp * 180 );	//90deg/fp0.5V -> 180倍	
	sprintf( cTempBuf, "%x   %x   %x   %d", ifp , zifp, aifp, (int)(-fp * 180) );	//90deg/fp0.5V -> 180倍	
	if(f_headtrack_on) {
		SetDlgItemText( hwnd, IDC_EDIT1, cTempBuf );
	} else {
		SetDlgItemText( hwnd, IDC_EDIT1, "" );
	}

	if(f_headtrack_on) {

		infoRMS.dLLDelay = 2803 + fp * 580;
		infoRMS.dLRDelay = 2997 - fp * 580;
		infoRMS.dRLDelay = 2997 + fp * 580;
		infoRMS.dRRDelay = 2803 - fp * 580;

//20130417 change start
//		infoRMS.dLLGain = 0.966 + fp * 0.2;
//		infoRMS.dLRGain = 1.033 - fp * 0.2;
//		infoRMS.dRLGain = 1.033 + fp * 0.2;
//		infoRMS.dRRGain = 0.966 - fp * 0.2;
		infoRMS.dLLGain = 1.033 - fp * 0.2;
		infoRMS.dLRGain = 0.966 + fp * 0.2;
		infoRMS.dRLGain = 0.966 - fp * 0.2;
		infoRMS.dRRGain = 1.033 + fp * 0.2;
//20130417 change end

	displaySetGain( hwnd);

	}

				CloseHandle(hComm);
		  }

         // Fill and send out a new buffer
		  FillBuffer((short *)(((PWAVEHDR) lParam)->lpData), nExcludeLen) ;
		  waveOutWrite (hWaveOut, (PWAVEHDR) lParam, sizeof (WAVEHDR)) ;
		  if( wvaWriteFlg == 1 ){
			fwrite( (short *)(((PWAVEHDR) lParam)->lpData), sizeof( short ), OUT_BUFFER_SIZE, fidoutput );
		  }

		  SendMessage( hSlider, TBM_SETPOS, (WPARAM)1, (LPARAM)lFileNowPos );

          return TRUE ;
		  
	 case MM_WOM_CLOSE:
          waveOutUnprepareHeader (hWaveOut, pWaveHdr1, sizeof (WAVEHDR)) ;
          waveOutUnprepareHeader (hWaveOut, pWaveHdr2, sizeof (WAVEHDR)) ;
		 
          free (pWaveHdr1) ;
          free (pWaveHdr2) ;
          free (pBuffer1) ;
          free (pBuffer2) ;
	
          hWaveOut = NULL ;
       
		  SetDlgItemText (hwnd, IDC_ONOFF, TEXT ("START")) ;

          EnableWindow(GetDlgItem(hwnd, IDC_WAVE), TRUE);
				 
		  if(wave_flg){
			    EnableWindow(GetDlgItem(hwnd, IDC_EDITFILE), TRUE);
				EnableWindow(GetDlgItem(hwnd, IDC_FILE), TRUE);
		  }

          if (bClosing){
			   EndDialog (hwnd, 0) ;
          }
          return TRUE ;

	
	 case MM_WIM_OPEN:  
		 
		  waveInAddBuffer(hWaveIn , pWaveHdri1 , sizeof(WAVEHDR));
		  waveInAddBuffer(hWaveIn , pWaveHdri2 , sizeof(WAVEHDR));	
		  
		  waveInStart(hWaveIn);

		  return TRUE;
		  
	 case MM_WIM_DATA:  
		  if (bShutOff){
			   waveInStop (hWaveIn) ;
               waveInClose (hWaveIn) ;
               return TRUE ;
          } 	
		  
		  waveInAddBuffer(hWaveIn , (PWAVEHDR) lParam , sizeof(WAVEHDR));	
	
		  return TRUE;
		       
	 case MM_WIM_CLOSE:	

		  waveInUnprepareHeader (hWaveIn, pWaveHdri1, sizeof (WAVEHDR)) ;
          waveInUnprepareHeader (hWaveIn, pWaveHdri2, sizeof (WAVEHDR)) ;

          free (pWaveHdri1) ;
          free (pWaveHdri2) ;

          free (pBuffer1) ;
          free (pBuffer2) ;
		 
		  if (bClosing){
			   EndDialog (hwnd, 0) ;
          }

		  hWaveIn = NULL ;
                    
          return TRUE ;  

     case WM_SYSCOMMAND:
          switch (wParam){
          case SC_CLOSE:
			  if( fid ){
    			  fclose( fid );
              }
			  UpdateWavHeader(fidoutput);
			  if( fidoutput ){
				  fclose( fidoutput );
			  }
			 
			  if(wave_flg){
				  if (hWaveOut != NULL){
					  bShutOff = TRUE ;
					  bClosing = TRUE ;
                    
                      waveOutReset (hWaveOut) ;
				  }
				  else{
				      EndDialog (hwnd, 0) ;
				  }
               	  return TRUE ;
			  }
			  //ReleaseReadScenario(sc_info, MAX_TDL_NUM);
	     }
          break ;
     }
     return FALSE ;
}

////////////////////////////////////////////////////////////////////////////////////////////////
FILE *setPcmFile( char *pcFname, FILE *pFile )
{
	if ( *pcFname == NULL ){
		return pFile;
	}
	pFile = fopen( pcFname, "rb" );
	if ( pFile == NULL ){
		return pFile;			
	}

	return pFile;
}

//////////////////////////////////////////////////////////////////
FILE *freadPcmFile( FILE *pFileP, int unBufLen, short *nDataBuf, int nExclude )
{
	int ret;
	if( NULL != pFileP	 ){
		ret = fread( nDataBuf, sizeof(short), unBufLen, pFileP );
		if( ret != unBufLen ){
			rewind( pFileP );
			fseek( pFileP, nExclude, SEEK_SET );	// wavヘッダ部を飛ばす
			ret = fread( nDataBuf, sizeof(short), OUT_BUFFER_SIZE, pFileP );
		}
	}else{
		memset( nDataBuf, 0, sizeof( short ) * unBufLen );
	}

	return pFileP;
}

////////////////////////////////////////////////////////////////////////////////////////////
LPITEMIDLIST GetItemIDList( char *p_cFileStr )   //IDリストを返す関数
{
	if( p_cFileStr == NULL ){
		return NULL;
	}

	LPITEMIDLIST pIDL;
	LPSHELLFOLDER pDesktopFolder; 

	if( ::SHGetDesktopFolder( &pDesktopFolder ) != NOERROR )
		return NULL;

	OLECHAR       ochPath[MAX_PATH];
	ULONG         chEaten;	//文字列のサイズを受け取ります。
	ULONG         dwAttributes;	//属性を受け取ります。
	HRESULT       hRes;

	::MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, p_cFileStr, -1, ochPath, MAX_PATH );

	//ITEMIDLISTの取得
	hRes = pDesktopFolder->ParseDisplayName( NULL, NULL, ochPath, &chEaten, &pIDL, &dwAttributes);
    
	if( hRes != NOERROR )
		pIDL = NULL;

	pDesktopFolder->Release();

	return pIDL;
}
	 
///////////////////////////////////////////////////////////////////////////////
void displaySetGain( HWND hWnd)
{
	char cTempBuf[ 256 ];
	memset( cTempBuf, 0, sizeof( char ) * 256 );	
	sprintf( cTempBuf, "%lf", infoRMS.dLLGain );
	SetWindowText( GetDlgItem( hWnd, IDC_EDIT_GAIN_LLGAIN ), cTempBuf );

  	memset( cTempBuf, 0, sizeof( char ) * 256 );	
	sprintf( cTempBuf, "%lf", infoRMS.dLRGain );
	SetWindowText( GetDlgItem( hWnd, IDC_EDIT_GAIN_LRGAIN ), cTempBuf );

  	memset( cTempBuf, 0, sizeof( char ) * 256 );	
	sprintf( cTempBuf, "%lf", infoRMS.dRLGain );
	SetWindowText( GetDlgItem( hWnd, IDC_EDIT_GAIN_RLGAIN ), cTempBuf );

  	memset( cTempBuf, 0, sizeof( char ) * 256 );	
	sprintf( cTempBuf, "%lf", infoRMS.dRRGain );
	SetWindowText( GetDlgItem( hWnd, IDC_EDIT_GAIN_RRGAIN ), cTempBuf );

  	memset( cTempBuf, 0, sizeof( char ) * 256 );	
	sprintf( cTempBuf, "%lf", infoRMS.dLLDelay );
	SetWindowText( GetDlgItem( hWnd, IDC_EDIT_DELAY_LLDELAY ), cTempBuf );

  	memset( cTempBuf, 0, sizeof( char ) * 256 );	
	sprintf( cTempBuf, "%lf", infoRMS.dLRDelay );
	SetWindowText( GetDlgItem( hWnd, IDC_EDIT_DELAY_LRDELAY ), cTempBuf );

  	memset( cTempBuf, 0, sizeof( char ) * 256 );	
	sprintf( cTempBuf, "%lf", infoRMS.dRLDelay );
	SetWindowText( GetDlgItem( hWnd, IDC_EDIT_DELAY_RLDELAY ), cTempBuf );

  	memset( cTempBuf, 0, sizeof( char ) * 256 );	
	sprintf( cTempBuf, "%lf", infoRMS.dRRDelay );
	SetWindowText( GetDlgItem( hWnd, IDC_EDIT_DELAY_RRDELAY ), cTempBuf );
}

///////////////////////////////////////////////////////////////////////////////
void displayGetGain( HWND hWnd)
{
	char cTempBuf[ 256 ];
	memset( cTempBuf, 0, sizeof( char ) * 256 );	
	GetWindowText( GetDlgItem( hWnd, IDC_EDIT_GAIN_LLGAIN ), cTempBuf,10 );
	infoRMS.dLLGain = atof( cTempBuf );

	memset( cTempBuf, 0, sizeof( char ) * 256 );	
	GetWindowText( GetDlgItem( hWnd, IDC_EDIT_GAIN_LRGAIN ), cTempBuf,10 );
	infoRMS.dLRGain = atof( cTempBuf );

	memset( cTempBuf, 0, sizeof( char ) * 256 );	
	GetWindowText( GetDlgItem( hWnd, IDC_EDIT_GAIN_RLGAIN ), cTempBuf,10 );
	infoRMS.dRLGain = atof( cTempBuf );

	memset( cTempBuf, 0, sizeof( char ) * 256 );	
	GetWindowText( GetDlgItem( hWnd, IDC_EDIT_GAIN_RRGAIN ), cTempBuf,10 );
	infoRMS.dRRGain = atof( cTempBuf );

}

void displayGetDelay( HWND hWnd)
{
	char cTempBuf[ 256 ];
	memset( cTempBuf, 0, sizeof( char ) * 256 );	
	GetWindowText( GetDlgItem( hWnd, IDC_EDIT_DELAY_LLDELAY ), cTempBuf,10 );
	infoRMS.dLLDelay = atof( cTempBuf );

	memset( cTempBuf, 0, sizeof( char ) * 256 );	
	GetWindowText( GetDlgItem( hWnd, IDC_EDIT_DELAY_LRDELAY ), cTempBuf,10 );
	infoRMS.dLRDelay = atof( cTempBuf );

	memset( cTempBuf, 0, sizeof( char ) * 256 );	
	GetWindowText( GetDlgItem( hWnd, IDC_EDIT_DELAY_RLDELAY ), cTempBuf,10 );
	infoRMS.dRLDelay = atof( cTempBuf );

	memset( cTempBuf, 0, sizeof( char ) * 256 );	
	GetWindowText( GetDlgItem( hWnd, IDC_EDIT_DELAY_RRDELAY ), cTempBuf,10 );
	infoRMS.dRRDelay = atof( cTempBuf );

}

