Skip to content
View in the app

A better way to browse. Learn more.

ResHax

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.
Help us keep the site running.

xmath result as float

Featured Replies

  • Author
  • Localization

StreamThread, posted Sat Feb 04, 2017 10:34 am (20605)


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
  • Localization

aluigi, posted Sat Feb 04, 2017 12:11 pm (20607)


quickbms works only with integers.
  • Author
  • Localization

StreamThread, posted Sat Feb 04, 2017 3:04 pm (20608)


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
  • Localization

aluigi, posted Sat Feb 04, 2017 4:20 pm (20610)


Unfortunately that's not possible.
Sorry.
  • Author
  • Localization

StreamThread, posted Tue Jun 06, 2017 8:10 pm (23882)


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
  • Localization

aluigi, posted Tue Jun 06, 2017 8:41 pm (23885)


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);
}
Guest
This topic is now closed to further replies.

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.