@@ -6,7 +6,6 @@ s.waitForBoot { | |||
thisProcess.openUDPPort(5005); | |||
n = NetAddr.new("0.0.0.0", 5005); | |||
o = OSCFunc({ arg msg, time, addr, recvPort; [msg, time, addr, recvPort].postln; }, '/radio', n); | |||
//OSCFunc.trace(true); | |||
// Create the synth definition and load it | |||
module = SynthDef.new("module", { | |||
@@ -34,13 +33,15 @@ s.waitForBoot { | |||
// Create multiple sound generators | |||
modules = []; | |||
3.do({ | |||
1.do({ | |||
arg index; | |||
var synth; | |||
synth = Synth.new("module", [\hue, 0.5, \saturation, 0.1, \value, 0.5, \pan, 0.5, \gain, 0.9]); | |||
modules.add(synth); | |||
}); | |||
"%".postf(modules[0]); | |||
// Hook up OSC | |||
f = { |msg, time, addr| | |||
if(msg[0] == '/radio') { | |||
@@ -0,0 +1,27 @@ | |||
s = Server.local; | |||
s.waitForBoot { | |||
var synth, module; | |||
// Create the synth definition and load it | |||
module = SynthDef.new("module", { | |||
var noise, crackle, mixer, oscillator, filtered_noise, tone, frequency, noise_level, qfactor, osc_level; | |||
tone = MouseX.kr(1, 0); | |||
frequency = MouseY.kr(200, 2000); | |||
qfactor = (tone)**4; | |||
osc_level = 1 - tone; | |||
noise_level = 1 - tone; | |||
oscillator = SinOsc.ar(frequency) * osc_level; | |||
crackle = Crackle.ar(tone + 1, 0.5); | |||
noise = WhiteNoise.ar(1); | |||
filtered_noise = BPF.ar(noise, frequency, qfactor) * noise_level; | |||
mixer = Mix.ar([crackle, filtered_noise]); | |||
Out.ar(0, mixer); | |||
}); | |||
module.load(s); | |||
s.sync; | |||
synth = Synth.new("module"); | |||
}; |
@@ -0,0 +1,28 @@ | |||
s = Server.local; | |||
s.waitForBoot { | |||
var synth, module; | |||
// Create the synth definition and load it | |||
module = SynthDef.new("module", { | |||
var mod, car, modPartial=2.401, carPartial=1, index=3, freq=440, mul=0.05; | |||
mod = SinOsc.ar( | |||
freq * modPartial, | |||
0, | |||
200 | |||
); | |||
car = SinOsc.ar( | |||
(freq * carPartial) + mod, | |||
0, | |||
mul | |||
); | |||
Out.ar(0, Disintegrator.ar(SinOsc.ar(440), 0.5)); | |||
}); | |||
module.load(s); | |||
s.sync; | |||
synth = Synth.new("module"); | |||
}; |
@@ -1,4 +1,5 @@ | |||
import math | |||
import time | |||
import itertools as it | |||
import cv2 | |||
from pythonosc import udp_client | |||
@@ -7,6 +8,7 @@ import numpy as np | |||
DENSITY = 4 | |||
RED = [0, 0, 255] | |||
N_COLORS = 3 | |||
LAST_MESSAGE_TIME = 0 | |||
def draw_rectangle(frame, sp, ep): | |||
@@ -14,7 +16,7 @@ def draw_rectangle(frame, sp, ep): | |||
return cv2.rectangle(frame, sp, ep, RED, 1) | |||
def analyze_block(frame, osc, index, sp, ep): | |||
def analyze_block(frame, osc, index, sp, ep, send=False): | |||
""" Analyze a block """ | |||
block = frame[sp[1]:ep[1], sp[0]:ep[0], 0:3] | |||
average_color = np.average(block, (0, 1)) | |||
@@ -26,13 +28,20 @@ def analyze_block(frame, osc, index, sp, ep): | |||
h, s, v = cv2.cvtColor(average_color, cv2.COLOR_BGR2HSV)[0][0] | |||
# Configure the oscillator | |||
osc.send_message( | |||
"/radio", | |||
[int(index), | |||
float(h / 255), | |||
float(s / 255), | |||
float(v / 255), .5]) | |||
if send and index == 0: | |||
print("Sending message") | |||
osc.send_message( | |||
"/radio", | |||
[int(index), | |||
float(h / 255), | |||
float(1), | |||
float(v / 255), .5]) | |||
# osc.send_message( | |||
# "/radio", | |||
# [int(index), | |||
# float(h / 255), | |||
# float(s / 255), | |||
# float(v / 255), .5]) | |||
# Draw the image | |||
for thickness, color in ((3, (0, 0, 0)), (1, (255, 255, 255))): | |||
frame = cv2.putText(frame, | |||
@@ -47,16 +56,21 @@ def analyze_block(frame, osc, index, sp, ep): | |||
def analyze(frame, osc): | |||
""" Analyze the full frame """ | |||
global LAST_MESSAGE_TIME | |||
height, width, d = frame.shape | |||
n = DENSITY | |||
m = math.ceil(n * (height / width)) | |||
dx = width / n | |||
dy = height / m | |||
send = False | |||
if time.time() - LAST_MESSAGE_TIME > 0.1: | |||
LAST_MESSAGE_TIME = time.time() | |||
send = True | |||
for index, (x, y) in enumerate(it.product(range(n), range(m))): | |||
sp = (int(x * dx), int(y * dy)) | |||
ep = (int(x * dx + dx), int(y * dy + dy)) | |||
frame = draw_rectangle(frame, sp, ep) | |||
frame = analyze_block(frame, osc, index, sp, ep) | |||
frame = analyze_block(frame, osc, index, sp, ep, send) | |||
return frame | |||