| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 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 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 class PeriodicWave final : public GarbageCollectedFinalized<PeriodicWave>, | 45 class PeriodicWave final : public GarbageCollectedFinalized<PeriodicWave>, |
| 46 public ScriptWrappable { | 46 public ScriptWrappable { |
| 47 DEFINE_WRAPPERTYPEINFO(); | 47 DEFINE_WRAPPERTYPEINFO(); |
| 48 | 48 |
| 49 public: | 49 public: |
| 50 static PeriodicWave* createSine(float sampleRate); | 50 static PeriodicWave* createSine(float sampleRate); |
| 51 static PeriodicWave* createSquare(float sampleRate); | 51 static PeriodicWave* createSquare(float sampleRate); |
| 52 static PeriodicWave* createSawtooth(float sampleRate); | 52 static PeriodicWave* createSawtooth(float sampleRate); |
| 53 static PeriodicWave* createTriangle(float sampleRate); | 53 static PeriodicWave* createTriangle(float sampleRate); |
| 54 | 54 |
| 55 // Creates an arbitrary periodic wave given the frequency components (Fourier
coefficients). | 55 // Creates an arbitrary periodic wave given the frequency components (Fourier |
| 56 // coefficients). |
| 56 static PeriodicWave* create(BaseAudioContext&, | 57 static PeriodicWave* create(BaseAudioContext&, |
| 57 size_t realLength, | 58 size_t realLength, |
| 58 const float* real, | 59 const float* real, |
| 59 size_t imagLength, | 60 size_t imagLength, |
| 60 const float* imag, | 61 const float* imag, |
| 61 bool normalize, | 62 bool normalize, |
| 62 ExceptionState&); | 63 ExceptionState&); |
| 63 | 64 |
| 64 static PeriodicWave* create(BaseAudioContext&, | 65 static PeriodicWave* create(BaseAudioContext&, |
| 65 DOMFloat32Array* real, | 66 DOMFloat32Array* real, |
| 66 DOMFloat32Array* imag, | 67 DOMFloat32Array* imag, |
| 67 bool normalize, | 68 bool normalize, |
| 68 ExceptionState&); | 69 ExceptionState&); |
| 69 | 70 |
| 70 static PeriodicWave* create(BaseAudioContext*, | 71 static PeriodicWave* create(BaseAudioContext*, |
| 71 const PeriodicWaveOptions&, | 72 const PeriodicWaveOptions&, |
| 72 ExceptionState&); | 73 ExceptionState&); |
| 73 | 74 |
| 74 virtual ~PeriodicWave(); | 75 virtual ~PeriodicWave(); |
| 75 | 76 |
| 76 // Returns pointers to the lower and higher wave data for the pitch range cont
aining | 77 // Returns pointers to the lower and higher wave data for the pitch range |
| 77 // the given fundamental frequency. These two tables are in adjacent "pitch" r
anges | 78 // containing the given fundamental frequency. These two tables are in |
| 78 // where the higher table will have the maximum number of partials which won't
alias when played back | 79 // adjacent "pitch" ranges where the higher table will have the maximum number |
| 79 // at this fundamental frequency. The lower wave is the next range containing
fewer partials than the higher wave. | 80 // of partials which won't alias when played back at this fundamental |
| 80 // Interpolation between these two tables can be made according to tableInterp
olationFactor. | 81 // frequency. The lower wave is the next range containing fewer partials than |
| 82 // the higher wave. Interpolation between these two tables can be made |
| 83 // according to tableInterpolationFactor. |
| 81 // Where values from 0 -> 1 interpolate between lower -> higher. | 84 // Where values from 0 -> 1 interpolate between lower -> higher. |
| 82 void waveDataForFundamentalFrequency(float, | 85 void waveDataForFundamentalFrequency(float, |
| 83 float*& lowerWaveData, | 86 float*& lowerWaveData, |
| 84 float*& higherWaveData, | 87 float*& higherWaveData, |
| 85 float& tableInterpolationFactor); | 88 float& tableInterpolationFactor); |
| 86 | 89 |
| 87 // Returns the scalar multiplier to the oscillator frequency to calculate wave
buffer phase increment. | 90 // Returns the scalar multiplier to the oscillator frequency to calculate wave |
| 91 // buffer phase increment. |
| 88 float rateScale() const { return m_rateScale; } | 92 float rateScale() const { return m_rateScale; } |
| 89 | 93 |
| 90 // The size of the FFT to use based on the sampling rate. | 94 // The size of the FFT to use based on the sampling rate. |
| 91 unsigned periodicWaveSize() const; | 95 unsigned periodicWaveSize() const; |
| 92 | 96 |
| 93 // The number of ranges needed for the given sampling rate and FFT size. | 97 // The number of ranges needed for the given sampling rate and FFT size. |
| 94 unsigned numberOfRanges() const { return m_numberOfRanges; } | 98 unsigned numberOfRanges() const { return m_numberOfRanges; } |
| 95 | 99 |
| 96 DEFINE_INLINE_TRACE() {} | 100 DEFINE_INLINE_TRACE() {} |
| 97 | 101 |
| 98 private: | 102 private: |
| 99 explicit PeriodicWave(float sampleRate); | 103 explicit PeriodicWave(float sampleRate); |
| 100 | 104 |
| 101 void generateBasicWaveform(int); | 105 void generateBasicWaveform(int); |
| 102 | 106 |
| 103 size_t m_v8ExternalMemory; | 107 size_t m_v8ExternalMemory; |
| 104 | 108 |
| 105 float m_sampleRate; | 109 float m_sampleRate; |
| 106 unsigned m_numberOfRanges; | 110 unsigned m_numberOfRanges; |
| 107 float m_centsPerRange; | 111 float m_centsPerRange; |
| 108 | 112 |
| 109 // The lowest frequency (in Hertz) where playback will include all of the part
ials. | 113 // The lowest frequency (in Hertz) where playback will include all of the |
| 110 // Playing back lower than this frequency will gradually lose more high-freque
ncy information. | 114 // partials. Playing back lower than this frequency will gradually lose more |
| 111 // This frequency is quite low (~10Hz @ 44.1KHz) | 115 // high-frequency information. This frequency is quite low (~10Hz @ 44.1KHz) |
| 112 float m_lowestFundamentalFrequency; | 116 float m_lowestFundamentalFrequency; |
| 113 | 117 |
| 114 float m_rateScale; | 118 float m_rateScale; |
| 115 | 119 |
| 116 // Maximum possible number of partials (before culling). | 120 // Maximum possible number of partials (before culling). |
| 117 unsigned maxNumberOfPartials() const; | 121 unsigned maxNumberOfPartials() const; |
| 118 | 122 |
| 119 unsigned numberOfPartialsForRange(unsigned rangeIndex) const; | 123 unsigned numberOfPartialsForRange(unsigned rangeIndex) const; |
| 120 | 124 |
| 121 void adjustV8ExternalMemory(int delta); | 125 void adjustV8ExternalMemory(int delta); |
| 122 | 126 |
| 123 // Creates tables based on numberOfComponents Fourier coefficients. | 127 // Creates tables based on numberOfComponents Fourier coefficients. |
| 124 void createBandLimitedTables(const float* real, | 128 void createBandLimitedTables(const float* real, |
| 125 const float* imag, | 129 const float* imag, |
| 126 unsigned numberOfComponents, | 130 unsigned numberOfComponents, |
| 127 bool disableNormalization); | 131 bool disableNormalization); |
| 128 Vector<std::unique_ptr<AudioFloatArray>> m_bandLimitedTables; | 132 Vector<std::unique_ptr<AudioFloatArray>> m_bandLimitedTables; |
| 129 }; | 133 }; |
| 130 | 134 |
| 131 } // namespace blink | 135 } // namespace blink |
| 132 | 136 |
| 133 #endif // PeriodicWave_h | 137 #endif // PeriodicWave_h |
| OLD | NEW |