5.23 to linear
Hi,
Could any help me with a function to convert 5.23 to Linear.
Ive got linear to 5.23 as per the help file OK. But having a bit of fun the other way.
Thanks
Brett
Do you just want to convert the integer part of your 5.23 number into a linear (28.0 format) number? If so, then you just have to do the inverse of what you do to go from 28.0 to 5.23. You multiply your value in 5.23 format by 2^-23 to shift the integer value down to the lsb of your 28.0 number. Does this help with what you're trying to do?
Hi.
I wanted to convert the entire number
I ended up with this
float From523(unsigned char* param_hex)
{
float ans;
unsigned long param227;
param227 = param_hex[0] ;
param227 = param227<<8;
param227 = param227 | param_hex[1] ;
param227 = param227<<8;
param227 = param227 | param_hex[2] ;
param227 = param227<<8;
param227 = param227 | param_hex[3] ;
param227 = param227 ^ 134217728; // invert the sign
param227 = param227 - 134217728;
ans = (float)param227/8388608;
return ans;
}
I am sure theres better ways to do this. But it worked for me
Do you mean converting the hex number stored in RAM to the linear decimal value referenced to full-scale audio?
I'm not sure about doing the calculations in a microcontroller, but if you think of the value in RAM as an integer, you can do it this way (at least on paper):
First of all, you know from the SigmaStudio documentation on number formats that a linear decimal value of 1.0 (or the peak of a 0 dBFS audio signal) is represented as 0000 1000 0000 0000 0000 0000 0000, or 0x0 0x80 0x00 0x00. Converting the hex to integer, we get 0800000h = 8388606. In other words, full scale in integer is 8388606.
So, to calculate any other value in linear (decimal), just convert from hex to integer and divide by 8388606.
Say for example we had 0x00 0x40 0x00 0x00, which is 0.5 in linear (decimal).
0400000h = 4194304 / 8388606 = 0.5.
Anyways, that's how it works on paper. My microcontroller programming skills are a little rusty so you might want to go about this a different way in your implementation.
Message was edited by: BrettG 101029 - Changed the naming conventions of linear, decimal, integer to avoid confusion.
yes Thats Correct
Just a crude way to implement in a Micro and to include the Sign So its -0.5
Please log in to reply.