Skip to content

Commit

Permalink
Tube Monster: more unit test work in progress.
Browse files Browse the repository at this point in the history
  • Loading branch information
cosinekitty committed Jan 26, 2025
1 parent b71d36b commit 75348e4
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 11 deletions.
5 changes: 3 additions & 2 deletions src/tubemonster_engine.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#include <stdexcept>
#include "tubemonster_engine.hpp"
#include "tubeunit_engine.hpp"

namespace Sapphire
{
Expand All @@ -22,7 +22,8 @@ namespace Sapphire
throw std::logic_error("Invalid sample rate in TubeUnitEngine");

// FIXFIXFIX do stuff here
leftOutput = rightOutput = 0;
leftOutput = leftInput;
rightOutput = rightInput;
}
};
}
Binary file added util/cmdline/input/DryGuitarForDon-16-bit.wav
Binary file not shown.
File renamed without changes.
39 changes: 30 additions & 9 deletions util/cmdline/tubemonster_standalone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,50 @@ int main()
using namespace std;
using namespace Sapphire;

const int SAMPLE_RATE = 44100;
const int CHANNELS = 2;
const int DURATION_SECONDS = 10;

WaveFileReader inwave;
const char *inWaveFileName = "input/DryGuitarForDon-16-bit.wav";
if (!inwave.Open(inWaveFileName))
{
fprintf(stderr, "ERROR: Cannot open input file: %s\n", inWaveFileName);
return 1;
}

const int CHANNELS = inwave.Channels();
const int SAMPLE_RATE = inwave.SampleRate();
printf("Sample rate = %d, channels = %d in: %s\n", SAMPLE_RATE, CHANNELS, inWaveFileName);

if (CHANNELS != 2)
{
fprintf(stderr, "Wrong number of channels in: %s\n", inWaveFileName);
return 1;
}

const int DURATION_SAMPLES = SAMPLE_RATE * DURATION_SECONDS;

TubeMonsterEngine engine;
engine.setSampleRate(SAMPLE_RATE);

ScaledWaveFileWriter wave;
const char *filename = "test/tubemonster.wav";
if (!wave.Open(filename, SAMPLE_RATE, CHANNELS))
ScaledWaveFileWriter outwave;
const char *outWaveFileName = "test/tubemonster.wav";
if (!outwave.Open(outWaveFileName, SAMPLE_RATE, CHANNELS))
{
fprintf(stderr, "ERROR: Cannot open output file: %s\n", filename);
fprintf(stderr, "ERROR: Cannot open output file: %s\n", outWaveFileName);
return 1;
}

float sample[CHANNELS];
float inSample[CHANNELS];
float outSample[CHANNELS];
for (int s = 0; s < DURATION_SAMPLES; ++s)
{
// FIXFIXFIX - Update engine parameters.
// FIXFIXFIX - Supply stereo input.
engine.process(sample[0], sample[1], 0.0f, 0.0f);
wave.WriteSamples(sample, CHANNELS);
size_t nread = inwave.Read(inSample, CHANNELS);
if ((int)nread < CHANNELS)
break;
engine.process(outSample[0], outSample[1], inSample[0], inSample[1]);
outwave.WriteSamples(outSample, CHANNELS);
}

return 0;
Expand Down

0 comments on commit 75348e4

Please sign in to comment.