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; inBuffers = NULL;
outBuffers = NULL; outBuffers = NULL;
status = status =
ConfigureAudioProc(sampleRate, bufferSize, outChannels, inChannels,
ConfigureAudioProc(sampleRate, bufferSize, outChannels, inChannels,
device); device);


AudioRender::gSampleRate = vSampleRate; AudioRender::gSampleRate = vSampleRate;
@@ -164,11 +164,9 @@ vBufferSize(bufferSize)
AudioRender::~AudioRender() AudioRender::~AudioRender()
{ {
if (status) { 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(inBuffers);
free(outBuffers); free(outBuffers);
} }
@@ -322,6 +320,8 @@ bool AudioRender::ConfigureAudioProc(float sampleRate, long bufferSize,
kAudioDevicePropertyBufferFrameSize, &size, kAudioDevicePropertyBufferFrameSize, &size,
&bufFrame); &bufFrame);
if (err != noErr) return false; if (err != noErr) return false;
JCALog("Internal buffer size %d.\n", bufFrame);


vBufferSize = (long) bufFrame; vBufferSize = (long) bufFrame;


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


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


return true; return true;
} }
@@ -408,6 +411,23 @@ bool AudioRender::StopAudio()
return false; 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, OSStatus AudioRender::process(AudioDeviceID inDevice,
const AudioTimeStamp * inNow, const AudioTimeStamp * inNow,
const AudioBufferList * inInputData, const AudioBufferList * inInputData,
@@ -428,28 +448,26 @@ OSStatus AudioRender::process(AudioDeviceID inDevice,
if (!*classe->isInterleaved) { if (!*classe->isInterleaved) {
for (unsigned int a = 0; a < inInputData->mNumberBuffers; a++) { for (unsigned int a = 0; a < inInputData->mNumberBuffers; a++) {
classe->inBuffers[channel] = classe->inBuffers[channel] =
(float *) inInputData->mBuffers[a].mData;
(float *) inInputData->mBuffers[a].mData;
channel++; channel++;
if (channel == classe->vInChannels)
break;
if (channel == classe->vInChannels) break;
} }
channel = 0; channel = 0;
for (unsigned int a = 0; a < outOutputData->mNumberBuffers; a++) { for (unsigned int a = 0; a < outOutputData->mNumberBuffers; a++) {
classe->outBuffers[channel] = classe->outBuffers[channel] =
(float *) outOutputData->mBuffers[a].mData;
(float *) outOutputData->mBuffers[a].mData;
channel++; channel++;
if (channel == classe->vOutChannels)
break;
if (channel == classe->vOutChannels) break;
} }
} else { } else {
for (unsigned int b = 0; b < inInputData->mNumberBuffers; b++) { for (unsigned int b = 0; b < inInputData->mNumberBuffers; b++) {
classe->channelsPerStream[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. 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++) { for (unsigned int b = 0; b < outOutputData->mNumberBuffers; b++) {
classe->out_channelsPerStream[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. 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() float **AudioRender::getADC()
{ {
if (AudioRender::theRender == NULL)
return NULL;
return AudioRender::theRender->inBuffers;
return (AudioRender::theRender == NULL) ? NULL : AudioRender::theRender->inBuffers;
} }


float **AudioRender::getDAC() 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, AudioBufferList * outOutputData,
const AudioTimeStamp * inOutputTime, const AudioTimeStamp * inOutputTime,
void *inClientData); void *inClientData);
static OSStatus notification(AudioDeviceID inDevice,
UInt32 inChannel,
Boolean isInput,
AudioDevicePropertyID inPropertyID,
void* inClientData);
static AudioRender *theRender; 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) int inChannels, int outChannels, char *device)
{ {
AudioRender *newInst = 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 newInst;
return NULL;
else {
delete newInst;
return NULL;
}
} }


void closePandaAudioInstance(void *instance) 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; int nDevices;
AudioDeviceID *theDeviceList; AudioDeviceID *theDeviceList;


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


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


for (chn = 0; chn < driver->capture_nchannels; chn++) { 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; 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); jack_activate(driver->client);
return 0; return 0;
@@ -232,15 +226,15 @@ coreaudio_driver_read(coreaudio_driver_t * driver, jack_nframes_t nframes)
} else { } else {
if (jack_port_connected(port) if (jack_port_connected(port)
&& (driver->incoreaudio[b] != NULL)) { && (driver->incoreaudio[b] != NULL)) {
int channels = driver->channelsPerStream[b];
int channels = driver->channelsPerInputStream[b];
if (channels <= chn) { if (channels <= chn) {
b++; 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 } else
return 0;
return 0;
} }
if (channels > 0) { if (channels > 0) {
float *in = driver->incoreaudio[b]; float *in = driver->incoreaudio[b];
@@ -285,15 +279,15 @@ coreaudio_driver_write(coreaudio_driver_t * driver, jack_nframes_t nframes)
} else { } else {
if (jack_port_connected(port) if (jack_port_connected(port)
&& (driver->outcoreaudio[b] != NULL)) { && (driver->outcoreaudio[b] != NULL)) {
int channels = driver->out_channelsPerStream[b];
int channels = driver->channelsPerOuputStream[b];
if (channels <= chn) { if (channels <= chn) {
b++; 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 } else
return 0;
return 0;
} }
if (channels > 0) { if (channels > 0) {
float *out = driver->outcoreaudio[b]; 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 * be serialized with the driver thread. Stopping the audio
* also stops that thread. */ * also stops that thread. */



closePandaAudioInstance(driver->stream); closePandaAudioInstance(driver->stream);


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


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


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


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


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


driver->client = client; driver->client = client;
driver->period_usecs = 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); setHostData(driver->stream, driver);
setCycleFun(driver->stream, coreaudio_runCycle); setCycleFun(driver->stream, coreaudio_runCycle);
setParameter(driver->stream, 'inte', &driver->isInterleaved); 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->incoreaudio = getPandaAudioInputs(driver->stream);
driver->outcoreaudio = getPandaAudioOutputs(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; driver->capture_nchannels = chan_in;


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


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




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

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




Loading…
Cancel
Save