source/SetupDBHeader.c

/*
**  Apple Macintosh Developer Technical Support
**
**  Routine demonstrating how to set up the DoubleBufferHeader for SndPlayDoubleBuffer.
**
**  by Mark Cookson, Apple Developer Technical Support
**
**  File:   SetupDBHeader.c
**
**  Copyright ©1996 Apple Computer, Inc.
**  All rights reserved.
**
**  You may incorporate this sample code into your applications without
**  restriction, though the sample code has been provided "AS IS" and the
**  responsibility for its operation is 100% yours.  However, what you are
**  not permitted to do is to redistribute the source as "Apple Sample
**  Code" after having made changes. If you're going to re-distribute the
**  source, we require that you make it clear in the source that the code
**  was descended from Apple Sample Code, but that you've made changes.
*/
 
#include "SetupDBHeader.h"
 
/*  Purpose:        This sets up the fields of the SndDoubleBufferHeader
                    structure.
                    This sets the value of the compFactor variable so that
                    you can tell if the sound is compressed, and if so by
                    how much (this is used for proper buffer sizing).
    Side Effects:   None.
*/
/*-----------------------------------------------------------------------*/
OSErr   SetupDBHeader   (SoundInfoPtr theSoundInfo,
                        Fixed sampleRate,
                        short sampleSize,
                        short numChannels,
                        short compressionID,
                        long compressionType)
/*-----------------------------------------------------------------------*/
{
    CompressionInfo         compInfo;
    OSErr                   err                 = noErr;
 
    err = GetCompressionInfo(compressionID, compressionType, numChannels, sampleSize, &compInfo);
    theSoundInfo->doubleHeader.dbhNumChannels       = numChannels;
    theSoundInfo->doubleHeader.dbhSampleSize        = compInfo.bytesPerSample * kBitsPerByte;
    theSoundInfo->doubleHeader.dbhCompressionID     = compInfo.compressionID;
    theSoundInfo->doubleHeader.dbhPacketSize        = compInfo.bytesPerPacket;
    theSoundInfo->doubleHeader.dbhSampleRate        = sampleRate;
    theSoundInfo->doubleHeader.dbhFormat            = compInfo.format;
 
    theSoundInfo->bytesPerFrame                     = compInfo.bytesPerFrame;
 
    switch (compressionType) {
        case NoneType:
        case kOffsetBinary:
        case kTwosComplement:
            theSoundInfo->compFactor = kNoCompression;
            break;
        case kULawCompression:
        case kCDXA2Compression:
            theSoundInfo->compFactor = kCompressByTwo;
            break;
        case kMACE3Compression:
            theSoundInfo->compFactor = kCompressByThree;
            break;
        case kIMACompression:
        case kCDXA4Compression:
        case 'ADPM':
            theSoundInfo->compFactor = kCompressByFour;
            break;
        case kMACE6Compression:
            theSoundInfo->compFactor = kCompressBySix;
            break;
        default:
            DebugPrint ("\pUnknown compression type, assuming 1:1 compression");
            theSoundInfo->compFactor = kNoCompression;
            break;
    }
 
    return err;
}