Page 1 of 1

Question about Boolean Vs Stream signals

PostPosted: Sat Jun 17, 2017 11:13 am
by Spogg
Hi all

I wonder could someone please help me clarify the difference between a Boolean input/output signal, and a stream signal that switches between 1 on 0, in DSP. Wikipedia suggests it’s the same thing, in logic anyway.

I had thought they were interchangeable but I found they’re not.

If I convert a Boolean signal to a Stream signal directly I get a huge level out. It would seem that a Boolean DSP signal represents true or false somehow and is not just 1 or 0.

The stock sine osc uses a “Boolean” signal to hard sync but it works with a 0-1 signal made to look Boolean (using streamboolout instead of just streamout). Martin very kindly made me an optimised sine with sync but this will only work with a “true” Boolean signal for hard sync.

It’s confusing this poor old Vulcan because, in green, they do seem interchangeable.

I need help!

Cheers

Spogg

Re: Question about Boolean Vs Stream signals

PostPosted: Sat Jun 17, 2017 12:52 pm
by tulamide
Don't forget that a stream always carries information for ALL individual tracks. If 3 notes were triggered, then the stream carries information for all 3. In case of a boolean stream it is the same. Each bit represents another track. In our example the stream will carry 3 different true/false signals. It will never be just 0 or 1. You can't just look at the sum of the bits.

More details will hopefully follow by the experts in DSP.

Re: Question about Boolean Vs Stream signals

PostPosted: Sat Jun 17, 2017 1:08 pm
by martinvicanek
If you look at the bit pattern it becomes evident:

bool "true": 11111111111111111111111111111111
float 1.0: 0 01111111 00000000000000000000000 (IEEE-754 format)
integer 1: 00000000000000000000000000000001

It is confusing, though, because in FS "green" they are all interchangeable.

Re: Question about Boolean Vs Stream signals

PostPosted: Sat Jun 17, 2017 2:43 pm
by Spogg
Thanks guys.

So a boolean false is all zeros then? Is this different to a stream value of zero? When I scoped a converted bool signal it switched between zero and HUGE!
I'm imagining that a bool signal carries some sort of header so that a DSP bool input "knows" whether it's a number or a true/false signal. Or it's just down to the input/output type specified in the code.

I think I get it now :D

Cheers

Spogg

Re: Question about Boolean Vs Stream signals

PostPosted: Sat Jun 17, 2017 3:17 pm
by KG_is_back
Spogg wrote:So a boolean false is all zeros then? Is this different to a stream value of zero?


Boolean False and 0 happen to be identical, because they are both just zeros. There is no header or anything to tell them apart. It is fully up to the programmer to determine which one should be used. Sidenote, boolean true (all 1s) happens to be identical with "QNaN" (quiet not a number), which is a special value that is used to detect invalid float operations (like division by zero or square root of negative number).

In fact, the stream and boolean stream connectors in flowstone are purely cosmetic - they compile to the exact same code. Only reason why they are there is for visual clarity.

Re: Question about Boolean Vs Stream signals

PostPosted: Sat Jun 17, 2017 3:28 pm
by Spogg
Thanks KG!

I found that

streamboolout out = (t > 1); gives the all 1s value when true

streamout out= 1 & (t > 1); gives 1 when the condition is met.

BUT

streamboolout out = 1 & (t > 1); gives the same as the streamout but is not necessarily recognised as a boolean input by another module.
I guess it depends on the code in the other module, since you say there is no difference in the way it's compiled.

Makes sense now thanks.

Spogg

Re: Question about Boolean Vs Stream signals

PostPosted: Sun Jun 18, 2017 3:15 am
by nix
to do the conversion in dsp it's->
bool to stream:

streamboolin abool;
streamout result;
result = abool & 1;

stream to bool:

streamin avalue;
streamboolout aboolresult;
aboolresult = avalue == 1 ;


I think they're right,
I tried them

Re: Question about Boolean Vs Stream signals

PostPosted: Sun Jun 18, 2017 7:59 am
by Spogg
Thanks nix.

I got to that understanding too. Eventually :lol:

The thing is that in DSP Boolean "True" isn't 1, it's zillions! Unlike in green :mrgreen:

Cheers

Spogg

Re: Question about Boolean Vs Stream signals

PostPosted: Sun Jun 18, 2017 1:52 pm
by tulamide
Spogg wrote:The thing is that in DSP Boolean "True" isn't 1, it's zillions!

Well :D (takes a deep breath) technically it isn't really zillions. The 32-bit float format (also called single-precision-float) has a special defined value:

Code: Select all
1 11111111 00000000000000000000000
The highest order bit tells us the sign. Unset = positive, set = negative
Following are 8 bits for the exponent.
Lastly 23 bits for the fraction part.


As you can see, the fraction part is completely unset. This value stands for "-infinity". So basically the number you get is even lower than a negative infinity.

:lol:

(Actually I don't know if a value of all bits set is even defined for single precision float, so probably you get unreliable values)

Re: Question about Boolean Vs Stream signals

PostPosted: Sun Jun 18, 2017 5:15 pm
by Spogg
Thanks tulamide.

A restless night with boolean nightmares awaits me.

:lol: