How accurate will this be....
[ccode]
float CompressDwordToFloat(unsigned long);
unsigned long DecompressDwordFromFloat(float lfValue);
float CompressDwordToFloat(unsigned long dwValue) throw()
{
double lfTemp = (double)dwValue / 16777216;
return static_cast<float>(lfTemp);
}
unsigned long DecompressDwordFromFloat(float lfValue) throw()
{
double lfTemp = lfValue;
lfTemp *= 16777216;
unsigned long dwTemp = static_cast<unsigned long>(lfTemp);
if (lfTemp - (double)dwTemp > 0.5)
{
++dwTemp;
}
return dwTemp;
}
[/ccode]
Every value I test works. Are there any problems with this? Since every value I've tested 'decompressed' correctly, I don't see why it would have any troubles. I wish to cut a buffer 'in half' and then compress it normally with zlib or other compression method.
I have yet to right the decoder, but....
I did finish the encoder today (right now only uses this method), I will write the decoder to decode back to wav later today and see if the resultant wave is the same as the source.
Attaching the encoder to this post.
Lightweight - 48.0 KB (No MFC, :D Win32 API app) - just zipped the compiled *.exe. Would be smaller if I used the '#pragma comment(linker,"/OPT:NOWIN98")' trick to make the linker align on 512 byte boundaries. :D
As far as playing goes, I'll write a plugin for WinAmp. :D
(Advice: for small apps with no msvcrt.dll dependencies, write Win32 apps that don't use any CRT functions and have the linker use single threaded crt library. Only thing that will be linked in in _WinMainCRTStartup. :p Just remember not to call any CRT functions, especially in worker threads.)
Thanks.... But another (floating point) problem....
FORGET IT....
FAILED TO COMPUTE == FLOAT == 32 BITS and DOUBLE == 64 bits.
Man I'm tired, I thought sizeof(float) == 16 bits.
I swear I read:
float == 16 bits
single = 32 bits
double = 64 bits
But I guess now that VC++ doesn't have single, and float is mapped to 32bits? Might be because VC++ maps long double (80 bits) to double (64 bits). So you don't have the long double type.
:confused: To heck if I know.
Just try it:
assert(sizeof(long double) == 10); // exception will be thrown, long double maps to double - size == 8
(OFF TOPIC: I just love VC++ :rolleyes: Should've spent money on Codewarrior. Better yet, just move to Linux. :D )