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

Untitled

By: a guest on May 8th, 2012  |  syntax: None  |  size: 0.67 KB  |  hits: 17  |  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. WAVEHDR* AudioPlayer::allocateBlocks(int size, int count)
  2. {
  3.         unsigned char* buffer;
  4.         int i;
  5.         WAVEHDR* blocks;
  6.         DWORD totalBufferSize = (size + sizeof(WAVEHDR)) * count;
  7.         /*
  8.          * allocate memory for the entire set in one go
  9.          */
  10.         if((buffer = (unsigned char *)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, totalBufferSize)) == NULL)
  11.         {
  12.                 fprintf(stderr, "Memory allocation error\n");
  13.                 ExitProcess(1);
  14.         }
  15.         /*
  16.          * and set up the pointers to each bit
  17.          */
  18.         blocks = (WAVEHDR*)buffer;
  19.         buffer += sizeof(WAVEHDR) * count;
  20.         for(i = 0; i < count; i++)
  21.         {
  22.                 blocks[i].dwBufferLength = size;
  23.                 blocks[i].lpData = (LPSTR)buffer;
  24.                 buffer += size;
  25.         }
  26.         return blocks;
  27. }