Install Steam
login
|
language
简体中文 (Simplified Chinese)
繁體中文 (Traditional Chinese)
日本語 (Japanese)
한국어 (Korean)
ไทย (Thai)
Български (Bulgarian)
Čeština (Czech)
Dansk (Danish)
Deutsch (German)
Español - España (Spanish - Spain)
Español - Latinoamérica (Spanish - Latin America)
Ελληνικά (Greek)
Français (French)
Italiano (Italian)
Bahasa Indonesia (Indonesian)
Magyar (Hungarian)
Nederlands (Dutch)
Norsk (Norwegian)
Polski (Polish)
Português (Portuguese - Portugal)
Português - Brasil (Portuguese - Brazil)
Română (Romanian)
Русский (Russian)
Suomi (Finnish)
Svenska (Swedish)
Türkçe (Turkish)
Tiếng Việt (Vietnamese)
Українська (Ukrainian)
Report a translation problem
so let's say we have the values:
[1,9,5,3] (=> this represents the audio data)
but instead of 4 points, we want 7 points (that's the easiest example)
then it becomes:
[1, 5, 9, 7, 5, 4, 3] ( we just averaged the numbers in between the existing data set, to calculate the numbers in between )
Now, if you would like to create a data set from 64 to 65, you can just put in into a formula, where it would take something like where the second value would be between the first and second, at 64/65*100% value etc.
var newData = [];
var data = array;
// If the Smooth library is available, use it instead for better results
if (!!Smooth) {
var s = Smooth(data, { method: Smooth.METHOD_CUBIC, scaleTo: newLength });
for (var i = 0; i < newLength; i++) {
newData = s(i);
}
} else {
var linearInterpolate = function(before, after, atPoint) {
return before + (after - before) * atPoint;
};
var springFactor = Number((data.length - 1) / (newLength - 1));
// assign first value
newData[0] = data[0];
for (var i = 1; i < newLength - 1; i++) {
var tmp = i * springFactor;
var before = Number(Math.floor(tmp)).toFixed();
var after = Number(Math.ceil(tmp)).toFixed();
var atPoint = tmp - before;
newData = linearInterpolate(data[before], data[after], atPoint);
}
// assign last value
newData[newLength - 1] = data[data.length - 1];
}
// Return the new array
return newData;
}
This is how it's impemented in JavaScript in the Wallpaper :P The ''Smooth'' Library, will also take the difference between the numbers into account, and 'smooths' it out using the Qubic Quadratic method. ( the fallback would be like I described in my first post )
Thanks for the reply, have a good day