<?xml version="1.0" encoding="UTF-8"?>

<!--
    Copyright (c) 2015 onox

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
-->

<PropertyList>

    <params>
        <doors>
            <left>/sim/multiplay/generic/float[1]</left>
            <right>/sim/multiplay/generic/float[0]</right>
        </doors>
        <windows>
            <left>/sim/multiplay/generic/float[3]</left>
            <right>/sim/multiplay/generic/float[4]</right>
        </windows>
    </params>

    <!-- Return a factor (>= 1.0) to boost the volume when one or both
         doors are open.
    -->
    <filter>
        <name>Volume Boost Doors Factor</name>
        <type>gain</type>
        <input>
            <condition>
                <property>/sim/current-view/internal</property>
            </condition>
            <expression>
                <sum>
                    <product>
                        <div>
                            <log>
                                <sum>
                                    <min>
                                        <sum>
                                            <!-- Left door fully open is 1.0. Fully closed is 0.0 -->
                                            <table>
                                                <property alias="/params/doors/left"/>
                                                <entry><ind>0.5</ind><dep>0.0</dep></entry>
                                                <entry><ind>0.65</ind><dep>0.7</dep></entry>
                                                <entry><ind>1.0</ind><dep>1.0</dep></entry>
                                            </table>

                                            <!-- Left window fully open is 1.0. Fully closed is 0.0 -->
                                            <table>
                                                <property alias="/params/windows/left"/>
                                                <entry><ind>0.5</ind><dep>0.0</dep></entry>
                                                <entry><ind>0.65</ind><dep>0.7</dep></entry>
                                                <entry><ind>1.0</ind><dep>1.0</dep></entry>
                                            </table>
                                        </sum>
                                        <value>1.0</value>
                                    </min>

                                    <min>
                                        <sum>
                                            <!-- Right door fully open is 1.0. Fully closed is 0.0 -->
                                            <table>
                                                <property alias="/params/doors/right"/>
                                                <entry><ind>0.5</ind><dep>0.0</dep></entry>
                                                <entry><ind>0.65</ind><dep>0.7</dep></entry>
                                                <entry><ind>1.0</ind><dep>1.0</dep></entry>
                                            </table>

                                            <!-- Right window fully open is 1.0. Fully closed is 0.0 -->
                                            <table>
                                                <property alias="/params/windows/right"/>
                                                <entry><ind>0.5</ind><dep>0.0</dep></entry>
                                                <entry><ind>0.65</ind><dep>0.7</dep></entry>
                                                <entry><ind>1.0</ind><dep>1.0</dep></entry>
                                            </table>
                                        </sum>
                                        <value>1.0</value>
                                    </min>

                                    <!-- Prevents math domain error because log2
                                         requires value >= 1.0.
                                    -->
                                    <value>1.0</value>
                                </sum>
                            </log>
                            <log>
                                <!-- log(x)/log(2) = log2(x) -->
                                <value>2.0</value>
                            </log>
                        </div>

                        <!-- 20 % extra volume if one door is open, 32 % if both -->
                        <value>0.2</value>
                    </product>
                    <value>1.0</value>
                </sum>
            </expression>
        </input>
        <input>
            <!-- 40 % extra volume if outside the aircraft -->
            <value>1.4</value>
        </input>
        <output>
            <property>/sim/model/c172p/sound/volume-boost-doors</property>
        </output>
    </filter>

    <filter>
        <name>Volume Boost Doors plus thunder1</name>
        <type>gain</type>
        <input>
            <expression>
                <product>
                    <property>/sim/model/c172p/sound/volume-boost-doors</property>
                    <property>/sim/model/c172p/sound/lightning/dist1</property>
                    <value>0.7142857142857143</value>
                </product>
            </expression>
        </input>
        <output>
            <property>/sim/model/c172p/sound/volume-boost-doors-thunder1</property>
        </output>
    </filter>

    <filter>
        <name>Volume Boost Doors plus thunder2</name>
        <type>gain</type>
        <input>
            <expression>
                <product>
                    <property>/sim/model/c172p/sound/volume-boost-doors</property>
                    <property>/sim/model/c172p/sound/lightning/dist2</property>
                    <value>0.7142857142857143</value>
                </product>
            </expression>
        </input>
        <output>
            <property>/sim/model/c172p/sound/volume-boost-doors-thunder2</property>
        </output>
    </filter>

    <filter>
        <name>Volume Boost Doors plus thunder3</name>
        <type>gain</type>
        <input>
            <expression>
                <product>
                    <property>/sim/model/c172p/sound/volume-boost-doors</property>
                    <property>/sim/model/c172p/sound/lightning/dist3</property>
                    <value>0.7142857142857143</value>
                </product>
            </expression>
        </input>
        <output>
            <property>/sim/model/c172p/sound/volume-boost-doors-thunder3</property>
        </output>
    </filter>

    <!-- Return a factor (>= 1.0) to boost the volume when left door is open -->
    <filter>
        <name>Volume Boost Left Door Factor</name>
        <type>gain</type>
        <input>
            <condition>
                <property>/sim/current-view/internal</property>
            </condition>
            <expression>
                <sum>
                    <product>
                        <div>
                            <log>
                                <sum>
                                    <min>
                                        <sum>
                                            <!-- Left door fully open is 1.0. Fully closed is 0.0 -->
                                            <table>
                                                <property alias="/params/doors/left"/>
                                                <entry><ind>0.5</ind><dep>0.0</dep></entry>
                                                <entry><ind>0.65</ind><dep>0.7</dep></entry>
                                                <entry><ind>1.0</ind><dep>1.0</dep></entry>
                                            </table>

                                            <!-- Left window fully open is 1.0. Fully closed is 0.0 -->
                                            <table>
                                                <property alias="/params/windows/left"/>
                                                <entry><ind>0.5</ind><dep>0.0</dep></entry>
                                                <entry><ind>0.65</ind><dep>0.7</dep></entry>
                                                <entry><ind>1.0</ind><dep>1.0</dep></entry>
                                            </table>
                                        </sum>
                                        <value>1.0</value>
                                    </min>

                                    <!-- Prevents math domain error because log2
                                         requires value >= 1.0.
                                    -->
                                    <value>1.0</value>
                                </sum>
                            </log>
                            <log>
                                <!-- log(x)/log(2) = log2(x) -->
                                <value>2.0</value>
                            </log>
                        </div>

                        <!-- 20 % extra volume if door is open -->
                        <value>0.2</value>
                    </product>
                    <value>1.0</value>
                </sum>
            </expression>
        </input>
        <input>
            <!-- 40 % extra volume if outside the aircraft -->
            <value>1.4</value>
        </input>
        <output>
            <property>/sim/model/c172p/sound/volume-boost-left-door</property>
        </output>
    </filter>

    <!-- Return a factor (>= 1.0) to boost the volume when right door is open -->
    <filter>
        <name>Volume Boost Right Door Factor</name>
        <type>gain</type>
        <input>
            <condition>
                <property>/sim/current-view/internal</property>
            </condition>
            <expression>
                <sum>
                    <product>
                        <div>
                            <log>
                                <sum>
                                    <min>
                                        <sum>
                                            <!-- Right door fully open is 1.0. Fully closed is 0.0 -->
                                            <table>
                                                <property alias="/params/doors/right"/>
                                                <entry><ind>0.5</ind><dep>0.0</dep></entry>
                                                <entry><ind>0.65</ind><dep>0.7</dep></entry>
                                                <entry><ind>1.0</ind><dep>1.0</dep></entry>
                                            </table>

                                            <!-- Right window fully open is 1.0. Fully closed is 0.0 -->
                                            <table>
                                                <property alias="/params/windows/right"/>
                                                <entry><ind>0.5</ind><dep>0.0</dep></entry>
                                                <entry><ind>0.65</ind><dep>0.7</dep></entry>
                                                <entry><ind>1.0</ind><dep>1.0</dep></entry>
                                            </table>
                                        </sum>
                                        <value>1.0</value>
                                    </min>

                                    <!-- Prevents math domain error because log2
                                         requires value >= 1.0.
                                    -->
                                    <value>1.0</value>
                                </sum>
                            </log>
                            <log>
                                <!-- log(x)/log(2) = log2(x) -->
                                <value>2.0</value>
                            </log>
                        </div>

                        <!-- 20 % extra volume if door is open -->
                        <value>0.2</value>
                    </product>
                    <value>1.0</value>
                </sum>
            </expression>
        </input>
        <input>
            <!-- 40 % extra volume if outside the aircraft -->
            <value>1.4</value>
        </input>
        <output>
            <property>/sim/model/c172p/sound/volume-boost-right-door</property>
        </output>
    </filter>

    <filter>
        <name>Spray Wake Speed</name>
        <type>noise-spike</type>
        <input>
            <property>/fdm/jsbsim/hydro/spray-wake-speed-kt-actual</property>
        </input>
        <output>
            <property>/sim/model/c172p/sound/spray-wake-speed</property>
        </output>

        <!-- High rate of change to give a quick, but not abrupt cut off
             of the pontoon wake sounds when the aircraft starts climbing
             during a takeoff from the water.
        -->
        <max-rate-of-change>20.0</max-rate-of-change>
    </filter>

</PropertyList>