Пример #1
0
static int process_cb(jack_nframes_t nframes, void *data)
{
   int i;
   jack_nframes_t f, avail[2], min_avail;
   jack_t *jd = (jack_t*)data;

   if (nframes <= 0)
   {
#ifdef HAVE_THREADS
      scond_signal(jd->cond);
#endif
      return 0;
   }

   avail[0] = jack_ringbuffer_read_space(jd->buffer[0]);
   avail[1] = jack_ringbuffer_read_space(jd->buffer[1]);
   min_avail = ((avail[0] < avail[1]) ? avail[0] : avail[1]) / sizeof(jack_default_audio_sample_t);

   if (min_avail > nframes)
      min_avail = nframes;

   for (i = 0; i < 2; i++)
   {
      jack_default_audio_sample_t *out = (jack_default_audio_sample_t*)jack_port_get_buffer(jd->ports[i], nframes);
      assert(out);
      jack_ringbuffer_read(jd->buffer[i], (char*)out, min_avail * sizeof(jack_default_audio_sample_t));

      for (f = min_avail; f < nframes; f++)
         out[f] = 0.0f;
   }
#ifdef HAVE_THREADS
   scond_signal(jd->cond);
#endif
   return 0;
}
Пример #2
0
void
JackLayer::read(AudioBuffer &buffer)
{
    for (unsigned i = 0; i < in_ringbuffers_.size(); ++i) {

        const size_t incomingSamples = jack_ringbuffer_read_space(in_ringbuffers_[i]) / sizeof(captureFloatBuffer_[0]);
        if (!incomingSamples)
            continue;

        captureFloatBuffer_.resize(incomingSamples);
        buffer.resize(incomingSamples);

        // write to output
        const size_t from_ringbuffer = jack_ringbuffer_read_space(in_ringbuffers_[i]);
        const size_t expected_bytes = std::min(incomingSamples * sizeof(captureFloatBuffer_[0]), from_ringbuffer);
        // FIXME: while we have samples to write AND while we have space to write them
        const size_t read_bytes = jack_ringbuffer_read(in_ringbuffers_[i],
                (char *) captureFloatBuffer_.data(), expected_bytes);
        if (read_bytes < expected_bytes) {
            RING_WARN("Dropped %zu bytes", expected_bytes - read_bytes);
            break;
        }

        /* Write the data one frame at a time.  This is
         * inefficient, but makes things simpler. */
        // FIXME: this is braindead, we should write blocks of samples at a time
        // convert a vector of samples from 1 channel to a float vector
        convertFromFloat(captureFloatBuffer_, *buffer.getChannel(i));
    }
}
Пример #3
0
static int jackrack_get_audio( mlt_frame frame, void **buffer, mlt_audio_format *format, int *frequency, int *channels, int *samples )
{
	// Get the filter service
	mlt_filter filter = mlt_frame_pop_audio( frame );

	// Get the filter properties
	mlt_properties filter_properties = MLT_FILTER_PROPERTIES( filter );

	int jack_frequency = mlt_properties_get_int( filter_properties, "_sample_rate" );

	// Get the producer's audio
	*format = mlt_audio_float;
	mlt_frame_get_audio( frame, buffer, format, &jack_frequency, channels, samples );
	
	// TODO: Deal with sample rate differences
	if ( *frequency != jack_frequency )
		mlt_log_error( MLT_FILTER_SERVICE( filter ), "mismatching frequencies JACK = %d actual = %d\n",
			jack_frequency, *frequency );
	*frequency = jack_frequency;

	// Initialise Jack ports and connections if needed
	if ( mlt_properties_get_int( filter_properties, "_samples" ) == 0 )
		mlt_properties_set_int( filter_properties, "_samples", *samples );
	
	// Get the filter-specific properties
	jack_ringbuffer_t **output_buffers = mlt_properties_get_data( filter_properties, "output_buffers", NULL );
	jack_ringbuffer_t **input_buffers = mlt_properties_get_data( filter_properties, "input_buffers", NULL );
//	pthread_mutex_t *output_lock = mlt_properties_get_data( filter_properties, "output_lock", NULL );
//	pthread_cond_t *output_ready = mlt_properties_get_data( filter_properties, "output_ready", NULL );
	
	// Process the audio
	float *q = (float*) *buffer;
	size_t size = *samples * sizeof(float);
	int j;
//	struct timespec tm = { 0, 0 };

	// Write into output ringbuffer
	for ( j = 0; j < *channels; j++ )
	{
		if ( jack_ringbuffer_write_space( output_buffers[j] ) >= size )
			jack_ringbuffer_write( output_buffers[j], (char*)( q + j * *samples ), size );
	}

	// Synchronization phase - wait for signal from Jack process
	while ( jack_ringbuffer_read_space( input_buffers[ *channels - 1 ] ) < size ) ;
		//pthread_cond_wait( output_ready, output_lock );
		
	// Read from input ringbuffer
	for ( j = 0; j < *channels; j++, q++ )
	{
		if ( jack_ringbuffer_read_space( input_buffers[j] ) >= size )
			jack_ringbuffer_read( input_buffers[j], (char*)( q + j * *samples ), size );
	}

	// help jack_sync() indicate when we are rolling
	mlt_position pos = mlt_frame_get_position( frame );
	mlt_properties_set_position( filter_properties, "_last_pos", pos );

	return 0;
}
Пример #4
0
static int process_cb(jack_nframes_t nframes, void *data)
{
   jack_t *jd = (jack_t*)data;
   if (nframes <= 0)
   {
      pthread_cond_signal(&jd->cond);
      return 0;
   }

   jack_nframes_t avail[2];
   avail[0] = jack_ringbuffer_read_space(jd->buffer[0]);
   avail[1] = jack_ringbuffer_read_space(jd->buffer[1]);
   jack_nframes_t min_avail = ((avail[0] < avail[1]) ? avail[0] : avail[1]) / sizeof(jack_default_audio_sample_t);

   if (min_avail > nframes)
      min_avail = nframes;

   for (int i = 0; i < 2; i++)
   {
      jack_default_audio_sample_t *out = (jack_default_audio_sample_t*)jack_port_get_buffer(jd->ports[i], nframes);
      assert(out);
      jack_ringbuffer_read(jd->buffer[i], (char*)out, min_avail * sizeof(jack_default_audio_sample_t));

      for (jack_nframes_t f = min_avail; f < nframes; f++)
      {
         out[f] = 0.0f;
      }
   }
   pthread_cond_signal(&jd->cond);
   return 0;
}
Пример #5
0
/*------------------------------------------------------------------------------
 *  Check wether read() would return anything
 *----------------------------------------------------------------------------*/
bool
JackDspSource :: canRead ( unsigned int   sec,
                           unsigned int   usec )    throw ( Exception )
{
    size_t available=0;
    
    if ( !isOpen() ) {
        return false;
    }
    
    // How many bytes available in ring buffer ?
    available = jack_ringbuffer_read_space( rb[0] );
    if (available)    return true;
    
    // Sleep and check again
    // FIXME: should we really sleep the full duration ?
    usleep( (sec*1000000) + usec );
    
    available = jack_ringbuffer_read_space( rb[0] );
    if (available) {
        return true;
    } else {
        return false;
    }
}
Пример #6
0
static inline void
update_playposition (int64_t decoder_position, float varispeed)
{
#ifdef ENABLE_RESAMPLING
	const int64_t latency = floor(jack_ringbuffer_read_space(rb) / myplayer->info.channels / sizeof(float) / m_fResampleRatio / varispeed);
#else
	const int64_t latency = floor(jack_ringbuffer_read_space(rb) / myplayer->info.channels);
#endif
	if (!play->config.loop || decoder_position > latency)
		play_position = decoder_position - latency;
	else
		play_position = m_frames + decoder_position - latency;
}
Пример #7
0
int
jack_ringbuffer_wait_for_read ( const jack_ringbuffer_t *r , 
				int nbytes , int fd )
{
  int space = (int) jack_ringbuffer_read_space ( r ) ;
  while ( space < nbytes ) {
    char b ;
    if ( read ( fd , &b , 1 ) == -1 ) {
      eprintf ( "%s: error reading communication pipe\n" , __func__ ) ;
      FAILURE ;
    }
    space = (int) jack_ringbuffer_read_space ( r ) ;
  }
  return space ;
}
Пример #8
0
static int process_jack(jack_nframes_t nframes, void* arg)
{
	int cnt;

	if (!ready) {
		return 0;
	}

	for(int i = 0; i < CHANNELS; i++) {
		out[i] = jack_port_get_buffer(outputports[i], nframes);
	}

	for(size_t i = 0; i < nframes; i++) {
		
		if (jack_ringbuffer_read_space(ringbuffer) >= SAMPLE_SIZE * CHANNELS) {

			for(int j = 0; j < CHANNELS; j++){
				jack_ringbuffer_read (ringbuffer, (char*)(out[j]+i), SAMPLE_SIZE);
			}

		} else {
			printf ("underrun\n");
			ready = 0;

			return 0;
		}
	}

	return 0;
}
Пример #9
0
void *
detect_note(void *arg)
{
	jack_thread_info_t *info = (jack_thread_info_t *)arg;
	jack_nframes_t samples_per_frame = info->channels;
	size_t bytes_per_frame = samples_per_frame * sample_size, bytes;
	gboolean done = FALSE;
  float sample, *frame;
	int i;

	frame = (float *)alloca(bytes_per_frame);

	pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
	pthread_mutex_lock(&detect_lock);
	info->status = 0;

	while (!done) {	
		while (info->can_capture &&
		      jack_ringbuffer_read_space(rb) >= bytes_per_frame) {

			jack_ringbuffer_read(rb, frame, bytes_per_frame);

			fftMeasure(1, bytes_per_frame, frame);
		}
		//wait for data
		pthread_cond_wait (&data_ready, &detect_lock);
	}

  pthread_mutex_unlock(&detect_lock);
}
Пример #10
0
static size_t rotter_read_from_ringbuffer(rotter_ringbuffer_t *ringbuffer, size_t desired_frames)
{
  size_t desired_bytes = desired_frames * sizeof(jack_default_audio_sample_t);
  size_t available_bytes = 0;
  int c, bytes_read = 0;

  // Is there enough in the ring buffers?
  for (c=0; c<channels; c++) {
    available_bytes = jack_ringbuffer_read_space( ringbuffer->buffer[c] );
    if (available_bytes <= 0) {
      // Try again later
      return 0;
    }
  }

  if (available_bytes > desired_bytes)
    available_bytes = desired_bytes;

  // Get the audio out of the ring buffer
  for (c=0; c<channels; c++) {
    // Copy frames from ring buffer to temporary buffer
    bytes_read = jack_ringbuffer_read( ringbuffer->buffer[c], (char*)tmp_buffer[c], available_bytes);
    if (bytes_read != available_bytes) {
      rotter_fatal( "Failed to read from ringbuffer %c channel %d.", ringbuffer->label, c);
      return 0;
    }
  }

  return bytes_read / sizeof(jack_default_audio_sample_t);
}
Пример #11
0
/** flush buffers and reset. Must only be called from the RT thread. */
void
Disk_Stream::base_flush ( bool is_output )
{
    THREAD_ASSERT( RT );

    /* flush buffers */
    for ( int i = _rb.size(); i--; )
        jack_ringbuffer_read_advance( _rb[ i ], jack_ringbuffer_read_space( _rb[ i ] ) );

/*  sem_destroy( &_blocks ); */

/*     if ( is_output ) */
/*         sem_init( &_blocks, 0, _total_blocks ); */
/*     else */
/*         sem_init( &_blocks, 0, 0 ); */

    if ( is_output )
    {
        int n;
        sem_getvalue( &_blocks, &n );

        n = _total_blocks - n;

        while ( n-- )
            sem_post( &_blocks );
    }
    else
    {
        sem_destroy( &_blocks );

        sem_init( &_blocks, 0, 0 );
    }


}
Пример #12
0
LIB_EXPORT size_t
jack_ringbuffer_read (jack_ringbuffer_t * rb, char *dest, size_t cnt)
{
	size_t free_cnt;
	size_t cnt2;
	size_t to_read;
	size_t n1, n2;

	if ((free_cnt = jack_ringbuffer_read_space (rb)) == 0) {
		return 0;
	}

	to_read = cnt > free_cnt ? free_cnt : cnt;

	cnt2 = rb->read_ptr + to_read;

	if (cnt2 > rb->size) {
		n1 = rb->size - rb->read_ptr;
		n2 = cnt2 & rb->size_mask;
	} else {
		n1 = to_read;
		n2 = 0;
	}

	memcpy (dest, &(rb->buf[rb->read_ptr]), n1);
	rb->read_ptr = (rb->read_ptr + n1) & rb->size_mask;

	if (n2) {
		memcpy (dest + n1, &(rb->buf[rb->read_ptr]), n2);
		rb->read_ptr = (rb->read_ptr + n2) & rb->size_mask;
	}

	return to_read;
}
Пример #13
0
/*
 * The process callback for this JACK application.
 * It is called by JACK at the appropriate times.
 * @nframes : 
 * @arg :
 */
int
process (jack_nframes_t nframes, void *arg)
{
  JackCard* obj = (JackCard*) arg;
  sample_t *out;
  sample_t *in;
  
  if (obj->clear && !obj->write.can_process) {
    out = (sample_t *) jack_port_get_buffer (obj->write.port, nframes);
    memset (out, 0, nframes * sizeof(sample_t));
    obj->clear = FALSE;
  }
  
  if (!obj->can_process)
    return 0;

  if(obj->read.can_process) {
    in = (sample_t *) jack_port_get_buffer (obj->read.port, nframes);
    jack_ringbuffer_write (obj->read.buffer, (void *) in, sizeof(sample_t) * nframes);
  }

  if (obj->write.can_process) {
    out = (sample_t *) jack_port_get_buffer (obj->write.port, nframes);
    memset (out, 0, nframes * sizeof(sample_t));
    if (obj->clear && jack_ringbuffer_read_space(obj->write.buffer) == 0) {
      obj->write.can_process = FALSE;
      if (!obj->read.open)
	obj->can_process = FALSE;
      obj->clear = FALSE;
      return 0;
    }
    jack_ringbuffer_read (obj->write.buffer, (void *) out, sizeof(sample_t) * nframes);
  }
  return 0;      
}
Пример #14
0
void *shout_thread(void *data) {
	STREAM_HDR *stream;
	size_t n;
	int ret;
	struct timespec nap;
	stream = (STREAM_HDR *)data;
	stream->streaming = 1;
	while (stream->streaming) {
		shout_sync(stream->shout);
		n = jack_ringbuffer_read_space(stream->ringbuf);
		if (n < 1) {
			nap.tv_sec = shout_wait.tv_sec;
			nap.tv_nsec = shout_wait.tv_nsec;
			while (nanosleep(&nap, &nap) != 0);
			continue;
			}
		if (n > stream->shoutbuf_size) {
			if (stream->shoutbuf != NULL) free(stream->shoutbuf);
			stream->shoutbuf = (char *)my_plain_malloc(n, "shout_thread");
			stream->shoutbuf_size = n;
			}
		jack_ringbuffer_read(stream->ringbuf, stream->shoutbuf, n);
		ret = shout_send(stream->shout,
				(const unsigned char *)stream->shoutbuf, n);
		if (ret != SHOUTERR_SUCCESS) {
			log_msg("send err: %s\n",
				shout_get_error(stream->shout));
			}
		}
	return NULL;
	}
Пример #15
0
void gui_ev(void)
{
    while(jack_ringbuffer_read_space(gui_ring) >= 2048) {
        jack_ringbuffer_read(gui_ring, gui_osc_buf, 2048);
        gui_dispatch(gui_osc_buf);
    }
}
Пример #16
0
void dsp_ev(void)
{
    while(jack_ringbuffer_read_space(dsp_ring) >= 2048) {
        jack_ringbuffer_read(dsp_ring, dsp_osc_buf, 2048);
        dsp_dispatch(dsp_osc_buf);
    }
}
Пример #17
0
/*
  mast_fill_input_buffer()
  Make sure input buffer if full of audio  
*/
size_t mast_fill_input_buffer( MastAudioBuffer* buffer )
{
	int frames_wanted = buffer->get_write_space();
	size_t bytes_wanted = frames_wanted * buffer->get_channels() * sizeof( mast_sample_t );
	size_t bytes_read = 0, frames_read = 0;



	// Keep checking that there is enough audio available
	while (jack_ringbuffer_read_space(g_ringbuffer) < bytes_wanted) {
		MAST_WARNING( "Not enough audio available in ringbuffer; waiting" );
		//MAST_DEBUG("Ring buffer is %u%% full", (jack_ringbuffer_read_space(g_ringbuffer)*100) / g_ringbuffer->size);

		// Wait for some more audio to become available
		pthread_mutex_lock(&g_ringbuffer_cond_mutex);
		pthread_cond_wait(&g_ringbuffer_cond, &g_ringbuffer_cond_mutex);
		pthread_mutex_unlock(&g_ringbuffer_cond_mutex);
	}

	// Copy frames from ring buffer to temporary buffer
	bytes_read = jack_ringbuffer_read(g_ringbuffer, (char*)buffer->get_write_ptr(), bytes_wanted);
	if (bytes_read<=0) MAST_FATAL( "Failed to read from ringbuffer" );
	if (bytes_read!=bytes_wanted) MAST_WARNING("Failed to read enough audio for a full packet");
	
	// Mark the space in the buffer as used
	frames_read = bytes_read / (buffer->get_channels() * sizeof( mast_sample_t ));
	buffer->add_frames( frames_read );

	// Return the number 
	return frames_read;
}
Пример #18
0
/** take a single block from the ringbuffers and send it out the
 *  attached track's ports */
nframes_t
Playback_DS::process ( nframes_t nframes )
{
    THREAD_ASSERT( RT );

    const size_t block_size = nframes * sizeof( sample_t );

//    printf( "process: %lu %lu %lu\n", _frame, _frame + nframes, nframes );

    for ( int i = channels(); i--;  )
    {
        void *buf = track()->output[ i ].buffer( nframes );

        if ( engine->freewheeling() )
        {
            /* only ever read nframes at a time */
            while ( jack_ringbuffer_read_space( _rb[i] ) < block_size )
                usleep( 10 * 1000 );
            
            jack_ringbuffer_read( _rb[ i ], ((char*)buf), block_size );
        }
        else
       {
            /* only ever read nframes at a time */
            if ( jack_ringbuffer_read_space( _rb[i] ) < block_size )
            {
                ++_xruns;
                memset( buf, 0, block_size );
                /* FIXME: we need to resync somehow */
            }
            else
            {
                jack_ringbuffer_read( _rb[ i ], (char*)buf, block_size );
            }
        }

        /* TODO: figure out a way to stop IO while muted without losing sync */
        if ( track()->mute() || ( Track::soloing() && ! track()->solo() ) )
            buffer_fill_with_silence( (sample_t*)buf, nframes );
    }

    block_processed();

    /* FIXME: bogus */
    return nframes;
}
Пример #19
0
int jack_audio_callback(jack_nframes_t nframes, void *arg) {
	int c,s;
	WfAudioInfo* nfo = &myplayer->info;

#ifdef JACK_MIDI
	int n;
	void *jack_buf = jack_port_get_buffer(jack_midi_port, nframes);
	int nevents = jack_midi_get_event_count(jack_buf);
	for (n=0; n<nevents; n++) {
		jack_midi_event_t ev;
		jack_midi_event_get(&ev, jack_buf, n);

		if (ev.size < 3 || ev.size > 3) continue; // filter note on/off
		else {
			event_queue[queued_events_end].time = ev.time;
			event_queue[queued_events_end].size = ev.size;
			memcpy (event_queue[queued_events_end].buffer, ev.buffer, ev.size);
			queued_events_end = (queued_events_end +1 ) % JACK_MIDI_QUEUE_SIZE;
		}
	}
	if (queued_events_start != queued_events_end) {
		/* Tell the midi thread there is work to do. */
		if(pthread_mutex_trylock(&midi_thread_lock) == 0) {
			pthread_cond_signal(&midi_ready);
			pthread_mutex_unlock(&midi_thread_lock);
		}
	}
#endif

	if (!player_active) return (0);

	for(c=0; c<nfo->channels; c++) {
		j_out[c] = (jack_default_audio_sample_t*) jack_port_get_buffer(j_output_port[c], nframes);
	}

	if(playpause || jack_ringbuffer_read_space(rb) < nfo->channels * nframes * sizeof(jack_default_audio_sample_t)) {
		silent = 1;
		for(c=0; c< nfo->channels; c++) {
			memset(j_out[c], 0, nframes * sizeof(jack_default_audio_sample_t));
		}
	} else {
		silent=0;
		/* de-interleave */
		for(s=0; s<nframes; s++) {
			for(c=0; c< nfo->channels; c++) {
				jack_ringbuffer_read(rb, (char*) &j_out[c][s], sizeof(jack_default_audio_sample_t));
			}
		}
	}

	/* Tell the player thread there is work to do. */
	if(pthread_mutex_trylock(&player_thread_lock) == 0) {
		pthread_cond_signal(&buffer_ready);
		pthread_mutex_unlock(&player_thread_lock);
	}

	return(0);
};
Пример #20
0
int ringbuffer_cread(jack_ringbuffer_t *rbuf, void *buf, size_t bufsz, int advance, uint32_t *tag, size_t *len)
/* C version: returns 1 on success and 0 on error */
	{
	jack_ringbuffer_data_t vec[2];
	hdr_t hdr;
	uint32_t len0;
	size_t cnt;

	/* peek for header */
	cnt = jack_ringbuffer_peek(rbuf, (char*)&hdr, sizeof(hdr));
	if(cnt != sizeof(hdr)) return 0;
	
	/* see if there are 'len' bytes of data available */
	cnt = jack_ringbuffer_read_space(rbuf);
	if( cnt < (sizeof(hdr) + hdr.len) ) return 0;

	/* check if data fits in the user provided buffer */
	if(hdr.len > bufsz )
		return luajack_error("not enough space for ringbuffer_read() "
						"(at least %u bytes needed)", hdr.len);
	

	*tag = hdr.tag;
	*len = hdr.len;

	if(hdr.len == 0) /* tag only */
		{ 
		if(advance)
			jack_ringbuffer_read_advance(rbuf, sizeof(hdr));
		if(bufsz>0) ((char*)buf)[0]='\0';
		return 1;
		}
				
	/* get the read vector */
	jack_ringbuffer_get_read_vector(rbuf, vec);

	/* copy the data part in the user provided buffer */
	
	if(vec[0].len >= (sizeof(hdr) + hdr.len)) /* all the data are in vec[0] */
		memcpy(buf, vec[0].buf + sizeof(hdr), hdr.len);
	else if(vec[0].len > sizeof(hdr)) /* part of the data are in vec[0] */
		{
		len0 = vec[0].len - sizeof(hdr);
		memcpy(buf, vec[0].buf + sizeof(hdr), len0);
		memcpy((char*)buf + len0, vec[1].buf, hdr.len - len0);
		}
	else /* part of the header and all of the data are in vec[1] */
		{
		len0 = sizeof(hdr) - vec[0].len; /* bytes oh header in vec[1] */
		memcpy((char*)buf, vec[1].buf + len0, hdr.len);
		}
	if(advance)	
		jack_ringbuffer_read_advance(rbuf, sizeof(hdr) + hdr.len);
	return 1;
	}
Пример #21
0
int ringbuffer_luaread(jack_ringbuffer_t *rbuf, lua_State *L, int advance)
/* tag, data = read()
 * returns tag=nil if there is not a complete message (header+data) in
 * the ringbuffer
 * if the header.len is 0, data is returned as an empty string ("")
 */
	{
	jack_ringbuffer_data_t vec[2];
	hdr_t hdr;
	uint32_t len;
	size_t cnt;

	/* peek for header */
	cnt = jack_ringbuffer_peek(rbuf, (char*)&hdr, sizeof(hdr));
	if(cnt != sizeof(hdr))
		{ lua_pushnil(L); return 1; }
	
	/* see if there are 'len' bytes of data available */
	cnt = jack_ringbuffer_read_space(rbuf);
	if( cnt < (sizeof(hdr) + hdr.len) )
		{ lua_pushnil(L); return 1; }
	
	lua_pushinteger(L, hdr.tag);

	if(hdr.len == 0) /* header only */
		{ 
		if(advance)
			jack_ringbuffer_read_advance(rbuf, sizeof(hdr));
		lua_pushstring(L, ""); 
		return 2; 
		}
		
	/* get the read vector */
	jack_ringbuffer_get_read_vector(rbuf, vec);

	//printf("vec[0].len=%u, vec[1].len=%u hdr.len=%u\n",vec[0].len,vec[1].len,hdr.len);
	if(vec[0].len >= (sizeof(hdr) + hdr.len)) /* data fits in vec[0] */
		lua_pushlstring(L, vec[0].buf + sizeof(hdr), hdr.len);
	else if(vec[0].len > sizeof(hdr))
		{
		len = vec[0].len - sizeof(hdr);
		lua_pushlstring(L, vec[0].buf + sizeof(hdr), len);
		lua_pushlstring(L, vec[1].buf, hdr.len - len);
		lua_concat(L, 2);
		}
	else /* vec[0] contains only the header or part of it (data is all in vec[1]) */
		{
		len = sizeof(hdr) - vec[0].len; /* the first len bytes in vec1 are part of the header */
		lua_pushlstring(L, vec[1].buf + len, hdr.len);
		}
	if(advance)
		jack_ringbuffer_read_advance(rbuf, sizeof(hdr) + hdr.len);
	return 2;
	}
Пример #22
0
void Lv2Worker::respond()
{
    uint32_t read_space = jack_ringbuffer_read_space(responseBuffer);
    while (read_space) {
        uint32_t size = 0;
        jack_ringbuffer_read(responseBuffer, (char*)&size, sizeof(size));
        jack_ringbuffer_read(responseBuffer, response, size);
        interface->work_response(handle, size, response);
        read_space -= sizeof(size) + size;
    }
}
Пример #23
0
void cbox_jackio_poll_ports(struct cbox_io_impl *impl, struct cbox_command_target *fb)
{
    struct cbox_jack_io_impl *jii = (struct cbox_jack_io_impl *)impl;

    while (jack_ringbuffer_read_space(jii->rb_autoconnect) >= sizeof(jack_port_t *))
    {
        jack_port_t *portobj;
        jack_ringbuffer_read(jii->rb_autoconnect, (char *)&portobj, sizeof(portobj));
        port_autoconnect(jii, portobj, fb);
    }
}
Пример #24
0
int jack_callback (jack_nframes_t nframes, void *arg) {
	int jack_bsize = nframes * sizeof(jack_default_audio_sample_t);
	const char *jack_b = jack_port_get_buffer(output_port, nframes);
	if (jack_ringbuffer_write(ringbuf, (void *) jack_b, jack_bsize) < jack_bsize) {
		fprintf(stderr, "buffer underrun!\n");
	}
	if ( rtmp_i && jack_ringbuffer_read_space(ringbuf) >= (buffer_samples * sizeof(jack_default_audio_sample_t)) ) {
		ev_async_send(loop, &async);
	}
	return 0;
}
Пример #25
0
static jack_nframes_t
cbjack_stream_data_ready(cubeb_stream * stream)
{
  jack_nframes_t max_num_frames = std::numeric_limits<jack_nframes_t>::max();
  for(unsigned int c = 0; c < stream->params.channels; c++) {
    size_t read_space = jack_ringbuffer_read_space(stream->ringbuffer[c]);
    jack_nframes_t nframes = read_space / sizeof(float);
    max_num_frames = std::min(nframes, max_num_frames);
  }
  return max_num_frames;
}
Пример #26
0
int AUD_JackDevice::jack_mix(jack_nframes_t length, void *data)
{
	AUD_JackDevice* device = (AUD_JackDevice*)data;
	unsigned int i;
	int count = device->m_specs.channels;
	char* buffer;

	if(device->m_sync)
	{
		// play silence while syncing
		for(unsigned int i = 0; i < count; i++)
			memset(jack_port_get_buffer(device->m_ports[i], length), 0, length * sizeof(float));
	}
	else
	{
		size_t temp;
		size_t readsamples = jack_ringbuffer_read_space(device->m_ringbuffers[0]);
		for(i = 1; i < count; i++)
			if((temp = jack_ringbuffer_read_space(device->m_ringbuffers[i])) < readsamples)
				readsamples = temp;

		readsamples = AUD_MIN(readsamples / sizeof(float), length);

		for(unsigned int i = 0; i < count; i++)
		{
			buffer = (char*)jack_port_get_buffer(device->m_ports[i], length);
			jack_ringbuffer_read(device->m_ringbuffers[i], buffer, readsamples * sizeof(float));
			if(readsamples < length)
				memset(buffer + readsamples * sizeof(float), 0, (length - readsamples) * sizeof(float));
		}

		if(pthread_mutex_trylock(&(device->m_mixingLock)) == 0)
		{
			pthread_cond_signal(&(device->m_mixingCondition));
			pthread_mutex_unlock(&(device->m_mixingLock));
		}
	}

	return 0;
}
Пример #27
0
unsigned int JackResampler::Read(jack_default_audio_sample_t* buffer, unsigned int frames)
{
    size_t len = jack_ringbuffer_read_space(fRingBuffer);
    jack_log("JackResampler::Read input available = %ld", len / sizeof(jack_default_audio_sample_t));

    if (len < frames * sizeof(jack_default_audio_sample_t)) {
        jack_error("JackResampler::Read : producer too slow, missing frames = %d", frames);
        return 0;
    } else {
        jack_ringbuffer_read(fRingBuffer, (char*)buffer, frames * sizeof(jack_default_audio_sample_t));
        return frames;
    }
}
Пример #28
0
sample_t* JacksRbPort_read_from_ringbuffer(T _this_, int *len) {

    size_t avail = jack_ringbuffer_read_space(_this_->rb);

    jack_nframes_t rb_size  = _this_->rb_size;
    size_t blen =  avail < rb_size ? avail : rb_size;

    jack_ringbuffer_read(_this_->rb, _this_->framebuf, blen);

    *len = blen;

    return _this_->framebuf;
}
Пример #29
0
int JackWinMMEDriver::Read()
{
    size_t size;

    for (int chan = 0; chan < fCaptureChannels; chan++)  {

        if (fGraphManager->GetConnectionsNum(fCapturePortList[chan]) > 0) {

            JackMidiBuffer* midi_buffer = GetInputBuffer(chan);

            if (jack_ringbuffer_read_space (fRingBuffer[chan]) == 0) {
                // Reset buffer
                midi_buffer->Reset(midi_buffer->nframes);
            } else {

                while ((size = jack_ringbuffer_read_space (fRingBuffer[chan])) > 0) {

                    //jack_info("jack_ringbuffer_read_space %d", size);
                    int ev_count = 0;
                    jack_ringbuffer_read(fRingBuffer[chan], (char*)&ev_count, sizeof(int));

                    if (ev_count > 0) {
                        for (int j = 0; j < ev_count; j++)  {
                            unsigned int event_len = 3;
                            // Read event actual data
                            jack_midi_data_t* dest = midi_buffer->ReserveEvent(0, event_len);
                            jack_ringbuffer_read(fRingBuffer[chan], (char*)dest, event_len);
                        }
                    }
                }
            }
        } else {
            //jack_info("Consume ring buffer");
            jack_ringbuffer_read_advance(fRingBuffer[chan], jack_ringbuffer_read_space(fRingBuffer[chan]));
        }
    }
    return 0;
}
Пример #30
0
/*------------------------------------------------------------------------------
 *  Check wether read() would return anything
 *----------------------------------------------------------------------------*/
bool
JackDspSource :: canRead ( unsigned int   sec,
                           unsigned int   usec )    throw ( Exception )
{
    const unsigned int max_wait_time  = sec * 1000000;
    const unsigned int wait_increment = 10000;
    unsigned int       cur_wait       = 0;

    if ( !isOpen() ) {
        return false;
    }

    while (max_wait_time > cur_wait) {
        bool canRead = true;

        for (unsigned int c = 0 ; c < getChannel() ; c++) {
            if (jack_ringbuffer_read_space(rb[c]) <= 0) {
                canRead = false;
            }
        }

        if (canRead) {
            return true;
        }

        cur_wait += wait_increment;
        usleep ( wait_increment );
    }

    usleep( usec );
    for (unsigned int c = 0 ; c < getChannel() ; c++) {
        if (jack_ringbuffer_read_space(rb[c]) <= 0) {
            return false;
        }
    }

    return true;
}