home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 February: Tool Chest / Dev.CD Feb 00 TC.toast / pc / what's new? / sample code / sound / sndplaydoublebuffer / _source / setupdbheader.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-12-14  |  2.9 KB  |  86 lines

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