diff --git a/src/internal_modules/roc_sndio/target_pulseaudio/roc_sndio/pulseaudio_backend.cpp b/src/internal_modules/roc_sndio/target_pulseaudio/roc_sndio/pulseaudio_backend.cpp index ed5005cf0..1e0c59250 100644 --- a/src/internal_modules/roc_sndio/target_pulseaudio/roc_sndio/pulseaudio_backend.cpp +++ b/src/internal_modules/roc_sndio/target_pulseaudio/roc_sndio/pulseaudio_backend.cpp @@ -60,7 +60,7 @@ IDevice* PulseaudioBackend::open_device(DeviceType device_type, } const char* PulseaudioBackend::name() const { - return "PulseAudio"; + return "pulseaudio"; } } // namespace sndio diff --git a/src/internal_modules/roc_sndio/target_pulseaudio/roc_sndio/pulseaudio_device.cpp b/src/internal_modules/roc_sndio/target_pulseaudio/roc_sndio/pulseaudio_device.cpp index 9035fb59a..9314a38a6 100644 --- a/src/internal_modules/roc_sndio/target_pulseaudio/roc_sndio/pulseaudio_device.cpp +++ b/src/internal_modules/roc_sndio/target_pulseaudio/roc_sndio/pulseaudio_device.cpp @@ -492,7 +492,7 @@ bool PulseaudioDevice::load_device_params_(const pa_sample_spec& device_spec) { } if (sample_spec_.sample_rate() == 0) { - sample_spec_.set_sample_rate((size_t)device_spec.rate); + sample_spec_.set_sample_rate(device_spec.rate); } if (!sample_spec_.channel_set().is_valid()) { @@ -527,7 +527,7 @@ bool PulseaudioDevice::load_device_params_(const pa_sample_spec& device_spec) { if (target_latency_ns_ <= 0 || target_latency_samples_ <= 0) { roc_log(LogError, - "pulseaudio %s: traget latency must be > 0:" + "pulseaudio %s: target latency must be > 0:" " target_latency=%.3fms target_latency_samples=%ld", device_type_to_str(device_type_), (double)target_latency_ns_ / core::Millisecond, diff --git a/src/internal_modules/roc_sndio/target_sndfile/roc_sndio/sndfile_backend.cpp b/src/internal_modules/roc_sndio/target_sndfile/roc_sndio/sndfile_backend.cpp index 5a1651ab8..53fae8038 100644 --- a/src/internal_modules/roc_sndio/target_sndfile/roc_sndio/sndfile_backend.cpp +++ b/src/internal_modules/roc_sndio/target_sndfile/roc_sndio/sndfile_backend.cpp @@ -22,11 +22,11 @@ SndfileBackend::SndfileBackend() { void SndfileBackend::discover_drivers(core::Array& driver_list) { SF_FORMAT_INFO format_info; - int total_number_of_drivers; + int total_number_of_drivers = 0; if (int errnum = sf_command(NULL, SFC_GET_FORMAT_MAJOR_COUNT, &total_number_of_drivers, sizeof(int))) { - roc_panic("sndfile backend: sf_command(SFC_GET_FORMAT_MAJOR_COUNT) failed %s", + roc_panic("sndfile backend: sf_command(SFC_GET_FORMAT_MAJOR_COUNT) failed: %s", sf_error_number(errnum)); } @@ -34,7 +34,7 @@ void SndfileBackend::discover_drivers(core::Array& drive format_info.format = format_index; if (int errnum = sf_command(NULL, SFC_GET_FORMAT_MAJOR, &format_info, sizeof(format_info))) { - roc_panic("sndfile backend: sf_command(SFC_GET_FORMAT_MAJOR) failed %s", + roc_panic("sndfile backend: sf_command(SFC_GET_FORMAT_MAJOR) failed: %s", sf_error_number(errnum)); } @@ -50,8 +50,7 @@ void SndfileBackend::discover_drivers(core::Array& drive if (!driver_list.push_back( DriverInfo(driver, DriverType_File, DriverFlag_SupportsSource | DriverFlag_SupportsSink, this))) { - roc_panic("sndfile backend: driver_list.push_back(DriverInfo) failed to add " - "driver"); + roc_panic("sndfile backend: allocation failed"); } } } @@ -114,5 +113,6 @@ IDevice* SndfileBackend::open_device(DeviceType device_type, const char* SndfileBackend::name() const { return "sndfile"; } + } // namespace sndio } // namespace roc diff --git a/src/internal_modules/roc_sndio/target_sndfile/roc_sndio/sndfile_extension_table.cpp b/src/internal_modules/roc_sndio/target_sndfile/roc_sndio/sndfile_extension_table.cpp index c95c9d213..a31ad01b9 100644 --- a/src/internal_modules/roc_sndio/target_sndfile/roc_sndio/sndfile_extension_table.cpp +++ b/src/internal_modules/roc_sndio/target_sndfile/roc_sndio/sndfile_extension_table.cpp @@ -6,11 +6,15 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include "sndfile_extension_table.h" -#include "sndfile.h" +#include "roc_sndio/sndfile_extension_table.h" +#include "roc_core/macro_helpers.h" -FileMap file_type_map[5] = { { SF_FORMAT_MAT4, "mat4", NULL }, - { SF_FORMAT_MAT5, "mat5", NULL }, - { SF_FORMAT_WAV, "wav", "wav" }, - { SF_FORMAT_NIST, "nist", NULL }, - { SF_FORMAT_WAVEX, "wavex", NULL } }; +#include + +FileMap file_type_map[ROC_ARRAY_SIZE(file_type_map)] = { + { SF_FORMAT_MAT4, "mat4", NULL }, // + { SF_FORMAT_MAT5, "mat5", NULL }, // + { SF_FORMAT_WAV, "wav", "wav" }, // + { SF_FORMAT_NIST, "nist", NULL }, // + { SF_FORMAT_WAVEX, "wavex", NULL }, // +}; 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 05dea2674..5a6a8218f 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 @@ -6,9 +6,8 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#define BUFFER_SIZE 512 - #include "roc_sndio/sndfile_sink.h" +#include "roc_audio/sample_spec_to_str.h" #include "roc_core/log.h" #include "roc_core/panic.h" #include "roc_sndio/backend_map.h" @@ -16,13 +15,17 @@ namespace roc { namespace sndio { + namespace { bool map_to_sub_format(SF_INFO& file_info_, int format_enum) { - // Provides the minimum number of sub formats needed to support all possible major - // formats - int high_to_low_sub_formats[4] = { SF_FORMAT_PCM_24, SF_FORMAT_PCM_16, - SF_FORMAT_DPCM_16 }; + // Provides the minimum number of sub formats needed to support all + // possible major formats + int high_to_low_sub_formats[] = { + SF_FORMAT_PCM_24, + SF_FORMAT_PCM_16, + SF_FORMAT_DPCM_16, + }; for (size_t format_attempt = 0; format_attempt < ROC_ARRAY_SIZE(high_to_low_sub_formats); format_attempt++) { @@ -37,7 +40,10 @@ bool map_to_sub_format(SF_INFO& file_info_, int format_enum) { } bool map_to_sndfile(const char** driver, const char* path, SF_INFO& file_info_) { - const char* file_extension; + roc_panic_if(!driver); + roc_panic_if(!path); + + const char* file_extension = NULL; const char* dot = strrchr(path, '.'); if (!dot || dot == path) { @@ -48,7 +54,9 @@ bool map_to_sndfile(const char** driver, const char* path, SF_INFO& file_info_) int format_enum = 0; + // First try to select format by iterating through file_map_index. if (*driver == NULL) { + // If driver is NULL, match by file extension. for (size_t file_map_index = 0; file_map_index < ROC_ARRAY_SIZE(file_type_map); file_map_index++) { if (file_type_map[file_map_index].file_extension != NULL) { @@ -61,6 +69,7 @@ bool map_to_sndfile(const char** driver, const char* path, SF_INFO& file_info_) } } } else { + // If driver is non-NULL, match by driver name. for (size_t file_map_index = 0; file_map_index < ROC_ARRAY_SIZE(file_type_map); file_map_index++) { if (strcmp(*driver, file_type_map[file_map_index].driver_name) == 0) { @@ -70,30 +79,34 @@ bool map_to_sndfile(const char** driver, const char* path, SF_INFO& file_info_) } } + // Then try to select format by iterating through all sndfile formats. if (format_enum == 0) { SF_FORMAT_INFO info; - int major_count, format_index; + int major_count = 0, format_index = 0; if (int errnum = sf_command(NULL, SFC_GET_FORMAT_MAJOR_COUNT, &major_count, sizeof(int))) { - roc_panic("sndfile backend: sf_command(SFC_GET_FORMAT_MAJOR_COUNT) failed %s", - sf_error_number(errnum)); + roc_panic( + "sndfile backend: sf_command(SFC_GET_FORMAT_MAJOR_COUNT) failed: %s", + sf_error_number(errnum)); } for (format_index = 0; format_index < major_count; format_index++) { info.format = format_index; if (int errnum = sf_command(NULL, SFC_GET_FORMAT_MAJOR, &info, sizeof(info))) { - roc_panic("sndfile backend: sf_command(SFC_GET_FORMAT_MAJOR) failed %s", + roc_panic("sndfile backend: sf_command(SFC_GET_FORMAT_MAJOR) failed: %s", sf_error_number(errnum)); } if (*driver == NULL) { + // If driver is NULL, match by file extension. if (strcmp(info.extension, file_extension) == 0) { format_enum = info.format; *driver = file_extension; break; } } else { + // If driver is non-NULL, match by driver name. if (strcmp(info.extension, *driver) == 0) { format_enum = info.format; break; @@ -106,13 +119,15 @@ bool map_to_sndfile(const char** driver, const char* path, SF_INFO& file_info_) return false; } - roc_log(LogDebug, "detected file format type `%s'", *driver); + roc_log(LogDebug, "detected file format type '%s'", *driver); file_info_.format = format_enum | file_info_.format; if (sf_format_check(&file_info_)) { + // Format is supported as is. return true; } else { + // Format may be supported if combined with a subformat. return map_to_sub_format(file_info_, format_enum); } } @@ -133,13 +148,6 @@ SndfileSink::SndfileSink(core::IArena& arena, const Config& config) return; } - frame_length_ = config.frame_length; - - if (frame_length_ == 0) { - roc_log(LogError, "sndfile sink: frame length is zero"); - return; - } - sample_spec_ = config.sample_spec; if (sample_spec_.sample_format() == audio::SampleFormat_Invalid) { @@ -159,7 +167,7 @@ SndfileSink::SndfileSink(core::IArena& arena, const Config& config) memset(&file_info_, 0, sizeof(file_info_)); - // TODO(gh-696): map format from sample_space + // TODO(gh-696): map format from sample_spec file_info_.format = SF_FORMAT_PCM_32; file_info_.channels = (int)sample_spec_.num_channels(); file_info_.samplerate = (int)sample_spec_.sample_rate(); @@ -184,6 +192,10 @@ bool SndfileSink::open(const char* driver, const char* path) { roc_panic("sndfile sink: can't call open() more than once"); } + if (!path) { + roc_panic("sndfile sink: path is null"); + } + if (!open_(driver, path)) { return false; } @@ -244,37 +256,21 @@ audio::SampleSpec SndfileSink::sample_spec() const { } core::nanoseconds_t SndfileSink::latency() const { - roc_panic_if(!valid_); - - if (!file_) { - roc_panic("sndfile sink: latency(): non-open output file"); - } - return 0; } bool SndfileSink::has_latency() const { - roc_panic_if(!valid_); - - if (!file_) { - roc_panic("sndfile sink: has_latency(): non-open output file"); - } - return false; } bool SndfileSink::has_clock() const { - roc_panic_if(!valid_); - - if (!file_) { - roc_panic("sndfile sink: has_clock(): non-open output file"); - } - return false; } void SndfileSink::write(audio::Frame& frame) { - roc_panic_if(!valid_); + if (!file_) { + roc_panic("sndfile sink: not opened"); + } audio::sample_t* frame_data = frame.raw_samples(); sf_count_t frame_left = (sf_count_t)frame.num_raw_samples(); 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 a23971e98..b90c754c0 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 @@ -28,8 +28,8 @@ namespace sndio { //! Sndfile sink. //! @remarks -//! Writes samples to output file or device. -//! Supports multiple drivers for different file types and audio systems. +//! Writes samples to output file. +//! Supports multiple drivers for different file types. class SndfileSink : public ISink, public core::NonCopyable<> { public: //! Initialize. @@ -43,11 +43,11 @@ class SndfileSink : public ISink, public core::NonCopyable<> { //! Open output file or device. //! //! @b Parameters - //! - @p driver is output driver name; - //! - @p path is output file or device name, "-" for stdout. + //! - @p driver is output format name; + //! - @p path is output file name, "-" for stdout. //! //! @remarks - //! If @p driver or @p path are NULL, defaults are used. + //! If @p driver is NULL, default is used. bool open(const char* driver, const char* path); //! Cast IDevice to ISink. @@ -93,7 +93,6 @@ class SndfileSink : public ISink, public core::NonCopyable<> { SNDFILE* file_; SF_INFO file_info_; - core::nanoseconds_t frame_length_; audio::SampleSpec sample_spec_; bool valid_; }; 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 b8ffaf674..e235a34d3 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 @@ -84,7 +84,6 @@ DeviceType SndfileSource::type() const { } DeviceState SndfileSource::state() const { - roc_panic_if(!valid_); return DeviceState_Active; } @@ -124,10 +123,8 @@ bool SndfileSource::restart() { } audio::SampleSpec SndfileSource::sample_spec() const { - roc_panic_if(!valid_); - if (!file_) { - roc_panic("sndfile source: sample_rate(): non-open output file"); + roc_panic("sndfile source: not opened"); } audio::ChannelSet channel_set; @@ -140,32 +137,14 @@ audio::SampleSpec SndfileSource::sample_spec() const { } core::nanoseconds_t SndfileSource::latency() const { - roc_panic_if(!valid_); - - if (!file_) { - roc_panic("sndfile source: latency(): non-open output file"); - } - return 0; } bool SndfileSource::has_latency() const { - roc_panic_if(!valid_); - - if (!file_) { - roc_panic("sndfile source: has_latency(): non-open input file"); - } - return false; } bool SndfileSource::has_clock() const { - roc_panic_if(!valid_); - - if (!file_) { - roc_panic("sndfile source: has_clock(): non-open input file"); - } - return false; } @@ -204,10 +183,8 @@ bool SndfileSource::read(audio::Frame& frame) { } bool SndfileSource::seek_(size_t offset) { - roc_panic_if(!valid_); - if (!file_) { - roc_panic("sndfile source: seek: non-open input file"); + roc_panic("sndfile source: can't seek: not opened"); } roc_log(LogDebug, "sndfile source: resetting position to %lu", (unsigned long)offset); diff --git a/src/internal_modules/roc_sndio/target_sndfile/roc_sndio/sndfile_source.h b/src/internal_modules/roc_sndio/target_sndfile/roc_sndio/sndfile_source.h index 60c2706b4..a4bc316c2 100644 --- a/src/internal_modules/roc_sndio/target_sndfile/roc_sndio/sndfile_source.h +++ b/src/internal_modules/roc_sndio/target_sndfile/roc_sndio/sndfile_source.h @@ -29,8 +29,8 @@ namespace sndio { //! Sndfile source. //! @remarks -//! Reads samples from input file or device. -//! Supports multiple drivers for different file types and audio systems. +//! Reads samples from input file. +//! Supports multiple drivers for different file types. class SndfileSource : public ISource, private core::NonCopyable<> { public: //! Initialize. @@ -44,11 +44,11 @@ class SndfileSource : public ISource, private core::NonCopyable<> { //! Open input file or device. //! //! @b Parameters - //! - @p driver is input driver name; - //! - @p path is input file or device name, "-" for stdin. + //! - @p driver is input format name; + //! - @p path is input file name, "-" for stdin. //! //! @remarks - //! If @p driver or @p path are NULL, defaults are used. + //! If @p driver is NULL, default is used. bool open(const char* driver, const char* path); //! Cast IDevice to ISink. diff --git a/src/internal_modules/roc_sndio/target_sox/roc_sndio/sox_backend.cpp b/src/internal_modules/roc_sndio/target_sox/roc_sndio/sox_backend.cpp index 20a40b5eb..5e5cca1df 100644 --- a/src/internal_modules/roc_sndio/target_sox/roc_sndio/sox_backend.cpp +++ b/src/internal_modules/roc_sndio/target_sox/roc_sndio/sox_backend.cpp @@ -295,7 +295,7 @@ IDevice* SoxBackend::open_device(DeviceType device_type, } const char* SoxBackend::name() const { - return "SoX"; + return "sox"; } } // namespace sndio diff --git a/src/tests/roc_sndio/test_backend_sink.cpp b/src/tests/roc_sndio/test_backend_sink.cpp index 0ce5867a1..d367069da 100644 --- a/src/tests/roc_sndio/test_backend_sink.cpp +++ b/src/tests/roc_sndio/test_backend_sink.cpp @@ -19,7 +19,7 @@ namespace sndio { namespace { -enum { FrameSize = 500, SampleRate = 44100, ChMask = 0x3 }; +enum { FrameSize = 500, SampleRate = 48000, ChMask = 0x3 }; core::HeapArena arena; @@ -53,7 +53,7 @@ TEST_GROUP(backend_sink) { } }; -TEST(backend_sink, write_open) { +TEST(backend_sink, open) { for (size_t n_backend = 0; n_backend < BackendMap::instance().num_backends(); n_backend++) { IBackend& backend = BackendMap::instance().nth_backend(n_backend); diff --git a/src/tests/roc_sndio/test_backend_source.cpp b/src/tests/roc_sndio/test_backend_source.cpp index 61601f475..4952898d4 100644 --- a/src/tests/roc_sndio/test_backend_source.cpp +++ b/src/tests/roc_sndio/test_backend_source.cpp @@ -25,19 +25,19 @@ namespace { enum { MaxBufSize = 8192, FrameSize = 500, - SampleRate = 44100, + SampleRate = 48000, ChMask = 0x3, NumChans = 2 }; -const audio::SampleSpec SampleSpecs(SampleRate, +const audio::SampleSpec sample_spec(SampleRate, audio::Sample_RawFormat, audio::ChanLayout_Surround, audio::ChanOrder_Smpte, ChMask); -const core::nanoseconds_t FrameDuration = FrameSize * core::Second - / core::nanoseconds_t(SampleSpecs.sample_rate() * SampleSpecs.num_channels()); +const core::nanoseconds_t frame_duration = FrameSize * core::Second + / core::nanoseconds_t(sample_spec.sample_rate() * sample_spec.num_channels()); core::HeapArena arena; core::BufferFactory buffer_factory(arena, MaxBufSize); @@ -66,14 +66,14 @@ TEST_GROUP(backend_source) { sink_config.sample_spec = audio::SampleSpec(SampleRate, audio::Sample_RawFormat, audio::ChanLayout_Surround, audio::ChanOrder_Smpte, ChMask); - sink_config.frame_length = FrameDuration; + sink_config.frame_length = frame_duration; source_config.sample_spec = audio::SampleSpec(); - source_config.frame_length = FrameDuration; + source_config.frame_length = frame_duration; } }; -TEST(backend_source, read_open) { +TEST(backend_source, open) { for (size_t n_backend = 0; n_backend < BackendMap::instance().num_backends(); n_backend++) { core::TempFile file("test.wav"); @@ -90,8 +90,8 @@ TEST(backend_source, read_open) { core::ScopedPtr backend_sink(backend_device->to_sink(), arena); CHECK(backend_sink != NULL); - Pump pump(buffer_factory, mock_source, NULL, *backend_sink, FrameDuration, - SampleSpecs, Pump::ModeOneshot); + Pump pump(buffer_factory, mock_source, NULL, *backend_sink, frame_duration, + sample_spec, Pump::ModeOneshot); CHECK(pump.is_valid()); CHECK(pump.run()); } @@ -136,8 +136,8 @@ TEST(backend_source, has_clock) { core::ScopedPtr backend_sink(backend_device->to_sink(), arena); CHECK(backend_sink != NULL); - Pump pump(buffer_factory, mock_source, NULL, *backend_sink, FrameDuration, - SampleSpecs, Pump::ModeOneshot); + Pump pump(buffer_factory, mock_source, NULL, *backend_sink, frame_duration, + sample_spec, Pump::ModeOneshot); CHECK(pump.is_valid()); CHECK(pump.run()); } @@ -171,13 +171,13 @@ TEST(backend_source, sample_rate_auto) { core::ScopedPtr backend_sink(backend_device->to_sink(), arena); CHECK(backend_sink != NULL); - Pump pump(buffer_factory, mock_source, NULL, *backend_sink, FrameDuration, - SampleSpecs, Pump::ModeOneshot); + Pump pump(buffer_factory, mock_source, NULL, *backend_sink, frame_duration, + sample_spec, Pump::ModeOneshot); CHECK(pump.is_valid()); CHECK(pump.run()); } source_config.sample_spec.set_sample_rate(0); - source_config.frame_length = FrameDuration; + source_config.frame_length = frame_duration; IDevice* backend_device = backend.open_device( DeviceType_Source, DriverType_File, "wav", file.path(), source_config, arena); @@ -209,8 +209,8 @@ TEST(backend_source, sample_rate_mismatch) { core::ScopedPtr backend_sink(backend_device->to_sink(), arena); CHECK(backend_sink != NULL); - Pump pump(buffer_factory, mock_source, NULL, *backend_sink, FrameDuration, - SampleSpecs, Pump::ModeOneshot); + Pump pump(buffer_factory, mock_source, NULL, *backend_sink, frame_duration, + sample_spec, Pump::ModeOneshot); CHECK(pump.is_valid()); CHECK(pump.run()); } @@ -244,8 +244,8 @@ TEST(backend_source, pause_resume) { core::ScopedPtr backend_sink(backend_device->to_sink(), arena); CHECK(backend_sink != NULL); - Pump pump(buffer_factory, mock_source, NULL, *backend_sink, FrameDuration, - SampleSpecs, Pump::ModeOneshot); + Pump pump(buffer_factory, mock_source, NULL, *backend_sink, frame_duration, + sample_spec, Pump::ModeOneshot); CHECK(pump.is_valid()); CHECK(pump.run()); } @@ -267,7 +267,7 @@ TEST(backend_source, pause_resume) { audio::Frame frame2(frame_data2, FrameSize * NumChans); backend_source->pause(); - if (strcmp(backend.name(), "SoX") == 0) { + if (strcmp(backend.name(), "sox") == 0) { // TODO(gh-706): check state CHECK(!backend_source->read(frame2)); @@ -313,8 +313,8 @@ TEST(backend_source, pause_restart) { core::ScopedPtr backend_sink(backend_device->to_sink(), arena); CHECK(backend_sink != NULL); - Pump pump(buffer_factory, mock_source, NULL, *backend_sink, FrameDuration, - SampleSpecs, Pump::ModeOneshot); + Pump pump(buffer_factory, mock_source, NULL, *backend_sink, frame_duration, + sample_spec, Pump::ModeOneshot); CHECK(pump.is_valid()); CHECK(pump.run()); } @@ -337,7 +337,7 @@ TEST(backend_source, pause_restart) { audio::sample_t frame_data2[FrameSize * NumChans] = {}; audio::Frame frame2(frame_data2, FrameSize * NumChans); - if (strcmp(backend.name(), "SoX") == 0) { + if (strcmp(backend.name(), "sox") == 0) { // TODO(gh-706): check state CHECK(!backend_source->read(frame2)); @@ -383,8 +383,8 @@ TEST(backend_source, eof_restart) { core::ScopedPtr backend_sink(backend_device->to_sink(), arena); CHECK(backend_sink != NULL); - Pump pump(buffer_factory, mock_source, NULL, *backend_sink, FrameDuration, - SampleSpecs, Pump::ModeOneshot); + Pump pump(buffer_factory, mock_source, NULL, *backend_sink, frame_duration, + sample_spec, Pump::ModeOneshot); CHECK(pump.is_valid()); CHECK(pump.run()); } diff --git a/src/tests/roc_sndio/test_pump.cpp b/src/tests/roc_sndio/test_pump.cpp index 47a44d3b2..3ea9c1857 100644 --- a/src/tests/roc_sndio/test_pump.cpp +++ b/src/tests/roc_sndio/test_pump.cpp @@ -19,33 +19,25 @@ #include "roc_sndio/backend_map.h" #include "roc_sndio/config.h" #include "roc_sndio/pump.h" -#ifdef ROC_TARGET_SNDFILE -#include "roc_sndio/sndfile_sink.h" -#include "roc_sndio/sndfile_source.h" -#endif // ROC_TARGET_SNDFILE -#ifdef ROC_TARGET_SOX -#include "roc_sndio/sox_sink.h" -#include "roc_sndio/sox_source.h" -#endif // ROC_TARGET_SOX namespace roc { namespace sndio { namespace { -enum { BufSize = 512, SampleRate = 44100, ChMask = 0x3 }; +enum { FrameSize = 512, SampleRate = 48000, ChMask = 0x3 }; -const audio::SampleSpec SampleSpecs(SampleRate, +const audio::SampleSpec sample_spec(SampleRate, audio::Sample_RawFormat, audio::ChanLayout_Surround, audio::ChanOrder_Smpte, ChMask); -const core::nanoseconds_t BufDuration = BufSize * core::Second - / core::nanoseconds_t(SampleSpecs.sample_rate() * SampleSpecs.num_channels()); +const core::nanoseconds_t frame_duration = FrameSize * core::Second + / core::nanoseconds_t(sample_spec.sample_rate() * sample_spec.num_channels()); core::HeapArena arena; -core::BufferFactory buffer_factory(arena, BufSize); +core::BufferFactory buffer_factory(arena, FrameSize); bool supports_wav(IBackend& backend) { bool supports = false; @@ -69,17 +61,17 @@ TEST_GROUP(pump) { void setup() { source_config.sample_spec = audio::SampleSpec(); - source_config.frame_length = BufDuration; + source_config.frame_length = frame_duration; sink_config.sample_spec = audio::SampleSpec(SampleRate, audio::Sample_RawFormat, audio::ChanLayout_Surround, audio::ChanOrder_Smpte, ChMask); - sink_config.frame_length = BufDuration; + sink_config.frame_length = frame_duration; } }; TEST(pump, write_read) { - enum { NumSamples = BufSize * 10 }; + enum { NumSamples = FrameSize * 10 }; for (size_t n_backend = 0; n_backend < BackendMap::instance().num_backends(); n_backend++) { @@ -99,12 +91,12 @@ TEST(pump, write_read) { CHECK(backend_device != NULL); core::ScopedPtr backend_sink(backend_device->to_sink(), arena); CHECK(backend_sink != NULL); - Pump pump(buffer_factory, mock_source, NULL, *backend_sink, BufDuration, - SampleSpecs, Pump::ModeOneshot); + Pump pump(buffer_factory, mock_source, NULL, *backend_sink, frame_duration, + sample_spec, Pump::ModeOneshot); CHECK(pump.is_valid()); CHECK(pump.run()); - CHECK(mock_source.num_returned() >= NumSamples - BufSize); + CHECK(mock_source.num_returned() >= NumSamples - FrameSize); } IDevice* backend_device = backend.open_device( @@ -115,8 +107,8 @@ TEST(pump, write_read) { CHECK(backend_source != NULL); test::MockSink mock_writer; - Pump pump(buffer_factory, *backend_source, NULL, mock_writer, BufDuration, - SampleSpecs, Pump::ModePermanent); + Pump pump(buffer_factory, *backend_source, NULL, mock_writer, frame_duration, + sample_spec, Pump::ModePermanent); CHECK(pump.is_valid()); CHECK(pump.run()); @@ -125,7 +117,7 @@ TEST(pump, write_read) { } TEST(pump, write_overwrite_read) { - enum { NumSamples = BufSize * 10 }; + enum { NumSamples = FrameSize * 10 }; for (size_t n_backend = 0; n_backend < BackendMap::instance().num_backends(); n_backend++) { @@ -145,8 +137,8 @@ TEST(pump, write_overwrite_read) { CHECK(backend_device != NULL); core::ScopedPtr backend_sink(backend_device->to_sink(), arena); CHECK(backend_sink != NULL); - Pump pump(buffer_factory, mock_source, NULL, *backend_sink, BufDuration, - SampleSpecs, Pump::ModeOneshot); + Pump pump(buffer_factory, mock_source, NULL, *backend_sink, frame_duration, + sample_spec, Pump::ModeOneshot); CHECK(pump.is_valid()); CHECK(pump.run()); } @@ -154,7 +146,7 @@ TEST(pump, write_overwrite_read) { mock_source.add(NumSamples); size_t num_returned1 = mock_source.num_returned(); - CHECK(num_returned1 >= NumSamples - BufSize); + CHECK(num_returned1 >= NumSamples - FrameSize); { IDevice* backend_device = backend.open_device( @@ -162,14 +154,14 @@ TEST(pump, write_overwrite_read) { CHECK(backend_device != NULL); core::ScopedPtr backend_sink(backend_device->to_sink(), arena); CHECK(backend_sink != NULL); - Pump pump(buffer_factory, mock_source, NULL, *backend_sink, BufDuration, - SampleSpecs, Pump::ModeOneshot); + Pump pump(buffer_factory, mock_source, NULL, *backend_sink, frame_duration, + sample_spec, Pump::ModeOneshot); CHECK(pump.is_valid()); CHECK(pump.run()); } size_t num_returned2 = mock_source.num_returned() - num_returned1; - CHECK(num_returned1 >= NumSamples - BufSize); + CHECK(num_returned1 >= NumSamples - FrameSize); IDevice* backend_device = backend.open_device( DeviceType_Source, DriverType_File, "wav", file.path(), source_config, arena); @@ -179,8 +171,8 @@ TEST(pump, write_overwrite_read) { test::MockSink mock_writer; - Pump pump(buffer_factory, *backend_source, NULL, mock_writer, BufDuration, - SampleSpecs, Pump::ModePermanent); + Pump pump(buffer_factory, *backend_source, NULL, mock_writer, frame_duration, + sample_spec, Pump::ModePermanent); CHECK(pump.is_valid()); CHECK(pump.run());