0

I am using the amazing Superpowered library (SuperpoweredAndroidAudioIO) for low-latency recording of audio. While the basic concepts are clear to me, I want to pass the recorded audio (which arrives in a buffer) back to an InputStream in Java (without recording to a file), from which I can then read the recorded audio and process it.

I guess this question could also be more generally asked - how to feed an InputStream in Java from a periodically updated buffer in C++?

Carsten
  • 3
  • 2
  • Yes, I understand - thanks a lot for the surprisingly simple suggestion, I'll give it a try and let you know how well it worked! – Carsten Nov 12 '17 at 12:58

1 Answers1

0

Well, the suggestion I received in a comment turned out to be a simple and working solution: Creation of pipe in C++:

 if (pipe(pipefd) == -1) {
    __android_log_print(ANDROID_LOG_VERBOSE, "C++", "Error creating pipe");
 }
...

Passing file descriptor to Java:

...
    return pipefd[0];
...

Then in Java/Android:

private ParcelFileDescriptor.AutoCloseInputStream underlyingStream;
ParcelFileDescriptor pfd = ParcelFileDescriptor.adoptFd(getFD());
underlyingStream = new ParcelFileDescriptor.AutoCloseInputStream(pfd);

Worked well for me, but of course I'm still happy to receive other suggestions.

Carsten
  • 3
  • 2