// This programme captures audio from 8 sources then writes them to a 8 channel wav file called 'capture'wav' // It is intended to demonstrate using JACK and FFADO with a Focusrite Saffire Pro 10 I/O // // It is compiled using the following command // gcc -Wall -lsndfile -ljack -lpthread -lrt -o wavCapture wavCapture.c // // A.Greensted // September 2010 #define _GNU_SOURCE // Declare this as GNU source so prototype for asprintf is define #include #include #include #include #include #include #include #include #define NUM_INPUT_PORTS 8 // Number of capture ports to connect to #define RING_BUFFER_SIZE 16384 // Ring Buffer size in frames int allConnected; // Flag specifying all inputs and outputs are connected jack_port_t **inputPortArray; // Array of pointers to input ports jack_default_audio_sample_t **inputBufferArray; // Array of pointers to input buffers jack_ringbuffer_t *ringBuffer; // Ring buffer to pass audio data between JACK and main threads int running; // Flag to control disk writing process pthread_mutex_t threadLock = PTHREAD_MUTEX_INITIALIZER; // Mutex to control ring buffer access pthread_cond_t dataReady = PTHREAD_COND_INITIALIZER; // Condition to signal data is available in ring buffer // This is called by the JACK server in a // special realtime thread once for each audio cycle. int jackProcess(jack_nframes_t nframes, void *arg) { int portNum; jack_nframes_t frameNum; // Only proceed if all ports have been connected if (allConnected == 0) return 0; // Get pointers to the capture port buffers for (portNum=0 ; portNum= bytesPerFrame) { // Read a single frame of data jack_ringbuffer_read(ringBuffer, (void *)frameBuffer, bytesPerFrame); // Write data to file sf_writef_float(sndFile, (float*)frameBuffer, 1); } } while (running); printf("Closing\n"); jack_client_close(client); sf_write_sync(sndFile); sf_close(sndFile); jack_ringbuffer_free(ringBuffer); return 0; }