Mercurial > hg > webaudioevaluationtool
comparison loudness.js @ 752:fab881bdeeac
Offline Context no longer promise type for Safari OSX support.
author | Nicholas Jillings <nicholas.jillings@eecs.qmul.ac.uk> |
---|---|
date | Mon, 21 Dec 2015 13:54:49 +0000 |
parents | 07c996307cbd |
children | 56ee920d5d85 |
comparison
equal
deleted
inserted
replaced
751:3b8069ea47d2 | 752:fab881bdeeac |
---|---|
5 * return gain values to correct for a target loudness or match loudness between | 5 * return gain values to correct for a target loudness or match loudness between |
6 * multiple objects | 6 * multiple objects |
7 */ | 7 */ |
8 | 8 |
9 var interval_cal_loudness_event = null; | 9 var interval_cal_loudness_event = null; |
10 | |
11 if (typeof OfflineAudioContext == "undefined"){ | |
12 var OfflineAudioContext = webkitOfflineAudioContext; | |
13 } | |
10 | 14 |
11 function calculateLoudness(buffer, timescale, target, offlineContext) | 15 function calculateLoudness(buffer, timescale, target, offlineContext) |
12 { | 16 { |
13 // This function returns the EBU R 128 specification loudness model and sets the linear gain required to match -23 LUFS | 17 // This function returns the EBU R 128 specification loudness model and sets the linear gain required to match -23 LUFS |
14 // buffer -> Web Audio API Buffer object | 18 // buffer -> Web Audio API Buffer object |
48 | 52 |
49 processSource.connect(KFilter); | 53 processSource.connect(KFilter); |
50 KFilter.connect(HPFilter); | 54 KFilter.connect(HPFilter); |
51 HPFilter.connect(offlineContext.destination); | 55 HPFilter.connect(offlineContext.destination); |
52 processSource.start(); | 56 processSource.start(); |
53 offlineContext.startRendering().then(function(renderedBuffer) { | 57 offlineContext.oncomplete = function(renderedBuffer) { |
54 // Have the renderedBuffer information, now continue processing | 58 // Have the renderedBuffer information, now continue processing |
59 if (typeof renderedBuffer.renderedBuffer == 'object') { | |
60 renderedBuffer = renderedBuffer.renderedBuffer; | |
61 } | |
55 switch(timescale) | 62 switch(timescale) |
56 { | 63 { |
57 case "I": | 64 case "I": |
58 var blockEnergy = calculateProcessedLoudness(renderedBuffer, 400, 0.75); | 65 var blockEnergy = calculateProcessedLoudness(renderedBuffer, 400, 0.75); |
59 // Apply the absolute gate | 66 // Apply the absolute gate |
93 } | 100 } |
94 } | 101 } |
95 var overallRelLoudness = calculateOverallLoudnessFromChannelBlocks(relgateEnergy); | 102 var overallRelLoudness = calculateOverallLoudnessFromChannelBlocks(relgateEnergy); |
96 buffer.lufs = overallRelLoudness; | 103 buffer.lufs = overallRelLoudness; |
97 } | 104 } |
98 }).catch(function(err) { | 105 }; |
99 console.log(err); | 106 offlineContext.startRendering(); |
100 buffer.lufs = 1; | |
101 }); | |
102 } | 107 } |
103 | 108 |
104 function calculateProcessedLoudness(buffer, winDur, overlap) | 109 function calculateProcessedLoudness(buffer, winDur, overlap) |
105 { | 110 { |
106 // Buffer Web Audio buffer node | 111 // Buffer Web Audio buffer node |