src/cdrom/macosx/AudioFilePlayer.c
author Ryan C. Gordon <icculus@icculus.org>
Sat, 12 Sep 2009 15:06:16 +0000
branchSDL-1.2
changeset 4190 386181851388
parent 4159 a1b03ba2fcd0
child 6137 4720145f848b
permissions -rw-r--r--
Fixed CD-ROM code to work with Mac OS X 10.6 SDK and 64-bit targets.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     1
/*
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     2
    SDL - Simple DirectMedia Layer
4159
a1b03ba2fcd0 Updated copyright date
Sam Lantinga <slouken@libsdl.org>
parents: 1793
diff changeset
     3
    Copyright (C) 1997-2009 Sam Lantinga
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     4
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     5
    This library is free software; you can redistribute it and/or
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     6
    modify it under the terms of the GNU Library General Public
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     7
    License as published by the Free Software Foundation; either
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     8
    version 2 of the License, or (at your option) any later version.
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     9
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    10
    This library is distributed in the hope that it will be useful,
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    13
    Library General Public License for more details.
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    14
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    15
    You should have received a copy of the GNU Library General Public
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    16
    License along with this library; if not, write to the Free
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    17
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    18
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    19
    Sam Lantinga
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    20
    slouken@libsdl.org
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    21
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    22
    This file based on Apple sample code. We haven't changed the file name, 
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    23
    so if you want to see the original search for it on apple.com/developer
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    24
*/
1402
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents: 1336
diff changeset
    25
#include "SDL_config.h"
4190
386181851388 Fixed CD-ROM code to work with Mac OS X 10.6 SDK and 64-bit targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
    26
#include "SDL_endian.h"
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    27
1487
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    28
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    29
    AudioFilePlayer.cpp
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    30
*/
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    31
#include "AudioFilePlayer.h"
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    32
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    33
/*
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    34
void ThrowResult (OSStatus result, const char* str)
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    35
{
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    36
    SDL_SetError ("Error: %s %d", str, result);
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    37
    throw result;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    38
}
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    39
*/
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    40
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    41
#if DEBUG
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    42
static void PrintStreamDesc (AudioStreamBasicDescription *inDesc)
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    43
{
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    44
    if (!inDesc) {
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    45
        printf ("Can't print a NULL desc!\n");
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    46
        return;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    47
    }
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    48
    
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    49
    printf ("- - - - - - - - - - - - - - - - - - - -\n");
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    50
    printf ("  Sample Rate:%f\n", inDesc->mSampleRate);
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    51
    printf ("  Format ID:%s\n", (char*)&inDesc->mFormatID);
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    52
    printf ("  Format Flags:%lX\n", inDesc->mFormatFlags);
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    53
    printf ("  Bytes per Packet:%ld\n", inDesc->mBytesPerPacket);
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    54
    printf ("  Frames per Packet:%ld\n", inDesc->mFramesPerPacket);
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    55
    printf ("  Bytes per Frame:%ld\n", inDesc->mBytesPerFrame);
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    56
    printf ("  Channels per Frame:%ld\n", inDesc->mChannelsPerFrame);
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    57
    printf ("  Bits per Channel:%ld\n", inDesc->mBitsPerChannel);
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    58
    printf ("- - - - - - - - - - - - - - - - - - - -\n");
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    59
}
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    60
#endif
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    61
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    62
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    63
static int AudioFilePlayer_SetDestination (AudioFilePlayer *afp, AudioUnit  *inDestUnit)
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    64
{
1487
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    65
    /*if (afp->mConnected) throw static_cast<OSStatus>(-1);*/ /* can't set dest if already engaged */
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    66
    if (afp->mConnected)
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    67
        return 0 ;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    68
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1143
diff changeset
    69
    SDL_memcpy(&afp->mPlayUnit, inDestUnit, sizeof (afp->mPlayUnit));
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    70
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    71
    OSStatus result = noErr;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    72
    
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    73
1487
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    74
        /* we can "down" cast a component instance to a component */
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    75
    ComponentDescription desc;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    76
    result = GetComponentInfo ((Component)*inDestUnit, &desc, 0, 0, 0);
1487
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    77
    if (result) return 0; /*THROW_RESULT("GetComponentInfo")*/
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    78
        
1487
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    79
        /* we're going to use this to know which convert routine to call
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    80
           a v1 audio unit will have a type of 'aunt'
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    81
           a v2 audio unit will have one of several different types. */
4190
386181851388 Fixed CD-ROM code to work with Mac OS X 10.6 SDK and 64-bit targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
    82
    if (desc.componentType != kAudioUnitType_Output) {
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    83
        result = badComponentInstance;
1487
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    84
        /*THROW_RESULT("BAD COMPONENT")*/
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    85
        if (result) return 0;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    86
    }
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    87
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    88
    /* Set the input format of the audio unit. */
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    89
    result = AudioUnitSetProperty (*inDestUnit,
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    90
                               kAudioUnitProperty_StreamFormat,
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    91
                               kAudioUnitScope_Input,
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    92
                               0,
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    93
                               &afp->mFileDescription,
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    94
                               sizeof (afp->mFileDescription));
1487
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
    95
        /*THROW_RESULT("AudioUnitSetProperty")*/
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    96
    if (result) return 0;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    97
    return 1;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    98
}
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    99
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   100
static void AudioFilePlayer_SetNotifier(AudioFilePlayer *afp, AudioFilePlayNotifier inNotifier, void *inRefCon)
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   101
{
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   102
    afp->mNotifier = inNotifier;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   103
    afp->mRefCon = inRefCon;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   104
}
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   105
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   106
static int AudioFilePlayer_IsConnected(AudioFilePlayer *afp)
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   107
{
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   108
    return afp->mConnected;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   109
}
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   110
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   111
static AudioUnit AudioFilePlayer_GetDestUnit(AudioFilePlayer *afp)
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   112
{
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   113
   return afp->mPlayUnit;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   114
}
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   115
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   116
static void AudioFilePlayer_Print(AudioFilePlayer *afp)
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   117
{
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   118
#if DEBUG    
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   119
    printf ("Is Connected:%s\n", (IsConnected() ? "true" : "false"));
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   120
    printf ("- - - - - - - - - - - - - - \n");
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   121
#endif
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   122
}
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   123
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   124
static void    AudioFilePlayer_SetStartFrame (AudioFilePlayer *afp, int frame)
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   125
{
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   126
    SInt64 position = frame * 2352;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   127
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   128
    afp->mStartFrame = frame;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   129
    afp->mAudioFileManager->SetPosition (afp->mAudioFileManager, position);
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   130
}
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   131
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   132
    
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   133
static int    AudioFilePlayer_GetCurrentFrame (AudioFilePlayer *afp)
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   134
{
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   135
    return afp->mStartFrame + (afp->mAudioFileManager->GetByteCounter(afp->mAudioFileManager) / 2352);
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   136
}
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   137
    
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   138
static void    AudioFilePlayer_SetStopFrame (AudioFilePlayer *afp, int frame)
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   139
{
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   140
    SInt64 position  = frame * 2352;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   141
    
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   142
    afp->mAudioFileManager->SetEndOfFile (afp->mAudioFileManager, position);
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   143
}
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   144
    
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   145
void delete_AudioFilePlayer(AudioFilePlayer *afp)
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   146
{
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   147
    if (afp != NULL)
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   148
    {
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   149
        afp->Disconnect(afp);
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   150
        
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   151
        if (afp->mAudioFileManager) {
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   152
            delete_AudioFileManager(afp->mAudioFileManager);
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   153
            afp->mAudioFileManager = 0;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   154
        }
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   155
    
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   156
        if (afp->mForkRefNum) {
1793
4d66375c2012 Date: Mon, 8 May 2006 14:19:30 -0700
Sam Lantinga <slouken@libsdl.org>
parents: 1487
diff changeset
   157
            FSCloseFork (afp->mForkRefNum);
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   158
            afp->mForkRefNum = 0;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   159
        }
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1143
diff changeset
   160
        SDL_free(afp);
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   161
    }
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   162
}
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   163
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   164
static int    AudioFilePlayer_Connect(AudioFilePlayer *afp)
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   165
{
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   166
#if DEBUG
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   167
    printf ("Connect:%x, engaged=%d\n", (int)afp->mPlayUnit, (afp->mConnected ? 1 : 0));
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   168
#endif
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   169
    if (!afp->mConnected)
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   170
    {           
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   171
        if (!afp->mAudioFileManager->DoConnect(afp->mAudioFileManager))
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   172
            return 0;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   173
1487
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   174
        /* set the render callback for the file data to be supplied to the sound converter AU */
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   175
        afp->mInputCallback.inputProc = afp->mAudioFileManager->FileInputProc;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   176
        afp->mInputCallback.inputProcRefCon = afp->mAudioFileManager;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   177
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   178
        OSStatus result = AudioUnitSetProperty (afp->mPlayUnit, 
4190
386181851388 Fixed CD-ROM code to work with Mac OS X 10.6 SDK and 64-bit targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   179
                            kAudioUnitProperty_SetRenderCallback,
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   180
                            kAudioUnitScope_Input, 
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   181
                            0,
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   182
                            &afp->mInputCallback, 
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   183
                            sizeof(afp->mInputCallback));
1487
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   184
        if (result) return 0;  /*THROW_RESULT("AudioUnitSetProperty")*/
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   185
        afp->mConnected = 1;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   186
    }
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   187
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   188
    return 1;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   189
}
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   190
1487
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   191
/* warning noted, now please go away ;-) */
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   192
/* #warning This should redirect the calling of notification code to some other thread */
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   193
static void    AudioFilePlayer_DoNotification (AudioFilePlayer *afp, OSStatus inStatus)
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   194
{
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   195
    if (afp->mNotifier) {
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   196
        (*afp->mNotifier) (afp->mRefCon, inStatus);
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   197
    } else {
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   198
        SDL_SetError ("Notification posted with no notifier in place");
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   199
        
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   200
        if (inStatus == kAudioFilePlay_FileIsFinished)
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   201
            afp->Disconnect(afp);
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   202
        else if (inStatus != kAudioFilePlayErr_FilePlayUnderrun)
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   203
            afp->Disconnect(afp);
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   204
    }
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   205
}
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   206
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   207
static void    AudioFilePlayer_Disconnect (AudioFilePlayer *afp)
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   208
{
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   209
#if DEBUG
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   210
    printf ("Disconnect:%x,%ld, engaged=%d\n", (int)afp->mPlayUnit, 0, (afp->mConnected ? 1 : 0));
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   211
#endif
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   212
    if (afp->mConnected)
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   213
    {
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   214
        afp->mConnected = 0;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   215
            
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   216
        afp->mInputCallback.inputProc = 0;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   217
        afp->mInputCallback.inputProcRefCon = 0;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   218
        OSStatus result = AudioUnitSetProperty (afp->mPlayUnit, 
4190
386181851388 Fixed CD-ROM code to work with Mac OS X 10.6 SDK and 64-bit targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   219
                                        kAudioUnitProperty_SetRenderCallback,
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   220
                                        kAudioUnitScope_Input, 
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   221
                                        0,
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   222
                                        &afp->mInputCallback, 
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   223
                                        sizeof(afp->mInputCallback));
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   224
        if (result) 
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   225
            SDL_SetError ("AudioUnitSetProperty:RemoveInputCallback:%ld", result);
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   226
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   227
        afp->mAudioFileManager->Disconnect(afp->mAudioFileManager);
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   228
    }
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   229
}
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   230
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   231
typedef struct {
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   232
    UInt32 offset;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   233
    UInt32 blockSize;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   234
} SSNDData;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   235
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   236
static int    AudioFilePlayer_OpenFile (AudioFilePlayer *afp, const FSRef *inRef, SInt64 *outFileDataSize)
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   237
{
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   238
    ContainerChunk chunkHeader;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   239
    ChunkHeader chunk;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   240
    SSNDData ssndData;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   241
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   242
    OSErr result;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   243
    HFSUniStr255 dfName;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   244
    ByteCount actual;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   245
    SInt64 offset;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   246
1487
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   247
    /* Open the data fork of the input file */
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   248
    result = FSGetDataForkName(&dfName);
1487
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   249
       if (result) return 0; /*THROW_RESULT("AudioFilePlayer::OpenFile(): FSGetDataForkName")*/
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   250
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   251
    result = FSOpenFork(inRef, dfName.length, dfName.unicode, fsRdPerm, &afp->mForkRefNum);
1487
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   252
       if (result) return 0; /*THROW_RESULT("AudioFilePlayer::OpenFile(): FSOpenFork")*/
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   253
 
1487
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   254
    /* Read the file header, and check if it's indeed an AIFC file */
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   255
    result = FSReadFork(afp->mForkRefNum, fsAtMark, 0, sizeof(chunkHeader), &chunkHeader, &actual);
1487
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   256
       if (result) return 0; /*THROW_RESULT("AudioFilePlayer::OpenFile(): FSReadFork")*/
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   257
4190
386181851388 Fixed CD-ROM code to work with Mac OS X 10.6 SDK and 64-bit targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   258
    if (SDL_SwapBE32(chunkHeader.ckID) != 'FORM') {
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   259
        result = -1;
1487
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   260
        if (result) return 0; /*THROW_RESULT("AudioFilePlayer::OpenFile(): chunk id is not 'FORM'");*/
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   261
    }
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   262
4190
386181851388 Fixed CD-ROM code to work with Mac OS X 10.6 SDK and 64-bit targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   263
    if (SDL_SwapBE32(chunkHeader.formType) != 'AIFC') {
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   264
        result = -1;
1487
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   265
        if (result) return 0; /*THROW_RESULT("AudioFilePlayer::OpenFile(): file format is not 'AIFC'");*/
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   266
    }
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   267
1487
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   268
    /* Search for the SSND chunk. We ignore all compression etc. information
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   269
       in other chunks. Of course that is kind of evil, but for now we are lazy
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   270
       and rely on the cdfs to always give us the same fixed format.
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   271
       TODO: Parse the COMM chunk we currently skip to fill in mFileDescription.
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   272
    */
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   273
    offset = 0;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   274
    do {
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   275
        result = FSReadFork(afp->mForkRefNum, fsFromMark, offset, sizeof(chunk), &chunk, &actual);
4190
386181851388 Fixed CD-ROM code to work with Mac OS X 10.6 SDK and 64-bit targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   276
        if (result) return 0; /*THROW_RESULT("AudioFilePlayer::OpenFile(): FSReadFork")*/
386181851388 Fixed CD-ROM code to work with Mac OS X 10.6 SDK and 64-bit targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   277
386181851388 Fixed CD-ROM code to work with Mac OS X 10.6 SDK and 64-bit targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   278
        chunk.ckID = SDL_SwapBE32(chunk.ckID);
386181851388 Fixed CD-ROM code to work with Mac OS X 10.6 SDK and 64-bit targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   279
        chunk.ckSize = SDL_SwapBE32(chunk.ckSize);
386181851388 Fixed CD-ROM code to work with Mac OS X 10.6 SDK and 64-bit targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   280
1487
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   281
        /* Skip the chunk data */
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   282
        offset = chunk.ckSize;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   283
    } while (chunk.ckID != 'SSND');
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   284
1487
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   285
    /* Read the header of the SSND chunk. After this, we are positioned right
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   286
       at the start of the audio data. */
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   287
    result = FSReadFork(afp->mForkRefNum, fsAtMark, 0, sizeof(ssndData), &ssndData, &actual);
4190
386181851388 Fixed CD-ROM code to work with Mac OS X 10.6 SDK and 64-bit targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   288
    if (result) return 0; /*THROW_RESULT("AudioFilePlayer::OpenFile(): FSReadFork")*/
386181851388 Fixed CD-ROM code to work with Mac OS X 10.6 SDK and 64-bit targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   289
386181851388 Fixed CD-ROM code to work with Mac OS X 10.6 SDK and 64-bit targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   290
    ssndData.offset = SDL_SwapBE32(ssndData.offset);
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   291
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   292
    result = FSSetForkPosition(afp->mForkRefNum, fsFromMark, ssndData.offset);
4190
386181851388 Fixed CD-ROM code to work with Mac OS X 10.6 SDK and 64-bit targets.
Ryan C. Gordon <icculus@icculus.org>
parents: 4159
diff changeset
   293
    if (result) return 0; /*THROW_RESULT("AudioFilePlayer::OpenFile(): FSSetForkPosition")*/
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   294
1487
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   295
    /* Data size */
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   296
    *outFileDataSize = chunk.ckSize - ssndData.offset - 8;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   297
1487
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   298
    /* File format */
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   299
    afp->mFileDescription.mSampleRate = 44100;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   300
    afp->mFileDescription.mFormatID = kAudioFormatLinearPCM;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   301
    afp->mFileDescription.mFormatFlags = kLinearPCMFormatFlagIsPacked | kLinearPCMFormatFlagIsSignedInteger;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   302
    afp->mFileDescription.mBytesPerPacket = 4;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   303
    afp->mFileDescription.mFramesPerPacket = 1;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   304
    afp->mFileDescription.mBytesPerFrame = 4;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   305
    afp->mFileDescription.mChannelsPerFrame = 2;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   306
    afp->mFileDescription.mBitsPerChannel = 16;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   307
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   308
    return 1;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   309
}
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   310
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   311
AudioFilePlayer *new_AudioFilePlayer (const FSRef *inFileRef)
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   312
{
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   313
    SInt64 fileDataSize  = 0;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   314
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1143
diff changeset
   315
    AudioFilePlayer *afp = (AudioFilePlayer *) SDL_malloc(sizeof (AudioFilePlayer));
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   316
    if (afp == NULL)
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   317
        return NULL;
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1143
diff changeset
   318
    SDL_memset(afp, '\0', sizeof (*afp));
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   319
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   320
    #define SET_AUDIOFILEPLAYER_METHOD(m) afp->m = AudioFilePlayer_##m
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   321
    SET_AUDIOFILEPLAYER_METHOD(SetDestination);
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   322
    SET_AUDIOFILEPLAYER_METHOD(SetNotifier);
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   323
    SET_AUDIOFILEPLAYER_METHOD(SetStartFrame);
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   324
    SET_AUDIOFILEPLAYER_METHOD(GetCurrentFrame);
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   325
    SET_AUDIOFILEPLAYER_METHOD(SetStopFrame);
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   326
    SET_AUDIOFILEPLAYER_METHOD(Connect);
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   327
    SET_AUDIOFILEPLAYER_METHOD(Disconnect);
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   328
    SET_AUDIOFILEPLAYER_METHOD(DoNotification);
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   329
    SET_AUDIOFILEPLAYER_METHOD(IsConnected);
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   330
    SET_AUDIOFILEPLAYER_METHOD(GetDestUnit);
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   331
    SET_AUDIOFILEPLAYER_METHOD(Print);
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   332
    SET_AUDIOFILEPLAYER_METHOD(OpenFile);
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   333
    #undef SET_AUDIOFILEPLAYER_METHOD
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   334
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   335
    if (!afp->OpenFile (afp, inFileRef, &fileDataSize))
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   336
    {
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1143
diff changeset
   337
        SDL_free(afp);
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   338
        return NULL;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   339
    }
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   340
        
1487
dc6b59e925a2 Cleaning up warnings on MacOS X
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
   341
    /* we want about 4 seconds worth of data for the buffer */
1143
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   342
    int bytesPerSecond = (UInt32) (4 * afp->mFileDescription.mSampleRate * afp->mFileDescription.mBytesPerFrame);
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   343
    
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   344
#if DEBUG
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   345
    printf("File format:\n");
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   346
    PrintStreamDesc (&afp->mFileDescription);
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   347
#endif
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   348
    
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   349
    afp->mAudioFileManager = new_AudioFileManager(afp, afp->mForkRefNum,
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   350
                                                  fileDataSize,
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   351
                                                  bytesPerSecond);
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   352
    if (afp->mAudioFileManager == NULL)
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   353
    {
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   354
        delete_AudioFilePlayer(afp);
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   355
        return NULL;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   356
    }
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   357
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   358
    return afp;
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   359
}
71a2648acc75 Replaced Mac OS X's C++ cdrom code with almost-direct translation to C. Sam
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   360