Пример #1
0
/* Callback called by JACK when audio is available
   Use as little CPU time as possible, just copy accross the audio
   into the ring buffer
*/
static int process_callback(jack_nframes_t nframes, void *arg)
{
	MastSendTool* tool = (MastSendTool*)arg;
	unsigned int channels = tool->get_input_channels();
    size_t to_write = 0, written = 0;
	unsigned int c,n;
	
	// Process channel by channel
	for (c=0; c < channels; c++)
	{	
        jack_default_audio_sample_t *buf = (jack_default_audio_sample_t*)
        	jack_port_get_buffer(g_jackport[c], nframes);
 
		// Interleave the left and right channels
		for(n=0; n<nframes; n++) {
			g_interleavebuf[(n*channels)+c] = buf[n];
		}
	}

	// Now write the interleaved audio to the ring buffer
	to_write = sizeof(float) * nframes * channels;
	written = jack_ringbuffer_write(g_ringbuffer, (char*)g_interleavebuf, to_write);
	if (to_write > written) {
		// If this goes wrong, then the buffer goes out of sync and we get static
		MAST_FATAL("Failed to write to ring ruffer, try increading the ring-buffer size");
		return 1;
	}
	
	// Signal the other thread that audio is available
	pthread_cond_signal(&g_ringbuffer_cond);

	// Success
	return 0;
}
Пример #2
0
// Callback called by JACK when buffersize changes
static int buffersize_callback(jack_nframes_t nframes, void *arg)
{
	MastSendTool* tool = (MastSendTool*)arg;
	int channels = tool->get_input_channels();
	MAST_DEBUG("JACK buffer size is %d samples long", nframes);

	// (re-)allocate conversion buffer
	g_interleavebuf = (jack_default_audio_sample_t*)
		realloc( g_interleavebuf, nframes * sizeof(float) * channels );
	if (g_interleavebuf == NULL) {
		MAST_FATAL("Failed to (re-)allocate the convertion buffer");
	}

	// Success
	return 0;
}