193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)/*
293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * Copyright (C) 2010, Google Inc. All rights reserved.
393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) *
493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * Redistribution and use in source and binary forms, with or without
593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * modification, are permitted provided that the following conditions
693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * are met:
793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * 1.  Redistributions of source code must retain the above copyright
893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) *    notice, this list of conditions and the following disclaimer.
993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * 2.  Redistributions in binary form must reproduce the above copyright
1093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) *    notice, this list of conditions and the following disclaimer in the
1193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) *    documentation and/or other materials provided with the distribution.
1293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) *
1393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
1493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
1593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
1693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
1793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
1893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
1993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
2093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
2293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) */
2493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
2593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)#ifndef WebAudioBus_h
2693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)#define WebAudioBus_h
2793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
2893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)#include "WebCommon.h"
2993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
301e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)#if INSIDE_BLINK
3193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)namespace WTF { template <typename T> class PassRefPtr; }
3293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)#endif
3393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
3451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)namespace blink {
3593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
36e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)class AudioBus;
3793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)class WebAudioBusPrivate;
3893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
3993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)// A container for multi-channel linear PCM audio data.
4093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)//
4193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)// WARNING: It is not safe to pass a WebAudioBus across threads!!!
4293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)//
431e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)class BLINK_PLATFORM_EXPORT WebAudioBus {
4493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)public:
4593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    WebAudioBus() : m_private(0) { }
4693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    ~WebAudioBus() { reset(); }
4702772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch
4893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    // initialize() allocates memory of the given length for the given number of channels.
491e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    void initialize(unsigned numberOfChannels, size_t length, double sampleRate);
5093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
5193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    // resizeSmaller() can only be called after initialize() with a new length <= the initialization length.
5293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    // The data stored in the bus will remain undisturbed.
531e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    void resizeSmaller(size_t newLength);
5493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
5593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    // reset() releases the memory allocated from initialize().
561e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    void reset();
5702772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch
581e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    unsigned numberOfChannels() const;
591e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    size_t length() const;
601e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    double sampleRate() const;
6102772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch
621e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    float* channelData(unsigned channelIndex);
6393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
641e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)#if INSIDE_BLINK
65e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    WTF::PassRefPtr<AudioBus> release();
6693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)#endif
6793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
6893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)private:
6993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    // Disallow copy and assign.
7093ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    WebAudioBus(const WebAudioBus&);
7193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)    void operator=(const WebAudioBus&);
7293ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
73e38fbeeb576b5094e34e038ab88d9d6a5c5c2214Torne (Richard Coles)    AudioBus* m_private;
7493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)};
7593ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
7651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)} // namespace blink
7793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)
7893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)#endif // WebAudioBus_h
79