ZenHAX
http://zenhax.com/

xmath result as float
http://zenhax.com/viewtopic.php?f=11&t=3763
Page 1 of 1

Author:  StreamThread [ Sat Feb 04, 2017 10:34 am ]
Post subject:  xmath result as float

Hello

How with xmath can get result as float?

E.g. my code:
Code:
xmath sndTime "1.0f * subchunk2Size / (bitsPerSample / 8.0f) / numChannels / sampleRate"

xmath sndTime "sndTime - 0.100f"


Vars:
Subchunk2Size 860160

BitsPerSample / 8.0 = 2

NumChannels 1

SampleRate 44100

Result must be ~= 9,752 but xmath return rounded value "9". It's wrong for next calculations with this result.

Is it possible to set a type of "sndTime" var as float?

Author:  aluigi [ Sat Feb 04, 2017 12:11 pm ]
Post subject:  Re: xmath result as float

quickbms works only with integers.

Author:  StreamThread [ Sat Feb 04, 2017 3:04 pm ]
Post subject:  Re: xmath result as float

Maybe possible add support of float values in the next Quick BMS update? For example, it will works only if Quick BMS starting with certain option.
That could be good innovation. I find Quick bms as the perfect tool for more different things.

Author:  aluigi [ Sat Feb 04, 2017 4:20 pm ]
Post subject:  Re: xmath result as float

Unfortunately that's not possible.
Sorry.

Author:  StreamThread [ Tue Jun 06, 2017 8:10 pm ]
Post subject:  Re: xmath result as float

Returning to this answer.

Maybe in that situation is possible use CallDLL function? Me need do only calculation with float values, result will written as integer value.
I'm tryed make this with C' like code, but BMS give errors:

Code:
set memory_file10 binary "
void fSubchunk2Size (int subchunk2Size2, int bitsPerSample2, int numChannels2, int sampleRate2) {
float sndTime;

 sndTime = 1.0 * subchunk2Size2 / (bitsPerSample2 / 8.0) / numChannels2 / sampleRate2;
 sndTime - 0.100;
 subchunk2Size2 = sndTime * sampleRate2 * numChannels2 * (bitsPerSample2 / 8.0);

 };"

get oggsize asize
get oggname filename
log MEMORY_FILE 0 oggsize
getDString chunkId 0x4 MEMORY_FILE #RIFF
get chunkSize long MEMORY_FILE
getDString format 0x4 MEMORY_FILE #WAVE
getDString subchunk1ID 0x4 MEMORY_FILE #fmt
get sunchunk1Size long MEMORY_FILE
get audioFormat short MEMORY_FILE
get numChannels short MEMORY_FILE
get sampleRate long MEMORY_FILE
get byteRate long MEMORY_FILE
get blockAlign short MEMORY_FILE
get bitsPerSample short MEMORY_FILE
getDString subchunk2ID 0x4 MEMORY_FILE #data
get subchunk2Size long MEMORY_FILE

#xmath sndTime "1.0f * subchunk2Size / (bitsPerSample / 8.0f) / numChannels / sampleRate"

#xmath sndTime "sndTime - 0.100f"


#xmath fSubchunk2Size "sndTime * sampleRate * numChannels * (bitsPerSample / 8.0)"

calldll MEMORY_FILE10 "fSubchunk2Size" "tcc" RET subchunk2Size bitsPerSample numChannels sampleRate

print "Event: %subchunk2size% , %RET%"
putVarChr MEMORY_FILE 0x28 subchunk2Size Long

#log oggname 0 oggsize MEMORY_FILE


I'm sure error can be in my C function. I hope, what BMS can work with this "trick" if my errors will corrected.

Author:  aluigi [ Tue Jun 06, 2017 8:41 pm ]
Post subject:  Re: xmath result as float

I don't suggest you to use quickbms for these things.

The error you get is caused by the necessity of using some external library because tcc is fantastic but requires to load some libraries (even the basic libc) from file... something that is not good with quickbms where you have no dependencies. Honestly I didn't know tcc had dependencies even for using floats, this was a "bad" surprise :(

So my advice is to NOT use quickbms for that thing, use a programming language.

If you want to continue with quickbms you have 2 other choices: using a dll or using just a pre-compiled function.
The dll is very easy but it will make your code big while for the pre-compiled function use the following:

Code:
set MEMORY_FILE10 binary "\x55\x89\xe5\x83\xec\x20\xdb\x45\x08\xdb\x45\x0c\xdd\x05\xc8\xb0\x40\x00\xde\xf9\xde\xf9\xdb\x45\x10\xde\xf9\xdb\x45\x14\xde\xf9\xd9\x5d\xfc\xd9\x45\xfc\xdd\x05\xd0\xb0\x40\x00\xde\xe9\xd9\x5d\xfc\xdb\x45\x14\xd8\x4d\xfc\xdb\x45\x10\xde\xc9\xdb\x45\x0c\xdd\x05\xc8\xb0\x40\x00\xde\xf9\xde\xc9\xd9\x7d\xea\x0f\xb7\x45\xea\xb4\x0c\x66\x89\x45\xe8\xd9\x6d\xe8\xdb\x5d\xe4\xd9\x6d\xea\x8b\x45\xe4\xc9\xc3"
calldll MEMORY_FILE10 0 "cdecl" subchunk2Size subchunk2Size bitsPerSample numChannels sampleRate

Yes, subchunk2Size is going to take the return value.

Original C code used to compile that data:
Code:
int fSubchunk2Size (int subchunk2Size2, int bitsPerSample2, int numChannels2, int sampleRate2) {
 float sndTime;
 sndTime = 1.0 * subchunk2Size2 / (bitsPerSample2 / 8.0) / numChannels2 / sampleRate2;
 sndTime -= 0.100;
 return sndTime * sampleRate2 * numChannels2 * (bitsPerSample2 / 8.0);
}

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Limited
https://www.phpbb.com/