X-Git-Url: http://git.tuebingen.mpg.de/?a=blobdiff_plain;f=osx_writer.c;h=9ea7ad454aafce0588a00a33f4122914e65f45ee;hb=b829b61f516298a0de3907cd4c30aef189dd8dd4;hp=e7fecc8262650e8a630b7892b9cabfb627fbc421;hpb=1e2990131a4c26662aa89df52f1ffeba922bf46d;p=paraslash.git diff --git a/osx_writer.c b/osx_writer.c index e7fecc82..9ea7ad45 100644 --- a/osx_writer.c +++ b/osx_writer.c @@ -99,9 +99,9 @@ static void fill_buffer(osx_buffer *b, short *source, long size) { float *dest; - PARA_INFO_LOG("%ld\n", size); if (b->remaining) /* Non empty buffer, must still be playing */ return; + PARA_INFO_LOG("%ld\n", size); if (b->size != size) { /* * Hey! What's that? Coudn't this buffer size be fixed @@ -113,9 +113,14 @@ static void fill_buffer(osx_buffer *b, short *source, long size) b->size = size; } dest = b->buffer; - while (size--) + while (size--) { + char *tmp = (char *)source; + char c = *tmp; + *tmp = *(tmp + 1); + *(tmp + 1) = c; /* *dest++ = ((*source++) + 32768) / 65536.0; */ *dest++ = (*source++) / 32768.0; + } b->ptr = b->buffer; b->remaining = b->size; } @@ -144,6 +149,7 @@ static OSStatus osx_callback(void * inClientData, /* wait for the results */ usleep(2000); } + PARA_INFO_LOG("buf %p: n = %ld, m= %ld\n", powd->from->buffer, n, m); /* * we dump what we can. In fact, just the necessary * should be sufficient @@ -208,8 +214,8 @@ static int osx_writer_open(struct writer_node *wn) format.mFormatID = kAudioFormatLinearPCM; /* flags specific to each format */ format.mFormatFlags = kLinearPCMFormatFlagIsFloat - | kLinearPCMFormatFlagIsBigEndian - | kLinearPCMFormatFlagIsPacked; + | kLinearPCMFormatFlagIsPacked + | kLinearPCMFormatFlagIsBigEndian; /* * We produce 2-channel audio. Now if we have a mega-super-hyper card for our * audio, it is its problem to convert it to 8-, 16-, 32- or 1024-channel data. @@ -239,7 +245,7 @@ static int osx_writer_open(struct writer_node *wn) kAudioUnitScope_Input, 0, &inputCallback, sizeof(inputCallback)) < 0) goto e3; - return 0; + return 1; e3: destroy_buffers(powd); e2: @@ -278,20 +284,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) + if (!need_new_buffer(wn)) return 1; - if (powd->to->remaining) /* Non empty buffer, must still be playing */ - 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; @@ -300,15 +316,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;