static void recording_stream_read_callback(pa_stream *stream, size_t nbytes, void *userdata) { SoundIoInStreamPrivate *is = (SoundIoInStreamPrivate*)userdata; SoundIoInStream *instream = &is->pub; assert(nbytes % instream->bytes_per_frame == 0); assert(nbytes > 0); int available_frame_count = nbytes / instream->bytes_per_frame; instream->read_callback(instream, 0, available_frame_count); }
static int instream_sample_rate_callback(jack_nframes_t nframes, void *arg) { SoundIoInStreamPrivate *is = (SoundIoInStreamPrivate *)arg; SoundIoInStream *instream = &is->pub; if (nframes == (jack_nframes_t)instream->sample_rate) { return 0; } else { instream->error_callback(instream, SoundIoErrorStreaming); return -1; } }
static int instream_buffer_size_callback(jack_nframes_t nframes, void *arg) { SoundIoInStreamPrivate *is = (SoundIoInStreamPrivate *)arg; SoundIoInStreamJack *isj = &is->backend_data.jack; SoundIoInStream *instream = &is->pub; if ((jack_nframes_t)isj->period_size == nframes) { return 0; } else { instream->error_callback(instream, SoundIoErrorStreaming); return -1; } }
static int instream_process_callback(jack_nframes_t nframes, void *arg) { SoundIoInStreamPrivate *is = (SoundIoInStreamPrivate *)arg; SoundIoInStream *instream = &is->pub; SoundIoInStreamJack *isj = &is->backend_data.jack; isj->frames_left = nframes; for (int ch = 0; ch < instream->layout.channel_count; ch += 1) { SoundIoInStreamJackPort *isjp = &isj->ports[ch]; isj->areas[ch].ptr = (char*)jack_port_get_buffer(isjp->dest_port, nframes); isj->areas[ch].step = instream->bytes_per_sample; } instream->read_callback(instream, isj->frames_left, isj->frames_left); return 0; }
static void recording_stream_state_callback(pa_stream *stream, void *userdata) { SoundIoInStreamPrivate *is = (SoundIoInStreamPrivate*)userdata; SoundIoInStreamPulseAudio *ispa = &is->backend_data.pulseaudio; SoundIoInStream *instream = &is->pub; SoundIo *soundio = instream->device->soundio; SoundIoPrivate *si = (SoundIoPrivate *)soundio; SoundIoPulseAudio *sipa = &si->backend_data.pulseaudio; switch (pa_stream_get_state(stream)) { case PA_STREAM_UNCONNECTED: case PA_STREAM_CREATING: case PA_STREAM_TERMINATED: break; case PA_STREAM_READY: ispa->stream_ready = true; pa_threaded_mainloop_signal(sipa->main_loop, 0); break; case PA_STREAM_FAILED: instream->error_callback(instream, SoundIoErrorStreaming); break; } }
static void instream_shutdown_callback(void *arg) { SoundIoInStreamPrivate *is = (SoundIoInStreamPrivate *)arg; SoundIoInStream *instream = &is->pub; instream->error_callback(instream, SoundIoErrorStreaming); }
static int instream_xrun_callback(void *arg) { SoundIoInStreamPrivate *is = (SoundIoInStreamPrivate *)arg; SoundIoInStream *instream = &is->pub; instream->overflow_callback(instream); return 0; }