C/C++録音と再生を実現


#include 
#include 
#include 
#pragma comment(lib, "winmm.lib") 

static BYTE*    file = (BYTE*)malloc(sizeof(BYTE) * 512);
static DWORD    hasRecorded = 0;
static BOOL     recurr = TRUE;
class USER
{
public:
	int a = 0;
	char b = 'a';
};

void CALLBACK callback(HWAVEIN   hwi,          //     
	UINT      uMsg,							   //   
	DWORD_PTR dwInstance,					   //   
	DWORD_PTR dwParam1,						   //   1
	DWORD_PTR dwParam2);					   //   2

int main()
{
	HWAVEIN         hWaveIn;		        //    
	HWAVEOUT        hWaveOut;		        //    
	WAVEFORMATEX    waveform;	            //       
	BYTE* pBuffer1, * pBuffer2;				//       (    )
	WAVEHDR         whdr_i1, whdr_i2;       //     
	WAVEHDR         whdr_o;                //     
	USER*			user = new USER();		//    
	
	//     
	int count = waveInGetNumDevs();
	printf("
:%d
", count); // WAVEINCAPS waveIncaps; MMRESULT mmResult = waveInGetDevCaps(0, &waveIncaps, sizeof(WAVEINCAPS));//2 std::cout <a,user2->b); // DWORD buflen = pwhdr->dwBufferLength; DWORD bytrecd = pwhdr->dwBytesRecorded; hasRecorded += bytrecd; // file = (BYTE*)realloc(file, hasRecorded * sizeof(BYTE)); // if (file) { memcpy(&file[hasRecorded-bytrecd], pwhdr->lpData, bytrecd); printf(" :%d byte
",hasRecorded); } // if (recurr) { // waveInAddBuffer(hwi, pwhdr, sizeof(WAVEHDR)); } } break; case WIM_CLOSE: // { printf(" ..
"); } break; default: break; } }