| 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 22 matching lines...) Expand all Loading... |
| 33 #include "core/dom/DOMTypedArray.h" | 33 #include "core/dom/DOMTypedArray.h" |
| 34 #include "platform/audio/AudioArray.h" | 34 #include "platform/audio/AudioArray.h" |
| 35 #include "wtf/Forward.h" | 35 #include "wtf/Forward.h" |
| 36 #include "wtf/Vector.h" | 36 #include "wtf/Vector.h" |
| 37 | 37 |
| 38 namespace blink { | 38 namespace blink { |
| 39 | 39 |
| 40 class PeriodicWave : public GarbageCollectedFinalized<PeriodicWave>, public Scri
ptWrappable { | 40 class PeriodicWave : public GarbageCollectedFinalized<PeriodicWave>, public Scri
ptWrappable { |
| 41 DEFINE_WRAPPERTYPEINFO(); | 41 DEFINE_WRAPPERTYPEINFO(); |
| 42 public: | 42 public: |
| 43 // Maximum array size allowed for creating PeriodicWave's. | |
| 44 static const unsigned kMaxPeriodicWaveArraySize; | |
| 45 static PeriodicWave* createSine(float sampleRate); | 43 static PeriodicWave* createSine(float sampleRate); |
| 46 static PeriodicWave* createSquare(float sampleRate); | 44 static PeriodicWave* createSquare(float sampleRate); |
| 47 static PeriodicWave* createSawtooth(float sampleRate); | 45 static PeriodicWave* createSawtooth(float sampleRate); |
| 48 static PeriodicWave* createTriangle(float sampleRate); | 46 static PeriodicWave* createTriangle(float sampleRate); |
| 49 | 47 |
| 50 // Creates an arbitrary periodic wave given the frequency components (Fourie
r coefficients). | 48 // Creates an arbitrary periodic wave given the frequency components (Fourie
r coefficients). |
| 51 static PeriodicWave* create(float sampleRate, DOMFloat32Array* real, DOMFloa
t32Array* imag); | 49 static PeriodicWave* create(float sampleRate, DOMFloat32Array* real, DOMFloa
t32Array* imag); |
| 52 | 50 |
| 53 // Returns pointers to the lower and higher wave data for the pitch range co
ntaining | 51 // Returns pointers to the lower and higher wave data for the pitch range co
ntaining |
| 54 // the given fundamental frequency. These two tables are in adjacent "pitch"
ranges | 52 // the given fundamental frequency. These two tables are in adjacent "pitch"
ranges |
| 55 // where the higher table will have the maximum number of partials which won
't alias when played back | 53 // where the higher table will have the maximum number of partials which won
't alias when played back |
| 56 // at this fundamental frequency. The lower wave is the next range containin
g fewer partials than the higher wave. | 54 // at this fundamental frequency. The lower wave is the next range containin
g fewer partials than the higher wave. |
| 57 // Interpolation between these two tables can be made according to tableInte
rpolationFactor. | 55 // Interpolation between these two tables can be made according to tableInte
rpolationFactor. |
| 58 // Where values from 0 -> 1 interpolate between lower -> higher. | 56 // Where values from 0 -> 1 interpolate between lower -> higher. |
| 59 void waveDataForFundamentalFrequency(float, float*& lowerWaveData, float*& h
igherWaveData, float& tableInterpolationFactor); | 57 void waveDataForFundamentalFrequency(float, float*& lowerWaveData, float*& h
igherWaveData, float& tableInterpolationFactor); |
| 60 | 58 |
| 61 // Returns the scalar multiplier to the oscillator frequency to calculate wa
ve buffer phase increment. | 59 // Returns the scalar multiplier to the oscillator frequency to calculate wa
ve buffer phase increment. |
| 62 float rateScale() const { return m_rateScale; } | 60 float rateScale() const { return m_rateScale; } |
| 63 | 61 |
| 64 unsigned periodicWaveSize() const { return m_periodicWaveSize; } | 62 // The size of the FFT to use based on the sampling rate. |
| 63 unsigned periodicWaveSize() const; |
| 64 |
| 65 // The number of ranges needed for the given sampling rate and FFT size. |
| 66 unsigned numberOfRanges() const { return m_numberOfRanges; } |
| 65 | 67 |
| 66 DEFINE_INLINE_TRACE() { } | 68 DEFINE_INLINE_TRACE() { } |
| 67 | 69 |
| 68 private: | 70 private: |
| 69 explicit PeriodicWave(float sampleRate); | 71 explicit PeriodicWave(float sampleRate); |
| 70 | 72 |
| 71 void generateBasicWaveform(int); | 73 void generateBasicWaveform(int); |
| 72 | 74 |
| 73 float m_sampleRate; | 75 float m_sampleRate; |
| 74 unsigned m_periodicWaveSize; | |
| 75 unsigned m_numberOfRanges; | 76 unsigned m_numberOfRanges; |
| 76 float m_centsPerRange; | 77 float m_centsPerRange; |
| 77 | 78 |
| 78 // The lowest frequency (in Hertz) where playback will include all of the pa
rtials. | 79 // The lowest frequency (in Hertz) where playback will include all of the pa
rtials. |
| 79 // Playing back lower than this frequency will gradually lose more high-freq
uency information. | 80 // Playing back lower than this frequency will gradually lose more high-freq
uency information. |
| 80 // This frequency is quite low (~10Hz @ 44.1KHz) | 81 // This frequency is quite low (~10Hz @ 44.1KHz) |
| 81 float m_lowestFundamentalFrequency; | 82 float m_lowestFundamentalFrequency; |
| 82 | 83 |
| 83 float m_rateScale; | 84 float m_rateScale; |
| 84 | 85 |
| 85 // Maximum possible number of partials (before culling). | 86 // Maximum possible number of partials (before culling). |
| 86 unsigned maxNumberOfPartials() const; | 87 unsigned maxNumberOfPartials() const; |
| 87 | 88 |
| 88 unsigned numberOfPartialsForRange(unsigned rangeIndex) const; | 89 unsigned numberOfPartialsForRange(unsigned rangeIndex) const; |
| 89 | 90 |
| 90 // Creates tables based on numberOfComponents Fourier coefficients. | 91 // Creates tables based on numberOfComponents Fourier coefficients. |
| 91 void createBandLimitedTables(const float* real, const float* imag, unsigned
numberOfComponents); | 92 void createBandLimitedTables(const float* real, const float* imag, unsigned
numberOfComponents); |
| 92 Vector<OwnPtr<AudioFloatArray>> m_bandLimitedTables; | 93 Vector<OwnPtr<AudioFloatArray>> m_bandLimitedTables; |
| 93 }; | 94 }; |
| 94 | 95 |
| 95 } // namespace blink | 96 } // namespace blink |
| 96 | 97 |
| 97 #endif // PeriodicWave_h | 98 #endif // PeriodicWave_h |
| OLD | NEW |