/*
 * Copyright (C) 2012, Google Inc. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1.  Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2.  Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

// OscillatorNode is an audio generator of periodic waveforms.
[
    Conditional=WEB_AUDIO
] interface OscillatorNode : AudioSourceNode {

    // Type constants.
    const unsigned short SINE = 0;
    const unsigned short SQUARE = 1;
    const unsigned short SAWTOOTH = 2;
    const unsigned short TRIANGLE = 3;
    const unsigned short CUSTOM = 4;

    [Custom=Setter] attribute DOMString type;

    // Playback state constants.
    const unsigned short UNSCHEDULED_STATE = 0;
    const unsigned short SCHEDULED_STATE = 1;
    const unsigned short PLAYING_STATE = 2;
    const unsigned short FINISHED_STATE = 3;

    readonly attribute unsigned short playbackState;

    readonly attribute AudioParam frequency; // in Hertz
    readonly attribute AudioParam detune; // in Cents

    [RaisesException] void start(optional double when);
    [RaisesException] void stop(optional double when);

    [RaisesException, ImplementedAs=start] void noteOn(double when);
    [RaisesException, ImplementedAs=stop] void noteOff(double when);

    void setPeriodicWave(PeriodicWave periodicWave);

    attribute EventHandler onended;
};
