MCPcopy Create free account
hub / github.com/AnswerDotAI/gpu.cpp / main

Function main

experimental/legacy/audio/run.cpp:80–148  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

78}
79
80int main(void) {
81 PaStreamParameters inputParameters, outputParameters;
82 PaStream *stream;
83 PaError err;
84
85 printf("\033[H\033[J");
86
87 printf("Turn down volume before starting.\nPress Enter to start.");
88 getchar();
89
90 printf("\033[H\033[J");
91
92 err = Pa_Initialize();
93 check(err == paNoError, "Error: Pa_Initialize failed.");
94
95 // Setup device
96
97 inputParameters = {
98 .device = Pa_GetDefaultInputDevice(),
99 .channelCount = 1,
100 .sampleFormat = PA_SAMPLE_TYPE,
101 .suggestedLatency =
102 Pa_GetDeviceInfo(Pa_GetDefaultInputDevice())->defaultLowInputLatency,
103 .hostApiSpecificStreamInfo = NULL};
104
105 check(inputParameters.device != paNoDevice,
106 "Error: No default input device.");
107
108 outputParameters = {.device = Pa_GetDefaultOutputDevice(),
109 .channelCount = 2,
110 .sampleFormat = PA_SAMPLE_TYPE,
111 .suggestedLatency =
112 Pa_GetDeviceInfo(Pa_GetDefaultOutputDevice())
113 ->defaultLowOutputLatency,
114 .hostApiSpecificStreamInfo = NULL};
115
116 if (outputParameters.device == paNoDevice) {
117 fprintf(stderr, "Error: No default output device.\n");
118 exit(1);
119 }
120
121 constexpr size_t kBufferTime = 4; // seconds
122 std::array<float, SAMPLE_RATE * kBufferTime> bufferAlloc;
123 // zero
124 for (size_t i = 0; i < bufferAlloc.size(); i++) {
125 bufferAlloc[i] = 0;
126 }
127
128 Buffer buffer = {bufferAlloc.data(), bufferAlloc.size()};
129
130 err = Pa_OpenStream(&stream, &inputParameters, &outputParameters, SAMPLE_RATE,
131 FRAMES_PER_BUFFER, 0,
132 /* paClipOff, */ /* we won't output out of range samples
133 so don't bother clipping them */
134 callback, reinterpret_cast<void *>(&buffer));
135 check(err == paNoError, "Error: Pa_OpenStream failed.");
136
137 err = Pa_StartStream(stream);

Callers

nothing calls this directly

Calls 1

checkFunction · 0.70

Tested by

no test coverage detected