Skip to content

Instantly share code, notes, and snippets.

@stellarpower
Created July 30, 2023 19:03
Show Gist options
  • Save stellarpower/a1e5a0f7232d54136e7d1e2ece900363 to your computer and use it in GitHub Desktop.
Save stellarpower/a1e5a0f7232d54136e7d1e2ece900363 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import random, sys, time
from pythonosc import dispatcher, osc_server, osc_message_builder, udp_client
MessageAddress = "/test"
TimeToCutStream = 10 # seconds
Host = "localhost"
Port = 9023
#Port = int(sys.argv[1])
client = udp_client.SimpleUDPClient(Host, Port)
def sendMessage():
valueToSend = float(random.random() * 2 + 1)
# Not sure on the latency of this call
# PyOSC proved much slower than Crystal so just running them back-to-back
client.send_message( MessageAddress, valueToSend ) # Should be ∊ (-1, +1)
# But can sleep if needed to simulate an approx sample rate without using accurate timers.
# sleep(...)
def example1():
###############################
## Example 1 - Send some packets really quickly; then shut off.
## Neuromore fills a buffer then continues to eat into it
## Expected behaviour: the engine should be operating realtime
## - if samples come in faster than the sample rate, these should be
## interpolated or packets should be dropped as stale data is little use.
###############################
SamplesToSend = 10 ** 4
# Send some data as quickly as possible - probably faster than the sample rate.
for i in range(SamplesToSend):
sendMessage()
# Now exit.
exit(0)
def example2():
###############################
## Example 2 - Send some packets quickly again; then shut off.
## When resumed, the values are plotted next to where the screen shut off -
## I.e. it goes back in time as if the pause didn't happen.
###############################
SamplesToSend = 10 ** 3
# Send some data to start. Screenshot 1
for i in range(SamplesToSend):
sendMessage()
# Now cut the stream for some time. Screenshot 1
time.sleep(TimeToCutStream)
# Resume sending data. Screenshot 2
while(True):
sendMessage()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment