Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 8th, 2012  |  syntax: None  |  size: 1.97 KB  |  hits: 14  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1.         // quick argument check
  2.         //if(argc != 2) {fprintf(stderr, "usage: %s <filename>\n", argv[0]);ExitProcess(1);}
  3.        
  4.         /*
  5.          * initialise the module variables
  6.          */
  7.         waveBlocks = allocateBlocks(BLOCK_SIZE, BLOCK_COUNT);
  8.         waveFreeBlockCount = BLOCK_COUNT;
  9.         waveCurrentBlock= 0;
  10.         InitializeCriticalSection(&waveCriticalSection);
  11.         /*
  12.          * try and open the file
  13.          */
  14.         if((MusicFile->hFile = CreateFile(
  15.         MusicFile->p_Path,
  16.         GENERIC_READ,
  17.         FILE_SHARE_READ,
  18.         NULL,
  19.         OPEN_EXISTING,
  20.         0,
  21.         NULL
  22.         )) == INVALID_HANDLE_VALUE)
  23.         {
  24.                 std::cout<<"unable to create file:"<< MusicFile->p_Path<<std::endl;
  25.                 ExitProcess(1);
  26.         }
  27.         /*
  28.          * set up the WAVEFORMATEX structure.
  29.          */
  30.  
  31.         MusicFile->wfx.nSamplesPerSec = MusicFile->SampleRate; /* sample rate */
  32.         MusicFile->wfx.wBitsPerSample = MusicFile->BitsPerSample; /* sample size */
  33.         MusicFile->wfx.nChannels= MusicFile->NumChannels; /* channels*/
  34.         MusicFile->wfx.cbSize = 0; /* size of _extra_ info */
  35.         MusicFile->wfx.wFormatTag = MusicFile->AudioFormat;
  36.         MusicFile->wfx.nBlockAlign = MusicFile->BlockAlign;
  37.         MusicFile->wfx.nAvgBytesPerSec = MusicFile->ByteRate;
  38.         printf("nSamplesPerSec: %d\n",MusicFile->wfx.nSamplesPerSec);
  39.         printf("wBitsPerSample: %d\n",MusicFile->wfx.wBitsPerSample);
  40.         printf("nChannels: %d\n",MusicFile->wfx.nChannels);
  41.         printf("cbSize: %d\n",MusicFile->wfx.cbSize);
  42.         printf("wFormatTag: %d\n",MusicFile->wfx.wFormatTag);
  43.         printf("nBlockAlign: %d\n",MusicFile->wfx.nBlockAlign);
  44.         printf("nAvgBytesPerSec: %d\n",MusicFile->wfx.nAvgBytesPerSec);
  45.         /*
  46.          * try to open the default wave device. WAVE_MAPPER is
  47.          * a constant defined in mmsystem.h, it always points to the
  48.          * default wave device on the system (some people have 2 or
  49.          * more sound cards).
  50.          */
  51.         if(waveOutOpen(
  52.         &hWaveOut,
  53.         WAVE_MAPPER,
  54.         &MusicFile->wfx,
  55.         (DWORD_PTR)waveOutProc,
  56.         (DWORD_PTR)&waveFreeBlockCount,
  57.         CALLBACK_FUNCTION
  58.         ) != MMSYSERR_NOERROR)
  59.         {
  60.                 std::cout<<"unable to open file:"<< MusicFile->p_Path<<std::endl;
  61.                 ExitProcess(1);
  62.         }