Welcome to %s forums

BrainModular Users Forum

Login Register

32/24 bits

I need help on a Patch
Post Reply
23fx23
Member
Posts: 2545
Contact:

Unread post by 23fx23 » 06 Jun 2010, 10:55

I try to pack some midi data to some 32bit number, for then to unpack to reduce my array size by 4.(but maybe useless?)

so I take ch+(msg*$100)+(code1*$10000)+(code2*$1000000) on input that goes to a script that use
shr,shr8,shr16,shr24 and that seems to work, but if the last byte(code2) is more than 0, the decoded channel (first byte)mess.
I suppose it's something linked to the fact that then the 16777216 wich multiply the 4rd byte is the Max possible integer?

Is there something special to do, or is it that general datas/tparameter are maxed to 24bits cause of the mantissa thing once
spoke about?
i manage to pack/unpack 24bits but not 32, is it possible?
here is the script:
var midi_32bits : Tparameter;
var ch,msg,code1,code2 : Tparameter;
// initialisation : create parameters
procedure init;
begin
midi_32bits := CreateParam('midi_32bits',ptDataField);setMax(midi_32bits,$100000000);
Ch := CreateParam('Ch',ptDataField);
Msg := CreateParam('msg',ptDataField);
code1 := CreateParam('code1',ptDataField);
code2 := CreateParam('code2',ptDataField);
SetIsOutPut(midi_32bits,false);
SetIsinPut(Ch,false);
SetIsInPut(Msg,false);
SetIsInPut(Code1,false);
SetIsInPut(Code2,false);
end;

procedure Callback(n:integer);
begin
if (n=midi_32bits) then DECODE_MIDI;
end;

// no process bloc
/////////////////////////////////////////////////
Procedure Decode_Midi;
var valout: dword;
BEGIN
valout:= round(getvalue(midi_32bits));
setvalue(CH, GetChValue(valout));
setvalue(MSG, GetMSGValue(valout));
setvalue(Code1, GetCode1Value(valout));
setvalue(Code2, GetCode2Value(valout));
END;
///////////////////////////////////////
function GetCHValue(midi: DWORD): Byte;
begin
Result := Byte(midi);
end;
///////////////////////////////////////
function GetMSGValue(midi: DWORD): Byte;
begin
Result := Byte(midi shr 8);
end;
///////////////////////////////////////
function GetCode1Value(midi: DWORD): Byte;
begin
Result := Byte(midi shr 16);
end;
////////////////////////////////////
function GetCode2Value(midi: DWORD): Byte;
begin
Result := Byte(midi shr 24);
end;
////////////////////////////////////]

23fx23
Member
Posts: 2545
Contact:

Unread post by 23fx23 » 06 Jun 2010, 16:00

mmmm ok that's all maybe too complex for me.

if i well understood usine, and generally all softs use float32 wich is not 4x8bits but
1 bit sig+ 7 bits exponment + 23 bits Significand +1 bit always1, wich mean max in precision is 24bit integer?
in fact 23bits ;)
that may explain the 16777216 limit mm., I guess that's why Midi is seen as float, whereas colors are integers?
ouch
the conversion i was after seems more complex than i thought hehe.
isn't there a code that converts a float32 to an fixed32 and vice/versa?

or how could we extract the 4 midi mess from the float we see on midi wires, then repack those 4 values as float32 again?

im after this because it could make an easy way to store / reacall midi messages.

actually I have a 3D array storing the 4 midi messages, for 4 values (X,Y,and Zon Zoff) values, wich multiplied by the nb of cellz start to make a consequent sized array, it could be theorically reduced by 4 if im not wrong?
but maybe as usual im searching way too complex hehe
anyway, just for learning..

any clues masterZ

edit need to apply that formula i guess?
http://en.wikipedia.org/wiki/Single_precision

bsork
Site Admin
Posts: 1334
Location: Asker, Norway
Contact:

Unread post by bsork » 07 Jun 2010, 08:12

Can't go into all the details here (not sure if I understand what you mean everywhere, either), but you don't gain much by manipulating 32 bit floats to or from the 4 Byte tMidi record. If the separate parts of tMidi is stored as four different elements in eg the Array module, you of course use four times the space, but that shouldn't worry anyone unless you're creating lots of large arrays. Even then, you'd probably not end using more space than your average two-bar loop... Within a script, there's no RAM to be gained, only CPU to spend.
Bjørn S

23fx23
Member
Posts: 2545
Contact:

Unread post by 23fx23 » 07 Jun 2010, 19:29

I guess i got no gain in the script internally, but as i need to make the array goes out of the script to be saved by a preset, then back in, I end up now with an array of 8192 lenght, (512cellz * 4(XYZonZoff) * 4(ch msg code1 code 2)).

but as you point its descent regarding audio, and what I could gain in space would propably be lost by the cpu increase of pack/unpacking .. so Ill stop to bother with such brainy things... works nice with normal system.

Post Reply

Who is online

Users browsing this forum: No registered users and 33 guests