static void do_jack_output(process_jack_t *proc) { output_port_t *port = (output_port_t*) proc->port; int nevents = jack_midi_get_event_count(proc->buffer); int i; if (nevents) debug_log("jack_out: %d events in %s", nevents, port->base.name); for (i=0; i<nevents; ++i) { jack_midi_event_t event; event_head_t hdr; jack_midi_event_get(&event, proc->buffer, i); if (jack_ringbuffer_write_space(port->base.data_ring) < event.size || jack_ringbuffer_write_space(port->base.event_ring) < sizeof(hdr)) { debug_log("jack_out: output buffer overflow on %s", port->base.name); break; } midi_pack_event(&port->packer, &event); jack_ringbuffer_write(port->base.data_ring, (char*)event.buffer, event.size); hdr.time = proc->frame_time + event.time + proc->nframes; hdr.size = event.size; jack_ringbuffer_write(port->base.event_ring, (char*)&hdr, sizeof(hdr)); debug_log("jack_out: sent %d-byte event at %ld", (int)event.size, (long)event.time); } }
static void vorbis_send(VORBIS_STREAM *stream) { jack_ringbuffer_write(stream->header.ringbuf, (const char *)stream->og.header, stream->og.header_len); jack_ringbuffer_write(stream->header.ringbuf, (const char *)stream->og.body, stream->og.body_len); return; }
void CALLBACK JackWinMMEDriver::MidiInProc(HMIDIIN hMidiIn, UINT wMsg, DWORD userData, DWORD dwParam1, DWORD dwParam2) { jack_ringbuffer_t* ringbuffer = (jack_ringbuffer_t*)userData; //jack_info("JackWinMMEDriver::MidiInProc 0\n"); switch (wMsg) { case MIM_OPEN: break; case MIM_ERROR: case MIM_DATA: { //jack_info("JackWinMMEDriver::MidiInProc"); // One event unsigned int num_packet = 1; jack_ringbuffer_write(ringbuffer, (char*)&num_packet, sizeof(unsigned int)); // Write event actual data jack_ringbuffer_write(ringbuffer, (char*)&dwParam1, 3); break; } case MIM_LONGERROR: case MIM_LONGDATA: /* Nothing for now */ break; } }
void *thread_blocked(void *arg){ int datasize=SOUND_BUFFER_SIZE*sizeof (REALTYPE); //try to get realtime sched_param sc; sc.sched_priority=50; int err=sched_setscheduler(0,SCHED_FIFO,&sc); pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS,NULL); pthread_mutex_lock(&zyn_thread_lock); while (jackfinish==0){ while (jack_ringbuffer_write_space(rb)>=datasize){ pthread_mutex_lock(&jackmaster->mutex); jackmaster->GetAudioOutSamples(SOUND_BUFFER_SIZE,jack_get_sample_rate(jackclient),jackoutl,jackoutr); pthread_mutex_unlock(&jackmaster->mutex); jack_ringbuffer_write(rb, (char *) jackoutl,datasize); jack_ringbuffer_write(rb, (char *) jackoutr,datasize); }; pthread_cond_wait(&more_data,&zyn_thread_lock); }; pthread_mutex_unlock(&zyn_thread_lock); return(0); };
LV2_Worker_Status Lv2Worker::scheduleWork(const void *data, uint32_t size) { printf("scheduling work of size %d\n", size); jack_ringbuffer_write(requestBuffer, (const char*)&size, sizeof(size)); jack_ringbuffer_write(requestBuffer, (const char*)data, size); sem_post(&semaphore); // wake up worker return LV2_WORKER_SUCCESS; }
void RtMidiOutJack :: sendMessage( std::vector<unsigned char> *message ) { int nBytes = message->size(); JackMidiData *data = static_cast<JackMidiData *> (apiData_); // Write full message to buffer jack_ringbuffer_write( data->buffMessage, ( const char * ) &( *message )[0], message->size() ); jack_ringbuffer_write( data->buffSize, ( char * ) &nBytes, sizeof( nBytes ) ); }
static void input_event(alsa_seqmidi_t *self, snd_seq_event_t *alsa_event, struct process_info* info) { jack_midi_data_t data[MAX_EVENT_SIZE]; stream_t *str = &self->stream[PORT_INPUT]; long size; int64_t alsa_time, time_offset; int64_t frame_offset, event_frame; port_t *port; port = port_get(str->ports, alsa_event->source); if (!port) return; /* * RPNs, NRPNs, Bank Change, etc. need special handling * but seems, ALSA does it for us already. */ snd_midi_event_reset_decode(str->codec); if ((size = snd_midi_event_decode(str->codec, data, sizeof(data), alsa_event))<0) return; // fixup NoteOn with vel 0 if ((data[0] & 0xF0) == 0x90 && data[2] == 0x00) { data[0] = 0x80 + (data[0] & 0x0F); data[2] = 0x40; } alsa_time = alsa_event->time.time.tv_sec * NSEC_PER_SEC + alsa_event->time.time.tv_nsec; time_offset = info->alsa_time - alsa_time; frame_offset = (info->sample_rate * time_offset) / NSEC_PER_SEC; event_frame = (int64_t)info->cur_frames - info->period_start - frame_offset + info->nframes; debug_log("input: %d bytes at event_frame = %d", (int)size, (int)event_frame); if (event_frame >= info->nframes && jack_ringbuffer_write_space(port->early_events) >= (sizeof(alsa_midi_event_t) + size)) { alsa_midi_event_t ev; ev.time = event_frame + info->period_start; ev.size = size; jack_ringbuffer_write(port->early_events, (char*)&ev, sizeof(ev)); jack_ringbuffer_write(port->early_events, (char*)data, size); debug_log("postponed to next frame +%d", (int) (event_frame - info->nframes)); return; } if (event_frame < 0) event_frame = 0; else if (event_frame >= info->nframes) event_frame = info->nframes - 1; jack_midi_event_write(port->jack_buf, event_frame, data, size); }
void JACKAudioSource::ReceiveAudio(float *inLeft, float *inRight, UINT frames) { if (!inLeft || !inRight) return; for (UINT j = 0, i = 0; i < frames; i++) { if (jack_ringbuffer_write_space(sampleBuffer) < (sizeof(float)*2)) break; jack_ringbuffer_write(sampleBuffer, (const char *)&inLeft[i], sizeof(float)); jack_ringbuffer_write(sampleBuffer, (const char *)&inRight[i], sizeof(float)); } }
int process (jack_nframes_t nframes, void *arg) { ad_rec_t *handle = (ad_rec_t *) arg; size_t buffer_size = jack_ringbuffer_write_space (handle->rbuffer); jack_default_audio_sample_t *in = (jack_default_audio_sample_t *) jack_port_get_buffer (handle->input_port, nframes); if (buffer_size <= 0) { fprintf(stderr, "JACK: buffer is full. Deactivating JACK client.\n"); return 1; } /* Write to jack ringbuffer which should be thread safe */ jack_ringbuffer_write (handle->rbuffer, (char*) in, sample_size * nframes); #ifdef MIC_SPEAKER_PASSTHROUGH_DEBUG jack_default_audio_sample_t *out = (jack_default_audio_sample_t *) jack_port_get_buffer (handle->output_port, nframes); /* Output mic output to speakers (Just for testing) */ memcpy (out, in, sample_size * nframes); #endif return 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; }
// Data transmission methods. bool qmidinetJackMidiDevice::sendData ( unsigned char *data, unsigned short len, int port ) const { if (port < 0 || port >= m_nports) return false; if (m_pJackBufferOut == NULL) return false; const unsigned int nlimit = jack_ringbuffer_write_space(m_pJackBufferOut); if (sizeof(qmidinetJackMidiEvent) + len < nlimit) { unsigned char achBuffer[nlimit]; unsigned char *pchBuffer = &achBuffer[0]; qmidinetJackMidiEvent *pJackEventOut = (struct qmidinetJackMidiEvent *) pchBuffer; pchBuffer += sizeof(qmidinetJackMidiEvent); memcpy(pchBuffer, data, len); pJackEventOut->event.time = jack_frame_time(m_pJackClient); pJackEventOut->event.buffer = (jack_midi_data_t *) pchBuffer; pJackEventOut->event.size = len; pJackEventOut->port = port; #ifdef CONFIG_DEBUG // - show (output) event for debug purposes... fprintf(stderr, "JACK MIDI Out Port %d:", port); for (unsigned int i = 0; i < len; ++i) fprintf(stderr, " 0x%02x", (unsigned char) pchBuffer[i]); fprintf(stderr, "\n"); #endif jack_ringbuffer_write(m_pJackBufferOut, (const char *) achBuffer, sizeof(qmidinetJackMidiEvent) + len); } return true; }
static int jack_process(jack_nframes_t nframes, void *arg) { int i; int samples_written, result; jack_t * priv = arg; int write_space; char *out; pthread_mutex_lock(&priv->active_mutex); // fprintf(stderr, "Jack Process %d\n", nframes); /* Check if there is enough space */ for(i = 0; i < priv->num_ports; i++) { if(!priv->ports[i].active) continue; write_space = jack_ringbuffer_write_space(priv->ports[i].buffer); if(write_space < nframes * sizeof(float)) { bg_log(BG_LOG_WARNING, LOG_DOMAIN, "Dropping %d samples", nframes); pthread_mutex_unlock(&priv->active_mutex); return 0; } } for(i = 0; i < priv->num_ports; i++) { if(!priv->ports[i].active) continue; samples_written = 0; out = jack_port_get_buffer(priv->ports[i].int_port, nframes); while(samples_written < nframes) { result = jack_ringbuffer_write(priv->ports[i].buffer, out + samples_written * sizeof(float), (nframes - samples_written) * sizeof(float)); #if 0 if(i) fprintf(stderr, "Write %d %d %ld\n", samples_written, f->valid_samples - samples_written, result); #endif result /= sizeof(float); samples_written += result; } } pthread_mutex_unlock(&priv->active_mutex); return 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; }
int JackClient::processJackCallback(jack_nframes_t nFrames, void* arg) { JackClient* jackClient = static_cast<JackClient*>(arg); jack_default_audio_sample_t* p_leftChannelInputAudioSamples = reinterpret_cast<jack_default_audio_sample_t*>(jack_port_get_buffer(m_p_leftChannelInputPort, nFrames)); jack_default_audio_sample_t* p_rightChannelInputAudioSamples = reinterpret_cast<jack_default_audio_sample_t*>(jack_port_get_buffer(m_p_rightChannelInputPort, nFrames)); jack_default_audio_sample_t sampleBuffer[nFrames]; uint32_t sampleIndex = 0; double avgSampleValue = 0; for (sampleIndex = 0; sampleIndex < nFrames; sampleIndex++) { avgSampleValue += fabs(p_leftChannelInputAudioSamples[sampleIndex]); avgSampleValue += fabs(p_rightChannelInputAudioSamples[sampleIndex]); } m_lastAudioSample = avgSampleValue / (2 * nFrames); // get avg of the two channels // TODO(scasa):check if this is right... for (uint32_t i = 0; i < nFrames; i++) { sampleBuffer[i] = (p_leftChannelInputAudioSamples[i] + p_rightChannelInputAudioSamples[i]) / 2; } const uint32_t writeSizeInByte = nFrames * sizeof(jack_default_audio_sample_t); if (jack_ringbuffer_write_space(jackClient->getRingBuffer()) >= writeSizeInByte) { // DEBUG_PRINT("write to ringbuffer, %d byte", writeSizeInByte); jack_ringbuffer_write(jackClient->getRingBuffer(), reinterpret_cast<const char*>(sampleBuffer), writeSizeInByte); } return 0; }
int JackLayer::process_capture(jack_nframes_t frames, void *arg) { JackLayer *context = static_cast<JackLayer*>(arg); for (unsigned i = 0; i < context->in_ringbuffers_.size(); ++i) { // read from input jack_default_audio_sample_t *in_buffers = static_cast<jack_default_audio_sample_t*>(jack_port_get_buffer(context->in_ports_[i], frames)); const size_t bytes_to_read = frames * sizeof(*in_buffers); size_t bytes_to_rb = jack_ringbuffer_write(context->in_ringbuffers_[i], (char *) in_buffers, bytes_to_read); // fill the rest with silence if (bytes_to_rb < bytes_to_read) { // TODO: set some flag for underrun? RING_WARN("Dropped %lu bytes", bytes_to_read - bytes_to_rb); } } /* Tell the ringbuffer thread there is work to do. If it is already * running, the lock will not be available. We can't wait * here in the process() thread, but we don't need to signal * in that case, because the ringbuffer thread will read all the * data queued before waiting again. */ if (context->ringbuffer_thread_mutex_.try_lock()) { context->data_ready_.notify_one(); context->ringbuffer_thread_mutex_.unlock(); } return 0; }
void *read_handler(void *arg) { int i, cntr; uint32_t rate = rate_thread; uint32_t size = size_thread; uint64_t buffer[3]; cntr = 0; while(cntr < (size + 1) * rate) { if(sock_thread < 0) break; if(*rx_cntr[0] < 1000) { usleep(100); continue; } for(i = 0; i < 500; ++i) { buffer[0] = *rx_data[0]; buffer[1] = *rx_data[1]; buffer[2] = *rx_data[2]; jack_ringbuffer_write(sweep_data, (char *)buffer, 24); } ++cntr; } return NULL; }
void dsp_message(const char *msg) { if(jack_ringbuffer_write_space(dsp_ring) >= 2048) jack_ringbuffer_write(dsp_ring, msg, 2048); else puts("dsp ringbuffer full..."); }
static void jack_process(alsa_seqmidi_t *self, struct process_info *info) { stream_t *str = &self->stream[info->dir]; port_jack_func process = port_type[info->dir].jack_func; int i, del=0; add_ports(str); // process ports for (i=0; i<PORT_HASH_SIZE; ++i) { port_t **pport = &str->ports[i]; while (*pport) { port_t *port = *pport; port->jack_buf = jack_port_get_buffer(port->jack_port, info->nframes); if (info->dir == PORT_INPUT) jack_midi_clear_buffer(port->jack_buf); if (!port->is_dead) (*process)(self, port, info); else if (jack_ringbuffer_write_space(self->port_del) >= sizeof(port)) { debug_log("jack: removed port %s", port->name); *pport = port->next; jack_ringbuffer_write(self->port_del, (char*)&port, sizeof(port)); del++; continue; } pport = &port->next; } } if (del) sem_post(&self->port_sem); }
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; }
static int write_to_ringbuffer(rotter_ringbuffer_t *rb, jack_nframes_t start, jack_nframes_t nframes) { size_t to_write = sizeof(jack_default_audio_sample_t) * nframes; unsigned int c; if (nframes <= 0) return 0; for (c=0; c < channels; c++) { size_t space = jack_ringbuffer_write_space(rb->buffer[c]); if (space < to_write) { // Glitch in audio is preferable to a fatal error or ring buffer corruption rb->overflow = 1; return 0; } } for (c=0; c < channels; c++) { jack_default_audio_sample_t *buf = jack_port_get_buffer(inport[c], nframes); size_t len = 0; len = jack_ringbuffer_write(rb->buffer[c], (char*)&buf[start], to_write); if (len < to_write) { rotter_fatal("Failed to write to ring buffer."); return 1; } } // Success return 0; }
/*------------------------------------------------------------------------------ * Callback called by JACK when audio is available * * Don't do anything too expensive here * - just shove audio samples in ring buffer *----------------------------------------------------------------------------*/ int JackDspSource :: process_callback( jack_nframes_t nframes, void *arg ) { JackDspSource* self = (JackDspSource*)arg; size_t to_write = sizeof (jack_default_audio_sample_t) * nframes; unsigned int c; // Wait until it is ready if (self->client == NULL) { return 0; } /* copy data to ringbuffer; one per channel */ for (c=0; c < self->getChannel(); c++) { char *buf = (char*)jack_port_get_buffer(self->ports[c], nframes); size_t len = jack_ringbuffer_write(self->rb[c], buf, to_write); if (len < to_write) { Reporter::reportEvent( 1, "failed to write to ring ruffer"); return 1; } } // Success return 0; }
/** @brief Write into the ring buffer. \param src the value to write */ void write(Type src){ if(getWriteSpace() <= 0){ //throw error!!!! return; } jack_ringbuffer_write(mRingBufferPtr, (char *)&src, sizeof(Type)); }
void ProduceAudioToBuffer(audioBuffer_t *buffer, int channel, uint8_t *data, int data_size) { if(buffer != NULL){ jack_ringbuffer_write (buffer->to_audio_buffers[channel], (char*) data, data_size); normalbuffer++; printf("NORMAL BUFFER: %d\n",normalbuffer); return; } return; }
void ProduceSyncToBuffer(audioBuffer_t *buffer, int channel, uint8_t *data, int data_size) { if(buffer != NULL){ jack_ringbuffer_write (buffer->sync_buffers[channel], (char*) data, data_size); syncbuffer++; printf("SYNC BUFFER: %d\n",syncbuffer); return; } return; }
void AUD_JackDevice::updateRingBuffers() { size_t size, temp; unsigned int samplesize = AUD_SAMPLE_SIZE(m_specs); unsigned int i, j; unsigned int channels = m_specs.channels; sample_t* buffer = m_buffer.getBuffer(); float* deinterleave = m_deinterleavebuf.getBuffer(); jack_transport_state_t state; jack_position_t position; pthread_mutex_lock(&m_mixingLock); while(m_valid) { if(m_sync > 1) { if(m_syncFunc) { state = jack_transport_query(m_client, &position); m_syncFunc(m_syncFuncData, state != JackTransportStopped, position.frame / (float) m_specs.rate); } for(i = 0; i < channels; i++) jack_ringbuffer_reset(m_ringbuffers[i]); } size = jack_ringbuffer_write_space(m_ringbuffers[0]); for(i = 1; i < channels; i++) if((temp = jack_ringbuffer_write_space(m_ringbuffers[i])) < size) size = temp; while(size > samplesize) { size /= samplesize; mix((data_t*)buffer, size); for(i = 0; i < channels; i++) { for(j = 0; j < size; j++) deinterleave[i * size + j] = buffer[i + j * channels]; jack_ringbuffer_write(m_ringbuffers[i], (char*)(deinterleave + i * size), size * sizeof(float)); } size = jack_ringbuffer_write_space(m_ringbuffers[0]); for(i = 1; i < channels; i++) if((temp = jack_ringbuffer_write_space(m_ringbuffers[i])) < size) size = temp; } if(m_sync > 1) { m_sync = 3; } pthread_cond_wait(&m_mixingCondition, &m_mixingLock); } pthread_mutex_unlock(&m_mixingLock); }
void pcap_callback(u_char* args, const struct pcap_pkthdr* packet_header, const u_char* packet) { unsigned char* test_stream_id; struct ethernet_header* eth_header; uint32_t* mybuf; uint32_t frame[CHANNELS]; jack_default_audio_sample_t jackframe[CHANNELS]; int cnt; static int total; eth_header = (struct ethernet_header*)(packet); if (0 != memcmp(ETHER_TYPE,eth_header->type,sizeof(eth_header->type))) { return; } test_stream_id = (unsigned char*)(packet + ETHERNET_HEADER_SIZE + SEVENTEEN22_HEADER_PART1_SIZE); if (0 != memcmp(test_stream_id, stream_id, STREAM_ID_SIZE)) { return; } mybuf = (uint32_t*) (packet + HEADER_SIZE); for(int i = 0; i < SAMPLES_PER_FRAME * CHANNELS; i+=CHANNELS) { memcpy(&frame[0], &mybuf[i], sizeof(frame)); for(int j = 0; j < CHANNELS; j++) { frame[j] = ntohl(frame[j]); /* convert to host-byte order */ frame[j] &= 0x00ffffff; /* ignore leading label */ frame[j] <<= 8; /* left-align remaining PCM-24 sample */ jackframe[j] = ((int32_t)frame[j])/(float)(MAX_SAMPLE_VALUE); } if ((cnt = jack_ringbuffer_write_space(ringbuffer)) >= SAMPLE_SIZE * CHANNELS) { jack_ringbuffer_write(ringbuffer, (void*)&jackframe[0], SAMPLE_SIZE * CHANNELS); } else { fprintf(stdout, "Only %i bytes available after %i samples.\n", cnt, total); } if (jack_ringbuffer_write_space(ringbuffer) <= SAMPLE_SIZE * CHANNELS * DEFAULT_RINGBUFFER_SIZE / 4) { /** Ringbuffer has only 25% or less write space available, it's time to tell jackd to read some data. */ ready = 1; } #ifdef LIBSND sf_writef_float(snd_file, jackframe, 1); #endif } }
static void port_connect_cb(jack_port_id_t port, int registered, void *arg) { struct cbox_jack_io_impl *jii = arg; if (registered) { jack_port_t *portobj = jack_port_by_id(jii->client, port); jack_ringbuffer_write(jii->rb_autoconnect, (char *)&portobj, sizeof(portobj)); } }
void jack_ringbuffer_write_exactly ( jack_ringbuffer_t *r , const char *buf , int n ) { int err = jack_ringbuffer_write ( r , buf , n ) ; if ( err != n ) { eprintf ( "%s: error writing ring buffer (%d != %d)\n" , __func__ , err , n ) ; FAILURE ; } }
static void jack_add_ports(midi_stream_t *str) { midi_port_t *port; while (can_pass(sizeof(port), str->jack.new_ports, str->midi.new_ports) && str->jack.nports < MAX_PORTS) { jack_ringbuffer_read(str->jack.new_ports, (char*)&port, sizeof(port)); str->jack.ports[str->jack.nports++] = port; port->state = PORT_ADDED_TO_MIDI; jack_ringbuffer_write(str->midi.new_ports, (char*)&port, sizeof(port)); } }
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; }