ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/MacOSX/MacOSX_sound_if.cpp
Revision: 1.1
Committed: 2006-07-28T13:42:29Z (18 years, 4 months ago) by nigel
Branch: MAIN
CVS Tags: nigel-build-19, HEAD
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

# User Rev Content
1 nigel 1.1 /*
2     * MacOSX_sound_if.h
3     * BasiliskII
4     *
5     * Copyright 2006 Daniel Sumorok. All rights reserved.
6     *
7     * This program is free software; you can redistribute it and/or modify
8     * it under the terms of the GNU General Public License as published by
9     * the Free Software Foundation; either version 2 of the License, or
10     * (at your option) any later version.
11     *
12     * This program is distributed in the hope that it will be useful,
13     * but WITHOUT ANY WARRANTY; without even the implied warranty of
14     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15     * GNU General Public License for more details.
16     *
17     * You should have received a copy of the GNU General Public License
18     * along with this program; if not, write to the Free Software
19     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20     */
21     #include "AudioBackEnd.h"
22     #include "MacOSX_sound_if.h"
23    
24     OSXsoundOutput::OSXsoundOutput() :
25     player(NULL),
26     callback(NULL) {
27     }
28    
29     void OSXsoundOutput::getMoreSamples(void *arg) {
30     OSXsoundOutput *me;
31    
32     me = (OSXsoundOutput *)arg;
33    
34     if(me == NULL) {
35     return;
36     }
37    
38     if(me->callback == NULL) {
39     return;
40     }
41    
42     me->callback();
43     }
44    
45     int OSXsoundOutput::start(int bitsPerSample, int numChannels, int sampleRate) {
46     stop();
47     player = new AudioBackEnd(bitsPerSample, numChannels, sampleRate);
48     if(player != NULL) {
49     player->setCallback(getMoreSamples, (void *)this);
50     player->Start();
51     }
52     return 0;
53     }
54    
55     int OSXsoundOutput::stop() {
56     if(player != NULL) {
57     player->Stop();
58     delete player;
59     player = NULL;
60     }
61     return 0;
62     }
63    
64     OSXsoundOutput::~OSXsoundOutput() {
65     stop();
66     }
67    
68     void OSXsoundOutput::setCallback(audioCallback fn) {
69     callback = fn;
70     }
71    
72     unsigned int OSXsoundOutput::bufferSizeFrames() {
73     if(player != NULL) {
74     return player->BufferSizeFrames();
75     }
76    
77     return 0;
78     }
79    
80     int OSXsoundOutput::sendAudioBuffer(void *buffer, int numFrames) {
81     if(player != NULL) {
82     return player->sendAudioBuffer(buffer, numFrames);
83     }
84    
85     return 0;
86     }