| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010, Google Inc. All rights reserved. | 2 * Copyright (C) 2010, Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 | 30 |
| 31 namespace AudioUtilities { | 31 namespace AudioUtilities { |
| 32 | 32 |
| 33 float decibelsToLinear(float decibels) | 33 float decibelsToLinear(float decibels) |
| 34 { | 34 { |
| 35 return powf(10, 0.05f * decibels); | 35 return powf(10, 0.05f * decibels); |
| 36 } | 36 } |
| 37 | 37 |
| 38 float linearToDecibels(float linear) | 38 float linearToDecibels(float linear) |
| 39 { | 39 { |
| 40 // It's not possible to calculate decibels for a zero linear value since it
would be -Inf. | 40 ASSERT(linear >= 0); |
| 41 // -1000.0 dB represents a very tiny linear value in case we ever reach this
case. | |
| 42 ASSERT(linear); | |
| 43 if (!linear) | |
| 44 return -1000; | |
| 45 | 41 |
| 46 return 20 * log10f(linear); | 42 return 20 * log10f(linear); |
| 47 } | 43 } |
| 48 | 44 |
| 49 double discreteTimeConstantForSampleRate(double timeConstant, double sampleRate) | 45 double discreteTimeConstantForSampleRate(double timeConstant, double sampleRate) |
| 50 { | 46 { |
| 51 return 1 - exp(-1 / (sampleRate * timeConstant)); | 47 return 1 - exp(-1 / (sampleRate * timeConstant)); |
| 52 } | 48 } |
| 53 | 49 |
| 54 size_t timeToSampleFrame(double time, double sampleRate) | 50 size_t timeToSampleFrame(double time, double sampleRate) |
| (...skipping 22 matching lines...) Expand all Loading... |
| 77 | 73 |
| 78 float maxAudioBufferSampleRate() | 74 float maxAudioBufferSampleRate() |
| 79 { | 75 { |
| 80 // Windows can support audio sampling rates this high, so allow AudioBuffer
rates this high as well. | 76 // Windows can support audio sampling rates this high, so allow AudioBuffer
rates this high as well. |
| 81 return 192000; | 77 return 192000; |
| 82 } | 78 } |
| 83 } // namespace AudioUtilities | 79 } // namespace AudioUtilities |
| 84 | 80 |
| 85 } // namespace blink | 81 } // namespace blink |
| 86 | 82 |
| OLD | NEW |