Dynamic sound
Moderator: Moderators
Dynamic sound
Is there some (maybe good and recommended) way how to continuously change properties of a played sound? For example, how to achieve playing of a sound (e.g. a simple sine) of which frequency, and possibly also other parameters, depend on position or velocity of a moving model? My case is that there are several different models and each of them needs to play such a sound. Any advice is appreciated.
Hi Rado1,
Try the following approach
K
Try the following approach

Code: Select all
<?xml version="1.0" encoding="iso-8859-1" ?>
<ZApplication Name="App" Caption="ZGameEditor application" CameraPosition="0 0 32">
<OnLoaded>
<Repeat Count="2" WhileExp="//">
<OnIteration>
<SpawnModel Model="Sprite"/>
</OnIteration>
</Repeat>
</OnLoaded>
<Content>
<Model Name="Sprite">
<Definitions>
<Sound Name="SpriteSound" Length="1000" BaseNoteNr="58.9199" Osc1PW="0.75" Pan="0.32"/>
</Definitions>
<OnRender>
<RenderSprite/>
</OnRender>
<OnUpdate>
<ZExpression>
<Expression>
<![CDATA[float velocity = clamp(sin((Sprite.Personality + 0.5) * App.Time), 0.0, 1.0);
Sprite.Rotation.Z += velocity * App.DeltaTime;
float angle = Sprite.Rotation.Z * PI * 2.0;
Sprite.Position.X = cos(angle) * 8.0;
Sprite.Position.Y = sin(angle) * 8.0;
SpriteSound.Pan = Sprite.Position.X / 24.0 + 0.5;
SpriteSound.BaseNoteNr = velocity * 60.0;
SpriteSound.Volume = clamp(velocity, 0.0, 0.5);]]>
</Expression>
</ZExpression>
<PlaySound Sound="SpriteSound" ByReference="255"/>
</OnUpdate>
</Model>
</Content>
</ZApplication>