Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RingDelayBufferTest: refactor includes and span creation #10843

Merged
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 28 additions & 21 deletions src/test/ringdelaybuffer_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include <span>

#include "test/mixxxtest.h"
#include "util/sample.h"
#include "util/samplebuffer.h"
#include "util/span.h"
#include "util/types.h"
Expand Down Expand Up @@ -48,36 +47,37 @@ TEST_F(RingDelayBufferTest, ReadWriteNoDelayTest) {
const CSAMPLE thirdExpectedResult[] = {-100.0, 100.0, -99.0, 99.0};

mixxx::SampleBuffer output(numSamples);
std::span<CSAMPLE> outputSpan = output.span();

EXPECT_EQ(m_pRingDelayBuffer->write(
mixxx::spanutil::spanFromPtrLen(inputBuffer, numSamples)),
numSamples);
EXPECT_EQ(m_pRingDelayBuffer->read(
output.span(), 0),
outputSpan, 0),
numSamples);

AssertIdenticalBufferEquals(output.span(),
AssertIdenticalBufferEquals(outputSpan,
mixxx::spanutil::spanFromPtrLen(firstExpectedResult, numSamples));

EXPECT_EQ(m_pRingDelayBuffer->write(
mixxx::spanutil::spanFromPtrLen(inputBufferHalf, numSamplesHalf)),
numSamplesHalf);
EXPECT_EQ(m_pRingDelayBuffer->read(
output.span(), 0),
outputSpan, 0),
numSamples);

AssertIdenticalBufferEquals(output.span(),
AssertIdenticalBufferEquals(outputSpan,
mixxx::spanutil::spanFromPtrLen(secondExpectedResult, numSamples));

// Write and read over one ring.
EXPECT_EQ(m_pRingDelayBuffer->write(
mixxx::spanutil::spanFromPtrLen(inputBuffer, numSamples)),
numSamples);
EXPECT_EQ(m_pRingDelayBuffer->read(
output.span(), 0),
outputSpan, 0),
numSamples);

AssertIdenticalBufferEquals(output.span(),
AssertIdenticalBufferEquals(outputSpan,
mixxx::spanutil::spanFromPtrLen(thirdExpectedResult, numSamples));
}

Expand All @@ -91,24 +91,25 @@ TEST_F(RingDelayBufferTest, ReadWriteDelayTest) {
const CSAMPLE thirdExpectedResult[] = {-50.0, 50.0, -99.0, 99.0};

mixxx::SampleBuffer output(numSamples);
std::span<CSAMPLE> outputSpan = output.span();

// Read without delay.
EXPECT_EQ(m_pRingDelayBuffer->write(
mixxx::spanutil::spanFromPtrLen(inputBuffer, numSamples)),
numSamples);
EXPECT_EQ(m_pRingDelayBuffer->read(
output.span(), 0),
outputSpan, 0),
numSamples);

AssertIdenticalBufferEquals(output.span(),
AssertIdenticalBufferEquals(outputSpan,
mixxx::spanutil::spanFromPtrLen(firstExpectedResult, numSamples));

// Read with delay.
EXPECT_EQ(m_pRingDelayBuffer->read(
output.span(), firstDelaySize),
outputSpan, firstDelaySize),
numSamples);

AssertIdenticalBufferEquals(output.span(),
AssertIdenticalBufferEquals(outputSpan,
mixxx::spanutil::spanFromPtrLen(secondExpectedResult, numSamples));

// Fill the second half of the delay buffer with the first input data.
Expand All @@ -118,10 +119,10 @@ TEST_F(RingDelayBufferTest, ReadWriteDelayTest) {

// Read with delay (not circle around).
EXPECT_EQ(m_pRingDelayBuffer->read(
output.span(), secondDelaySize),
outputSpan, secondDelaySize),
numSamples);

AssertIdenticalBufferEquals(output.span(),
AssertIdenticalBufferEquals(outputSpan,
mixxx::spanutil::spanFromPtrLen(thirdExpectedResult, numSamples));
}

Expand All @@ -134,17 +135,20 @@ static void BM_WriteReadWholeBufferNoDelay(benchmark::State& state) {
mixxx::SampleBuffer input(numSamples);
mixxx::SampleBuffer output(numSamples);

std::span<CSAMPLE> inputSpan = input.span();
std::span<CSAMPLE> outputSpan = output.span();

input.fill(0.0f);

for (auto _ : state) {
state.PauseTiming();
m_ringDelayBuffer.clear();
state.ResumeTiming();

m_ringDelayBuffer.write(input.span());
m_ringDelayBuffer.read(output.span(), 0);
m_ringDelayBuffer.write(input.span());
m_ringDelayBuffer.read(output.span(), 0);
m_ringDelayBuffer.write(inputSpan);
m_ringDelayBuffer.read(outputSpan, 0);
m_ringDelayBuffer.write(inputSpan);
m_ringDelayBuffer.read(outputSpan, 0);
}
}
BENCHMARK(BM_WriteReadWholeBufferNoDelay)->Range(64, 4 << 10);
Expand All @@ -159,17 +163,20 @@ static void BM_WriteReadWholeBufferDelay(benchmark::State& state) {
mixxx::SampleBuffer input(numSamples);
mixxx::SampleBuffer output(numSamples);

std::span<CSAMPLE> inputSpan = input.span();
std::span<CSAMPLE> outputSpan = output.span();

input.fill(0.0f);

for (auto _ : state) {
state.PauseTiming();
m_ringDelayBuffer.clear();
state.ResumeTiming();

m_ringDelayBuffer.write(input.span());
m_ringDelayBuffer.read(output.span(), delaySize);
m_ringDelayBuffer.write(input.span());
m_ringDelayBuffer.read(output.span(), delaySize);
m_ringDelayBuffer.write(inputSpan);
m_ringDelayBuffer.read(outputSpan, delaySize);
m_ringDelayBuffer.write(inputSpan);
m_ringDelayBuffer.read(outputSpan, delaySize);
}
}
BENCHMARK(BM_WriteReadWholeBufferDelay)->Range(64, 4 << 10);
Expand Down