Skip to content

Commit

Permalink
Re-added time-domain plot
Browse files Browse the repository at this point in the history
  • Loading branch information
KristofferStrube committed Dec 21, 2023
1 parent 3577683 commit a2b7cbd
Showing 1 changed file with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,15 @@
<circle cx="100" cy="100" r="90" fill="orange" stroke="orangered"></circle>
</svg>

<h3>Time Domain</h3>
<hr />
<Plot Data="timeDomainMeasurements" />
<h3>Spectrogram</h3>
<hr />
<SpectrogramPlot Analyser=analyser UpperFrequency="40" Height="400" />
<SpectrogramPlot Analyser=analyser UpperFrequency="40" />

@code {
bool makingMeasurements = false;
static readonly float[] timpsFrequencies = new float[] { 1.00f, 1.50f, 1.98f, 2.44f };
static readonly float[] timpsAmplitudes = new float[] { 1, 0.8f, 0.6f, 0.2f };
static readonly float[] timpsDecays = new float[] { 4.5f, 7.5f, 9f, 8.5f };
Expand All @@ -46,6 +50,24 @@
}
}

public async Task Analyze()
{
if (makingMeasurements) return;
makingMeasurements = true;

int bufferLength = (int)await analyser.GetFrequencyBinCountAsync();
var timeDomainDataArray = await Uint8Array.CreateAsync(JSRuntime, bufferLength);

while (makingMeasurements)
{
await analyser.GetByteTimeDomainDataAsync(timeDomainDataArray);

timeDomainMeasurements = await timeDomainDataArray.GetByteArrayAsync();
await Task.Delay(1);
StateHasChanged();
}
}

public async Task PlayTimps(PointerEventArgs eventArgs)
{
await Initialize();
Expand Down Expand Up @@ -93,6 +115,8 @@
var noiseAmplifierGain = await noiseAmplifier.GetGainAsync();
await noiseAmplifierGain.LinearRampToValueAtTimeAsync(0.2f, time + 0.3);
await noiseAmplifierGain.LinearRampToValueAtTimeAsync(0, time + timpsDecays.Max() * 0.1);

await Analyze();
}

public async Task StopSound()
Expand All @@ -104,6 +128,7 @@

public async ValueTask DisposeAsync()
{
makingMeasurements = false;
await StopSound();
}
}
Expand Down

0 comments on commit a2b7cbd

Please sign in to comment.