linux - Can you use a PortAudio callback to write back to a stream's input buffer? -
at highlevel, goal take microphone input 1 stream, processing on it, , copy microphone input stream. latter being default device, other applications (which reasons out of hands, can't specify other device) can record default device , still processed input.
here's snippet of code:
int stream1_callback(const void *card_capture, void *card_playback, unsigned long framecount, const pastreamcallbacktimeinfo *timeinfo, pastreamcallbackflags statusflags, void *userdata) { main_t *data = (main_t *) userdata; // unused(card_capture); unused(card_playback); unused(framecount); unused(timeinfo); unused(statusflags); // unused(userdata); deinterleave_i16_i16(card_capture, data->mic_unprocessed, num_mics, blocksize_48khz); printf("de-interleaved!\n"); process_microphones(data->mic_unprocessed, data->mic_processed); printf("processed!\n"); return 0; } int stream2_callback(const void *inputbuffer, void *outputbuffer, unsigned long framecount, const pastreamcallbacktimeinfo *timeinfo, pastreamcallbackflags statusflags, void *userdata) { main_t *data = (main_t *) userdata; // unused(inputbuffer); unused(outputbuffer); unused(framecount); unused(timeinfo); unused(statusflags); // unused(userdata); interleave_i16_i16(data->mic_processed, (int16 *)inputbuffer, 1, blocksize_16khz); printf("interleaved!\n"); return 0; } int main() { // ... /* -- setup stream1 -- */ err = pa_openstream(&stream1, &stream1inputparams, null, 48000, blocksize_48khz, panoflag, stream1_callback, &main_data); if (err != panoerror) { goto error; } /* -- setup stream2 -- */ err = pa_opendefaultstream(&stream2, 1, 0, paint16, 16000, blocksize_16khz, stream2_callback, &main_data); if (err != panoerror) { goto error; } //... }
so i'm wondering if callback's input buffer writable. or if there other (better) way can write input of device.
in general, capture devices cannot written to; go directly hardware.
to able inject own samples data capture device, driver must written allow that. case loopback driver, snd-aloop
.
Comments
Post a Comment