diff --git a/src/internal_modules/roc_sndio/target_sndfile/roc_sndio/sndfile_sink.cpp b/src/internal_modules/roc_sndio/target_sndfile/roc_sndio/sndfile_sink.cpp index 9a7799a69..6f002e61e 100644 --- a/src/internal_modules/roc_sndio/target_sndfile/roc_sndio/sndfile_sink.cpp +++ b/src/internal_modules/roc_sndio/target_sndfile/roc_sndio/sndfile_sink.cpp @@ -133,7 +133,7 @@ SndfileSink::SndfileSink(core::IArena& arena, const Config& config) memset(&sf_info_out_, 0, sizeof(sf_info_out_)); - sf_info_out_.format = SF_FORMAT_PCM_32; //change back to 32 after testing + sf_info_out_.format = SF_FORMAT_PCM_32; sf_info_out_.channels = (int)config.sample_spec.num_channels(); sf_info_out_.samplerate = (int)config.sample_spec.sample_rate(); @@ -240,31 +240,41 @@ bool SndfileSink::has_clock() const { void SndfileSink::write(audio::Frame& frame) { roc_panic_if(!valid_); - const audio::sample_t* frame_data = frame.samples(); size_t frame_size = frame.num_samples(); + + + //roc_log(LogDebug, "Frame_size: %lu", frame_size); audio::sample_t* buffer_data = buffer_.data(); size_t buffer_pos = 0; while (frame_size > 0) { for (; buffer_pos < buffer_size_ && frame_size > 0; buffer_pos++) { + buffer_data[buffer_pos] = *frame_data; frame_data++; frame_size--; } if (buffer_pos == buffer_size_) { + + //roc_log(LogDebug, "sndfile sink: buffer_data and buffer_pos being passed to write_() are: %f, and %lu, also buffer_size_ is: %lu", (double)*buffer_data, buffer_pos, buffer_size_); + write_(buffer_data, buffer_pos); buffer_pos = 0; } } - + + + //roc_log(LogDebug, "sndfile sink: buffer_data and buffer_pos being passed to FINAL write_() are: %f, and %lu", (double)*buffer_data, buffer_pos); write_(buffer_data, buffer_pos); + } bool SndfileSink::setup_buffer_() { buffer_size_ = sample_spec_.ns_2_samples_overall(frame_length_); + roc_log(LogInfo, "sndfile sink: buffer size is %lu", buffer_size_); if (buffer_size_ == 0) { roc_log(LogError, "sndfile sink: buffer size is zero"); return false; @@ -291,6 +301,10 @@ bool SndfileSink::open_(const char* driver, const char* path) { int bits = 0; sf_info_out_.format = map_to_sndfile(sf_info_out_, driver, bits); + if(!sf_format_check(&sf_info_out_)){ + roc_panic("sndfile sink: sf_format_check detected invalid format parameters"); + } + sndfile_output_ = sf_open(path, SFM_WRITE, &sf_info_out_); if (!sndfile_output_) { roc_log(LogDebug, "sndfile sink: can't open: driver=%s path=%s", driver, path); @@ -313,11 +327,12 @@ bool SndfileSink::open_(const char* driver, const char* path) { (unsigned long)bits, out_rate, in_rate, (unsigned long)sf_info_out_.channels, (int)is_file_); + sf_seek(sndfile_output_, 0, SEEK_SET); + return true; } -void SndfileSink::write_(const audio::sample_t * samples, size_t n_samples) { - +void SndfileSink::write_(const audio::sample_t* samples, size_t n_samples) { if (n_samples > 0) { if (sf_write_float(sndfile_output_, samples, (sf_count_t)n_samples) != (sf_count_t)n_samples) { roc_log(LogError, "sndfile sink: failed to write output buffer"); diff --git a/src/internal_modules/roc_sndio/target_sndfile/roc_sndio/sndfile_sink.h b/src/internal_modules/roc_sndio/target_sndfile/roc_sndio/sndfile_sink.h index 9ba14b78c..e4ae09c7f 100644 --- a/src/internal_modules/roc_sndio/target_sndfile/roc_sndio/sndfile_sink.h +++ b/src/internal_modules/roc_sndio/target_sndfile/roc_sndio/sndfile_sink.h @@ -83,7 +83,7 @@ class SndfileSink : public ISink, public core::NonCopyable<> { private: bool setup_buffer_(); bool open_(const char* driver, const char* path); - void write_(const audio::sample_t* samples, size_t n_samples); + void write_(const audio::sample_t * samples, size_t n_samples); void close_(); SNDFILE * sndfile_output_; diff --git a/src/internal_modules/roc_sndio/target_sndfile/roc_sndio/sndfile_source.cpp b/src/internal_modules/roc_sndio/target_sndfile/roc_sndio/sndfile_source.cpp index 37b4c6664..fbab31419 100644 --- a/src/internal_modules/roc_sndio/target_sndfile/roc_sndio/sndfile_source.cpp +++ b/src/internal_modules/roc_sndio/target_sndfile/roc_sndio/sndfile_source.cpp @@ -370,6 +370,8 @@ bool SndfileSource::open_() { (unsigned long)sample_rate_, (unsigned long)sf_info_in_.channels, (unsigned long)0, (int)is_file_); + sf_seek(sndfile_input_, 0, SEEK_SET); + return true; }