BitArray for floats?


#1

is it possible to use the BitArray class for floats ?

for (int channel = 0; channel < getNumInputChannels(); ++channel)
    {
		float *p = buffer.getSampleData (channel);
		int size = buffer.getNumSamples();

		for (int x=0; x<size; x++)
        {
			float k = *(p+x);
			bit.setBitRangeAsInt (0, 32, (unsigned int)k);

			/* transformation */
			
			float newValue = (float)bit.getBitRangeAsInt(0,32);
        }
   }

someting like that ? but this does not work, a constant stream o 0s.

Any other easy/fast ways to do BIT manipulation on FLOATS ?


#2

eek! Don’t really understand what you’re trying to do there!

You can of course just reinterpret_cast a float* to an int*, but if you ever find yourself doing that, you should try to find a less hacky approach to whatever the problem is.


#3

i need to mess witht he bit represenation of a audio sample (all samples in a buffer in a VST plugin)

i don’t know what’s the best way to do that, i never really did any bit operations in my apps, BitArray seemed like the best way to do that.

what i need to do is, XOR, AND, OR set/clear each bit in a 32bit float variable that’s inside a AudioSampleBuffer.


#4

That sounds insane… Why are you doing it??


#5

ok if it’s insane I ain’t doing it :slight_smile:

it was an idea for a VST bit crusher plugin, i got the idea for a Doepfer presentation. they showed a module for their ModularSYnth system, that did operations on bits, (xor or and and others) and it sounded very nice, so i thought that has to be easy in the DSP world, since what we deal with is numbers, but i can’t get around to doing this.

anyway, i need to get on with my reading (unions and stuff) and IEE float specification and i’ll get to it, i just thought BitArray could be of use here, cause it’s a much nice interface then all those weird BIT frownies that look like japaneese ads for sex toys.


#6

usually float number are normalized in the [-1;1] range so most of the time if you just round them to the nearest integer you’d get zero…

I’d suggest you to first scale your input by 2^(numbits-1) before rounding to int.

then you can use the & ^ | operators on ints and convert back to float.


#7

this is what i had in mind:

http://www.doepfer.de/a1891.htm

the sound demo is amazing in my opinion.


#8

ok so i decided, i’l try, i got through some docs and some examples and this is what i came up with

http://code.google.com/p/bitmangler/

it does not process only display bit representation of incoming samples (one sample per buffer cycle every 10th cycle, first channel only, so it doesn’t eat all your cpu)

i used a UNION just like jules did in his rountfloatoint conversion, now it’s a matter of the processing code for those bit operations, from what i remember bit operations are not very efficient performance wise, but i’m not sure.


#9

You can definitely make some lovely nasty (?) noises this way!

You’ve probably already thought of this but you may need to check your samples for NaNs and INFs and set them to something sensible (zero?) before outputting them from the plugin after doing arbitrary bitwise ops on floats.


#10

very nice lcd font you have… what font you’ve used so far ?

btw, mangling bits of floating point data is one of the things i would like to experiment with. nice one !


#11

i downloaded a freeware lcd font off the internet, used the font serializer, the font is in the svn google repos it’s called lcd.bin


#12

I’d bet they use a fixed point signal representation for their bit mangling operations. let us know if you manage to get the results you want using floating point.


#13

or they scale the values, treating them as integers, so they will not have problem by XORing or ANDing two numbers with different exponent and mantissa length.


#14

i did some updates, however i’m getting problems with the bit conversions, this is the way i did them:

http://code.google.com/p/bitmangler/source/browse/trunk/bitManglerFloat.cpp

however i don’t know if this is the right way to do it.

i followed this: http://bytes.com/forum/thread558570.html in terms of bit operations.

can anyone give me any more bit operation examples ?

anyway i updated the plug it has 4 operations
http://code.google.com/p/bitmangler/


#15

i made a class that handles all float bit operations if anyone ever wants to use it:

http://code.google.com/p/bitmangler/source/browse/trunk/bitFloat.h
http://code.google.com/p/bitmangler/source/browse/trunk/bitFloat.cpp

i have a question, is it a good idea to inline those methods that do bit operations ? will this help with performance, i saw this in roundfloatotin in juce but i don’t know what impact does this have, i’ve made some timing test on vc6 and i see no difference with inline and without, but maybe i’m missing something ?


#16

the compiler might inline those functions anyway?