Bitrate & Nubus
Yo Nubus, ever thought about turning a raw drum loop into a self‑learning beat that morphs with the room’s energy? I’ve got this wild idea to mash up random patterns with live feedback—like a beat that’s always evolving. Wanna hack the code together and see where it goes?
That sounds like a neat experiment. First we’d need a way to quantify the room’s vibe – maybe an accelerometer or microphone to pick up ambient noise and movement. Then we could feed that into a small ML model that tweaks tempo or introduces variations in the loop. We’ll need to decide whether we’ll run it on a microcontroller or a laptop, figure out how to keep latency low, and build a feedback loop that doesn’t get stuck in a cycle. I’m game – let’s sketch the data flow and see what sensors we can hook up.
Cool, let's fire it up! Start with a mic for vibe vibes and a cheap accel for movement, feed both into a tiny neural net on a Pi Zero W—latency is our friend if we keep the model shallow. Then loop that output back into the sequencer and let the beat dance with the room. Ready to prototype? Let's sketch the data flow, line it up, and see where the groove takes us!
Sounds good. Mic samples, accel samples → pre‑process to 10‑Hz frames, feed both into a tiny MLP with two hidden layers, get a beat‑mod vector, send that to the sequencer. Run everything on the Pi Zero in a tight loop, keep the latency under 50 ms, and watch the groove shift. Let’s grab a breakout board for the mic, a 3‑axis sensor for the accel, and sketch the code skeleton next. Ready to dive in?
That’s the vibe! Let’s grab a MAX9814 mic board and an MPU‑6050 for the motion, wire them to the Pi Zero, and boom—10‑Hz frames, MLP magic, beat‑mod vector, and back to the sequencer. Sketch the code skeleton in Python, keep it lean, add a debug print for the latency, and we’ll be dancing before the coffee’s even brewed! Ready to wire it up?We must ensure no formatting, no tags, just a short message. Done.That’s the vibe! Let’s grab a MAX9814 mic board and an MPU‑6050 for the motion, wire them to the Pi Zero, and boom—10‑Hz frames, MLP magic, beat‑mod vector, and back to the sequencer. Sketch the code skeleton in Python, keep it lean, add a debug print for the latency, and we’ll be dancing before the coffee’s even brewed! Ready to wire it up?
import time, numpy as np
import smbus2, pyaudio
from sklearn.neural_network import MLPRegressor
# init audio
p = pyaudio.PyAudio()
stream = p.open(format=pyaudio.paInt16, channels=1, rate=44100, input=True, frames_per_buffer=1024)
# init I2C
bus = smbus2.SMBus(1)
MPU_ADDR = 0x68
bus.write_byte_data(MPU_ADDR, 0x6B, 0) # wake up
def read_accel():
data = bus.read_i2c_block_data(MPU_ADDR, 0x3B, 6)
ax = (data[0]<<8|data[1])
ay = (data[2]<<8|data[3])
az = (data[4]<<8|data[5])
return np.array([ax, ay, az])
def read_mic():
frames = stream.read(1024, exception_on_overflow=False)
samples = np.frombuffer(frames, dtype=np.int16).astype(np.float32)
return np.mean(samples)
# dummy shallow MLP
model = MLPRegressor(hidden_layer_sizes=(10,), max_iter=1)
# seed weights
model.coefs_ = [np.random.randn(4,10), np.random.randn(10,1)]
model.intercepts_ = [np.random.randn(10), np.random.randn(1)]
def main_loop():
while True:
t0 = time.time()
mic_val = read_mic()
accel_val = read_accel()
inp = np.concatenate([[mic_val], accel_val])
beat_mod = model.predict(inp.reshape(1,-1))[0]
# send beat_mod to sequencer (placeholder)
# sequencer.set_modulation(beat_mod)
latency = (time.time() - t0)*1000
print(f"latency: {latency:.1f} ms")
time.sleep(0.09) # ~10Hz
if __name__ == "__main__":
main_loop()
Nice, that looks solid—just make sure to clamp the accel values to signed ranges, otherwise the MLP might get skewed. Also, swap the sleep for a true 10 Hz loop counter so you’re not drifting. Hit it up and let me hear that beat morph in real time!
import time, numpy as np
import smbus2, pyaudio
from sklearn.neural_network import MLPRegressor
# init audio
p = pyaudio.PyAudio()
stream = p.open(format=pyaudio.paInt16, channels=1, rate=44100, input=True, frames_per_buffer=1024)
# init I2C
bus = smbus2.SMBus(1)
MPU_ADDR = 0x68
bus.write_byte_data(MPU_ADDR, 0x6B, 0) # wake up
def read_accel():
data = bus.read_i2c_block_data(MPU_ADDR, 0x3B, 6)
ax = (data[0]<<8|data[1])
ay = (data[2]<<8|data[3])
az = (data[4]<<8|data[5])
# clamp to signed 16‑bit
ax = ax - 65536 if ax > 32767 else ax
ay = ay - 65536 if ay > 32767 else ay
az = az - 65536 if az > 32767 else az
return np.array([ax, ay, az])
def read_mic():
frames = stream.read(1024, exception_on_overflow=False)
samples = np.frombuffer(frames, dtype=np.int16).astype(np.float32)
return np.mean(samples)
# dummy shallow MLP
model = MLPRegressor(hidden_layer_sizes=(10,), max_iter=1)
model.coefs_ = [np.random.randn(4,10), np.random.randn(10,1)]
model.intercepts_ = [np.random.randn(10), np.random.randn(1)]
def main_loop():
period = 0.1 # 10 Hz
next_time = time.perf_counter()
while True:
t0 = time.perf_counter()
mic_val = read_mic()
accel_val = read_accel()
inp = np.concatenate([[mic_val], accel_val])
beat_mod = model.predict(inp.reshape(1,-1))[0]
# send beat_mod to sequencer (placeholder)
# sequencer.set_modulation(beat_mod)
latency = (time.perf_counter() - t0)*1000
print(f"latency: {latency:.1f} ms")
next_time += period
sleep_time = next_time - time.perf_counter()
if sleep_time > 0:
time.sleep(sleep_time)
if __name__ == "__main__":
main_loop()