OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2011, Google Inc. All rights reserved. | 2 * Copyright (C) 2011, 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 13 matching lines...) Expand all Loading... |
24 | 24 |
25 #include "config.h" | 25 #include "config.h" |
26 | 26 |
27 #if ENABLE(WEB_AUDIO) | 27 #if ENABLE(WEB_AUDIO) |
28 | 28 |
29 #include "modules/webaudio/WaveShaperProcessor.h" | 29 #include "modules/webaudio/WaveShaperProcessor.h" |
30 | 30 |
31 #include "modules/webaudio/WaveShaperDSPKernel.h" | 31 #include "modules/webaudio/WaveShaperDSPKernel.h" |
32 | 32 |
33 namespace WebCore { | 33 namespace WebCore { |
34 | 34 |
35 WaveShaperProcessor::WaveShaperProcessor(float sampleRate, size_t numberOfChanne
ls) | 35 WaveShaperProcessor::WaveShaperProcessor(float sampleRate, size_t numberOfChanne
ls) |
36 : AudioDSPKernelProcessor(sampleRate, numberOfChannels) | 36 : AudioDSPKernelProcessor(sampleRate, numberOfChannels) |
| 37 , m_oversample(OverSampleNone) |
37 { | 38 { |
38 } | 39 } |
39 | 40 |
40 WaveShaperProcessor::~WaveShaperProcessor() | 41 WaveShaperProcessor::~WaveShaperProcessor() |
41 { | 42 { |
42 if (isInitialized()) | 43 if (isInitialized()) |
43 uninitialize(); | 44 uninitialize(); |
44 } | 45 } |
45 | 46 |
46 PassOwnPtr<AudioDSPKernel> WaveShaperProcessor::createKernel() | 47 PassOwnPtr<AudioDSPKernel> WaveShaperProcessor::createKernel() |
47 { | 48 { |
48 return adoptPtr(new WaveShaperDSPKernel(this)); | 49 return adoptPtr(new WaveShaperDSPKernel(this)); |
49 } | 50 } |
50 | 51 |
51 void WaveShaperProcessor::setCurve(Float32Array* curve) | 52 void WaveShaperProcessor::setCurve(Float32Array* curve) |
52 { | 53 { |
53 // This synchronizes with process(). | 54 // This synchronizes with process(). |
54 MutexLocker processLocker(m_processLock); | 55 MutexLocker processLocker(m_processLock); |
55 | 56 |
56 m_curve = curve; | 57 m_curve = curve; |
57 } | 58 } |
58 | 59 |
| 60 void WaveShaperProcessor::setOversample(OverSampleType oversample) |
| 61 { |
| 62 // This synchronizes with process(). |
| 63 MutexLocker processLocker(m_processLock); |
| 64 |
| 65 m_oversample = oversample; |
| 66 |
| 67 if (oversample != OverSampleNone) { |
| 68 for (unsigned i = 0; i < m_kernels.size(); ++i) { |
| 69 WaveShaperDSPKernel* kernel = static_cast<WaveShaperDSPKernel*>(m_ke
rnels[i].get()); |
| 70 kernel->lazyInitializeOversampling(); |
| 71 } |
| 72 } |
| 73 } |
| 74 |
59 void WaveShaperProcessor::process(const AudioBus* source, AudioBus* destination,
size_t framesToProcess) | 75 void WaveShaperProcessor::process(const AudioBus* source, AudioBus* destination,
size_t framesToProcess) |
60 { | 76 { |
61 if (!isInitialized()) { | 77 if (!isInitialized()) { |
62 destination->zero(); | 78 destination->zero(); |
63 return; | 79 return; |
64 } | 80 } |
65 | 81 |
66 bool channelCountMatches = source->numberOfChannels() == destination->number
OfChannels() && source->numberOfChannels() == m_kernels.size(); | 82 bool channelCountMatches = source->numberOfChannels() == destination->number
OfChannels() && source->numberOfChannels() == m_kernels.size(); |
67 ASSERT(channelCountMatches); | 83 ASSERT(channelCountMatches); |
68 if (!channelCountMatches) | 84 if (!channelCountMatches) |
69 return; | 85 return; |
70 | 86 |
71 // The audio thread can't block on this lock, so we call tryLock() instead. | 87 // The audio thread can't block on this lock, so we call tryLock() instead. |
72 MutexTryLocker tryLocker(m_processLock); | 88 MutexTryLocker tryLocker(m_processLock); |
73 if (tryLocker.locked()) { | 89 if (tryLocker.locked()) { |
74 // For each channel of our input, process using the corresponding WaveSh
aperDSPKernel into the output channel. | 90 // For each channel of our input, process using the corresponding WaveSh
aperDSPKernel into the output channel. |
75 for (unsigned i = 0; i < m_kernels.size(); ++i) | 91 for (unsigned i = 0; i < m_kernels.size(); ++i) |
76 m_kernels[i]->process(source->channel(i)->data(), destination->chann
el(i)->mutableData(), framesToProcess); | 92 m_kernels[i]->process(source->channel(i)->data(), destination->chann
el(i)->mutableData(), framesToProcess); |
77 } else { | 93 } else { |
78 // Too bad - the tryLock() failed. We must be in the middle of a setCurv
e() call. | 94 // Too bad - the tryLock() failed. We must be in the middle of a setCurv
e() call. |
79 destination->zero(); | 95 destination->zero(); |
80 } | 96 } |
81 } | 97 } |
82 | 98 |
83 } // namespace WebCore | 99 } // namespace WebCore |
84 | 100 |
85 #endif // ENABLE(WEB_AUDIO) | 101 #endif // ENABLE(WEB_AUDIO) |
OLD | NEW |