ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/MacOSX/AudioBackEnd.h
Revision: 1.1
Committed: 2006-07-28T13:15:18Z (18 years, 3 months ago) by nigel
Content type: text/plain
Branch: MAIN
CVS Tags: nigel-build-19, HEAD
Error occurred while calculating annotation data.
Log Message:
Working audio output by Daniel Sumorok.
Not quite the way I wanted to do it but it will do for now.
(on a real Mac, the real audio hardware should be able to pull/grab the data
 from our buffers - an extra thread with its own set of buffers is wasteful!)

File Contents

# Content
1 /*
2 *
3 * This is based on Apple example software AudioBackEnd.cpp
4 *
5 * Copyright © 2004 Apple Computer, Inc., All Rights Reserved
6 * Original Apple code modified by Daniel Sumorok
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22
23 #ifndef __AudioBackEnd_H__
24 #define __AudioBackEnd_H__
25
26 #define checkErr( err) \
27 if(err) {\
28 OSStatus error = static_cast<OSStatus>(err);\
29 fprintf(stderr, "AudioBackEnd Error: %ld -> %s: %d\n", error,\
30 __FILE__, \
31 __LINE__\
32 );\
33 fflush(stdout);\
34 }
35
36 #include <CoreAudio/CoreAudio.h>
37 #include <AudioToolbox/AudioToolbox.h>
38 #include <AudioUnit/AudioUnit.h>
39 #include <pthread.h>
40 #include "AudioDevice.h"
41
42 typedef void (*playthruCallback)(void *arg);
43
44 class AudioBackEnd {
45 public:
46 AudioBackEnd(int bitsPerSample, int numChannels, int sampleRate);
47 ~AudioBackEnd();
48 OSStatus Init();
49 OSStatus Start();
50 OSStatus Stop();
51 Boolean IsRunning();
52 void setCallback(playthruCallback func, void *arg);
53 UInt32 BufferSizeFrames();
54 int sendAudioBuffer(void *buffer, int numFrames);
55 private:
56 OSStatus SetupGraph();
57 OSStatus CallbackSetup();
58 OSStatus SetupBuffers();
59
60 static OSStatus OutputProc(void *inRefCon,
61 AudioUnitRenderActionFlags *ioActionFlags,
62 const AudioTimeStamp *inTimeStamp,
63 UInt32 inBusNumber,
64 UInt32 inNumberFrames,
65 AudioBufferList * ioData);
66
67 AudioDevice mOutputDevice;
68
69 AUGraph mGraph;
70 AUNode mOutputNode;
71 AudioUnit mOutputUnit;
72 int mBitsPerSample;
73 int mSampleRate;
74 int mNumChannels;
75 playthruCallback mCallback;
76 void *mCallbackArg;
77 UInt32 mBufferSizeFrames;
78 UInt32 mFramesProcessed;
79 UInt8 *mAudioBuffer;
80 UInt32 mAudioBufferWriteIndex;
81 UInt32 mAudioBufferReadIndex;
82 UInt32 mBytesPerFrame;
83 UInt32 mAudioBufferSize;
84 };
85
86 #endif //__AudioBackEnd_H__