From 1d58cd7a72d5423c08f52eaa770625a6c5cf0650 Mon Sep 17 00:00:00 2001 From: Torben Hohn Date: Wed, 27 May 2009 10:45:35 +0200 Subject: [PATCH] make ringbuffer alloc mem via FPI_MemAlloc, and say 1024 latency. seems to work fine now --- flashsupport.c | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/flashsupport.c b/flashsupport.c index 8649803..e186847 100644 --- a/flashsupport.c +++ b/flashsupport.c @@ -1086,11 +1086,12 @@ static void *jack_flash_thread( void *arg ) //sem_wait( &(p->semaphore) ); //usleep( 50 ); + sem_wait( &(p->semaphore) ); while( !p->quit ) { - sem_wait( &(p->semaphore) ); FPI_SoundOutput_FillBuffer(p, (char*) buffer, bufsize); if( jack_ringbuffer_write( p->buffer, (char*)buffer, bufsize ) != bufsize ) printf( "something is wrong\n" ); + sem_wait( &(p->semaphore) ); } return NULL; @@ -1157,6 +1158,27 @@ static int jack_process_cb( jack_nframes_t nframes, void *arg ) return 0; } +jack_ringbuffer_t * +FPI_jack_ringbuffer_create (size_t sz) +{ + int power_of_two; + jack_ringbuffer_t *rb; + + rb = FPI_Mem_Alloc (sizeof (jack_ringbuffer_t)); + + for (power_of_two = 1; 1 << power_of_two < sz; power_of_two++); + + rb->size = 1 << power_of_two; + rb->size_mask = rb->size; + rb->size_mask -= 1; + rb->write_ptr = 0; + rb->read_ptr = 0; + rb->buf = FPI_Mem_Alloc (rb->size); + rb->mlocked = 0; + + return rb; +} + static void *FPX_SoundOutput_Open(void) { struct jack_output_data *p=NULL; @@ -1190,7 +1212,7 @@ static void *FPX_SoundOutput_Open(void) { flash_frames = jack_get_buffer_size( p->client ) * 44100 / jack_rate; bufsize = 2*flash_frames * sizeof( int16_t ); - p->buffer = jack_ringbuffer_create( bufsize * 6 ); + p->buffer = FPI_jack_ringbuffer_create( bufsize * 6 ); sem_init( &(p->semaphore), 0, 0 ); pthread_create( &(p->tid), NULL, jack_flash_thread, p ); @@ -1224,7 +1246,7 @@ static void *FPX_SoundOutput_Open(void) { // the semaphore represents the number of writeable buffers in // the ringbuffer. we add 1 for the initial sem_wait. - //for(i=0; i<( 5 + 1 ); i++ ) + for(i=0; i<( 3 + 1 ); i++ ) sem_post( &(p->semaphore) ); return p; @@ -1242,7 +1264,8 @@ static int FPX_SoundOutput_Close(void *ptr) { //assert(p); if( p->tid ) { p->quit = 1; - //sem_post( &(p->semaphore) ); + usleep(300); + sem_post( &(p->semaphore) ); pthread_join( p->tid, NULL ); } @@ -1258,7 +1281,7 @@ static int FPX_SoundOutput_Latency(void *ptr) { // heh ? jack has no latency :P struct jack_output_data *p = ptr; //return jack_ringbuffer_read_space( p->buffer ) / 4; - return 0; + return 1024; } #endif -- 2.11.4.GIT