Skip to content

Commit

Permalink
fix: loudnessmap
Browse files Browse the repository at this point in the history
  • Loading branch information
lideming committed Dec 23, 2024
1 parent b20b656 commit b7bebf8
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions Controllers/TracksController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,16 +177,18 @@ public async Task<ActionResult> GetAudioAnalytics(int id)
});
var pcm = proc.StandardOutput.BaseStream;
var buffer = new byte[64 * 1024];
var haveRead = 0;
while(true) {
var read = await pcm.ReadAsync(buffer, 0, buffer.Length);
var read = await pcm.ReadAsync(buffer.AsMemory(haveRead));
if (read == 0) break;
if (read < 256) continue;
haveRead += read;
if (haveRead < 256) continue;
int sum = 0;
for (var i = 0; i < read; i += 256) {
for (var i = 0; i < haveRead; i += 256) {
var x = (sbyte)buffer[i];
sum += x * x;
}
int count = read / 256;
int count = haveRead / 256;
var rms = Math.Sqrt(sum / count);
ms.WriteByte((byte)rms);
}
Expand Down

0 comments on commit b7bebf8

Please sign in to comment.