开发者

What is the significance of the number 93 in Unicode?

Since there is currently no universal way to read live data from an audio track in JavaScript I'm using a small library/API to read volume data from a text file that I converted from an MP3 offline.

The string looks like this

!!!!!!!!!!!!!!!!!!!!!!!!!!###"~{~||ysvgfiw`gXg}i}|mbnTaac[Wb~v|xqsfSeYiV`R
][\Z^RdZ\XX`Ihb\O`3Z1W*I'D'H&J&J'O&M&O%O&I&M&S&R&R%U&W&T&V&m%\%n%[%Y%I&O'P'G
'L(V'X&I'F(O&a&h'[&W'P&C'](I&R&Y'\)\'Y'G(O'X'b'f&N&S&U'N&P&J'N)O'R)K'T开发者_Python百科(f|`|d
//etc...

and the idea is basically that at a given point in the song the Unicode number of the character at the corresponding point in the text file yields a nominal value to represent volume.

The library translates the data (in this case, a stereo track) with the following (simplified here):

getVolume = function(sampleIndex,o) {
    o.left = Math.min(1,(this.data.charCodeAt(sampleIndex*2|0)-33)/93);
    o.right = Math.min(1,(this.data.charCodeAt(sampleIndex*2+1|0)-33)/93);
    }

I'd like some insight into how the file was encoded in the first place, and how I'm making use of it here.

What is the significance of 93 and 33?

What is the purpose of the bitwise |?

Is this a common means of porting information (ie, does it have a name), or is there a better way to do it?


It looks like the range of the characters in that file are from ! to ~. ! has an ASCII code of 33 and ~ has an ASCII code of 126. 126-33 = 93.


33 and 93 are used for normalizing values beween ! and ~.

What is the significance of the number 93 in Unicode?

var data = '!';
Math.min(1,(data.charCodeAt(0*2)-33)/93); // will yield 0

 

var data = '~';
Math.min(1,(data.charCodeAt(0*2)-33)/93); // will yield 1

 

var data = '"';
Math.min(1,(data.charCodeAt(0*2)-33)/93); // will yield 0.010752688172043012

 

var data = '#';
Math.min(1,(data.charCodeAt(0*2)-33)/93); // will yield 0.021505376344086023

// ... and so on

The |0 is there due to the fact that sampleIndex*2 or sampleIndex*2+1 will yield a non-integer value when being passed a non-integer sampleIndex. |0 truncates the decimal part just in case someone sends in an incorrectly formatted sampleIndex (i.e. non-integer).


Doing a bitwise OR with zero will truncate the number on the LHS to a integer. Not sure about the rest of your question though, sorry.

93 and 33 are ASCII codes (not unicode) for the characters "]" and "!" respectively. Hope that helps a bit.


This will help you forever:

http://www.asciitable.com/

ASCIII codes for everything.

Enjoy!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜