// This test checks when decoding HE-AAC using MediaSource or HTTP playback, the
// audio is decoded correctly (in particular with the SBR part). This means
// that the extradata describing the encoded AAC stream have been communicated
// correctly to the audio decoder. For this, we check that there is energy
// above 10kHz using the Web Audio API when playing white noise, which has
// maximum energy accross the audible spectrum.
// Return the index corresponding for a particular frequency in an array
// containing frequency data from a FFT.
function binIndexForFrequency(frequency, fftSize, sampleRate) {
return (1 + Math.round((frequency * fftSize) / sampleRate));
}
async function checkHighFrequencyContent(element) {
const ac = new AudioContext();
await ac.resume();
const mediaElementSource = ac.createMediaElementSource(element);
const analyser = new AnalyserNode(ac);
// Undo the volume scaling applied globally during test. This is fine because
// the audio isn't routed to an actual audio output device in this test, it's
// just analyzed with the Web Audio API.
const gain = new GainNode(ac);
const testVolumeScaling =
parseFloat(SpecialPowers.getCharPref("media.volume_scale"));
gain.gain.value = 1 / parseFloat(testVolumeScaling);
mediaElementSource.connect(gain).connect(analyser)
const spectrum = new Float32Array(analyser.frequencyBinCount);
const indexFor15kHz =
binIndexForFrequency(15000, analyser.fftSize, ac.sampleRate);
// Wait a few hundreds of milliseconds
while (!element.ended) {
await once(element, "timeupdate");
analyser.getFloatFrequencyData(spectrum);
if (spectrum[indexFor15kHz] > -50) {
ok(spectrum[indexFor15kHz] > -50,
`Energy present at 15kHz (bin index: ${indexFor15kHz}) when playing white noise encoded in HE-AAC ${spectrum[indexFor15kHz]}`);
return;
}
}
ok(false,
`No energy present at 15kHz (bin index: ${indexFor15kHz}) when playing white noise encoded in HE-AAC (last value ${spectrum[indexFor15kHz]})`);
}
runWithMSE(async (ms, el) => {
// First check with MSE playback
el.controls = true;
await once(ms, "sourceopen");
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.