Glider vario: Add nasal controller for sound pitch
Adds a sound frequency controller to glider-instrumentation-sdk.nas, used for the ilec-sc7. This allows: - Simpler <sound>.xml files to integrate the glider variometer. - More accurate frequency scaling (frequency scales exponentially with vertical speed, so that perceived changes in pitch are linear with vertical speed). - Fixes that the variometer sound would not drop at negative vertical speeds.
This commit is contained in:
parent
741fc5c43b
commit
59b9aeb271
3 changed files with 89 additions and 55 deletions
|
@ -409,3 +409,34 @@ var SpeedCmdVario = {
|
||||||
if (me.on_update != nil) me.on_update(me.output);
|
if (me.on_update != nil) me.on_update(me.output);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
# Vario sound pitch controller
|
||||||
|
# Computes the frequency factor for a variometer sound.
|
||||||
|
#
|
||||||
|
# var vario_sound = SoundPitchController.new(
|
||||||
|
# input: Object connected to the pitch controller input, e.g. a variometer reading.
|
||||||
|
# max_pitch: (optional) Maximum sound frequency factor, the output will be
|
||||||
|
# in the range [1/max_pitch, max_pitch], default 2.
|
||||||
|
# max_input: Value of input for which max_pitch is reached.
|
||||||
|
# on_update: (optional) function to call whenever a new output is available
|
||||||
|
|
||||||
|
var SoundPitchController = {
|
||||||
|
parents: [InstrumentComponent],
|
||||||
|
|
||||||
|
new: func(input, max_input, max_pitch = 2, on_update = nil) {
|
||||||
|
return {
|
||||||
|
parents: [me],
|
||||||
|
input: input,
|
||||||
|
max_pitch: max_pitch,
|
||||||
|
max_input: max_input,
|
||||||
|
on_update: on_update,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
|
update: func {
|
||||||
|
var input = math.clamp(me.input.output, -me.max_input, me.max_input);
|
||||||
|
me.output = math.pow(me.max_pitch, input / me.max_input);
|
||||||
|
|
||||||
|
if (me.on_update != nil) me.on_update(me.output);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
|
@ -7,60 +7,57 @@ You will need to :
|
||||||
* modify your sound.xml, including the following lines :
|
* modify your sound.xml, including the following lines :
|
||||||
|
|
||||||
<variometer-up>
|
<variometer-up>
|
||||||
<name>variometer-up</name>
|
<name>variometer-up</name>
|
||||||
<mode>looped</mode>
|
<mode>looped</mode>
|
||||||
<path>Instruments-3d/glider/vario/ilec-sc7/vario.wav</path>
|
<path>Instruments-3d/glider/vario/ilec-sc7/vario.wav</path>
|
||||||
<condition>
|
<condition>
|
||||||
<and>
|
|
||||||
<greater-than>
|
|
||||||
<property>instrumentation/ilec-sc7/audio</property>
|
|
||||||
<value>0</value>
|
|
||||||
</greater-than>
|
|
||||||
<greater-than>
|
|
||||||
<property>instrumentation/ilec-sc7/te-reading-mps</property>
|
|
||||||
<value>0.01</value>
|
|
||||||
</greater-than>
|
|
||||||
</and>
|
|
||||||
</condition>
|
|
||||||
<pitch>
|
|
||||||
<property>instrumentation/ilec-sc7/te-reading-mps</property>
|
|
||||||
<factor>0.246</factor>
|
|
||||||
<offset>1.0</offset>
|
|
||||||
</pitch>
|
|
||||||
<volume>
|
|
||||||
<property>instrumentation/ilec-sc7/volume</property>
|
|
||||||
<max>1</max>
|
|
||||||
</volume>
|
|
||||||
</variometer-up>
|
|
||||||
|
|
||||||
<variometer-down>
|
|
||||||
<name>variometer-down</name>
|
|
||||||
<mode>looped</mode>
|
|
||||||
<path>Instruments-3d/glider/vario/ilec-sc7/vario2.wav</path>
|
|
||||||
<condition>
|
|
||||||
<and>
|
<and>
|
||||||
<equals>
|
<greater-than>
|
||||||
<property>instrumentation/ilec-sc7/audio</property>
|
<property>instrumentation/ilec-sc7/audio</property>
|
||||||
<value>2</value>
|
<value>0</value>
|
||||||
</equals>
|
</greater-than>
|
||||||
<greater-than>
|
<greater-than>
|
||||||
<property>instrumentation/ilec-sc7/te-reading-mps</property>
|
<property>instrumentation/ilec-sc7/te-reading-mps</property>
|
||||||
<value>-10.66</value>
|
<value>0.01</value>
|
||||||
</greater-than>
|
</greater-than>
|
||||||
<less-than>
|
|
||||||
<property>instrumentation/ilec-sc7/te-reading-mps</property>
|
|
||||||
<value>-0.01</value>
|
|
||||||
</less-than>
|
|
||||||
</and>
|
</and>
|
||||||
</condition>
|
</condition>
|
||||||
<pitch>
|
<pitch>
|
||||||
<property>instrumentation/ilec-sc7/te-reading-neg</property>
|
<property>/instrumentation/ilec-sc7/sound-pitch</property>
|
||||||
<factor>-0.05</factor>
|
<offset>0</offset><!-- Do not remove, default is 1 -->
|
||||||
<offset>1.0</offset>
|
</pitch>
|
||||||
</pitch>
|
<volume>
|
||||||
<volume>
|
<property>instrumentation/ilec-sc7/volume</property>
|
||||||
<property>instrumentation/ilec-sc7/volume</property>
|
<max>1</max>
|
||||||
<max>1</max>
|
</volume>
|
||||||
</volume>
|
</variometer-up>
|
||||||
|
|
||||||
|
<variometer-down>
|
||||||
|
<name>variometer-down</name>
|
||||||
|
<mode>looped</mode>
|
||||||
|
<path>Instruments-3d/glider/vario/ilec-sc7/vario2.wav</path>
|
||||||
|
<condition>
|
||||||
|
<and>
|
||||||
|
<equals>
|
||||||
|
<property>instrumentation/ilec-sc7/audio</property>
|
||||||
|
<value>2</value>
|
||||||
|
</equals>
|
||||||
|
<greater-than>
|
||||||
|
<property>instrumentation/ilec-sc7/te-reading-mps</property>
|
||||||
|
<value>-10.66</value>
|
||||||
|
</greater-than>
|
||||||
|
<less-than>
|
||||||
|
<property>instrumentation/ilec-sc7/te-reading-mps</property>
|
||||||
|
<value>-0.01</value>
|
||||||
|
</less-than>
|
||||||
|
</and>
|
||||||
|
</condition>
|
||||||
|
<pitch>
|
||||||
|
<property>/instrumentation/ilec-sc7/sound-pitch</property>
|
||||||
|
<offset>0</offset><!-- Do not remove, default is 1 -->
|
||||||
|
</pitch>
|
||||||
|
<volume>
|
||||||
|
<property>instrumentation/ilec-sc7/volume</property>
|
||||||
|
<max>1</max>
|
||||||
|
</volume>
|
||||||
</variometer-down>
|
</variometer-down>
|
||||||
|
|
|
@ -9,6 +9,7 @@ setprop("/instrumentation/ilec-sc7/lcd-digits-abs", 0);
|
||||||
setprop("/instrumentation/ilec-sc7/lcd-digits-sgn", 0);
|
setprop("/instrumentation/ilec-sc7/lcd-digits-sgn", 0);
|
||||||
setprop("/instrumentation/ilec-sc7/te-reading-mps", 0);
|
setprop("/instrumentation/ilec-sc7/te-reading-mps", 0);
|
||||||
setprop("/instrumentation/variometer/te-reading-mps", 0);
|
setprop("/instrumentation/variometer/te-reading-mps", 0);
|
||||||
|
setprop("/instrumentation/ilec-sc7/sound-pitch", 1);
|
||||||
|
|
||||||
# Helper function for updating lcd display
|
# Helper function for updating lcd display
|
||||||
var update_lcd_props = func(value) {
|
var update_lcd_props = func(value) {
|
||||||
|
@ -34,6 +35,11 @@ var sc7_needle = Dampener.new(
|
||||||
dampening: 3,
|
dampening: 3,
|
||||||
on_update: update_prop("/instrumentation/ilec-sc7/te-reading-mps"));
|
on_update: update_prop("/instrumentation/ilec-sc7/te-reading-mps"));
|
||||||
|
|
||||||
|
var sc7_sound = SoundPitchController.new(
|
||||||
|
input: sc7_needle,
|
||||||
|
max_input: 5,
|
||||||
|
on_update: update_prop("/instrumentation/ilec-sc7/sound-pitch"));
|
||||||
|
|
||||||
var extra_needle = Dampener.new(
|
var extra_needle = Dampener.new(
|
||||||
input: probe,
|
input: probe,
|
||||||
dampening: 2.7,
|
dampening: 2.7,
|
||||||
|
@ -66,7 +72,7 @@ setlistener("instrumentation/ilec-sc7/sensitivity",
|
||||||
# Wrap everything together into an instrument
|
# Wrap everything together into an instrument
|
||||||
var fast_instruments = UpdateLoop.new(
|
var fast_instruments = UpdateLoop.new(
|
||||||
update_period: 0,
|
update_period: 0,
|
||||||
components: [probe, sc7_needle, extra_needle],
|
components: [probe, sc7_needle, sc7_sound, extra_needle],
|
||||||
enable: 1);
|
enable: 1);
|
||||||
|
|
||||||
var slow_instruments = UpdateLoop.new(
|
var slow_instruments = UpdateLoop.new(
|
||||||
|
|
Loading…
Add table
Reference in a new issue