X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=osx_writer.c;h=2af553db4386561ff58cc1652be235f30f8f551a;hp=4162badd5d82c4b4053c4581266e17dd3e0ecf0f;hb=db02b614d1231685e64b27b4838c7cd699e51790;hpb=1b2dd40d3d28a68613b0215f0765235afb64984a diff --git a/osx_writer.c b/osx_writer.c index 4162badd..2af553db 100644 --- a/osx_writer.c +++ b/osx_writer.c @@ -50,6 +50,7 @@ struct private_osx_writer_data { sem_t *semaphore; osx_buffer *from; /* Current buffers */ osx_buffer *to; + unsigned samplerate; }; @@ -181,6 +182,8 @@ static int osx_writer_open(struct writer_node *wn) AudioStreamBasicDescription format; char s[10]; int m, ret; + struct writer_node_group *wng = wn->wng; + struct osx_write_args_info *conf = wn->conf; wn->private_data = powd; /* where did that default audio output go? */ @@ -209,7 +212,11 @@ static int osx_writer_open(struct writer_node *wn) * AND you want the DefaultOutputUnit to do any format conversions * necessary from your format to the device's format. */ - format.mSampleRate = 44100.0; /* The sample rate of the audio stream */ + if (!conf->samplerate_given && wng->samplerate) + powd->samplerate = *wng->samplerate; + else + powd->samplerate = conf->samplerate_arg; + format.mSampleRate = powd->samplerate; /* The specific encoding type of audio stream*/ format.mFormatID = kAudioFormatLinearPCM; /* flags specific to each format */ @@ -284,20 +291,30 @@ static void osx_writer_close(struct writer_node *wn) free(powd); } +static int need_new_buffer(struct writer_node *wn) +{ + struct writer_node_group *wng = wn->wng; + struct private_osx_writer_data *powd = wn->private_data; + + if (*wng->loaded < sizeof(short)) + return 0; + if (powd->to->remaining) /* Non empty buffer, must still be playing */ + return 0; + return 1; +} + static int osx_write_post_select(__a_unused struct sched *s, struct writer_node *wn) { struct private_osx_writer_data *powd = wn->private_data; struct writer_node_group *wng = wn->wng; - short *data = (short*)wng->buf + wn->written; + short *data = (short*)wng->buf; - if (*wng->loaded <= wn->written) - return 1; - if (powd->to->remaining) /* Non empty buffer, must still be playing */ + if (!need_new_buffer(wn)) return 1; - fill_buffer(powd->to, data, (*wng->loaded - wn->written) / sizeof(short)); + fill_buffer(powd->to, data, *wng->loaded / sizeof(short)); powd->to = powd->to->next; - wn->written += (*wng->loaded - wn->written); + wn->written = *wng->loaded; if (!powd->play) { if (AudioOutputUnitStart(powd->output)) return -1; @@ -306,15 +323,8 @@ static int osx_write_post_select(__a_unused struct sched *s, return 1; } -static int osx_write_pre_select(struct sched *s, struct writer_node *wn) +static int osx_write_pre_select(struct sched *s, __a_unused struct writer_node *wn) { - struct writer_node_group *wng = wn->wng; - struct private_osx_writer_data *powd = wn->private_data; - -// if (!*wng->loaded) -// return 1; -// if (powd->to->remaining) /* Non empty buffer, must still be playing */ -// return 1; s->timeout.tv_sec = 0; s->timeout.tv_usec = 20; return 1;