Skip to content

Instantly share code, notes, and snippets.

@jpcima
Created August 9, 2018 14:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jpcima/044c1040236fed413d5adf91deaa90fe to your computer and use it in GitHub Desktop.
Save jpcima/044c1040236fed413d5adf91deaa90fe to your computer and use it in GitHub Desktop.
RtAudio #123
#include "RtAudio.h"
#include <string.h>
#include <unistd.h>
static int channels = 0;
int audio_callback(
void *outputBuffer, void *inputBuffer,
unsigned int nFrames,
double streamTime,
RtAudioStreamStatus status,
void *userData)
{
memset(outputBuffer, 0, channels * nFrames * sizeof(float));
return 0;
}
int main(int argc, char *argv[])
{
int channels = 0;
if (argc != 2 || (channels = atoi(argv[1])) < 1) {
fprintf(stderr, "You must pass a channel count argument!\n");
return 1;
}
::channels = channels;
RtAudio *audio = new RtAudio(RtAudio::UNIX_JACK);
RtAudio::StreamParameters inp;
inp.nChannels = channels;
inp.deviceId = audio->getDefaultInputDevice();
RtAudio::StreamParameters outp;
outp.nChannels = channels;
outp.deviceId = audio->getDefaultOutputDevice();
RtAudio::StreamOptions opts;
opts.flags = RTAUDIO_JACK_DONT_CONNECT;
opts.streamName = "RtAudio with JACK";
unsigned rate = audio->getDeviceInfo(inp.deviceId).preferredSampleRate;
unsigned bs = 1024;
fprintf(stderr, "Open Stream\n");
audio->openStream(&outp, &inp, RTAUDIO_FLOAT32, rate, &bs, &audio_callback, nullptr, &opts);
fprintf(stderr, "Start Stream\n");
audio->startStream();
for (;;)
pause();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment