mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 03:44:02 +02:00
added slider for local audio attenuation
This commit is contained in:
parent
bdf39186de
commit
67de87d114
3 changed files with 80 additions and 3 deletions
|
@ -14,6 +14,7 @@ var delayScale = 100.0;
|
|||
var fanoutScale = 10.0;
|
||||
var speedScale = 20;
|
||||
var factorScale = 5.0;
|
||||
var localFactorScale = 1.0;
|
||||
var reflectiveScale = 100.0;
|
||||
var diffusionScale = 100.0;
|
||||
var absorptionScale = 100.0;
|
||||
|
@ -223,6 +224,45 @@ var factorThumb = Overlays.addOverlay("image", {
|
|||
alpha: 1
|
||||
});
|
||||
|
||||
var localFactorY = topY;
|
||||
topY += sliderHeight;
|
||||
|
||||
var localFactorLabel = Overlays.addOverlay("text", {
|
||||
x: 40,
|
||||
y: localFactorY,
|
||||
width: 60,
|
||||
height: sliderHeight,
|
||||
color: { red: 0, green: 0, blue: 0},
|
||||
textColor: { red: 255, green: 255, blue: 255},
|
||||
topMargin: 6,
|
||||
leftMargin: 5,
|
||||
text: "Local\nFactor:"
|
||||
});
|
||||
|
||||
|
||||
var localFactorSlider = Overlays.addOverlay("image", {
|
||||
// alternate form of expressing bounds
|
||||
bounds: { x: 100, y: localFactorY, width: 150, height: sliderHeight},
|
||||
subImage: { x: 46, y: 0, width: 200, height: 71 },
|
||||
imageURL: "https://s3-us-west-1.amazonaws.com/highfidelity-public/images/slider.png",
|
||||
color: { red: 255, green: 255, blue: 255},
|
||||
alpha: 1
|
||||
});
|
||||
|
||||
|
||||
var localFactorMinThumbX = 110;
|
||||
var localFactorMaxThumbX = localFactorMinThumbX + 110;
|
||||
var localFactorThumbX = localFactorMinThumbX + ((localFactorMaxThumbX - localFactorMinThumbX) * (AudioReflector.getLocalAudioAttenuationFactor() / localFactorScale));
|
||||
var localFactorThumb = Overlays.addOverlay("image", {
|
||||
x: localFactorThumbX,
|
||||
y: localFactorY+9,
|
||||
width: 18,
|
||||
height: 17,
|
||||
imageURL: "https://s3-us-west-1.amazonaws.com/highfidelity-public/images/thumb.png",
|
||||
color: { red: 0, green: 128, blue: 128},
|
||||
alpha: 1
|
||||
});
|
||||
|
||||
var reflectiveY = topY;
|
||||
topY += sliderHeight;
|
||||
|
||||
|
@ -347,6 +387,10 @@ function scriptEnding() {
|
|||
Overlays.deleteOverlay(factorThumb);
|
||||
Overlays.deleteOverlay(factorSlider);
|
||||
|
||||
Overlays.deleteOverlay(localFactorLabel);
|
||||
Overlays.deleteOverlay(localFactorThumb);
|
||||
Overlays.deleteOverlay(localFactorSlider);
|
||||
|
||||
Overlays.deleteOverlay(speedLabel);
|
||||
Overlays.deleteOverlay(speedThumb);
|
||||
Overlays.deleteOverlay(speedSlider);
|
||||
|
@ -389,6 +433,7 @@ var movingSliderDelay = false;
|
|||
var movingSliderFanout = false;
|
||||
var movingSliderSpeed = false;
|
||||
var movingSliderFactor = false;
|
||||
var movingSliderLocalFactor = false;
|
||||
var movingSliderReflective = false;
|
||||
var movingSliderDiffusion = false;
|
||||
var movingSliderAbsorption = false;
|
||||
|
@ -444,6 +489,19 @@ function mouseMoveEvent(event) {
|
|||
AudioReflector.setDistanceAttenuationScalingFactor(factor);
|
||||
}
|
||||
|
||||
if (movingSliderLocalFactor) {
|
||||
newThumbX = event.x - thumbClickOffsetX;
|
||||
if (newThumbX < localFactorMinThumbX) {
|
||||
newThumbX = localFactorMminThumbX;
|
||||
}
|
||||
if (newThumbX > localFactorMaxThumbX) {
|
||||
newThumbX = localFactorMaxThumbX;
|
||||
}
|
||||
Overlays.editOverlay(localFactorThumb, { x: newThumbX } );
|
||||
var localFactor = ((newThumbX - localFactorMinThumbX) / (localFactorMaxThumbX - localFactorMinThumbX)) * localFactorScale;
|
||||
AudioReflector.setLocalAudioAttenuationFactor(localFactor);
|
||||
}
|
||||
|
||||
if (movingSliderAbsorption) {
|
||||
newThumbX = event.x - thumbClickOffsetX;
|
||||
if (newThumbX < absorptionMinThumbX) {
|
||||
|
@ -504,6 +562,10 @@ function mousePressEvent(event) {
|
|||
movingSliderFactor = true;
|
||||
thumbClickOffsetX = event.x - factorThumbX;
|
||||
}
|
||||
if (clickedOverlay == localFactorThumb) {
|
||||
movingSliderLocalFactor = true;
|
||||
thumbClickOffsetX = event.x - localFactorThumbX;
|
||||
}
|
||||
if (clickedOverlay == diffusionThumb) {
|
||||
movingSliderDiffusion = true;
|
||||
thumbClickOffsetX = event.x - diffusionThumbX;
|
||||
|
@ -543,6 +605,13 @@ function mouseReleaseEvent(event) {
|
|||
factorThumbX = newThumbX;
|
||||
}
|
||||
|
||||
if (movingSliderLocalFactor) {
|
||||
movingSliderLocalFactor = false;
|
||||
var localFactor = ((newThumbX - localFactorMinThumbX) / (localFactorMaxThumbX - localFactorMinThumbX)) * localFactorScale;
|
||||
AudioReflector.setLocalAudioAttenuationFactor(localFactor);
|
||||
localFactorThumbX = newThumbX;
|
||||
}
|
||||
|
||||
if (movingSliderReflective) {
|
||||
movingSliderReflective = false;
|
||||
var reflective = ((newThumbX - reflectiveMinThumbX) / (reflectiveMaxThumbX - reflectiveMinThumbX)) * reflectiveScale;
|
||||
|
|
|
@ -18,6 +18,7 @@ const float DEFAULT_DISTANCE_SCALING_FACTOR = 2.0f;
|
|||
const float MAXIMUM_DELAY_MS = 1000.0 * 20.0f; // stop reflecting after path is this long
|
||||
const int DEFAULT_DIFFUSION_FANOUT = 5;
|
||||
const int ABSOLUTE_MAXIMUM_BOUNCE_COUNT = 10;
|
||||
const float DEFAULT_LOCAL_ATTENUATION_FACTOR = 0.125;
|
||||
|
||||
const float SLIGHTLY_SHORT = 0.999f; // slightly inside the distance so we're on the inside of the reflection point
|
||||
|
||||
|
@ -29,6 +30,7 @@ AudioReflector::AudioReflector(QObject* parent) :
|
|||
_preDelay(DEFAULT_PRE_DELAY),
|
||||
_soundMsPerMeter(DEFAULT_MS_DELAY_PER_METER),
|
||||
_distanceAttenuationScalingFactor(DEFAULT_DISTANCE_SCALING_FACTOR),
|
||||
_localAudioAttenuationFactor(DEFAULT_LOCAL_ATTENUATION_FACTOR),
|
||||
_diffusionFanout(DEFAULT_DIFFUSION_FANOUT),
|
||||
_absorptionRatio(DEFAULT_ABSORPTION_RATIO),
|
||||
_diffusionRatio(DEFAULT_DIFFUSION_RATIO),
|
||||
|
@ -36,6 +38,7 @@ AudioReflector::AudioReflector(QObject* parent) :
|
|||
_lastPreDelay(DEFAULT_PRE_DELAY),
|
||||
_lastSoundMsPerMeter(DEFAULT_MS_DELAY_PER_METER),
|
||||
_lastDistanceAttenuationScalingFactor(DEFAULT_DISTANCE_SCALING_FACTOR),
|
||||
_lastLocalAudioAttenuationFactor(DEFAULT_LOCAL_ATTENUATION_FACTOR),
|
||||
_lastDiffusionFanout(DEFAULT_DIFFUSION_FANOUT),
|
||||
_lastAbsorptionRatio(DEFAULT_ABSORPTION_RATIO),
|
||||
_lastDiffusionRatio(DEFAULT_DIFFUSION_RATIO)
|
||||
|
@ -237,10 +240,9 @@ void AudioReflector::processLocalAudio(unsigned int sampleTime, const QByteArray
|
|||
int numberOfSamples = samples.size() / sizeof(int16_t);
|
||||
int16_t* monoSamples = (int16_t*)samples.data();
|
||||
int16_t* stereoSamples = (int16_t*)stereoInputData.data();
|
||||
const float LOCAL_SIGNAL_ATTENUATION = 0.125f;
|
||||
for (int i = 0; i < numberOfSamples; i++) {
|
||||
stereoSamples[i* NUM_CHANNELS_OUTPUT] = monoSamples[i] * LOCAL_SIGNAL_ATTENUATION;
|
||||
stereoSamples[(i * NUM_CHANNELS_OUTPUT) + 1] = monoSamples[i] * LOCAL_SIGNAL_ATTENUATION;
|
||||
stereoSamples[i* NUM_CHANNELS_OUTPUT] = monoSamples[i] * _localAudioAttenuationFactor;
|
||||
stereoSamples[(i * NUM_CHANNELS_OUTPUT) + 1] = monoSamples[i] * _localAudioAttenuationFactor;
|
||||
}
|
||||
echoAudio(sampleTime, stereoInputData, outputFormat);
|
||||
}
|
||||
|
|
|
@ -93,6 +93,10 @@ public slots:
|
|||
float getDistanceAttenuationScalingFactor() const { return _distanceAttenuationScalingFactor; }
|
||||
void setDistanceAttenuationScalingFactor(float factor) { _distanceAttenuationScalingFactor = factor; }
|
||||
|
||||
/// scales attenuation of local audio to be louder or softer than the default attenuation
|
||||
float getLocalAudioAttenuationFactor() const { return _localAudioAttenuationFactor; }
|
||||
void setLocalAudioAttenuationFactor(float factor) { _localAudioAttenuationFactor = factor; }
|
||||
|
||||
/// number of points of diffusion from each reflection point, as fanout increases there are more chances for secondary
|
||||
/// echoes, but each diffusion ray is quieter and therefore more likely to be below the sound floor
|
||||
int getDiffusionFanout() const { return _diffusionFanout; }
|
||||
|
@ -171,6 +175,7 @@ private:
|
|||
float _preDelay;
|
||||
float _soundMsPerMeter;
|
||||
float _distanceAttenuationScalingFactor;
|
||||
float _localAudioAttenuationFactor;
|
||||
|
||||
int _diffusionFanout; // number of points of diffusion from each reflection point
|
||||
|
||||
|
@ -186,6 +191,7 @@ private:
|
|||
float _lastPreDelay;
|
||||
float _lastSoundMsPerMeter;
|
||||
float _lastDistanceAttenuationScalingFactor;
|
||||
float _lastLocalAudioAttenuationFactor;
|
||||
int _lastDiffusionFanout;
|
||||
float _lastAbsorptionRatio;
|
||||
float _lastDiffusionRatio;
|
||||
|
|
Loading…
Reference in a new issue