open sound control touchosc iphone

rjandsam

Member
Hi i was just after some advice with regards to the osc protocol and its compatibility with a picaxe. I have read up on the protocol and from what I can make of it the touchosc app pumps out float32. So my question is do I need a maths coprocessor to read this data stream into a picaxe. I can already recieve the data over udp into the picaxe as variables but cant make sense of the slider data being sent which is a 0-255 slider. If the data was being sent as integer there would not be an issue hence the maths processor idea to convert the data on the fly.
Thank you in advance
RICH
 

eclectic

Moderator
Hi i was just after some advice with regards to the osc protocol and its compatibility with a picaxe. I have read up on the protocol and from what I can make of it the touchosc app pumps out float32. So my question is do I need a maths coprocessor to read this data stream into a picaxe. I can already recieve the data over udp into the picaxe as variables but cant make sense of the slider data being sent which is a 0-255 slider. If the data was being sent as integer there would not be an issue hence the maths processor idea to convert the data on the fly.
Thank you in advance
RICH
Sorry if I'm behind the times with modern idiom
but,

osc / float32 / slider data / udp ?

Could you provide a couple of references
for us out in the metaphorical sticks? :)

e
 

hippy

Technical Support
Staff member
@ rjandsam : I would guess you probably know more about OSC than anyone here.

It seems to be a protocol issue more than anything else and the question of the PICAXE needing a maths coprocessor is a little difficult to answer without knowing what is being sent to the PICAXE and what that represents and how it needs converting.

I'm not familiar with OSC, its protocol nor how you are bridging UDP to PICAXE but it should be possible to convert float32 to 0-255 without a maths co-processor. It may be easier to to do the conversion in the bridge between UDP and the PICAXE.
 

rjandsam

Member
Sorry for that.
Here are a couple of links.
http://frieder-weiss.de/eyecon/Manual/udp-osc.htm
http://archive.cnmat.berkeley.edu/OpenSoundControl/OSC-spec-examples.html
http://hexler.net/software/touchosc
http://opensoundcontrol.org/spec-1_0
I hope this helps, please forgive me for not sending any links with the first post.
I just dont want to over complicate something that maybe done with just the picaxe.
Looking online i can see a few people have done this with arduino through a pc but i want it to be direct, i have used another more basic app and that sends the data as int32 this works fine with the setup i have designed i just like the layout of touchosc better as you can do so much more.
Thanks again
 

rjandsam

Member
Sorry again, here is my set-up the iphone sends the data from the app over my wifi network this then arrives at my wiznet ethernet to serial converter this then talks to my 28x2 at 19200t if the data is sent as integer from the osc app that lets you send the data as float or integer then all is fine and it works great the problem is when i use float i dont know how to convert the data.
THANKS for all of the advice so far, please also note i probably dont know half as much as you guys.
 

hippy

Technical Support
Staff member
That seems to be the most useful page; the slider presumably being sent as an OSC message in the form ...

/someaddress,fsomedata

or something like that, and presumably you are parsing that in the UDP to PICAXE bridge. Do you have any examples of what data bytes are sent or you extract from the UDP packet and are passed to the PICAXE and what that represents in terms of slider position ?

I think if we can get the problem down to "I have this set of bytes and the PICAXE needs to treat them as this number" then we can probably find an answer without even having to know anything about the OSC protocol itself.
 

rjandsam

Member
THANKS Hippy,
Its great to be able to get help on pull your hair out things like this.
I will be back working on it tomorrow so i will collect the serial data and see if you can make sense of whats happening.
The data arives like 2f 73 6c 69 64 65 72 31 00 00 00 00 2c 66 00 00 00 00 00 00 this is /slider1 ,f at the bottom 0
and the top after 2c 66 00 00 43 7f 00 00 at around the centre it is 2c 66 00 00 43 09 18 c6 just above the bottom the slider reads 2c 66 00 00 41 c5 6b 5b
In integer mode only the last byte changes from 0-255 000-ff.
Hope this is enough for now.
 

lbenson

Senior Member
>iphone sends the data from the app over my wifi network this then arrives at my wiznet ethernet to serial converter this then talks to my 28x2 at 19200t

Now for your chance to prime the forum's pump: can you post your schematic and code for wiznet-to-28X2? Unless I have missed it, this magic has not previously been revealed to the forumites.
 

hippy

Technical Support
Staff member
Thanks RICH, that's just what we need. So, lined up -

Top : 2c 66 00 00 43 7f 00 00
Mid : 2c 66 00 00 43 09 18 c6
Bot : 2c 66 00 00 41 c5 6b 5b

Trimmed down to 4 bytes -

Top : 43 7f 00 00
Mid : 43 09 18 c6
Bot : 41 c5 6b 5b

Then it's just a question of what order the 4-byte set is in, which bits are mantissa, exponent and sign bits.

Bunged into ... http://babbage.cs.qc.cuny.edu/IEEE-754/32bit.html ...

Top : 43 7f 00 00 = 255
Mid : 43 09 18 c6 = 137.09677124023438
Bot : 41 c5 6b 5b = 24.677419662475586

Which looks about right so I think we can say they are IEEE-754 format ...

Bit 31 sign ( always zero here )

Bits 30 to 23 exponent with a bias of 127

Bits 22 to 0 mantissa

So just a case of bit masking and shifting. To make it easier we can almost certainly drop the right-most byte and put the second and third in a word variable, then shift according to the exponent.

So something like below, but not exhaustively tested, and no rounding done ...

1111111100000000 E=134 = 255
1000100100011000 E=134 = 137
1100010101101011 E=131 = 24

Code:
#Terminal 4800

Symbol w0.lsb = b0
Symbol w0.msb = b1
Symbol w1.lsb = b2
Symbol w1.msb = b3

Do
  w1 = $437f : w0 = $0000 : Gosub Convert
  w1 = $4309 : w0 = $18c6 : Gosub Convert
  w1 = $41c5 : w0 = $6b5b : Gosub Convert
  SerTxd( CR, LF )
  Pause 5000
Loop

Convert:

  w0.lsb = w0.msb
  w0.msb = w1.lsb

  w0 = w0 | $8000

  w1 = w1 / $80

  SerTxd( #bit15, #bit14, #bit13, #bit12 )
  SerTxd( #bit11, #bit10, #bit9,  #bit8 )
  SerTxd( #bit7,  #bit6,  #bit5,  #bit4 )
  SerTxd( #bit3,  #bit2,  #bit1,  #bit0 )
  SerTxd( " E=", #w1, 9 , " = " )

  Do While w1 < 134
    w0 = w0 / 2
    w1 = w1 + 1
  Loop

  SerTxd( #w0.msb, CR, LF )

  Return
 
Last edited:

rjandsam

Member
Hi Hippy,
No more hair pulling the code works great for on the fly conversion, I just take the slider value from b23 and hey presto
Once again thank you for your help Hippy, I can now interface the code into my project.
The wiznet board i am using is the WIZ105SR and it is very easy to connect into your designs as it is just serial over tcp or udp.
here is the working OSC example with code provided by Hippy

#Terminal 4800
#picaxe 28x2
setfreq em32
Symbol w11.lsb = b22
Symbol w11.msb = b23
Symbol w10.lsb = b20
Symbol w10.msb = b21
main:
serin [800,main],b.1,t19200_32,("/Slider1"),b0,b0,b0,b0,b0,b0,b21,b20,b23,b22

Convert:
w11.lsb = w11.msb
w11.msb = w10.lsb
w11 = w11 | $8000
w10 = w10 / $80
Do While w10 < 134
w11 = w11 / 2
w10 = w10 + 1
Loop
SerTxd( #w11.msb, CR, LF )
goto main
 

hippy

Technical Support
Staff member
Glad it's working and, now more awake than than in the late hours, it's more obvious there's scope for optimisation, reducing size and increasing speed of conversion; only the first two bytes of the float32 have to be used ...

Code:
#Terminal 4800

Do
  w0 = $437f : Gosub Convert
  w0 = $4309 : Gosub Convert
  w0 = $41c5 : Gosub Convert
  SerTxd( CR, LF )
  Pause 5000
Loop

Convert:

  b1 = w0 / $80
  b0 = b0 | $80

  SerTxd( #bit7,  #bit6,  #bit5,  #bit4 )
  SerTxd( #bit3,  #bit2,  #bit1,  #bit0 )
  SerTxd( " E=", #b1, 9 , " = " )

  Do While b1 < 134
    b0 = b0 / 2
    b1 = b1 + 1
  Loop

  SerTxd( #b0, CR, LF )

  Return
And even more efficiently for a 28X2 ...

Code:
#Picaxe 28X2
#Terminal 9600

Do
  w0 = $437f : Gosub Convert
  w0 = $4309 : Gosub Convert
  w0 = $41c5 : Gosub Convert
  SerTxd( CR, LF )
  Pause 5000
Loop

Convert:

  b1 = 17279 - w0 / $80
  b0 = b0 | $80 >> b1

  SerTxd( #b0, CR, LF )

  Return
The -

b1 = 17279 - w0 / $80

is actually -

b1 = w0 / $80
b1 = 134 - b1

where -

17279 = ( 134 * $80 ) | $7F
 

rjandsam

Member
Hi Hippy,
I have just arrived home and seen the modified code it works a dream, thank you once more.
I am pretty sure that this code will come in very handy for anybody interested in the OSC protocol.

#Terminal 9600
#picaxe 28x2

setfreq em32

main:
serin [800,main],b.1,t19200_32,("/Slider1"),b0,b0,b0,b0,b0,b0,b21,b20,b0,b0

Convert:
b21 = 17279 - w10 / $80
b20 = b20 | $80 >> b1
SerTxd( #b20, CR, LF )
goto main
 

hippy

Technical Support
Staff member
One final note; we didn't deal with an actual zero - $00000000 in float32 - but this should fix that ...

Code:
Convert:
  If w10 <> 0 Then
    b21 = 17279 - w10 / $80
    b20 = b20 | $80 >> b1
  End If
  SerTxd( #b20, CR, LF )
 

rjandsam

Member
Thanks Hippy, i suppose that this could be classed as final code for anybody needing an OSC float32 Kick-start.
 

drgipatel

New Member
control osc over iPhone

Were you successful with the control as I'm looking for a way to control a picaxe with an iPhone osc app any guide ?
 
Top