1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
#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();
}
|