Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Race condition in Microphone capture #94

Open
cpiber opened this issue Feb 28, 2024 · 0 comments
Open

Race condition in Microphone capture #94

cpiber opened this issue Feb 28, 2024 · 0 comments

Comments

@cpiber
Copy link

cpiber commented Feb 28, 2024

In start_capture, you initialize capturing. You do this by setting p->capturing = true, and then initializing the WAV writer.

musializer/src/plug.c

Lines 1260 to 1270 in 9ddb4d2

p->capturing = true;
const char *recording_file_path = "recording.wav";
drwav_data_format format = {0};
format.container = drwav_container_riff;
format.format = DR_WAVE_FORMAT_IEEE_FLOAT;
format.channels = 2;
format.sampleRate = 44100;
format.bitsPerSample = 32;
if (!drwav_init_file_write(&p->wav, recording_file_path, &format, NULL)) {

However, in the callback, you simply use the WAV writer as soon as p->capturing is true. Meaning that you might be using an uninitialized WAV (Note that this exact thing happened in the last stream, though the code looked a little different, when you tried to use a debugger).

musializer/src/plug.c

Lines 487 to 491 in 9ddb4d2

if (p->capturing) {
// TODO: according to documentation drwav_write_pcm_frames may not write all the frames.
// Make sure it does.
drwav_write_pcm_frames(&p->wav, frames, bufferData);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant