Skip to content

Commit

Permalink
Better timing.
Browse files Browse the repository at this point in the history
  • Loading branch information
KristofferStrube committed Dec 21, 2023
1 parent 5d61276 commit 281fd3e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
{
var gain = await timpOscillatorAmplifiers[i].GetGainAsync();
await gain.SetValueAsync(await gain.GetValueAsync());
await gain.LinearRampToValueAtTimeAsync(timpsAmplitudes[i] / timpsAmplitudes.Sum(), time + 0.1);
await gain.LinearRampToValueAtTimeAsync(timpsAmplitudes[i] / timpsAmplitudes.Sum(), time + 0.3);
var endTime = time + timpsDecays[i] * 0.1;
await gain.LinearRampToValueAtTimeAsync(0, endTime);
lastTimpTime[i] = endTime;
Expand All @@ -91,7 +91,7 @@
await noiseCarrier.StartAsync();
await noiseModulator.StartAsync();
var noiseAmplifierGain = await noiseAmplifier.GetGainAsync();
await noiseAmplifierGain.LinearRampToValueAtTimeAsync(0.2f, time + 0.1);
await noiseAmplifierGain.LinearRampToValueAtTimeAsync(0.2f, time + 0.3);
await noiseAmplifierGain.LinearRampToValueAtTimeAsync(0, time + timpsDecays.Max() * 0.1);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,18 @@ protected override async Task OnAfterRenderAsync(bool _)
running = true;

int bufferLength = (int)await Analyser.GetFrequencyBinCountAsync();
Uint8Array frequencyDataArray = await Uint8Array.CreateAsync(JSRuntime, bufferLength);
Uint8Array frequencyDataArray = await Uint8Array.CreateAsync(JSRuntime, Math.Min(bufferLength, UpperFrequency - LowerFrequency));

DateTimeOffset start = DateTimeOffset.UtcNow;
DateTimeOffset lastTime = DateTimeOffset.UtcNow;
while (running)
{
await Task.Delay(1);

await Analyser.GetByteFrequencyDataAsync(frequencyDataArray);
data.Add((await frequencyDataArray.GetByteArrayAsync())[LowerFrequency..UpperFrequency]);

DateTimeOffset currentTime = DateTimeOffset.UtcNow;
intervals.Add(((lastTime - start).TotalMilliseconds, (currentTime - lastTime).TotalMilliseconds));
var intervalLength = (currentTime - lastTime).TotalMilliseconds;
intervals.Add(((lastTime - start).TotalMilliseconds, intervalLength));

if ((currentTime - start).TotalMilliseconds > TimeInSeconds * 1000)
{
Expand All @@ -64,6 +63,8 @@ protected override async Task OnAfterRenderAsync(bool _)
lastTime = currentTime;

StateHasChanged();
await Task.Delay(Math.Max(1, 100 - (int)intervalLength));

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static async Task<AnalyserNode> CreateAsync(IJSRuntime jSRuntime, BaseAud
protected AnalyserNode(IJSRuntime jSRuntime, IJSObjectReference jSReference) : base(jSRuntime, jSReference) { }

/// <summary>
/// Get a reference to the bytes held by the <see cref="Float32Array"/> passed as an argument.
/// Gets a reference to the bytes held by the <see cref="Float32Array"/> passed as an argument.
/// Copies the current frequency data into those bytes.
/// </summary>
/// <remarks>
Expand All @@ -62,7 +62,7 @@ public async Task GetFloatFrequencyDataAsync(Float32Array array)
}

/// <summary>
/// Get a reference to the bytes held by the <see cref="Uint8Array"/> passed as an argument.
/// Gets a reference to the bytes held by the <see cref="Uint8Array"/> passed as an argument.
/// Copies the current time-domain data (waveform data) into those bytes.
/// </summary>
/// <remarks>
Expand All @@ -77,7 +77,7 @@ public async Task GetByteFrequencyDataAsync(Uint8Array array)
}

/// <summary>
/// Get a reference to the bytes held by the <see cref="Float32Array"/> passed as an argument.
/// Gets a reference to the bytes held by the <see cref="Float32Array"/> passed as an argument.
/// Copies the current time-domain data (waveform data) into those bytes.
/// </summary>
/// <remarks>
Expand All @@ -92,7 +92,7 @@ public async Task GetFloatTimeDomainDataAsync(Float32Array array)
}

/// <summary>
/// Get a reference to the bytes held by the <see cref="Uint8Array"/> passed as an argument.
/// Gets a reference to the bytes held by the <see cref="Uint8Array"/> passed as an argument.
/// Copies the current time-domain data (waveform data) into those bytes.
/// </summary>
/// <remarks>
Expand Down

0 comments on commit 281fd3e

Please sign in to comment.