SampleRateAvail.c

/*
    File:       SampleRateAvail.c
 
    Contains:   This snippet checks for the number of sample rates available on 
                a given Mac and lists those rates.
 
    Written by: Kevin Mellander 
 
    Copyright:  Copyright © 1994-1999 by Apple Computer, Inc., All Rights Reserved.
 
                You may incorporate this Apple sample source code into your program(s) without
                restriction. This Apple sample source code has been provided "AS IS" and the
                responsibility for its operation is yours. You are not permitted to redistribute
                this Apple sample source code as "Apple sample source 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 source
                code, but that you've made changes.
 
    Change History (most recent first):
                7/29/1999   Karl Groethe    Updated for Metrowerks Codewarror Pro 2.1 and
                                            Fixed struct alignment to support PPC compile
                
 
*/
#include <SoundInput.h>
#include <ToolUtils.h>
#include <Types.h>
#include <stdio.h>
 
#pragma options align=mac68k
struct soundRateData{
        short numberOfRatesSupported;
        Handle ratesSupported;
    } soundRateInfo;
#pragma options align=reset
 
void main()
{
    OSErr   soundErr = 0;
    long    mySIRefNum;
    short   setSoundMeterState = 1;
    Fixed   *myFixedPointer;
    Fixed   myFixedVariable;
    register unsigned long loopCounter;
    
    soundRateInfo.numberOfRatesSupported = 0;
    soundRateInfo.ratesSupported = nil;
    
        
    //Open the sound input device
    soundErr = SPBOpenDevice("\p",siWritePermission,&mySIRefNum);
    if (soundErr != noErr)
{
        DebugStr("\p Failure at call to SPBOpenDevice.");
        ExitToShell();
}
        
    //Get the number of rates supported
    soundErr = SPBGetDeviceInfo(mySIRefNum,siSampleRateAvailable,(Ptr) &soundRateInfo);
    if (soundErr != noErr)
        DebugStr("\p Failure at call to SPBSetDeviceInfo set to 0");
    else
        printf("The number of sample rates supported by this recording device is %d \n \n And the sample rates supported are: \n", soundRateInfo.numberOfRatesSupported);
    
    //Now parse our list of sample rates to determine which are supported 
    myFixedPointer = (Fixed *)(*(soundRateInfo.ratesSupported))    ;
    
    for(loopCounter=0; loopCounter < soundRateInfo.numberOfRatesSupported; loopCounter++)
    {
        myFixedVariable = *myFixedPointer;
        switch (myFixedVariable)
        {
            case 0xAC440000:
                printf("\t44.1 kHz\n");
                break;
            case 0x56EE8BA3:
                printf("\t22.254 kHz\n");
                break;
            case 0x56220000:
                printf("\t22.050 kHz\n");
                break;
            case 0x2B7745D1:
                printf("\t11.127 kHz\n");
                break;
            case 0x2B110000:
                printf("\t11.025 kHz\n");
                break;
            case 0x1CFA2E8B:
                printf("\t7.418 kHz\n");
                break;
            case 0x15BBA2E8:
                printf("\t5.563 kHz\n");
                break;
            default:
                printf("I do not have a listing for this sample rate\n");
        }
        myFixedPointer++;
    }
    
    //We're done so close the device
    soundErr = SPBCloseDevice(mySIRefNum);
    if (soundErr != noErr)
        DebugStr("\p Failure at call to SPBCloseDevice");
}