Browse Source

Cleanup + Xrun detection (to be finished)

git-svn-id: svn+ssh://jackaudio.org/trunk/jack@823 0c269be4-1314-0410-8aa9-9f06e86f4224
tags/0.109.0
letz 21 years ago
parent
commit
d49f609d9c
5 changed files with 115 additions and 99 deletions
  1. +34
    -20
      drivers/coreaudio/AudioRender.cpp
  2. +5
    -0
      drivers/coreaudio/AudioRender.h
  3. +7
    -4
      drivers/coreaudio/AudioRenderBridge.cpp
  4. +66
    -72
      drivers/coreaudio/coreaudio_driver.c
  5. +3
    -3
      drivers/coreaudio/coreaudio_driver.h

+ 34
- 20
drivers/coreaudio/AudioRender.cpp View File

@@ -142,7 +142,7 @@ vBufferSize(bufferSize)
inBuffers = NULL;
outBuffers = NULL;
status =
ConfigureAudioProc(sampleRate, bufferSize, outChannels, inChannels,
ConfigureAudioProc(sampleRate, bufferSize, outChannels, inChannels,
device);

AudioRender::gSampleRate = vSampleRate;
@@ -164,11 +164,9 @@ vBufferSize(bufferSize)
AudioRender::~AudioRender()
{
if (status) {
if (isProcessing)
AudioDeviceStop(vDevice, process);
OSStatus err = AudioDeviceRemoveIOProc(vDevice, process);
if (err == noErr)
status = false;
if (isProcessing) AudioDeviceStop(vDevice, process);
AudioDeviceRemoveIOProc(vDevice, process);
AudioDeviceRemovePropertyListener(vDevice,0,true,kAudioDeviceProcessorOverload,notification);
free(inBuffers);
free(outBuffers);
}
@@ -322,6 +320,8 @@ bool AudioRender::ConfigureAudioProc(float sampleRate, long bufferSize,
kAudioDevicePropertyBufferFrameSize, &size,
&bufFrame);
if (err != noErr) return false;
JCALog("Internal buffer size %d.\n", bufFrame);

vBufferSize = (long) bufFrame;

@@ -380,6 +380,9 @@ bool AudioRender::ConfigureAudioProc(float sampleRate, long bufferSize,

err = AudioDeviceAddIOProc(vDevice, process, this);
if (err != noErr) return false;
err = AudioDeviceAddPropertyListener(vDevice,0,true,kAudioDeviceProcessorOverload,notification,this);
if (err != noErr) return false;

return true;
}
@@ -408,6 +411,23 @@ bool AudioRender::StopAudio()
return false;
}

OSStatus AudioRender::notification(AudioDeviceID inDevice,
UInt32 inChannel,
Boolean isInput,
AudioDevicePropertyID inPropertyID,
void* inClientData)
{
AudioRender *classe = (AudioRender *) inClientData;
switch(inPropertyID) {
case kAudioDeviceProcessorOverload:
JCALog("notification kAudioDeviceProcessorOverload\n");
break;
}
}

OSStatus AudioRender::process(AudioDeviceID inDevice,
const AudioTimeStamp * inNow,
const AudioBufferList * inInputData,
@@ -428,28 +448,26 @@ OSStatus AudioRender::process(AudioDeviceID inDevice,
if (!*classe->isInterleaved) {
for (unsigned int a = 0; a < inInputData->mNumberBuffers; a++) {
classe->inBuffers[channel] =
(float *) inInputData->mBuffers[a].mData;
(float *) inInputData->mBuffers[a].mData;
channel++;
if (channel == classe->vInChannels)
break;
if (channel == classe->vInChannels) break;
}
channel = 0;
for (unsigned int a = 0; a < outOutputData->mNumberBuffers; a++) {
classe->outBuffers[channel] =
(float *) outOutputData->mBuffers[a].mData;
(float *) outOutputData->mBuffers[a].mData;
channel++;
if (channel == classe->vOutChannels)
break;
if (channel == classe->vOutChannels) break;
}
} else {
for (unsigned int b = 0; b < inInputData->mNumberBuffers; b++) {
classe->channelsPerStream[b] =
(int) inInputData->mBuffers[b].mNumberChannels;
(int) inInputData->mBuffers[b].mNumberChannels;
classe->inBuffers[b] = (float *) inInputData->mBuffers[b].mData; // but jack will read only the inBuffers[0], anyway that should not be a problem.
}
for (unsigned int b = 0; b < outOutputData->mNumberBuffers; b++) {
classe->out_channelsPerStream[b] =
(int) outOutputData->mBuffers[b].mNumberChannels;
(int) outOutputData->mBuffers[b].mNumberChannels;
classe->outBuffers[b] = (float *) outOutputData->mBuffers[b].mData; // but jack will read only the outBuffers[0], anyway that should not be a problem.
}
}
@@ -460,14 +478,10 @@ OSStatus AudioRender::process(AudioDeviceID inDevice,

float **AudioRender::getADC()
{
if (AudioRender::theRender == NULL)
return NULL;
return AudioRender::theRender->inBuffers;
return (AudioRender::theRender == NULL) ? NULL : AudioRender::theRender->inBuffers;
}

float **AudioRender::getDAC()
{
if (AudioRender::theRender == NULL)
return NULL;
return AudioRender::theRender->outBuffers;
return (AudioRender::theRender == NULL) ? NULL : AudioRender::theRender->outBuffers;
}

+ 5
- 0
drivers/coreaudio/AudioRender.h View File

@@ -74,5 +74,10 @@ class AudioRender {
AudioBufferList * outOutputData,
const AudioTimeStamp * inOutputTime,
void *inClientData);
static OSStatus notification(AudioDeviceID inDevice,
UInt32 inChannel,
Boolean isInput,
AudioDevicePropertyID inPropertyID,
void* inClientData);
static AudioRender *theRender;
};

+ 7
- 4
drivers/coreaudio/AudioRenderBridge.cpp View File

@@ -31,11 +31,14 @@ void *openPandaAudioInstance(float sampleRate, long bufferSize,
int inChannels, int outChannels, char *device)
{
AudioRender *newInst =
new AudioRender(sampleRate, bufferSize, inChannels, outChannels,
device);
if (newInst->status)
new AudioRender(sampleRate, bufferSize, inChannels, outChannels,
device);
if (newInst->status)
return newInst;
return NULL;
else {
delete newInst;
return NULL;
}
}

void closePandaAudioInstance(void *instance)


+ 66
- 72
drivers/coreaudio/coreaudio_driver.c View File

@@ -66,15 +66,13 @@ static OSStatus get_device_id_from_num(int i, AudioDeviceID * id)
int nDevices;
AudioDeviceID *theDeviceList;

theStatus =
AudioHardwareGetPropertyInfo(kAudioHardwarePropertyDevices,
theStatus = AudioHardwareGetPropertyInfo(kAudioHardwarePropertyDevices,
&theSize, NULL);
nDevices = theSize / sizeof(AudioDeviceID);
theDeviceList =
(AudioDeviceID *) malloc(nDevices * sizeof(AudioDeviceID));
theStatus =
AudioHardwareGetProperty(kAudioHardwarePropertyDevices, &theSize,
theDeviceList);
theStatus = AudioHardwareGetProperty(kAudioHardwarePropertyDevices,
&theSize, theDeviceList);

*id = theDeviceList[i];
return theStatus;
@@ -111,50 +109,46 @@ coreaudio_driver_attach(coreaudio_driver_t * driver,
*/

for (chn = 0; chn < driver->capture_nchannels; chn++) {
//snprintf (buf, sizeof(buf) - 1, "capture_%lu", chn+1);
snprintf(buf, sizeof(buf) - 1, "%s:out%lu", driver->driver_name,
chn + 1);

if ((port = jack_port_register(driver->client, buf,
JACK_DEFAULT_AUDIO_TYPE, port_flags,
0)) == NULL) {
jack_error("coreaudio: cannot register port for %s", buf);
break;
}

//snprintf (buf, sizeof(buf) - 1, "capture_%lu", chn+1);
snprintf(buf, sizeof(buf) - 1, "%s:out%lu", driver->driver_name,
chn + 1);

if ((port =
jack_port_register(driver->client, buf,
JACK_DEFAULT_AUDIO_TYPE, port_flags,
0)) == NULL) {
jack_error("coreaudio: cannot register port for %s", buf);
break;
}

/* XXX fix this so that it can handle: systemic (external) latency
*/

jack_port_set_latency(port, driver->frames_per_cycle);
/* XXX fix this so that it can handle: systemic (external) latency
*/

driver->capture_ports =
jack_slist_append(driver->capture_ports, port);
jack_port_set_latency(port, driver->frames_per_cycle);
driver->capture_ports =
jack_slist_append(driver->capture_ports, port);
}

port_flags = JackPortIsInput | JackPortIsPhysical | JackPortIsTerminal;

for (chn = 0; chn < driver->playback_nchannels; chn++) {
//snprintf (buf, sizeof(buf) - 1, "playback_%lu", chn+1);
snprintf(buf, sizeof(buf) - 1, "%s:in%lu", driver->driver_name,
chn + 1);

if ((port =
jack_port_register(driver->client, buf,
JACK_DEFAULT_AUDIO_TYPE, port_flags,
0)) == NULL) {
jack_error("coreaudio: cannot register port for %s", buf);
break;
}
for (chn = 0; chn < driver->playback_nchannels; chn++) {
//snprintf (buf, sizeof(buf) - 1, "playback_%lu", chn+1);
snprintf(buf, sizeof(buf) - 1, "%s:in%lu", driver->driver_name,
chn + 1);

/* XXX fix this so that it can handle: systemic (external) latency
*/
if ((port = jack_port_register(driver->client, buf,
JACK_DEFAULT_AUDIO_TYPE, port_flags,
0)) == NULL) {
jack_error("coreaudio: cannot register port for %s", buf);
break;
}

jack_port_set_latency(port, driver->frames_per_cycle);
driver->playback_ports =
jack_slist_append(driver->playback_ports, port);
}
/* XXX fix this so that it can handle: systemic (external) latency
*/

jack_port_set_latency(port, driver->frames_per_cycle);
driver->playback_ports =
jack_slist_append(driver->playback_ports, port);
}

jack_activate(driver->client);
return 0;
@@ -232,15 +226,15 @@ coreaudio_driver_read(coreaudio_driver_t * driver, jack_nframes_t nframes)
} else {
if (jack_port_connected(port)
&& (driver->incoreaudio[b] != NULL)) {
int channels = driver->channelsPerStream[b];
int channels = driver->channelsPerInputStream[b];
if (channels <= chn) {
b++;
if (driver->numberOfStreams > 1
&& b < driver->numberOfStreams) {
channels = driver->channelsPerStream[b];
chn = 0;
if (driver->numberOfInputStreams > 1
&& b < driver->numberOfInputStreams) {
channels = driver->channelsPerInputStream[b];
chn = 0;
} else
return 0;
return 0;
}
if (channels > 0) {
float *in = driver->incoreaudio[b];
@@ -285,15 +279,15 @@ coreaudio_driver_write(coreaudio_driver_t * driver, jack_nframes_t nframes)
} else {
if (jack_port_connected(port)
&& (driver->outcoreaudio[b] != NULL)) {
int channels = driver->out_channelsPerStream[b];
int channels = driver->channelsPerOuputStream[b];
if (channels <= chn) {
b++;
if (driver->out_numberOfStreams > 1
&& b < driver->out_numberOfStreams) {
channels = driver->out_channelsPerStream[b];
chn = 0;
if (driver->numberOfOuputStreams > 1
&& b < driver->numberOfOuputStreams) {
channels = driver->channelsPerOuputStream[b];
chn = 0;
} else
return 0;
return 0;
}
if (channels > 0) {
float *out = driver->outcoreaudio[b];
@@ -330,16 +324,15 @@ coreaudio_driver_bufsize(coreaudio_driver_t * driver,
* be serialized with the driver thread. Stopping the audio
* also stops that thread. */


closePandaAudioInstance(driver->stream);

driver->stream =
openPandaAudioInstance((float) driver->frame_rate,
openPandaAudioInstance((float) driver->frame_rate,
driver->frames_per_cycle, driver->capturing,
driver->playing, &driver->driver_name[0]);

if (!driver->stream)
return FALSE;
return FALSE;

setHostData(driver->stream, driver);
setCycleFun(driver->stream, coreaudio_runCycle);
@@ -406,7 +399,7 @@ static jack_driver_t *coreaudio_driver_new(char *name,
}

driver->stream =
openPandaAudioInstance((float) rate, frames_per_cycle, chan_in,
openPandaAudioInstance((float) rate, frames_per_cycle, chan_in,
chan_out, &deviceName[0]);

if (!driver->stream)
@@ -414,25 +407,25 @@ static jack_driver_t *coreaudio_driver_new(char *name,

driver->client = client;
driver->period_usecs =
(((float) driver->frames_per_cycle) / driver->frame_rate) *
1000000.0f;
(((float) driver->frames_per_cycle) / driver->frame_rate) *
1000000.0f;

setHostData(driver->stream, driver);
setCycleFun(driver->stream, coreaudio_runCycle);
setParameter(driver->stream, 'inte', &driver->isInterleaved);
setParameter(driver->stream, 'nstr', &driver->numberOfStreams);
setParameter(driver->stream, 'nstO', &driver->out_numberOfStreams);
setParameter(driver->stream, 'nstr', &driver->numberOfInputStreams);
setParameter(driver->stream, 'nstO', &driver->numberOfOuputStreams);

JCALog("There are %d input streams.\n", driver->numberOfStreams);
JCALog("There are %d output streams.\n", driver->out_numberOfStreams);
JCALog("There are %d input streams.\n", driver->numberOfInputStreams);
JCALog("There are %d output streams.\n", driver->numberOfOuputStreams);

driver->channelsPerStream =
(int *) malloc(sizeof(int) * driver->numberOfStreams);
driver->out_channelsPerStream =
(int *) malloc(sizeof(int) * driver->out_numberOfStreams);
driver->channelsPerInputStream =
(int *) malloc(sizeof(int) * driver->numberOfInputStreams);
driver->channelsPerOuputStream =
(int *) malloc(sizeof(int) * driver->numberOfOuputStreams);

setParameter(driver->stream, 'cstr', driver->channelsPerStream);
setParameter(driver->stream, 'cstO', driver->out_channelsPerStream);
setParameter(driver->stream, 'cstr', driver->channelsPerInputStream);
setParameter(driver->stream, 'cstO', driver->channelsPerOuputStream);

driver->incoreaudio = getPandaAudioInputs(driver->stream);
driver->outcoreaudio = getPandaAudioOutputs(driver->stream);
@@ -441,7 +434,8 @@ static jack_driver_t *coreaudio_driver_new(char *name,
driver->capture_nchannels = chan_in;

strcpy(&driver->driver_name[0], &deviceName[0]);
jack_init_time();
// steph
//jack_init_time();
return ((jack_driver_t *) driver);

error:
@@ -457,8 +451,8 @@ static void coreaudio_driver_delete(coreaudio_driver_t * driver)
{
/* Close coreaudio stream and terminate */
closePandaAudioInstance(driver->stream);
free(driver->channelsPerStream);
free(driver->out_channelsPerStream);
free(driver->channelsPerInputStream);
free(driver->channelsPerOuputStream);
free(driver);
}



+ 3
- 3
drivers/coreaudio/coreaudio_driver.h View File

@@ -54,9 +54,9 @@ typedef struct {
float **incoreaudio;
float **outcoreaudio;
int isInterleaved;
int numberOfStreams;
int out_numberOfStreams;
int *channelsPerStream, *out_channelsPerStream;
int numberOfInputStreams;
int numberOfOuputStreams;
int *channelsPerInputStream, *channelsPerOuputStream;
char driver_name[256];
void *stream;



Loading…
Cancel
Save