Adjust CoreAudio driver latency

Signed-off-by: Claudio Matsuoka <cmatsuoka@gmail.com>
master
Claudio Matsuoka 12 years ago
parent 8058998e1a
commit 638d109dde
  1. 2
      Changelog
  2. 81
      src/sound_coreaudio.c
  3. 6
      src/xmp.1

@ -2,7 +2,7 @@ Stable versions
--------------- ---------------
4.0.10 (): 4.0.10 ():
- Update deprecated calls in CoreAudio driver - Adjust CoreAudio driver latency
4.0.9 (20140926): 4.0.9 (20140926):
- Add option '-p' to set the default pan amplitude - Add option '-p' to set the default pan amplitude

@ -132,12 +132,17 @@ static int init(struct options *options)
AudioComponent comp; AudioComponent comp;
AudioComponentDescription cd; AudioComponentDescription cd;
AURenderCallbackStruct rc; AURenderCallbackStruct rc;
OSStatus err; OSStatus status;
UInt32 size, max_frames; UInt32 size, max_frames;
//char **parm = options->driver_parm; int latency = 250;
char **parm = options->driver_parm;
//parm_init(parm); parm_init(parm);
//parm_end(); chkparm1("buffer", latency = strtoul(token, NULL, 0));
parm_end();
if (latency < 20)
latency = 20;
ad.mSampleRate = options->rate; ad.mSampleRate = options->rate;
ad.mFormatID = kAudioFormatLinearPCM; ad.mFormatID = kAudioFormatLinearPCM;
@ -168,48 +173,30 @@ static int init(struct options *options)
cd.componentFlags = 0; cd.componentFlags = 0;
cd.componentFlagsMask = 0; cd.componentFlagsMask = 0;
if ((comp = AudioComponentFindNext(NULL, &cd)) == NULL) { if ((comp = AudioComponentFindNext(NULL, &cd)) == NULL)
fprintf(stderr, "error: FindNextComponent\n"); goto err;
return -1;
}
if ((err = AudioComponentInstanceNew(comp, &au))) { if ((status = AudioComponentInstanceNew(comp, &au)))
fprintf(stderr, "error: OpenAComponent (%d)\n", (int)err); goto err1;
return -1;
}
if ((err = AudioUnitInitialize(au))) { if ((status = AudioUnitInitialize(au)))
fprintf(stderr, "error: AudioUnitInitialize (%d)\n", (int)err); goto err1;
return -1;
}
if ((err = AudioUnitSetProperty(au, kAudioUnitProperty_StreamFormat, if ((status = AudioUnitSetProperty(au, kAudioUnitProperty_StreamFormat,
kAudioUnitScope_Input, 0, &ad, sizeof(ad)))) { kAudioUnitScope_Input, 0, &ad, sizeof(ad))))
fprintf(stderr, "error: AudioUnitSetProperty: StreamFormat (%d)\n", (int)err); goto err1;
fprintf(stderr, "mSampleRate = %lf\n", ad.mSampleRate);
fprintf(stderr, "mFormatID = 0x%x\n", (unsigned)ad.mFormatID);
fprintf(stderr, "mFormatFlags = 0x%x\n", (unsigned)ad.mFormatFlags);
fprintf(stderr, "mChannelsPerFrame = %d\n", (int)ad.mChannelsPerFrame);
fprintf(stderr, "mBitsPerChannel = %d\n", (int)ad.mBitsPerChannel);
fprintf(stderr, "mBytesPerFrame = %d\n", (int)ad.mBytesPerFrame);
fprintf(stderr, "mBytesPerPacket = %d\n", (int)ad.mBytesPerPacket);
fprintf(stderr, "mFramesPerPacket = %d\n", (int)ad.mFramesPerPacket);
return -1;
}
size = sizeof(UInt32); size = sizeof(UInt32);
if ((err = AudioUnitGetProperty(au, kAudioDevicePropertyBufferSize, if ((status = AudioUnitGetProperty(au, kAudioDevicePropertyBufferSize,
kAudioUnitScope_Input, 0, &max_frames, &size))) { kAudioUnitScope_Input, 0, &max_frames, &size)))
fprintf(stderr, "error: AudioUnitGetProperty: BufferSize (%d)\n", (int)err); goto err1;
return -1;
}
chunk_size = max_frames; chunk_size = max_frames;
num_chunks = (options->rate * ad.mBytesPerFrame + chunk_size - 1) / num_chunks = (options->rate * ad.mBytesPerFrame * latency / 1000
chunk_size; + chunk_size - 1) / chunk_size;
buffer_len = (num_chunks + 1) * chunk_size; buffer_len = (num_chunks + 1) * chunk_size;
buffer = calloc(num_chunks + 1, chunk_size); if ((buffer = calloc(num_chunks + 1, chunk_size)) == NULL)
goto err;
rc.inputProc = render_proc; rc.inputProc = render_proc;
rc.inputProcRefCon = 0; rc.inputProcRefCon = 0;
@ -218,13 +205,19 @@ static int init(struct options *options)
buf_write_pos = 0; buf_write_pos = 0;
paused = 1; paused = 1;
if ((err = AudioUnitSetProperty(au, kAudioUnitProperty_SetRenderCallback, if ((status = AudioUnitSetProperty(au,
kAudioUnitScope_Input, 0, &rc, sizeof(rc)))) { kAudioUnitProperty_SetRenderCallback,
fprintf(stderr, "error: AudioUnitSetProperty: SetRenderCallback (%d)\n", (int)err); kAudioUnitScope_Input, 0, &rc, sizeof(rc))))
return -1; goto err2;
}
return 0; return 0;
err2:
free(buffer);
err1:
fprintf(stderr, "initialization error: %d\n", (int)status);
err:
return -1;
} }
@ -268,10 +261,12 @@ static void flush(void)
static void onpause(void) static void onpause(void)
{ {
AudioOutputUnitStop(au);
} }
static void onresume(void) static void onresume(void)
{ {
AudioOutputUnitStart(au);
} }
struct sound_driver sound_coreaudio = { struct sound_driver sound_coreaudio = {

@ -1,4 +1,4 @@
.TH "XMP" "1" "Version 4\&.0\&.9" "Sep 2014" "Extended Module Player" .TH "XMP" "1" "Version 4\&.0\&.10" "Nov 2014" "Extended Module Player"
.PP .PP
.SH "NAME" .SH "NAME"
xmp - Extended Module Player xmp - Extended Module Player
@ -179,6 +179,10 @@ The default is 128\&.
.IP "\fB\-D\fP \fIbuffer=size\fP" .IP "\fB\-D\fP \fIbuffer=size\fP"
Set the size in bytes of the audio buffer\&. Default value is 32 Kb\&. Set the size in bytes of the audio buffer\&. Default value is 32 Kb\&.
.PP .PP
CoreAudio driver options:
.IP "\fB\-D\fP \fIbuffer=value\fP"
Set buffer size in ms\&. Default value is 250.
.PP
HP-UX and Solaris driver options: HP-UX and Solaris driver options:
.IP "\fB\-D\fP \fIgain=value\fP" .IP "\fB\-D\fP \fIgain=value\fP"
Set the audio gain\&. Valid values range from 0 to 255\&. Set the audio gain\&. Valid values range from 0 to 255\&.

Loading…
Cancel
Save