1a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch/*
2a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch * Copyright (C) 2010, Google Inc. All rights reserved.
3a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch *
4a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch * Redistribution and use in source and binary forms, with or without
5a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch * modification, are permitted provided that the following conditions
6a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch * are met:
7a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch * 1.  Redistributions of source code must retain the above copyright
8a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch *    notice, this list of conditions and the following disclaimer.
9a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch * 2.  Redistributions in binary form must reproduce the above copyright
10a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch *    notice, this list of conditions and the following disclaimer in the
11a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch *    documentation and/or other materials provided with the distribution.
12a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch *
13a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
14a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
17a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch */
24a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch
25a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch#ifndef DelayDSPKernel_h
26a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch#define DelayDSPKernel_h
27a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch
28a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch#include "AudioArray.h"
29a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch#include "AudioDSPKernel.h"
30a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch#include "DelayProcessor.h"
31a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch
32a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochnamespace WebCore {
33a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch
34a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochclass DelayProcessor;
35a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch
36a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochclass DelayDSPKernel : public AudioDSPKernel {
37a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochpublic:
38a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch    DelayDSPKernel(DelayProcessor*);
39a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch    DelayDSPKernel(double maxDelayTime, double sampleRate);
40a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch
41a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch    virtual void process(const float* source, float* destination, size_t framesToProcess);
42a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch    virtual void reset();
43a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch
44a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch    double maxDelayTime() const { return m_maxDelayTime; }
45a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch
46a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch    void setDelayFrames(double numberOfFrames) { m_desiredDelayFrames = numberOfFrames; }
47a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch
48a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochprivate:
49a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch    AudioFloatArray m_buffer;
50a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch    double m_maxDelayTime;
51a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch    int m_writeIndex;
52a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch    double m_currentDelayTime;
53a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch    double m_smoothingRate;
54a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch    bool m_firstTime;
55a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch    double m_desiredDelayFrames;
56a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch
57a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch    DelayProcessor* delayProcessor() { return static_cast<DelayProcessor*>(processor()); }
58a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch};
59a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch
60a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch} // namespace WebCore
61a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch
62a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch#endif // DelayDSPKernel_h
63