proper way to cnvert float to int16 and otherr questions

Pixilang programming language
Post Reply
ainegil
Posts: 168
Joined: Thu Sep 22, 2022 11:37 pm

proper way to cnvert float to int16 and otherr questions

Post by ainegil »

at the moment i use

intvalue = (floatvalue * 32767) div 1

to force the value to be Int16 but I assume thats not how is done usually?

and another qustion I have is is there a quick and elegant way to have linear interpooation
on the wavetable generator?

I assume it coukd be hacked with two voices playing a sample apart and adjusting the volume each tick but than it seems more resonable to make a custom player.

and another qustion is, is there a way to relate the output of rand() to a seed?

for many RND generators the output and input is the same number
like
a = rand()
b = rand()
c = rand()
rand_ seed(a)
rand() == b

but this seems not the case here?
User avatar
NightRadio
Site Admin
Posts: 3941
Joined: Fri Jan 23, 2004 12:28 am
Location: Ekaterinburg. Russia
Contact:

Re: proper way to cnvert float to int16 and otherr questions

Post by NightRadio »

intvalue = (floatvalue * 32767) div 1
to force the value to be Int16 but I assume thats not how is done usually?
Actually this is correct way :)
Another (maybe a bit faster) way: intvalue = (floatvalue * 32767) |0

is there a quick and elegant way to have linear interpooation
on the wavetable generator?
Use FLOAT32 table and destination container - in this case linear interpolation will be used

is there a way to relate the output of rand() to a seed?
for many RND generators the output and input is the same number
Not for rand() unfortunately.
But you can use your own random generator based on this code:
rand_next = rand_next * 1103515245 + 12345
ainegil
Posts: 168
Joined: Thu Sep 22, 2022 11:37 pm

Re: proper way to cnvert float to int16 and otherr questions

Post by ainegil »

Thanks.

I will probably use shift registers for speed.
Background is that I have a nice synthesis that is based on derivatives of impulse responses.
And the idea is for a fast synthesis you can use a sequence from a random number generator instead of sample lookup. I think thats faster, but I am not sure, at any rate you can implement it in hardware without memory.
You search for the right sequence seed offline.
It works surprisungly well ( the samples are not transposed but synched with constant pitch)
Post Reply