Пример #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;
}
Пример #3
0
int main(int argc, char **argv)
{
    MastSendTool *tool = NULL;
    SF_INFO sfinfo;


    // Create the send tool object
    tool = new MastSendTool( MAST_TOOL_NAME );
    tool->enable_scheduling();

    // Parse the command line arguments
    // and configure the session
    parse_cmd_line( argc, argv, tool );

    // Open the input file by filename
    memset( &sfinfo, 0, sizeof(sfinfo) );
    g_input_file = sf_open(g_filename, SFM_READ, &sfinfo);
    if (g_input_file == NULL) MAST_FATAL("Failed to open input file:\n%s", sf_strerror(NULL));
    tool->set_input_channels( sfinfo.channels );
    tool->set_input_samplerate( sfinfo.samplerate );

    // Display some information about the input file
    print_file_info( g_input_file, &sfinfo );

    // Setup signal handlers
    mast_setup_signals();

    // Run the main loop
    tool->run();

    // Clean up
    delete tool;


    // Close input file
    if (sf_close( g_input_file )) {
        MAST_ERROR("Failed to close input file:\n%s", sf_strerror(g_input_file));
    }


    // Success !
    return 0;
}
Пример #4
0
int main(int argc, char **argv)
{
	MastSendTool *tool = NULL;
	jack_client_t* client = NULL;


	// Create the send tool object
	tool = new MastSendTool( MAST_TOOL_NAME );


	// Parse the command line arguments 
	// and configure the session
	parse_cmd_line( argc, argv, tool );


	// Initialise Jack
	client = init_jack( tool );
	if (client==NULL) MAST_FATAL( "Failed to initialise JACK client" );
	
	// Get the samplerate of the JACK Router
	tool->set_input_samplerate( jack_get_sample_rate( client ) );
	
	// Setup signal handlers
	mast_setup_signals();

	// Run the main loop
	tool->run();
	
	// Clean up
	delete tool;
	

	// Shut down JACK
	deinit_jack( client );

	
	// Success !
	return 0;
}