src/cdrom/macosx/AudioFilePlayer.h
author Sam Lantinga <slouken@libsdl.org>
Sun, 28 May 2006 13:04:16 +0000
branchSDL-1.3
changeset 1662 782fd950bd46
parent 1487 dc6b59e925a2
child 1668 4da1ee79c9af
permissions -rw-r--r--
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.

WARNING: None of the video drivers have been updated for the new API yet! The API is still under design and very fluid.

The code is now run through a consistent indent format:
indent -i4 -nut -nsc -br -ce

The headers are being converted to automatically generate doxygen documentation.
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@613
    36
slouken@653
    37
#include "SDL_error.h"
slouken@613
    38
slouken@1662
    39
const char *AudioFilePlayerErrorStr (OSStatus error);
slouken@613
    40
icculus@1143
    41
/*
slouken@613
    42
void ThrowResult (OSStatus result, const char *str);
slouken@613
    43
slouken@613
    44
#define THROW_RESULT(str)                                       \
slouken@613
    45
    if (result) {                                               \
slouken@613
    46
        ThrowResult (result, str);                              \
slouken@613
    47
    }
icculus@1143
    48
*/
slouken@613
    49
slouken@1662
    50
typedef void (*AudioFilePlayNotifier) (void *inRefCon, OSStatus inStatus);
slouken@613
    51
slouken@1662
    52
enum
slouken@1662
    53
{
slouken@613
    54
    kAudioFilePlayErr_FilePlayUnderrun = -10000,
slouken@613
    55
    kAudioFilePlay_FileIsFinished = -10001,
slouken@613
    56
    kAudioFilePlay_PlayerIsUninitialized = -10002
slouken@613
    57
};
slouken@613
    58
slouken@613
    59
icculus@1143
    60
struct S_AudioFileManager;
slouken@613
    61
slouken@613
    62
#pragma mark __________ AudioFilePlayer
icculus@1143
    63
typedef struct S_AudioFilePlayer
slouken@613
    64
{
slouken@1487
    65
/*public:*/
slouken@1662
    66
    int (*SetDestination) (struct S_AudioFilePlayer * afp,
slouken@1662
    67
                           AudioUnit * inDestUnit);
slouken@1662
    68
    void (*SetNotifier) (struct S_AudioFilePlayer * afp,
slouken@1662
    69
                         AudioFilePlayNotifier inNotifier, void *inRefCon);
slouken@1662
    70
    void (*SetStartFrame) (struct S_AudioFilePlayer * afp, int frame);  /* seek in the file */
slouken@1662
    71
    int (*GetCurrentFrame) (struct S_AudioFilePlayer * afp);    /* get the current frame position */
slouken@1662
    72
    void (*SetStopFrame) (struct S_AudioFilePlayer * afp, int frame);   /* set limit in the file */
slouken@1662
    73
    int (*Connect) (struct S_AudioFilePlayer * afp);
slouken@1662
    74
    void (*Disconnect) (struct S_AudioFilePlayer * afp);
slouken@1662
    75
    void (*DoNotification) (struct S_AudioFilePlayer * afp, OSStatus inError);
slouken@1662
    76
    int (*IsConnected) (struct S_AudioFilePlayer * afp);
slouken@1662
    77
      AudioUnit (*GetDestUnit) (struct S_AudioFilePlayer * afp);
slouken@1662
    78
    void (*Print) (struct S_AudioFilePlayer * afp);
slouken@613
    79
slouken@1487
    80
/*private:*/
slouken@1662
    81
    AudioUnit mPlayUnit;
slouken@1662
    82
    SInt16 mForkRefNum;
slouken@613
    83
slouken@1662
    84
    AudioUnitInputCallback mInputCallback;
slouken@1662
    85
slouken@1662
    86
    AudioStreamBasicDescription mFileDescription;
slouken@1662
    87
slouken@1662
    88
    int mConnected;
slouken@1662
    89
slouken@1662
    90
    struct S_AudioFileManager *mAudioFileManager;
slouken@1662
    91
slouken@1662
    92
    AudioFilePlayNotifier mNotifier;
slouken@1662
    93
    void *mRefCon;
slouken@1662
    94
slouken@1662
    95
    int mStartFrame;
slouken@1662
    96
slouken@613
    97
#pragma mark __________ Private_Methods
slouken@1662
    98
slouken@1662
    99
    int (*OpenFile) (struct S_AudioFilePlayer * afp, const FSRef * inRef,
slouken@1662
   100
                     SInt64 * outFileSize);
icculus@1143
   101
} AudioFilePlayer;
icculus@1143
   102
icculus@1143
   103
slouken@1662
   104
AudioFilePlayer *new_AudioFilePlayer (const FSRef * inFileRef);
slouken@1662
   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@1662
   113
    /* this method should NOT be called by an object of this class
slouken@1662
   114
       as it is called by the parent's Disconnect() method */
slouken@1662
   115
    void (*Disconnect) (struct S_AudioFileManager * afm);
slouken@1662
   116
    int (*DoConnect) (struct S_AudioFileManager * afm);
slouken@1662
   117
      OSStatus (*Read) (struct S_AudioFileManager * afm, char *buffer,
slouken@1662
   118
                        UInt32 * len);
slouken@1662
   119
    const char *(*GetFileBuffer) (struct S_AudioFileManager * afm);
slouken@1662
   120
    const AudioFilePlayer *(*GetParent) (struct S_AudioFileManager * afm);
slouken@1662
   121
    void (*SetPosition) (struct S_AudioFileManager * afm, SInt64 pos);  /* seek/rewind in the file */
slouken@1662
   122
    int (*GetByteCounter) (struct S_AudioFileManager * afm);    /* return actual bytes streamed to audio hardware */
slouken@1662
   123
    void (*SetEndOfFile) (struct S_AudioFileManager * afm, SInt64 pos); /* set the "EOF" (will behave just like it reached eof) */
slouken@768
   124
slouken@1487
   125
/*protected:*/
slouken@1662
   126
    AudioFilePlayer *mParent;
slouken@1662
   127
    SInt16 mForkRefNum;
slouken@1662
   128
    SInt64 mAudioDataOffset;
slouken@1662
   129
slouken@1662
   130
    char *mFileBuffer;
slouken@1662
   131
slouken@1662
   132
    int mByteCounter;
slouken@1662
   133
slouken@1662
   134
    int mReadFromFirstBuffer;
slouken@1662
   135
    int mLockUnsuccessful;
slouken@1662
   136
    int mIsEngaged;
slouken@1662
   137
slouken@1662
   138
    int mNumTimesAskedSinceFinished;
slouken@1662
   139
slouken@1662
   140
slouken@1662
   141
    void *mTmpBuffer;
slouken@1662
   142
    UInt32 mBufferSize;
slouken@1662
   143
    UInt32 mBufferOffset;
slouken@1662
   144
/*public:*/
slouken@1662
   145
    UInt32 mChunkSize;
slouken@1662
   146
    SInt64 mFileLength;
slouken@1662
   147
    SInt64 mReadFilePosition;
slouken@1662
   148
    int mWriteToFirstBuffer;
slouken@1662
   149
    int mFinishedReadingData;
slouken@1662
   150
slouken@1662
   151
/*protected:*/
slouken@1662
   152
      OSStatus (*Render) (struct S_AudioFileManager * afm,
slouken@1662
   153
                          AudioBuffer * ioData);
slouken@1662
   154
      OSStatus (*GetFileData) (struct S_AudioFileManager * afm,
slouken@1662
   155
                               void **inOutData, UInt32 * inOutDataSize);
slouken@1662
   156
    void (*AfterRender) (struct S_AudioFileManager * afm);
icculus@1143
   157
slouken@1487
   158
/*public:*/
slouken@1662
   159
    /*static */
slouken@1662
   160
      OSStatus (*FileInputProc) (void *inRefCon,
slouken@1662
   161
                                 AudioUnitRenderActionFlags inActionFlags,
slouken@1662
   162
                                 const AudioTimeStamp * inTimeStamp,
slouken@1662
   163
                                 UInt32 inBusNumber, AudioBuffer * ioData);
icculus@1143
   164
} AudioFileManager;
icculus@1143
   165
icculus@1143
   166
slouken@1662
   167
AudioFileManager *new_AudioFileManager (AudioFilePlayer * inParent,
slouken@1662
   168
                                        SInt16 inForkRefNum,
slouken@1662
   169
                                        SInt64 inFileLength,
slouken@1662
   170
                                        UInt32 inChunkSize);
slouken@1662
   171
slouken@1662
   172
void delete_AudioFileManager (AudioFileManager * afm);
slouken@613
   173
slouken@613
   174
#endif
slouken@1662
   175
/* vi: set ts=4 sw=4 expandtab: */