Page 1 of 1

Sound Meter

Posted: Sat Aug 10, 2019 10:45 am
by Ats
Hi, I'm trying to make a little sound meter in order to simplify the setup of the audio mixing in Omeganaut. But I don't know how or if I can get the volume of the sound currently playing... I tried to get values from Sound and AudioMixer without success.
Here's my test:

Code: Select all

<?xml version="1.0" encoding="iso-8859-1" ?>
<ZApplication Name="App" Caption="ZGameEditor application" FileVersion="2">
  <OnLoaded>
    <SpawnModel Model="AudioMeter" Position="0 -2 -1"/>
  </OnLoaded>
  <OnUpdate>
    <KeyPress Comment="left click" Keys="{">
      <OnPressed>
        <ZExpression Comment="play sound" Expression="@PlaySound(Sound:SoundVisor);"/>
      </OnPressed>
    </KeyPress>
  </OnUpdate>
  <Content>
    <Sound Name="SoundBounce" Length="0.2" Volume="1" BaseNoteNr="60" Osc1Waveform="2" UseOsc2="1" Osc2Waveform="1" Osc2Volume="0.1" UseFilter="1" FilterCutoff="0.2498" Mod0Active="1" Mod0Destination="13" Mod0Amount="1" Mod1Active="1" Mod1Destination="11" Mod1Amount="1" Env0Active="1" Env0AttackTime="0.16" Env0DecayTime="0.66" Env0SustainLevel="0.26" Env0ReleaseTime="4.66" Lfo0IsBipolar="1" Lfo0Speed="0.74"/>
    <Sound Name="SoundVisor" Volume="0.1784" BaseNoteNr="30" UseFilter="1" FilterCutoff="0.1299" FilterQ="0.2597" Mod0Active="1" Mod0Destination="11" Mod0Amount="1" Mod1Amount="0.4" Mod2Source="2" Mod2Destination="1" Mod2Amount="0.27" Mod3Destination="7" Mod3Amount="0.32" Env0Active="1" Env0AttackTime="2.4" Env0DecayTime="1.12" Env0SustainLevel="0.208" Env0ReleaseTime="1.32" PatternString=""/>
    <Mesh Name="VolumeBarMesh">
      <Producers>
        <MeshBox Scale="1 0.2 1" Grid2DOnly="255"/>
      </Producers>
    </Mesh>
    <Model Name="AudioMeter">
      <OnUpdate>
        <ZExpression Comment="Get audio volume?">
          <Expression>
<![CDATA[// http://www.zgameeditor.org/index.php/ComponentRef/Sound
// http://www.zgameeditor.org/index.php/ComponentRef/AudioMixer

VolumeMeterN.Count = floor(Mixer.MasterVolume * 10);]]>
          </Expression>
        </ZExpression>
      </OnUpdate>
      <OnRender>
        <Repeat Name="VolumeMeterN">
          <OnIteration>
            <ZExpression Comment="set volume meter">
              <Expression>
<![CDATA[VolumeBarTransform.Translate.Y = VolumeMeterN.Iteration * 0.5;
VolumeBarColor.Color.R = VolumeMeterN.Iteration * 0.1;
VolumeBarColor.Color.G = 1 - VolumeMeterN.Iteration * 0.1;]]>
              </Expression>
            </ZExpression>
            <RenderTransformGroup Name="VolumeBarTransform">
              <Children>
                <RenderSetColor Name="VolumeBarColor" Color="1 0 0 1"/>
                <RenderMesh Mesh="VolumeBarMesh"/>
              </Children>
            </RenderTransformGroup>
          </OnIteration>
        </Repeat>
      </OnRender>
    </Model>
    <AudioMixer Name="Mixer" Ch0Active="1" Ch0Volume="0.5" Ch0DelayLength="0.1" Ch1Active="1" Ch1Volume="0.5" Ch1DelayLength="0.1"/>
  </Content>
</ZApplication>

Re: Sound Meter

Posted: Sat Aug 10, 2019 11:29 am
by Kjell
Hi Ats,

I'm afraid this is not possible ( out of the box ). The easiest workaround would probably be to wrap the IAudioMeterInformation interface in a DLL so you can call GetPeakValue from ZGE.

By the way, the MasterVolume property simply controls the overall volume of all audio in your project, it doesn't give you the peak levels used for volume meters.

K

Re: Sound Meter

Posted: Sat Aug 10, 2019 5:55 pm
by Ats
Thanks Kjell, but it's a bit complicated for me... Then I'll use an external VU meter program that is able to catch ZGE sounds, if possible.