fix(mp3): remove dead FrameSize field, fix CBR duration ID3 exclusion, add MPEG2 bitrate table, pin CBR test assertions
This commit is contained in:
@@ -164,14 +164,23 @@ public class AudioProcessorTests
|
||||
[Test]
|
||||
public async Task Mp3_CbrMetadata_ParsedCorrectly()
|
||||
{
|
||||
var path = await WriteAudioAsync(BuildMinimalMp3(bitrateKbps: 128, sampleRate: 44100, stereo: true), ".mp3");
|
||||
// BuildMinimalMp3: bitrateKbps=128, sampleRate=44100, stereo=true, no Xing tag, no ID3 tag.
|
||||
// frameSize = floor(144 * 128000 / 44100) = 417 bytes; bufferSize = max(417, 48) = 417.
|
||||
// CBR duration = (bufferLength - frameStart) / (bitrateKbps * 125) = 417 / 16000 ≈ 0.0261 s.
|
||||
const int bitrateKbps = 128;
|
||||
const int sampleRate = 44100;
|
||||
var frameSize = (int)Math.Floor(144.0 * (bitrateKbps * 1000) / sampleRate); // 417
|
||||
var bufferSize = Math.Max(frameSize, 4 + 32 + 12); // max(417, 48) = 417
|
||||
var expectedDuration = (double)bufferSize / (bitrateKbps * 125); // frameStart = 0 (no ID3)
|
||||
|
||||
var path = await WriteAudioAsync(BuildMinimalMp3(bitrateKbps: bitrateKbps, sampleRate: sampleRate, stereo: true), ".mp3");
|
||||
|
||||
var audio = await new Mp3AudioProcessor().ProcessMp3FileAsync(path);
|
||||
|
||||
Assert.That(audio, Is.Not.Null);
|
||||
Assert.That(audio!.Extension, Is.EqualTo(".mp3"));
|
||||
Assert.That(audio.Duration, Is.GreaterThan(0.0));
|
||||
Assert.That(audio.Bitrate, Is.GreaterThan(0));
|
||||
Assert.That(audio.Bitrate, Is.EqualTo(bitrateKbps));
|
||||
Assert.That(audio.Duration, Is.EqualTo(expectedDuration).Within(0.01));
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
||||
Reference in New Issue
Block a user