Skip to content

Race condition in Microphone capture #94

Open
@cpiber

Description

@cpiber

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);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions