ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/MacOSX/audio_macosx.cpp
(Generate patch)

Comparing BasiliskII/src/MacOSX/audio_macosx.cpp (file contents):
Revision 1.1 by nigel, 2002-03-16T03:59:58Z vs.
Revision 1.6 by gbeauche, 2008-01-01T09:40:32Z

# Line 1 | Line 1
1   /*
2 < *  audio_MacOSX.cpp - Based on audio_dummy.cpp
2 > *  audio_macosx.cpp - Audio support, implementation Mac OS X
3 > *  Copyright (C) 2006, Daniel Sumorok
4   *
5 < *      $Id$
5 < *
6 < *  Basilisk II (C) 1997-2002 Christian Bauer
5 > *  Basilisk II (C) 1997-2008 Christian Bauer
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
# Line 21 | Line 20
20   */
21  
22   #include "sysdeps.h"
23 +
24 + #include <sys/ioctl.h>
25 + #include <unistd.h>
26 + #include <errno.h>
27 + #include <pthread.h>
28 + #include <semaphore.h>
29 +
30 + #include "cpu_emulation.h"
31 + #include "main.h"
32   #include "prefs.h"
33 + #include "user_strings.h"
34   #include "audio.h"
35   #include "audio_defs.h"
36 + #include "MacOSX_sound_if.h"
37  
38 < #define DEBUG 1
38 > #define DEBUG 0
39   #include "debug.h"
40  
41  
42 < #include "main_macosx.h"
43 <
44 < #import <CoreFoundation/CoreFoundation.h>
45 <
46 < #import <CoreAudio/CoreAudio.h>
47 <
48 <
49 <
50 < AudioDeviceID   device   = kAudioDeviceUnknown;
42 > // The currently selected audio parameters (indices in
43 > // audio_sample_rates[] etc. vectors)
44 > static int audio_sample_rate_index = 0;
45 > static int audio_sample_size_index = 0;
46 > static int audio_channel_count_index = 0;
47 >
48 > // Prototypes
49 > static OSXsoundOutput *soundOutput = NULL;
50 > static bool main_mute = false;
51 > static bool speaker_mute = false;
52  
53   /*
54   *  Initialization
55   */
56 + static int audioInt(void);
57  
58 < void AudioInit(void)
58 > static bool open_audio(void)
59   {
60 <        int     count;
60 >        AudioStatus.sample_rate = audio_sample_rates[audio_sample_rate_index];
61 >        AudioStatus.sample_size = audio_sample_sizes[audio_sample_size_index];
62 >        AudioStatus.channels = audio_channel_counts[audio_channel_count_index];
63  
64 <        // Init audio status and feature flags
65 <        AudioStatus.sample_rate = 44100 << 16;
52 <        AudioStatus.sample_size = 16;
53 <        AudioStatus.channels = 2;
54 <        AudioStatus.mixer = 0;
55 <        AudioStatus.num_sources = 0;
56 <        audio_component_flags = cmpWantsRegisterMessage | kStereoOut | k16BitOut;
64 >        if (soundOutput)
65 >                delete soundOutput;
66  
67 <        // Only one sample format is supported
68 <        audio_sample_rates.push_back(44100 << 16);
69 <        audio_sample_sizes.push_back(16);
70 <        audio_channel_counts.push_back(2);
67 >        soundOutput = new OSXsoundOutput();
68 >        soundOutput->start(AudioStatus.sample_size, AudioStatus.channels,
69 >                                           AudioStatus.sample_rate >> 16);
70 >        soundOutput->setCallback(audioInt);
71 >        audio_frames_per_block = soundOutput->bufferSizeFrames();
72 >
73 >        audio_open = true;
74 >        return true;
75 > }
76  
77 + void AudioInit(void)
78 + {
79          // Sound disabled in prefs? Then do nothing
80          if (PrefsFindBool("nosound"))
81                  return;
82  
83 +        //audio_sample_sizes.push_back(8);
84 +        audio_sample_sizes.push_back(16);
85  
86 <        // Get default audio device
86 >        audio_channel_counts.push_back(1);
87 >        audio_channel_counts.push_back(2);
88 >        
89 >        audio_sample_rates.push_back(11025 << 16);
90 >        audio_sample_rates.push_back(22050 << 16);
91 >        audio_sample_rates.push_back(44100 << 16);
92  
93 <        count = sizeof(device);
94 <        err = AudioHardwareGetProperty(kAudioHardwarePropertyDefaultOutputDevice,
95 <                                                                          &count, (void *) &device);
96 <        if ( err != noErr || device == kAudioDeviceUnknown )
74 <        {
75 <                NSLog(@"Failed to get default audio output device");
76 <                audio_open = false;
77 <                return;
78 <        }
93 >        // Default to highest supported values
94 >        audio_sample_rate_index   = audio_sample_rates.size() - 1;
95 >        audio_sample_size_index   = audio_sample_sizes.size() - 1;
96 >        audio_channel_count_index = audio_channel_counts.size() - 1;
97  
98 +        AudioStatus.mixer = 0;
99 +        AudioStatus.num_sources = 0;
100 +        audio_component_flags = cmpWantsRegisterMessage | kStereoOut | k16BitOut;
101 +        audio_component_flags = 0;
102  
103 <        // Audio not available
82 <        audio_open = false;
103 >        open_audio();
104   }
105  
106  
# Line 87 | Line 108 | void AudioInit(void)
108   *  Deinitialization
109   */
110  
111 + static void close_audio(void)
112 + {
113 +        D(bug("Closing Audio\n"));
114 +
115 +        if (soundOutput)
116 +        {
117 +                delete soundOutput;
118 +                soundOutput = NULL;
119 +        }
120 +        
121 +        audio_open = false;
122 + }
123 +
124   void AudioExit(void)
125   {
126 +        // Close audio device
127 +        close_audio();
128   }
129  
130  
# Line 98 | Line 134 | void AudioExit(void)
134  
135   void audio_enter_stream()
136   {
137 +        // Streaming thread is always running to avoid clicking noises
138   }
139  
140  
# Line 107 | Line 144 | void audio_enter_stream()
144  
145   void audio_exit_stream()
146   {
147 +        // Streaming thread is always running to avoid clicking noises
148   }
149  
150  
# Line 117 | Line 155 | void audio_exit_stream()
155   void AudioInterrupt(void)
156   {
157          D(bug("AudioInterrupt\n"));
158 +        uint32 apple_stream_info;
159 +        uint32 numSamples;
160 +        int16 *p;
161 +        M68kRegisters r;
162 +
163 +        if (!AudioStatus.mixer)
164 +        {
165 +                numSamples = 0;
166 +                soundOutput->sendAudioBuffer((void *)p, (int)numSamples);
167 +                D(bug("AudioInterrupt done\n"));
168 +                return;
169 +        }
170 +
171 +        // Get data from apple mixer
172 +        r.a[0] = audio_data + adatStreamInfo;
173 +        r.a[1] = AudioStatus.mixer;
174 +        Execute68k(audio_data + adatGetSourceData, &r);
175 +        D(bug(" GetSourceData() returns %08lx\n", r.d[0]));
176 +
177 +        apple_stream_info = ReadMacInt32(audio_data + adatStreamInfo);
178 +        if (apple_stream_info && (main_mute == false) && (speaker_mute == false))
179 +        {
180 +                numSamples = ReadMacInt32(apple_stream_info + scd_sampleCount);
181 +                p = (int16 *)Mac2HostAddr(ReadMacInt32(apple_stream_info + scd_buffer));
182 +        }
183 +        else
184 +        {
185 +                numSamples = 0;
186 +                p = NULL;
187 +        }
188 +
189 +        soundOutput->sendAudioBuffer((void *)p, (int)numSamples);
190 +
191 +        D(bug("AudioInterrupt done\n"));
192   }
193  
194  
# Line 128 | Line 200 | void AudioInterrupt(void)
200  
201   bool audio_set_sample_rate(int index)
202   {
203 +        close_audio();
204 +        audio_sample_rate_index = index;
205 +        return open_audio();
206   }
207  
208   bool audio_set_sample_size(int index)
209   {
210 +        close_audio();
211 +        audio_sample_size_index = index;
212 +        return open_audio();
213   }
214  
215   bool audio_set_channels(int index)
216   {
217 +        close_audio();
218 +        audio_channel_count_index = index;
219 +        return open_audio();
220   }
221  
141
222   /*
223 < *  Get/set volume controls (volume values received/returned have the left channel
224 < *  volume in the upper 16 bits and the right channel volume in the lower 16 bits;
225 < *  both volumes are 8.8 fixed point values with 0x0100 meaning "maximum volume"))
223 > *  Get/set volume controls (volume values received/returned have the
224 > *  left channel volume in the upper 16 bits and the right channel
225 > *  volume in the lower 16 bits; both volumes are 8.8 fixed point
226 > *  values with 0x0100 meaning "maximum volume"))
227   */
147
228   bool audio_get_main_mute(void)
229   {
230 <        return false;
230 >        return main_mute;
231   }
232  
233   uint32 audio_get_main_volume(void)
# Line 157 | Line 237 | uint32 audio_get_main_volume(void)
237  
238   bool audio_get_speaker_mute(void)
239   {
240 <        return false;
240 >        return speaker_mute;
241   }
242  
243   uint32 audio_get_speaker_volume(void)
# Line 167 | Line 247 | uint32 audio_get_speaker_volume(void)
247  
248   void audio_set_main_mute(bool mute)
249   {
250 +        main_mute = mute;
251   }
252  
253   void audio_set_main_volume(uint32 vol)
# Line 175 | Line 256 | void audio_set_main_volume(uint32 vol)
256  
257   void audio_set_speaker_mute(bool mute)
258   {
259 +        speaker_mute = mute;
260   }
261  
262   void audio_set_speaker_volume(uint32 vol)
263   {
264   }
265 +
266 + static int audioInt(void)
267 + {
268 +        SetInterruptFlag(INTFLAG_AUDIO);
269 +        TriggerInterrupt();
270 +        return 0;
271 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines