<phyphox version="1.7" locale="en">
  <title>Sound duration</title>
  <category>Timers</category>
  <description>
        Measure the duration of a sound, noise, tone, etc.

        This experiment allows to measure the duration of a loud acoustic signal. You might want to adjust the threshold, giving the level at which the stop watch is triggered (ranging from 0 to 1).

        After starting the experiment, the clock will start on the first noise exceeding the threshold and will be stopped when the sound level is below that threshold for longer period. To repeat the experiment, clear the data and start again.
    </description>
  <icon>SD</icon>
  <data-containers>
    <container>threshold</container>
    <container size="16384">recording</container>
    <container>rate</container>
    <container size="8192">i</container>
    <container>i2first</container>
    <container>i2last</container>
    <container>ifirst</container>
    <container>ilast</container>
    <container>tfirst</container>
    <container>tlast</container>
    <container init="0">currentfirst</container>
    <container init="0">currentlast</container>
    <container>currentinterval</container>
    <container>limit</container>
    <container>last</container>
    <container size="0">tlist</container>
    <container size="0">tlistshow</container>
    <container size="0">tindex</container>
    <container size="1">tcount</container>
    <container size="1">tcount-1</container>
    <container>avgInterval</container>
    <container>avgRate</container>
    <container>avgBPM</container>
    <container>t0</container>
    <container>t1</container>
    <container>t2</container>
    <container>t3</container>
    <container>t4</container>
    <container>t5</container>
    <container>t0effective</container>
    <container>t1effective</container>
    <container>t2effective</container>
    <container>t3effective</container>
    <container>t4effective</container>
    <container>t5effective</container>
    <container>tmax</container>
    <container>count</container>
    <container init="0">index</container>
  </data-containers>
  <translations>
    <translation locale="de">
      <title>Schalldauer</title>
      <category>Zeitmessung</category>
      <description>
        Stoppe die Dauer eines Geräuschs, Tons, usw.

                Dieses Experiment ermöglicht es dir, die Dauer eines akustischen Signals zu messen. Hierzu muss die Schwelle so eingestellt werden, dass sie über den Umgebungsgeräuschen, aber unter der Lautstärke des Auslösegeräusches liegt (im Bereich von 0 bis 1).

                Nachdem das Experiment gestartet wurde, beginnt die Zeitmessung mit dem ersten Geräusch das die Schwelle überschreitet und wird beendet wenn die Schwelle nicht mehr überschritten wurde. Um das Experiment zu wiederholen, lösche die Daten und starte erneut.
    </description>
      <string original="Simple">Einfach</string>
      <string original="Sequence">Sequenz</string>
      <string original="Threshold">Schwelle</string>
      <string original="Time">Zeit</string>
      <string original="Time 1">Zeit 1</string>
      <string original="Time 2">Zeit 2</string>
      <string original="Time 3">Zeit 3</string>
      <string original="Time 4">Zeit 4</string>
      <string original="Time 5">Zeit 5</string>
      <string original="Change the threshold to be above the environmental noise level, but below the trigger noise (you can try the audio scope experiment to check these).">Ändere die Schwelle auf einen Wert oberhalb der Umgebungsgeräusche, aber unterhalb des Auslösegeräusches (dies kannst du zum Beispiel im Experiment "Audio Oszilloskop" prüfen).</string>
      <string original="Unfortunately, this won't work on slow phones. Please compare to a regular clock first, to make sure, that the experiment is working as expected.">Leider funktioniert dieses Experiment nicht auf langsamen Geräten. Bitte vergleiche es erst mit einer normalen Uhr, um sicherzugehen, dass es wie gewünscht arbeitet.</string>
      <string original="Many">Viele</string>
      <string original="Events">Ereignisse</string>
      <string original="Event number">Ereignis-Nummer</string>
      <string original="Time interval">Zeitintervall</string>
      <string original="Average interval">Mittleres Intervall</string>
      <string original="Average rate">Mittlere Rate</string>
      <string original="Average rate (bpm)">Mittlere Rate (bpm)</string>
    </translation>
  </translations>
  <input>
    <audio>
      <output>recording</output>
      <output component="rate">rate</output>
    </audio>
  </input>
  <views>
    <view label="Simple">
      <edit label="Threshold" unit="a.u." default="0.1" signed="false" min="0" max="1">
        <output>threshold</output>
      </edit>
      <value label="Time" size="3" precision="3" unit="s">
        <input>t0</input>
      </value>
      <button label="Reset">
        <input type="empty"/>
        <output>tlist</output>
        <input type="value">0</input>
        <output>index</output>
      </button>
      <separator height="1"/>
      <info label="Change the threshold to be above the environmental noise level, but below the trigger noise (you can try the audio scope experiment to check these)."/>
      <separator height="1"/>
      <info label="Unfortunately, this won't work on slow phones. Please compare to a regular clock first, to make sure, that the experiment is working as expected."/>
    </view>
    <view label="Sequence">
      <value label="Time 1" size="3" precision="3" unit="s">
        <input>t0</input>
      </value>
      <value label="Time 2" size="3" precision="3" unit="s">
        <input>t1</input>
      </value>
      <value label="Time 3" size="3" precision="3" unit="s">
        <input>t2</input>
      </value>
      <value label="Time 4" size="3" precision="3" unit="s">
        <input>t3</input>
      </value>
      <value label="Time 5" size="3" precision="3" unit="s">
        <input>t4</input>
      </value>
      <separator height="1"/>
      <button label="Reset">
        <input type="empty"/>
        <output>tlist</output>
        <input type="value">0</input>
        <output>index</output>
      </button>
    </view>
    <view label="Many">
      <graph label="Events" labelX="Event number" labelY="Time interval" unitY="s">
        <input axis="x">tindex</input>
        <input axis="y" style="vbars" lineWidth="0.9">tlistshow</input>
      </graph>
      <value label="Average interval" size="2" precision="3" unit="s">
        <input>avgInterval</input>
      </value>
      <value label="Average rate" size="2" precision="2" unit="Hz">
        <input>avgRate</input>
      </value>
      <value label="Average rate (bpm)" size="2" precision="1" unit="1/min">
        <input>avgBPM</input>
      </value>
      <button label="Reset">
        <input type="empty"/>
        <output>tlist</output>
        <input type="value">0</input>
        <output>index</output>
      </button>
    </view>
  </views>
  <analysis>
    <count>
      <input clear="false">recording</input>
      <output>count</output>
    </count>
    <max multiple="true">
      <input as="y">recording</input>
      <input clear="false" as="threshold">threshold</input>
      <output as="position">i</output>
    </max>
    <first>
        <input clear="false">i</input>
        <output>ifirst</output>
    </first>
    <append>
        <input>i</input>
        <output>ilast</output>
    </append>
    <add>
      <input>ifirst</input>
      <input clear="false">index</input>
      <output>i2first</output>
    </add>
    <add>
      <input>ilast</input>
      <input clear="false">index</input>
      <output>i2last</output>
    </add>
    <const>
        <input type="value" as="value">0</input>
        <input type="value" as="length">1</input>
        <output>tfirst</output>
    </const>
    <const>
        <input type="value" as="value">0</input>
        <input type="value" as="length">1</input>
        <output>tlast</output>
    </const>
    <divide>
      <input>i2first</input>
      <input clear="false">rate</input>
      <output clear="false">tfirst</output>
    </divide>
    <divide>
      <input>i2last</input>
      <input clear="false">rate</input>
      <output clear="false">tlast</output>
    </divide>

    <if equal="true">
        <input clear="false">currentfirst</input>
        <input type="value">0</input>
        <input clear="false">tfirst</input>
        <output clear="false">currentfirst</output>
    </if>

    <if greater="true">
        <input clear="false">tlast</input>
        <input type="value">0</input>
        <input clear="false">tlast</input>
        <output clear="false">currentlast</output>
    </if>

    <subtract>
        <input clear="false">currentlast</input>
        <input clear="false">currentfirst</input>
        <output>currentinterval</output>
    </subtract>

    <if greater="true">
        <input clear="false">tlast</input>
        <input type="value">0</input>
        <input type="value">0</input>
        <output clear="false">currentinterval</output>
    </if>

    <if greater="true">
        <input clear="false">currentinterval</input>
        <input type="value">0</input>
        <input clear="false">currentinterval</input>
        <output clear="false">tlist</output>
    </if>

    <if greater="true">
        <input clear="false">currentinterval</input>
        <input type="value">0</input>
        <input type="value">0</input>
        <output clear="false">currentfirst</output>
    </if>

    <if greater="true">
        <input clear="false">currentinterval</input>
        <input type="value">0</input>
        <input type="value">0</input>
        <output clear="false">currentlast</output>
    </if>

    <if greater="true">
        <input clear="false">currentinterval</input>
        <input type="value">0</input>
        <input type="value">0</input>
        <output clear="false">currentinterval</output>
    </if>

    <append>
      <input clear="false">tlist</input>
      <input type="value">0</input>
      <output clear="true">tlistshow</output>
    </append>

    <count>
      <input clear="false">tlistshow</input>
      <output>tcount</output>
    </count>
    <subtract>
      <input clear="false">tcount</input>
      <input type="value">1</input>
      <output>tcount-1</output>
    </subtract>
    <ramp>
      <input as="start" type="value">0</input>
      <input as="stop">tcount-1</input>
      <input as="length">tcount</input>
      <output>tindex</output>
    </ramp>

    <average>
      <input clear="false">tlist</input>
      <output>avgInterval</output>
    </average>
    <divide>
      <input type="value">1</input>
      <input clear="false">avgInterval</input>
      <output>avgRate</output>
    </divide>
    <multiply>
      <input clear="false">avgRate</input>
      <input type="value">60</input>
      <output>avgBPM</output>
    </multiply>

    <add>
      <input clear="false">index</input>
      <input>count</input>
      <output>index</output>
    </add>
    <divide>
      <input clear="false">index</input>
      <input clear="false">rate</input>
      <output>tmax</output>
    </divide>
    <const>
      <output>t0</output>
    </const>
    <const>
      <output>t1</output>
    </const>
    <const>
      <output>t2</output>
    </const>
    <const>
      <output>t3</output>
    </const>
    <const>
      <output>t4</output>
    </const>
    <const>
      <output>t5</output>
    </const>
    <subrange>
      <input as="from" type="value">0</input>
      <input as="length" type="value">1</input>
      <input as="in" clear="false">tlist</input>
      <output clear="false">t0</output>
    </subrange>
    <subrange>
      <input as="from" type="value">1</input>
      <input as="length" type="value">1</input>
      <input as="in" clear="false">tlist</input>
      <output clear="false">t1</output>
    </subrange>
    <subrange>
      <input as="from" type="value">2</input>
      <input as="length" type="value">1</input>
      <input as="in" clear="false">tlist</input>
      <output clear="false">t2</output>
    </subrange>
    <subrange>
      <input as="from" type="value">3</input>
      <input as="length" type="value">1</input>
      <input as="in" clear="false">tlist</input>
      <output clear="false">t3</output>
    </subrange>
    <subrange>
      <input as="from" type="value">4</input>
      <input as="length" type="value">1</input>
      <input as="in" clear="false">tlist</input>
      <output clear="false">t4</output>
    </subrange>
    <subrange>
      <input as="from" type="value">5</input>
      <input as="length" type="value">1</input>
      <input as="in" clear="false">tlist</input>
      <output clear="false">t5</output>
    </subrange>
    <if less="true" equal="true">
      <input clear="false">t5</input>
      <input type="value">0</input>
      <input clear="false">tmax</input>
      <input clear="false">t5</input>
      <output>t5effective</output>
    </if>
    <if less="true" equal="true">
      <input clear="false">t4</input>
      <input type="value">0</input>
      <input clear="false">tmax</input>
      <input clear="false">t4</input>
      <output>t4effective</output>
    </if>
    <if less="true" equal="true">
      <input clear="false">t3</input>
      <input type="value">0</input>
      <input clear="false">tmax</input>
      <input clear="false">t3</input>
      <output>t3effective</output>
    </if>
    <if less="true" equal="true">
      <input clear="false">t2</input>
      <input type="value">0</input>
      <input clear="false">tmax</input>
      <input clear="false">t2</input>
      <output>t2effective</output>
    </if>
    <if less="true" equal="true">
      <input clear="false">t1</input>
      <input type="value">0</input>
      <input clear="false">tmax</input>
      <input clear="false">t1</input>
      <output>t1effective</output>
    </if>
    <if less="true" equal="true">
      <input clear="false">t0</input>
      <input type="value">0</input>
      <input clear="false">tmax</input>
      <input clear="false">t0</input>
      <output>t0effective</output>
    </if>
  </analysis>
  <export>
    <set name="All">
      <data name="interval (s)">tlist</data>
    </set>
  </export>
</phyphox>
