src/cdrom/macosx/AudioFilePlayer.h
author Sam Lantinga <slouken@libsdl.org>
Fri, 28 Dec 2007 18:15:43 +0000
branchSDL-1.2
changeset 4103 9df8136abec0
parent 1487 dc6b59e925a2
child 4159 a1b03ba2fcd0
permissions -rw-r--r--
Date: Wed, 14 Nov 2007 22:20:27 -0500
From: Calvin Vette
Subject: Fix to compile SDL-1.2 SVN on OS X Leopard

I found I needed to add a conditional check for Leopard to compile
cleanly on 1.2-SVN (20071114):

#include <AudioUnit/AudioUnit.h>
#ifdef AVAILABLE_MAC_OS_X_VERSION_10_5_AND_LATER
#include <AudioUnit/AUNTComponent.h>
#endif

where there is now just:
#include <AudioUnit/AudioUnit.h>
slouken@613
     1
/*
slouken@613
     2
    SDL - Simple DirectMedia Layer
slouken@769
     3
    Copyright (C) 1997-2004 Sam Lantinga
slouken@613
     4
slouken@613
     5
    This library is free software; you can redistribute it and/or
slouken@613
     6
    modify it under the terms of the GNU Library General Public
slouken@613
     7
    License as published by the Free Software Foundation; either
slouken@613
     8
    version 2 of the License, or (at your option) any later version.
slouken@613
     9
slouken@613
    10
    This library is distributed in the hope that it will be useful,
slouken@613
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@613
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@613
    13
    Library General Public License for more details.
slouken@613
    14
slouken@613
    15
    You should have received a copy of the GNU Library General Public
slouken@613
    16
    License along with this library; if not, write to the Free
slouken@613
    17
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
slouken@613
    18
slouken@613
    19
    Sam Lantinga
slouken@613
    20
    slouken@libsdl.org
slouken@613
    21
slouken@613
    22
    This file based on Apple sample code. We haven't changed the file name, 
slouken@613
    23
    so if you want to see the original search for it on apple.com/developer
slouken@613
    24
*/
slouken@1402
    25
#include "SDL_config.h"
slouken@613
    26
slouken@1487
    27
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
slouken@1487
    28
    AudioFilePlayer.h
slouken@1487
    29
*/
slouken@613
    30
#ifndef __AudioFilePlayer_H__
slouken@613
    31
#define __AudioFilePlayer_H__
slouken@613
    32
slouken@613
    33
#include <CoreServices/CoreServices.h>
slouken@613
    34
slouken@613
    35
#include <AudioUnit/AudioUnit.h>
slouken@4103
    36
#ifdef AVAILABLE_MAC_OS_X_VERSION_10_5_AND_LATER
slouken@4103
    37
#include <AudioUnit/AUNTComponent.h>
slouken@4103
    38
#endif
slouken@613
    39
slouken@653
    40
#include "SDL_error.h"
slouken@613
    41
slouken@613
    42
const char* AudioFilePlayerErrorStr (OSStatus error);
slouken@613
    43
icculus@1143
    44
/*
slouken@613
    45
void ThrowResult (OSStatus result, const char *str);
slouken@613
    46
slouken@613
    47
#define THROW_RESULT(str)                                       \
slouken@613
    48
    if (result) {                                               \
slouken@613
    49
        ThrowResult (result, str);                              \
slouken@613
    50
    }
icculus@1143
    51
*/
slouken@613
    52
slouken@613
    53
typedef void (*AudioFilePlayNotifier)(void          *inRefCon,
slouken@613
    54
                                    OSStatus        inStatus);
slouken@613
    55
slouken@613
    56
enum {
slouken@613
    57
    kAudioFilePlayErr_FilePlayUnderrun = -10000,
slouken@613
    58
    kAudioFilePlay_FileIsFinished = -10001,
slouken@613
    59
    kAudioFilePlay_PlayerIsUninitialized = -10002
slouken@613
    60
};
slouken@613
    61
slouken@613
    62
icculus@1143
    63
struct S_AudioFileManager;
slouken@613
    64
slouken@613
    65
#pragma mark __________ AudioFilePlayer
icculus@1143
    66
typedef struct S_AudioFilePlayer
slouken@613
    67
{
slouken@1487
    68
/*public:*/
icculus@1143
    69
    int             (*SetDestination)(struct S_AudioFilePlayer *afp, AudioUnit *inDestUnit);
icculus@1143
    70
    void            (*SetNotifier)(struct S_AudioFilePlayer *afp, AudioFilePlayNotifier inNotifier, void *inRefCon);
slouken@1487
    71
    void            (*SetStartFrame)(struct S_AudioFilePlayer *afp, int frame); /* seek in the file */
slouken@1487
    72
    int             (*GetCurrentFrame)(struct S_AudioFilePlayer *afp); /* get the current frame position */
slouken@1487
    73
    void            (*SetStopFrame)(struct S_AudioFilePlayer *afp, int frame);   /* set limit in the file */
icculus@1143
    74
    int             (*Connect)(struct S_AudioFilePlayer *afp);
icculus@1143
    75
    void            (*Disconnect)(struct S_AudioFilePlayer *afp);
icculus@1143
    76
    void            (*DoNotification)(struct S_AudioFilePlayer *afp, OSStatus inError);
icculus@1143
    77
    int             (*IsConnected)(struct S_AudioFilePlayer *afp);
icculus@1143
    78
    AudioUnit       (*GetDestUnit)(struct S_AudioFilePlayer *afp);
icculus@1143
    79
    void            (*Print)(struct S_AudioFilePlayer *afp);
slouken@613
    80
slouken@1487
    81
/*private:*/
slouken@613
    82
    AudioUnit                       mPlayUnit;
slouken@768
    83
    SInt16                          mForkRefNum;
slouken@613
    84
    
slouken@613
    85
    AudioUnitInputCallback          mInputCallback;
slouken@613
    86
slouken@613
    87
    AudioStreamBasicDescription     mFileDescription;
slouken@613
    88
    
icculus@1143
    89
    int                             mConnected;
slouken@613
    90
    
icculus@1143
    91
    struct S_AudioFileManager*      mAudioFileManager;
slouken@613
    92
    
slouken@613
    93
    AudioFilePlayNotifier           mNotifier;
slouken@613
    94
    void*                           mRefCon;
slouken@613
    95
    
slouken@613
    96
    int                             mStartFrame;
slouken@613
    97
    
slouken@613
    98
#pragma mark __________ Private_Methods
slouken@613
    99
    
icculus@1143
   100
    int          (*OpenFile)(struct S_AudioFilePlayer *afp, const FSRef *inRef, SInt64 *outFileSize);
icculus@1143
   101
} AudioFilePlayer;
icculus@1143
   102
icculus@1143
   103
icculus@1143
   104
AudioFilePlayer *new_AudioFilePlayer(const FSRef    *inFileRef);
icculus@1143
   105
void delete_AudioFilePlayer(AudioFilePlayer *afp);
icculus@1143
   106
icculus@1143
   107
slouken@613
   108
slouken@613
   109
#pragma mark __________ AudioFileManager
icculus@1143
   110
typedef struct S_AudioFileManager
slouken@613
   111
{
slouken@1487
   112
/*public:*/
slouken@1487
   113
        /* this method should NOT be called by an object of this class
slouken@1487
   114
           as it is called by the parent's Disconnect() method */
icculus@1143
   115
    void                (*Disconnect)(struct S_AudioFileManager *afm);
icculus@1143
   116
    int                 (*DoConnect)(struct S_AudioFileManager *afm);
icculus@1143
   117
    OSStatus            (*Read)(struct S_AudioFileManager *afm, char *buffer, UInt32 *len);
icculus@1143
   118
    const char*         (*GetFileBuffer)(struct S_AudioFileManager *afm);
icculus@1143
   119
    const AudioFilePlayer *(*GetParent)(struct S_AudioFileManager *afm);
slouken@1487
   120
    void                (*SetPosition)(struct S_AudioFileManager *afm, SInt64 pos);  /* seek/rewind in the file */
slouken@1487
   121
    int                 (*GetByteCounter)(struct S_AudioFileManager *afm);  /* return actual bytes streamed to audio hardware */
slouken@1487
   122
    void                (*SetEndOfFile)(struct S_AudioFileManager *afm, SInt64 pos);  /* set the "EOF" (will behave just like it reached eof) */
slouken@613
   123
   
slouken@1487
   124
/*protected:*/
icculus@1143
   125
    AudioFilePlayer*    mParent;
slouken@768
   126
    SInt16              mForkRefNum;
slouken@768
   127
    SInt64              mAudioDataOffset;
slouken@613
   128
    
slouken@768
   129
    char*               mFileBuffer;
slouken@613
   130
slouken@768
   131
    int                 mByteCounter;
slouken@768
   132
icculus@1143
   133
    int                mReadFromFirstBuffer;
icculus@1143
   134
    int                mLockUnsuccessful;
icculus@1143
   135
    int                mIsEngaged;
slouken@768
   136
    
slouken@768
   137
    int                 mNumTimesAskedSinceFinished;
slouken@768
   138
slouken@935
   139
slouken@935
   140
	void*               mTmpBuffer;
slouken@935
   141
	UInt32              mBufferSize;
slouken@935
   142
	UInt32              mBufferOffset;
slouken@1487
   143
/*public:*/
icculus@1143
   144
    UInt32              mChunkSize;
slouken@768
   145
    SInt64              mFileLength;
slouken@768
   146
    SInt64              mReadFilePosition;
icculus@1143
   147
    int                 mWriteToFirstBuffer;
icculus@1143
   148
    int                 mFinishedReadingData;
slouken@768
   149
slouken@1487
   150
/*protected:*/
icculus@1143
   151
    OSStatus            (*Render)(struct S_AudioFileManager *afm, AudioBuffer *ioData);
icculus@1143
   152
    OSStatus            (*GetFileData)(struct S_AudioFileManager *afm, void** inOutData, UInt32 *inOutDataSize);
icculus@1143
   153
    void                (*AfterRender)(struct S_AudioFileManager *afm);
icculus@1143
   154
slouken@1487
   155
/*public:*/
slouken@1487
   156
    /*static*/
icculus@1143
   157
    OSStatus            (*FileInputProc)(void                             *inRefCon,
icculus@1143
   158
                                         AudioUnitRenderActionFlags      inActionFlags,
icculus@1143
   159
                                         const AudioTimeStamp            *inTimeStamp,
icculus@1143
   160
                                         UInt32                          inBusNumber,
icculus@1143
   161
                                         AudioBuffer                     *ioData);
icculus@1143
   162
} AudioFileManager;
icculus@1143
   163
icculus@1143
   164
icculus@1143
   165
AudioFileManager *new_AudioFileManager (AudioFilePlayer *inParent,
icculus@1143
   166
                      SInt16          inForkRefNum, 
icculus@1143
   167
                      SInt64          inFileLength,
icculus@1143
   168
                      UInt32          inChunkSize);
slouken@613
   169
    
icculus@1143
   170
void delete_AudioFileManager(AudioFileManager *afm);
slouken@613
   171
slouken@613
   172
#endif
icculus@1143
   173