home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 November: Tool Chest / Dev.CD Nov 98 TC.toast / Sample Code / Snippets / Sound / SndPlayDoubleBuffer / _source / SetupDBHeader.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-11-15  |  2.7 KB  |  82 lines  |  [TEXT/CWIE]

  1. /*
  2. **    Apple Macintosh Developer Technical Support
  3. **
  4. **    Routine demonstrating how to set up the DoubleBufferHeader for SndPlayDoubleBuffer.
  5. **
  6. **    by Mark Cookson, Apple Developer Technical Support
  7. **
  8. **    File:    SetupDBHeader.c
  9. **
  10. **    Copyright ©1996 Apple Computer, Inc.
  11. **    All rights reserved.
  12. **
  13. **    You may incorporate this sample code into your applications without
  14. **    restriction, though the sample code has been provided "AS IS" and the
  15. **    responsibility for its operation is 100% yours.  However, what you are
  16. **    not permitted to do is to redistribute the source as "Apple Sample
  17. **    Code" after having made changes. If you're going to re-distribute the
  18. **    source, we require that you make it clear in the source that the code
  19. **    was descended from Apple Sample Code, but that you've made changes.
  20. */
  21.  
  22. #include "SetupDBHeader.h"
  23.  
  24. /*    Purpose:        This sets up the fields of the SndDoubleBufferHeader
  25.                     structure.
  26.                     This sets the value of the compFactor variable so that
  27.                     you can tell if the sound is compressed, and if so by
  28.                     how much (this is used for proper buffer sizing).
  29.     Side Effects:    None.
  30. */
  31. /*-----------------------------------------------------------------------*/
  32. OSErr    SetupDBHeader    (SoundInfoPtr theSoundInfo,
  33.                         Fixed sampleRate,
  34.                         short sampleSize,
  35.                         short numChannels,
  36.                         short compressionID,
  37.                         long compressionType)
  38. /*-----------------------------------------------------------------------*/
  39. {
  40.     CompressionInfo            compInfo;
  41.     OSErr                    err                    = noErr;
  42.  
  43.     err = GetCompressionInfo(compressionID, compressionType, numChannels, sampleSize, &compInfo);
  44.     theSoundInfo->doubleHeader.dbhNumChannels        = numChannels;
  45.     theSoundInfo->doubleHeader.dbhSampleSize        = compInfo.bytesPerSample * kBitsPerByte;
  46.     theSoundInfo->doubleHeader.dbhCompressionID        = compInfo.compressionID;
  47.     theSoundInfo->doubleHeader.dbhPacketSize        = compInfo.bytesPerPacket;
  48.     theSoundInfo->doubleHeader.dbhSampleRate        = sampleRate;
  49.     theSoundInfo->doubleHeader.dbhFormat            = compInfo.format;
  50.  
  51.     theSoundInfo->bytesPerFrame                        = compInfo.bytesPerFrame;
  52.  
  53.     switch (compressionType) {
  54.         case NoneType:
  55.         case kOffsetBinary:
  56.         case kTwosComplement:
  57.             theSoundInfo->compFactor = kNoCompression;
  58.             break;
  59.         case kULawSubType:
  60.         case kCDXA2SubType:
  61.             theSoundInfo->compFactor = kCompressByTwo;
  62.             break;
  63.         case kMace3SubType:
  64.             theSoundInfo->compFactor = kCompressByThree;
  65.             break;
  66.         case kIMA4SubType:
  67.         case kCDXA4SubType:
  68.         case 'ADPM':
  69.             theSoundInfo->compFactor = kCompressByFour;
  70.             break;
  71.         case kMace6SubType:
  72.             theSoundInfo->compFactor = kCompressBySix;
  73.             break;
  74.         default:
  75.             DebugPrint ("\pUnknown compression type, assuming 1:1 compression");
  76.             theSoundInfo->compFactor = kNoCompression;
  77.             break;
  78.     }
  79.  
  80.     return err;
  81. }
  82.