Skip to content

Instantly share code, notes, and snippets.

@RelativisticMechanic
Created March 22, 2018 19:54
Show Gist options
  • Save RelativisticMechanic/9df906d1175eacde2e5a7ba2993e79b8 to your computer and use it in GitHub Desktop.
Save RelativisticMechanic/9df906d1175eacde2e5a7ba2993e79b8 to your computer and use it in GitHub Desktop.
Portaudio Test
int audio_interface_play_sound(int channels, int sample_rate, int len, uint16_t* data)
{
PaStream* stream;
PaError err = Pa_OpenDefaultStream(&stream, 0, 1, paInt16, sample_rate, 256, audio_interface_callback, data);
if(err != paNoError)
{
fprintf(stderr, "stdgfx: error opening audio stream %s\n", Pa_GetErrorText(err));
return -1;
}
return audio_interface_add_sound(stream, channels, sample_rate, len, data);
}
static int audio_interface_callback( const void *inputBuffer, void *outputBuffer,
unsigned long framesPerBuffer,
const PaStreamCallbackTimeInfo* timeInfo,
PaStreamCallbackFlags statusFlags,
void *userData )
{
uint16_t* out = (uint16_t*)outputBuffer;
uint16_t* data = (uint16_t*)((uintptr_t)userData + test_len*sizeof(uint16_t));
// Pass data to the output buffer??
for(int i = 0; i < framesPerBuffer; i++)
{
*out++ = *data++;
test_len++;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment