Loudness

From Unify Community Wiki
(Difference between revisions)
Jump to: navigation, search
(Description)
(JavaScript - Loop.js)
Line 16: Line 16:
 
}
 
}
 
</javascript>
 
</javascript>
 +
 +
== C# - Loop.cs ==
 +
<csharp>
 +
using UnityEngine;
 +
using System.Collections;
 +
 +
public class Loudness : MonoBehaviour {
 +
public float loudness = 1;
 +
 +
private float oneNinth;
 +
 +
void Start() {
 +
oneNinth = (float) (1.0 / 9.0);
 +
}
 +
 +
void Update () {
 +
audio.volume = oneNinth * (Mathf.Pow(10, loudness) - 1);
 +
}
 +
}
 +
}
 +
</csharp>

Revision as of 19:20, 12 September 2008

Description

Unity's standard volume control uses a "linear taper", and humans hear on an exponential scale. "Loudness", unlike the Audio Source's "Volume", will yield perceptually equivalent loudness changes for equivalent value changes. (Changing the Loudness from 0.2 to 0.3 will yield a similar difference in loudness between 0.7 to 0.8, etc.)

JavaScript - Loop.js

<javascript> static var loudness : float = 1; private var oneNinth : float;

function Start() { oneNinth = 1.0 / 9.0; }

function Update () { audio.volume = oneNinth * (Mathf.Pow(10, loudness) - 1); } </javascript>

C# - Loop.cs

<csharp> using UnityEngine; using System.Collections;

public class Loudness : MonoBehaviour { public float loudness = 1;

private float oneNinth;

void Start() { oneNinth = (float) (1.0 / 9.0); }

void Update () { audio.volume = oneNinth * (Mathf.Pow(10, loudness) - 1); } } } </csharp>

Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox