HEADACHE CODE:




  // suck a bit out of this sample
  // either just the lower bit, or average the first 3 or 4 together
  float fbit = 0.0f;
  BYTE bit;
  BYTE checkbit = 0x01;

  for (int bc = 0; bc < bps; bc++)
   fbit += (float)((*gb & (checkbit<<bc)) >> bc); // get the bit

  // average down the bit value
  fbit /= (float)bps;

  // decide to make it a 0 or a 1.
  if (fbit < 0.5f)
   bit = 0;
  else
   bit = 1;

  // Mix up the DWORD in the correct way so that
  // the oldest bit goes out and the newest bit comes in.
  //     E       F     |     B           E    |     A            D     |     D           E
  //  7 6 5 4 3 2 1 0  |15 14 13 12 11 10 9 8 |23 22 21 20 19 18 17 16 |31 30 29 28 27 26 25 24
  //                   |                      |                        |
  // BYTE:   D                    C                        B                      A

  // shift BYTE D to the right and OR in the bottom of byte C
  tempb = ((BYTE*)&id);
  *tempb = *tempb >> 1;
  *tempb |= ((*(tempb+1) & 0x1) << 7);

  // shift BYTE C to the right and OR in the bottom of byte B.
  tempb = ((BYTE*)&id) + 1;
  *tempb = *tempb >> 1;
  *tempb |= ((*(tempb+1) & 0x1) << 7);

  // shift BYTE B to the right and OR in the bottom of byte A.
  tempb = ((BYTE*)&id) + 2;
  *tempb = *tempb >> 1;
  *tempb |= ((*(tempb+1) & 0x1) << 7);

  // shift BYTE A to the right and OR in the new bit. (31 becomes 32)
  tempb = ((BYTE*)&id) + 3;
  *tempb = *tempb >> 1;
  *tempb |= ((bit) << 7);

  // increment buffer by sample size (8 or 16 bits) * number of bits per byte
  gb += globalpsi.dwSampleSize;

  // increment our global pointer to the start of the hidden stuff
  startofhidden++;
  bitoffset += globalpsi.dwSampleSize;