Skip to content

Instantly share code, notes, and snippets.

@CosineP
Created July 14, 2018 21:45
Show Gist options
  • Save CosineP/c2811cd9b7461b05046f15d4ae2f0183 to your computer and use it in GitHub Desktop.
Save CosineP/c2811cd9b7461b05046f15d4ae2f0183 to your computer and use it in GitHub Desktop.
A failing mumlib / portaudio program
#include "mumlib.hpp"
#include "portaudio.h"
#include <thread>
#define SAMPLE_RATE (8000)
#define print printf
mumlib::Mumlib *mumble;
int staticCallback(const void *inputBuffer, void *outputBuffer,
unsigned long framesPerBuffer,
const PaStreamCallbackTimeInfo* timeInfo,
PaStreamCallbackFlags statusFlags,
void * _) {
int16_t *in = (int16_t*)inputBuffer;
mumble->sendAudioData(in, (uint32_t)framesPerBuffer);
return 0;
}
void run(void) {
mumble->run();
}
int main() {
// init Mumble
mumlib::MumlibConfiguration conf;
conf.opusEncoderBitrate = SAMPLE_RATE;
mumlib::BasicCallback myCallback;
mumble = new mumlib::Mumlib(myCallback, conf);
mumble->connect("nv.cosinegaming.com", 64738, "mumlib_example", "");
std::thread(run);
// Init PortAudio
auto err = Pa_Initialize();
if (err != paNoError) {
print( "Init: PortAudio error:");
print(Pa_GetErrorText( err ) );
return 1;
}
//
/* Open an audio I/O stream. */
PaStream *stream;
err = Pa_OpenDefaultStream( &stream,
1, // In
0, // Out
paInt16,
SAMPLE_RATE,
paFramesPerBufferUnspecified,
staticCallback,
nullptr // Send this object so we can bind to C
);
if (err != paNoError) {
print( "Open: PortAudio error:");
print(Pa_GetErrorText( err ) );
return 1;
}
err = Pa_StartStream(stream);
if (err != paNoError) {
print( "Resume: PortAudio error:");
print(Pa_GetErrorText( err ) );
}
Pa_Sleep(5000);
delete mumble;
mumble = nullptr;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment