Setting Javascript objects to use Int8 and Int16

352 Views Asked by At

I've got a very large datastructure, part of which shown below.

var Data =
    {
        MIDISource          : {id: 0, val: 1, harm: 0},         

        MIDIChannel         : {id: 1, val: 1, harm: 1},         
        MIDISplit           : {id: 2, val: 0, harm: 1},
        MultiTouch          : {id: 3, val: 1, harm: 1},
        TouchFreq           : {id: 4, val: 0, harm: 1},
        TouchLevel          : {id: 5, val: 0, harm: 1},
        TouchAttack         : {id: 6, val: 0, harm: 1},
        PitchWheelSens      : {id: 7, val: 0, harm: 1},
        ModWheelTarg        : {id: 8, val: 0, harm: 1},
        ModWheelSens        : {id: 9, val: 0, harm: 1},

        Fundamental         : {id: 21, val: 1, harm: 2},
        EvenHarmonics       : {id: 22, val: 1, harm: 2},
        
       // etc for about 5000 more datapoints


    };

All datapoints are accessed as for example

Data.EvenHarmonics[harm].val

id can be any value from 0 to 127, as can harm, both being fixed for each datapoint. Val can be any value from 0 to 2047. At present I assume each id, harm and val are stored however normal Javascript variables are stored, and it runs fine.

However I also have some large arrays of audio data and found changing these to use Float32 definitely speeded things up, for example

const _SineTableMax = 2047;
var SineLevels = new Float32Array(128 * (_SineTableMax + 1));

I thus wondered if I could store each point of Data in a single 32 bit location, id and harm as Int8 and val as Int16. But I can't see an obvious way of mapping Data in this manner.

Any suggestions ?

0

There are 0 best solutions below