Skip to content

Commit

Permalink
fix(audio): initialize WriteFile before writing audio frames
Browse files Browse the repository at this point in the history
- Add initialization check in WriteFile to ensure file is properly set up before writing
- Call initFile with filename when first writing audio frames
- Prevent potential errors from writing to an uninitialized file
  • Loading branch information
sinkingsugar committed Jan 25, 2025
1 parent 1c9c3c2 commit c825bf1
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions shards/modules/audio/audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1199,6 +1199,11 @@ struct WriteFile {
if (input.payload.audioValue.channels != _channels) {
throw ActivationError("Input has an invalid number of audio channels");
}
if (!_initialized) {
const auto fname = SHSTRVIEW(_filename.get());
initFile(fname);
_initialized = true;
}
ma_encoder_write_pcm_frames(&_encoder, input.payload.audioValue.samples, input.payload.audioValue.nsamples, NULL);
return input;
}
Expand Down

0 comments on commit c825bf1

Please sign in to comment.