| OLD | NEW | 
|    1 function createGraph(options) { |    1 function createGraph(options) { | 
|    2     var context = new OfflineAudioContext(1, renderFrames, sampleRate); |    2     var context = new OfflineAudioContext(1, renderFrames, sampleRate); | 
|    3  |    3  | 
|    4     // Use a default sawtooth wave for the test signal.  We want something is a |    4     // Use a default sawtooth wave for the test signal.  We want something is a | 
|    5     // bit more harmonic content than a sine wave, but otherwise it doesn't |    5     // bit more harmonic content than a sine wave, but otherwise it doesn't | 
|    6     // really matter. |    6     // really matter. | 
|    7     var src = context.createOscillator(); |    7     var src = context.createOscillator(); | 
|    8     src.type = "sawtooth"; |    8     src.type = "sawtooth"; | 
|    9  |    9  | 
|   10     var analyser = context.createAnalyser(); |   10     var analyser = context.createAnalyser(); | 
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   75 function clipMagnitude(limit, x) { |   75 function clipMagnitude(limit, x) { | 
|   76     for (var k = 0; k < x.length; ++k) |   76     for (var k = 0; k < x.length; ++k) | 
|   77         x[k] = Math.max(limit, x[k]) |   77         x[k] = Math.max(limit, x[k]) | 
|   78 } |   78 } | 
|   79  |   79  | 
|   80 // Compare the float frequency data in dB, |freqData|, against the expected valu
     e, |   80 // Compare the float frequency data in dB, |freqData|, against the expected valu
     e, | 
|   81 // |expectedFreq|. |options| is a dictionary with the property |floatRelError| f
     or setting the |   81 // |expectedFreq|. |options| is a dictionary with the property |floatRelError| f
     or setting the | 
|   82 // comparison threshold and |precision| for setting the printed precision.  Sett
     ing |precision| to |   82 // comparison threshold and |precision| for setting the printed precision.  Sett
     ing |precision| to | 
|   83 // |undefined| means printing all digits.  If |options.precision} doesn't exist,
      use a default |   83 // |undefined| means printing all digits.  If |options.precision} doesn't exist,
      use a default | 
|   84 // precision. |   84 // precision. | 
|   85 function compareFloatFreq(message, freqData, expectedFreq, options) { |   85 function compareFloatFreq(message, freqData, expectedFreq, should, options) { | 
|   86     // Any dB values below -100 is pretty much in the noise due to round-off in |   86     // Any dB values below -100 is pretty much in the noise due to round-off in | 
|   87     // the (single-precisiion) FFT, so just clip those values to -100. |   87     // the (single-precisiion) FFT, so just clip those values to -100. | 
|   88     var lowerLimit = -100; |   88     var lowerLimit = -100; | 
|   89     clipMagnitude(lowerLimit, expectedFreq); |   89     clipMagnitude(lowerLimit, expectedFreq); | 
|   90  |   90  | 
|   91     var actual = freqData; |   91     var actual = freqData; | 
|   92     clipMagnitude(lowerLimit, actual); |   92     clipMagnitude(lowerLimit, actual); | 
|   93  |   93  | 
|   94     // Default precision for printing the FFT data.  Distinguish between options
     .precision existing |   94     var success = should(actual, message) | 
|   95     // or not.  If it does, use whatever value is there, including undefined. |  | 
|   96     var defaultPrecision = options.hasOwnProperty("precision") ? options.precisi
     on : 3; |  | 
|   97  |  | 
|   98     var success = Should(message, actual, { |  | 
|   99             verbose: true, |  | 
|  100             precision: defaultPrecision |  | 
|  101         }) |  | 
|  102         .beCloseToArray(expectedFreq, { |   95         .beCloseToArray(expectedFreq, { | 
|  103             relativeThreshold: options.floatRelError || 0, |   96             relativeThreshold: options.floatRelError || 0, | 
|  104         }); |   97         }); | 
|  105  |   98  | 
|  106     return { |   99     return { | 
|  107         success: success, |  100         success: success, | 
|  108         expected: expectedFreq |  101         expected: expectedFreq | 
|  109     }; |  102     }; | 
|  110 } |  103 } | 
|  111  |  104  | 
| (...skipping 10 matching lines...) Expand all  Loading... | 
|  122 // Convert the float frequency data, |floatFreqData|, to byte values using the |  115 // Convert the float frequency data, |floatFreqData|, to byte values using the | 
|  123 // dB limits |minDecibels| and |maxDecibels|.  The new byte array is returned. |  116 // dB limits |minDecibels| and |maxDecibels|.  The new byte array is returned. | 
|  124 function convertFloatToByte(floatFreqData, minDecibels, maxDecibels) { |  117 function convertFloatToByte(floatFreqData, minDecibels, maxDecibels) { | 
|  125     var scale = 255 / (maxDecibels - minDecibels); |  118     var scale = 255 / (maxDecibels - minDecibels); | 
|  126  |  119  | 
|  127     return floatFreqData.map(function (x) { |  120     return floatFreqData.map(function (x) { | 
|  128         var value = Math.floor(scale * (x - minDecibels)); |  121         var value = Math.floor(scale * (x - minDecibels)); | 
|  129         return Math.min(255, Math.max(0, value)); |  122         return Math.min(255, Math.max(0, value)); | 
|  130     }); |  123     }); | 
|  131 } |  124 } | 
| OLD | NEW |