summaryrefslogblamecommitdiffstats
path: root/src/sound.c
blob: 49de8993a9505f77609a2f440423f927eed6756d (plain) (tree)




















































                                                                                                           
#include "sound.h"


static void
StreamFinished( void* synthData )
{
  synth_t *synth = (synth_t *) synthData;
}

void
init_sound(synth_t * synth, PaStreamCallback *streamCallback)
{
  Pa_Initialize();

  int i;
  const   PaDeviceInfo *deviceInfo;
  for( i=0; i< Pa_GetDeviceCount(); i++ ) {
    deviceInfo = Pa_GetDeviceInfo( i );
    //if (!strcmp("HyperX Cloud II Wireless: USB Audio (hw:2,0)", deviceInfo->name)) break;
    printf("dev: %s || %f\n", deviceInfo->name, deviceInfo->defaultSampleRate);
    //if (!strcmp("HDA Intel PCH: ALC1220 Analog (hw:0,0)", deviceInfo->name)) break;
    if (!strcmp("pulse", deviceInfo->name)) break;
  }


  PaStreamParameters outputParameters;
  outputParameters.device = i; Pa_GetDefaultOutputDevice(); /* default output device */
  printf("-------\nSelected device: %s\n-------\n", Pa_GetDeviceInfo(outputParameters.device)->name);
  outputParameters.channelCount = 2;       /* stereo output */
  outputParameters.sampleFormat = paFloat32; /* 32 bit floating point output */
  outputParameters.suggestedLatency = Pa_GetDeviceInfo( outputParameters.device )->defaultLowOutputLatency;
  outputParameters.hostApiSpecificStreamInfo = NULL;

  Pa_OpenStream(&(synth->stream),
                NULL, /* no input */
                &outputParameters,
                SAMPLE_RATE,
                FRAMES_PER_BUFFER,
                paClipOff,      /* we won't output out of range samples so don't bother clipping them */
                streamCallback,
                synth );

  Pa_SetStreamFinishedCallback(synth->stream, &StreamFinished);
  Pa_StartStream(synth->stream);
}

void
destroy_sound(synth_t * synth)
{
  Pa_StopStream( synth->stream );
  Pa_CloseStream( synth->stream );
  Pa_Terminate();
}