
Untitled
By: a guest on
May 8th, 2012 | syntax:
None | size: 1.97 KB | hits: 14 | expires: Never
// quick argument check
//if(argc != 2) {fprintf(stderr, "usage: %s <filename>\n", argv[0]);ExitProcess(1);}
/*
* initialise the module variables
*/
waveBlocks = allocateBlocks(BLOCK_SIZE, BLOCK_COUNT);
waveFreeBlockCount = BLOCK_COUNT;
waveCurrentBlock= 0;
InitializeCriticalSection(&waveCriticalSection);
/*
* try and open the file
*/
if((MusicFile->hFile = CreateFile(
MusicFile->p_Path,
GENERIC_READ,
FILE_SHARE_READ,
NULL,
OPEN_EXISTING,
0,
NULL
)) == INVALID_HANDLE_VALUE)
{
std::cout<<"unable to create file:"<< MusicFile->p_Path<<std::endl;
ExitProcess(1);
}
/*
* set up the WAVEFORMATEX structure.
*/
MusicFile->wfx.nSamplesPerSec = MusicFile->SampleRate; /* sample rate */
MusicFile->wfx.wBitsPerSample = MusicFile->BitsPerSample; /* sample size */
MusicFile->wfx.nChannels= MusicFile->NumChannels; /* channels*/
MusicFile->wfx.cbSize = 0; /* size of _extra_ info */
MusicFile->wfx.wFormatTag = MusicFile->AudioFormat;
MusicFile->wfx.nBlockAlign = MusicFile->BlockAlign;
MusicFile->wfx.nAvgBytesPerSec = MusicFile->ByteRate;
printf("nSamplesPerSec: %d\n",MusicFile->wfx.nSamplesPerSec);
printf("wBitsPerSample: %d\n",MusicFile->wfx.wBitsPerSample);
printf("nChannels: %d\n",MusicFile->wfx.nChannels);
printf("cbSize: %d\n",MusicFile->wfx.cbSize);
printf("wFormatTag: %d\n",MusicFile->wfx.wFormatTag);
printf("nBlockAlign: %d\n",MusicFile->wfx.nBlockAlign);
printf("nAvgBytesPerSec: %d\n",MusicFile->wfx.nAvgBytesPerSec);
/*
* try to open the default wave device. WAVE_MAPPER is
* a constant defined in mmsystem.h, it always points to the
* default wave device on the system (some people have 2 or
* more sound cards).
*/
if(waveOutOpen(
&hWaveOut,
WAVE_MAPPER,
&MusicFile->wfx,
(DWORD_PTR)waveOutProc,
(DWORD_PTR)&waveFreeBlockCount,
CALLBACK_FUNCTION
) != MMSYSERR_NOERROR)
{
std::cout<<"unable to open file:"<< MusicFile->p_Path<<std::endl;
ExitProcess(1);
}