Skip to content

Commit

Permalink
Merge branch 'test_modifications' into libsndfile_support
Browse files Browse the repository at this point in the history
for loop implmentation for first testcase finished
  • Loading branch information
Hrick87 committed Feb 20, 2024
2 parents e4b102c + b0e8536 commit 454c20b
Show file tree
Hide file tree
Showing 12 changed files with 87 additions and 67 deletions.
2 changes: 2 additions & 0 deletions src/internal_modules/roc_sndio/ibackend.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ class IBackend {
const char* path,
const Config& config,
core::IArena& arena) = 0;

virtual const char* name() const = 0;
};

} // namespace sndio
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,9 @@ IDevice* PulseaudioBackend::open_device(DeviceType device_type,
return device.release();
}

const char* PulseaudioBackend::name() const{
return "PulseAudio";
}

} // namespace sndio
} // namespace roc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class PulseaudioBackend : public IBackend, core::NonCopyable<> {
const char* path,
const Config& config,
core::IArena& arena);

virtual const char* name() const;
};

} // namespace sndio
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,5 +110,9 @@ IDevice* SndfileBackend::open_device(DeviceType device_type,

roc_panic("sndfile backend: invalid device type");
}

const char* SndfileBackend::name() const {
return "sndfile";
}
} // namespace sndio
} // namespace roc
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,12 @@ class SndfileBackend : public IBackend, core::NonCopyable<> {
const char* path,
const Config& config,
core::IArena& arena);

virtual const char* name() const;
};



} // namespace sndio
} // namespace roc

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,11 @@ bool SndfileSource::read(audio::Frame& frame) {
if (!file_) {
roc_panic("sndfile source: read: non-open input file");
}

audio::sample_t * frame_data = frame.raw_samples();
size_t num_channels = (size_t)file_info_.channels;
sf_count_t frame_left = (sf_count_t)frame.num_raw_samples();
sf_count_t samples_per_ch = (sf_count_t)(frame.num_raw_samples() / num_channels);
size_t samples_per_ch = frame.num_raw_samples() / num_channels;

sf_count_t n_samples = sf_read_float(file_, frame_data, frame_left);
if(sf_error(file_) != 0){
Expand All @@ -199,9 +199,9 @@ bool SndfileSource::read(audio::Frame& frame) {
eof_ = true;
}

if (n_samples < samples_per_ch) {
memset(frame.raw_samples() + (unsigned long)n_samples * num_channels, 0,
(unsigned long)(samples_per_ch - n_samples) * num_channels * sizeof(audio::sample_t));
if ((size_t)n_samples < samples_per_ch) {
memset(frame.raw_samples() + (size_t)n_samples * num_channels, 0,
(samples_per_ch - (size_t)n_samples) * num_channels * sizeof(audio::sample_t));
}

return !eof_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,5 +294,9 @@ IDevice* SoxBackend::open_device(DeviceType device_type,
roc_panic("sox backend: invalid device type");
}

const char* SoxBackend::name() const{
return "SoX";
}

} // namespace sndio
} // namespace roc
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ class SoxBackend : public IBackend, core::NonCopyable<> {
const Config& config,
core::IArena& arena);

virtual const char* name() const;

private:
bool first_created_;
};
Expand Down
5 changes: 5 additions & 0 deletions src/internal_modules/roc_sndio/wav_backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "roc_sndio/wav_sink.h"
#include "roc_sndio/wav_source.h"


namespace roc {
namespace sndio {

Expand Down Expand Up @@ -76,5 +77,9 @@ IDevice* WavBackend::open_device(DeviceType device_type,
roc_panic("wav backend: invalid device type");
}

const char* WavBackend::name() const {
return "wav";
}

} // namespace sndio
} // namespace roc
2 changes: 2 additions & 0 deletions src/internal_modules/roc_sndio/wav_backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class WavBackend : public IBackend, core::NonCopyable<> {
const char* path,
const Config& config,
core::IArena& arena);

virtual const char* name() const;
};

} // namespace sndio
Expand Down
1 change: 1 addition & 0 deletions src/internal_modules/roc_sndio/wav_source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ bool WavSource::read(audio::Frame& frame) {
}

bool WavSource::open_(const char* path) {

if (file_opened_) {
roc_panic("wav source: already opened");
}
Expand Down
114 changes: 52 additions & 62 deletions src/tests/roc_sndio/test_pump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@

#include "roc_core/buffer_factory.h"
#include "roc_core/heap_arena.h"
#include "roc_core/scoped_ptr.h"
#include "roc_core/stddefs.h"
#include "roc_core/temp_file.h"
#include "roc_sndio/config.h"
#include "roc_sndio/pump.h"
#include "roc_sndio/backend_map.h"
#ifdef ROC_TARGET_SOX
#include "roc_sndio/sox_sink.h"
#include "roc_sndio/sox_source.h"
Expand Down Expand Up @@ -55,79 +57,67 @@ TEST_GROUP(pump) {
};

TEST(pump, write_read) {
#ifdef ROC_TARGET_SOX
{ enum { NumSamples = BufSize * 10 };

test::MockSource mock_source;
mock_source.add(NumSamples);

core::TempFile file("test.wav");

{
SoxSink sox_sink(arena, config);
CHECK(sox_sink.open(NULL, file.path()));

Pump pump(buffer_factory, mock_source, NULL, sox_sink, BufDuration, SampleSpecs,
Pump::ModeOneshot);
CHECK(pump.is_valid());
CHECK(pump.run());

CHECK(mock_source.num_returned() >= NumSamples - BufSize);
}
{

SoxSource sox_source(arena, config);
CHECK(sox_source.open(NULL, file.path()));

test::MockSink mock_writer;

Pump pump(buffer_factory,
sox_source,
NULL,
mock_writer,
BufDuration,
SampleSpecs,
Pump::ModePermanent);
CHECK(pump.is_valid());
CHECK(pump.run());

mock_writer.check(0, mock_source.num_returned());
}
#endif // ROC_TARGET_SOX

#ifdef ROC_TARGET_SNDFILE
{
enum { NumSamples = BufSize * 10 };

for(size_t n_backend = 0; n_backend < BackendMap::instance().num_backends(); n_backend++){
test::MockSource mock_source;
mock_source.add(NumSamples);
core::TempFile file("test.wav");


test::MockSource mock_source;
mock_source.add(NumSamples);
IBackend &backend = BackendMap::instance().nth_backend(n_backend);
printf("Currently on: %s\n", backend.name());
fflush(stdout);

{
IDevice *backend_device = backend.open_device(DeviceType_Sink, DriverType_File, "wav", file.path(), config, arena);
if(backend_device == NULL){
printf("Failing sink test: %s\n", backend.name());
fflush(stdout);
}
else{
printf("Passing sink test: %s\n", backend.name());
fflush(stdout);
core::ScopedPtr<ISink> backend_sink(backend_device->to_sink(), arena);
Pump pump(buffer_factory, mock_source, NULL, *backend_sink, BufDuration, SampleSpecs,
Pump::ModeOneshot);
CHECK(pump.is_valid());
CHECK(pump.run());

CHECK(mock_source.num_returned() >= NumSamples - BufSize);
}
}
printf("File path: %s\n", file.path());
fflush(stdout);

IDevice *backend_device = backend.open_device(DeviceType_Source, DriverType_File, "wav", file.path(), config, arena);
if(backend_device == NULL){
printf("Failing source test: %s\n", backend.name());
fflush(stdout);
continue;
}

core::TempFile file("test.wav");
printf("Passing source test: %s\n\n", backend.name());

core::ScopedPtr<ISource> backend_source(backend_device->to_source(), arena);

{
SndfileSink sndfile_sink(arena, config);
CHECK(sndfile_sink.open(NULL, file.path()));
test::MockSink mock_writer;

Pump pump(buffer_factory, mock_source, NULL, sndfile_sink, BufDuration,
SampleSpecs, Pump::ModeOneshot);
Pump pump(buffer_factory,
*backend_source,
NULL,
mock_writer,
BufDuration,
SampleSpecs,
Pump::ModePermanent);
CHECK(pump.is_valid());
CHECK(pump.run());

CHECK(mock_source.num_returned() >= NumSamples - BufSize);
mock_writer.check(0, mock_source.num_returned());
}

SoxSource sndfile_source(arena, config);
CHECK(sndfile_source.open(NULL, file.path()));

test::MockSink mock_writer;

Pump pump(buffer_factory, sndfile_source, NULL, mock_writer, BufDuration, SampleSpecs,
Pump::ModePermanent);
CHECK(pump.is_valid());
CHECK(pump.run());

mock_writer.check(0, mock_source.num_returned());
}
#endif // ROC_TARGET_SNDFILE
} // namespace roc

TEST(pump, write_overwrite_read) {
Expand Down

0 comments on commit 454c20b

Please sign in to comment.