mirror of https://github.com/xemu-project/xemu.git
coreaudio: do not use global variables where possible
Signed-off-by: Kővágó, Zoltán <DirtY.iCE.hu@gmail.com> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
This commit is contained in:
parent
191e1f0acd
commit
d1f52a1d70
|
@ -32,20 +32,16 @@
|
||||||
#define AUDIO_CAP "coreaudio"
|
#define AUDIO_CAP "coreaudio"
|
||||||
#include "audio_int.h"
|
#include "audio_int.h"
|
||||||
|
|
||||||
struct {
|
static int isAtexit;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
int buffer_frames;
|
int buffer_frames;
|
||||||
int nbuffers;
|
int nbuffers;
|
||||||
int isAtexit;
|
} CoreaudioConf;
|
||||||
} conf = {
|
|
||||||
.buffer_frames = 512,
|
|
||||||
.nbuffers = 4,
|
|
||||||
.isAtexit = 0
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef struct coreaudioVoiceOut {
|
typedef struct coreaudioVoiceOut {
|
||||||
HWVoiceOut hw;
|
HWVoiceOut hw;
|
||||||
pthread_mutex_t mutex;
|
pthread_mutex_t mutex;
|
||||||
int isAtexit;
|
|
||||||
AudioDeviceID outputDeviceID;
|
AudioDeviceID outputDeviceID;
|
||||||
UInt32 audioDevicePropertyBufferFrameSize;
|
UInt32 audioDevicePropertyBufferFrameSize;
|
||||||
AudioStreamBasicDescription outputStreamBasicDescription;
|
AudioStreamBasicDescription outputStreamBasicDescription;
|
||||||
|
@ -161,7 +157,7 @@ static inline UInt32 isPlaying (AudioDeviceID outputDeviceID)
|
||||||
|
|
||||||
static void coreaudio_atexit (void)
|
static void coreaudio_atexit (void)
|
||||||
{
|
{
|
||||||
conf.isAtexit = 1;
|
isAtexit = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int coreaudio_lock (coreaudioVoiceOut *core, const char *fn_name)
|
static int coreaudio_lock (coreaudioVoiceOut *core, const char *fn_name)
|
||||||
|
@ -296,6 +292,7 @@ static int coreaudio_init_out(HWVoiceOut *hw, struct audsettings *as,
|
||||||
int err;
|
int err;
|
||||||
const char *typ = "playback";
|
const char *typ = "playback";
|
||||||
AudioValueRange frameRange;
|
AudioValueRange frameRange;
|
||||||
|
CoreaudioConf *conf = drv_opaque;
|
||||||
|
|
||||||
/* create mutex */
|
/* create mutex */
|
||||||
err = pthread_mutex_init(&core->mutex, NULL);
|
err = pthread_mutex_init(&core->mutex, NULL);
|
||||||
|
@ -337,16 +334,16 @@ static int coreaudio_init_out(HWVoiceOut *hw, struct audsettings *as,
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (frameRange.mMinimum > conf.buffer_frames) {
|
if (frameRange.mMinimum > conf->buffer_frames) {
|
||||||
core->audioDevicePropertyBufferFrameSize = (UInt32) frameRange.mMinimum;
|
core->audioDevicePropertyBufferFrameSize = (UInt32) frameRange.mMinimum;
|
||||||
dolog ("warning: Upsizing Buffer Frames to %f\n", frameRange.mMinimum);
|
dolog ("warning: Upsizing Buffer Frames to %f\n", frameRange.mMinimum);
|
||||||
}
|
}
|
||||||
else if (frameRange.mMaximum < conf.buffer_frames) {
|
else if (frameRange.mMaximum < conf->buffer_frames) {
|
||||||
core->audioDevicePropertyBufferFrameSize = (UInt32) frameRange.mMaximum;
|
core->audioDevicePropertyBufferFrameSize = (UInt32) frameRange.mMaximum;
|
||||||
dolog ("warning: Downsizing Buffer Frames to %f\n", frameRange.mMaximum);
|
dolog ("warning: Downsizing Buffer Frames to %f\n", frameRange.mMaximum);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
core->audioDevicePropertyBufferFrameSize = conf.buffer_frames;
|
core->audioDevicePropertyBufferFrameSize = conf->buffer_frames;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* set Buffer Frame Size */
|
/* set Buffer Frame Size */
|
||||||
|
@ -380,7 +377,7 @@ static int coreaudio_init_out(HWVoiceOut *hw, struct audsettings *as,
|
||||||
"Could not get device buffer frame size\n");
|
"Could not get device buffer frame size\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
hw->samples = conf.nbuffers * core->audioDevicePropertyBufferFrameSize;
|
hw->samples = conf->nbuffers * core->audioDevicePropertyBufferFrameSize;
|
||||||
|
|
||||||
/* get StreamFormat */
|
/* get StreamFormat */
|
||||||
propertySize = sizeof(core->outputStreamBasicDescription);
|
propertySize = sizeof(core->outputStreamBasicDescription);
|
||||||
|
@ -444,7 +441,7 @@ static void coreaudio_fini_out (HWVoiceOut *hw)
|
||||||
int err;
|
int err;
|
||||||
coreaudioVoiceOut *core = (coreaudioVoiceOut *) hw;
|
coreaudioVoiceOut *core = (coreaudioVoiceOut *) hw;
|
||||||
|
|
||||||
if (!conf.isAtexit) {
|
if (!isAtexit) {
|
||||||
/* stop playback */
|
/* stop playback */
|
||||||
if (isPlaying(core->outputDeviceID)) {
|
if (isPlaying(core->outputDeviceID)) {
|
||||||
status = AudioDeviceStop(core->outputDeviceID, audioDeviceIOProc);
|
status = AudioDeviceStop(core->outputDeviceID, audioDeviceIOProc);
|
||||||
|
@ -487,7 +484,7 @@ static int coreaudio_ctl_out (HWVoiceOut *hw, int cmd, ...)
|
||||||
|
|
||||||
case VOICE_DISABLE:
|
case VOICE_DISABLE:
|
||||||
/* stop playback */
|
/* stop playback */
|
||||||
if (!conf.isAtexit) {
|
if (!isAtexit) {
|
||||||
if (isPlaying(core->outputDeviceID)) {
|
if (isPlaying(core->outputDeviceID)) {
|
||||||
status = AudioDeviceStop(core->outputDeviceID, audioDeviceIOProc);
|
status = AudioDeviceStop(core->outputDeviceID, audioDeviceIOProc);
|
||||||
if (status != kAudioHardwareNoError) {
|
if (status != kAudioHardwareNoError) {
|
||||||
|
@ -500,28 +497,36 @@ static int coreaudio_ctl_out (HWVoiceOut *hw, int cmd, ...)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static CoreaudioConf glob_conf = {
|
||||||
|
.buffer_frames = 512,
|
||||||
|
.nbuffers = 4,
|
||||||
|
};
|
||||||
|
|
||||||
static void *coreaudio_audio_init (void)
|
static void *coreaudio_audio_init (void)
|
||||||
{
|
{
|
||||||
|
CoreaudioConf *conf = g_malloc(sizeof(CoreaudioConf));
|
||||||
|
*conf = glob_conf;
|
||||||
|
|
||||||
atexit(coreaudio_atexit);
|
atexit(coreaudio_atexit);
|
||||||
return &coreaudio_audio_init;
|
return conf;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void coreaudio_audio_fini (void *opaque)
|
static void coreaudio_audio_fini (void *opaque)
|
||||||
{
|
{
|
||||||
(void) opaque;
|
g_free(opaque);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct audio_option coreaudio_options[] = {
|
static struct audio_option coreaudio_options[] = {
|
||||||
{
|
{
|
||||||
.name = "BUFFER_SIZE",
|
.name = "BUFFER_SIZE",
|
||||||
.tag = AUD_OPT_INT,
|
.tag = AUD_OPT_INT,
|
||||||
.valp = &conf.buffer_frames,
|
.valp = &glob_conf.buffer_frames,
|
||||||
.descr = "Size of the buffer in frames"
|
.descr = "Size of the buffer in frames"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
.name = "BUFFER_COUNT",
|
.name = "BUFFER_COUNT",
|
||||||
.tag = AUD_OPT_INT,
|
.tag = AUD_OPT_INT,
|
||||||
.valp = &conf.nbuffers,
|
.valp = &glob_conf.nbuffers,
|
||||||
.descr = "Number of buffers"
|
.descr = "Number of buffers"
|
||||||
},
|
},
|
||||||
{ /* End of list */ }
|
{ /* End of list */ }
|
||||||
|
|
Loading…
Reference in New Issue