Skip to content

Commit

Permalink
chore(maintenance)#: Update example program to use project reference …
Browse files Browse the repository at this point in the history
…for SharpPipe rather than the nuget package
  • Loading branch information
BlueCyro committed Sep 11, 2024
1 parent 86ea009 commit 694a297
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 16 deletions.
44 changes: 29 additions & 15 deletions SharpPipe.Example/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,29 @@ public static void Main(string[] args)
{
// Make a new SoundPipe object and feed it to the ZitaReverb
using SoundPipe pipe = new(); // Defaults to sample rate of 44100hz

// Bathroom preset
ZitaParameters zitaParams = new()
{
InDelay = 5f,
Crossover = 200f,
RT60Low = 1.49f,
RT60Mid = 1.3f,
HighFrequencyDamping = 5000f,
EQ1Frequency = 120f,
EQ1Level = 8f,
EQ2Frequency = 1200f,
EQ2Level = 6.5545f,
Mix = 0.7f,
Level = 7f
};

// Set up a zita reverb object
using ZitaReverb zita = new(pipe);

zita.InDelay = 5f;
zita.Crossover = 200f;
zita.RT60Low = 1.49f;
zita.RT60Mid = 1.3f;
zita.HighFrequencyDamping = 5000f;
zita.EQ1Frequency = 120f;
zita.EQ1Level = 8f;
zita.EQ2Frequency = 1200f;
zita.EQ2Level = 6.5545f;
zita.Mix = 0.7f;
zita.Level = 7f;
// Since ZitaParameters and ZitaReverb both implement
// IZitaFilter, their parameters can be interchanged very easily
zita.FromOther(zitaParams);


// Read a raw file and cast the read bytes to floats
Expand All @@ -32,14 +42,18 @@ public static void Main(string[] args)
byte[] outputFile = new byte[inputFile.Length];
Span<float> outputSamples = MemoryMarshal.Cast<byte, float>(outputFile);

// Dummy reference because the output only has a single channel
float dummy = 0f;
ref float dummyRef = ref dummy;
// Left and right channel variables
float left = 0f;
float right = 0f;

// Process each sample individually
for (int i = 0; i < samples.Length; i++)
{
zita.Compute(samples[i], samples[i], ref dummyRef, ref outputSamples[i]);
// Pass in both samples since this is a mono input.
// You would usually pass in the left and right sample and receive
// a processed left and right sample in return
zita.Compute(samples[i], samples[i], ref left, ref right);
outputSamples[i] = (left + right) / 2f; // Average into a single sample
}


Expand Down
2 changes: 1 addition & 1 deletion SharpPipe.Example/SharpPipe.Example.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="YellowDogMan.SharpPipe" Version="1.0.0" />
<ProjectReference Include="..\SharpPipe\SharpPipe.csproj" />
</ItemGroup>

</Project>

0 comments on commit 694a297

Please sign in to comment.