From 896e7e70b1e75242ace97bbecfee2db6fee7400e Mon Sep 17 00:00:00 2001 From: Veikko Sariola Date: Thu, 22 Oct 2020 23:29:37 +0300 Subject: [PATCH] Add Opcode type to bridge, and pull the opcodes from the cgo side. --- bridge/bridge.go.in | 45 ++++++++++++++++++++++++++++++++++++++++++- bridge/bridge_test.go | 6 ++---- 2 files changed, 46 insertions(+), 5 deletions(-) diff --git a/bridge/bridge.go.in b/bridge/bridge.go.in index bf79edf..c1d8cfe 100644 --- a/bridge/bridge.go.in +++ b/bridge/bridge.go.in @@ -10,6 +10,49 @@ import "C" type SynthState = C.SynthState +type Opcode byte + +var ( // cannot be const as the rhs are not known at compile-time + Add = Opcode(C.su_add_id) + Addp = Opcode(C.su_addp_id) + Pop = Opcode(C.su_pop_id) + Loadnote = Opcode(C.su_loadnote_id) + Mul = Opcode(C.su_mul_id) + Mulp = Opcode(C.su_mulp_id) + Push = Opcode(C.su_push_id) + Xch = Opcode(C.su_xch_id) + Distort = Opcode(C.su_distort_id) + Hold = Opcode(C.su_hold_id) + Crush = Opcode(C.su_crush_id) + Gain = Opcode(C.su_gain_id) + Invgain = Opcode(C.su_invgain_id) + Filter = Opcode(C.su_filter_id) + Clip = Opcode(C.su_clip_id) + Pan = Opcode(C.su_pan_id) + Delay = Opcode(C.su_delay_id) + Compres = Opcode(C.su_compres_id) + Advance = Opcode(C.su_advance_id) + Speed = Opcode(C.su_speed_id) + Out = Opcode(C.su_out_id) + Outaux = Opcode(C.su_outaux_id) + Aux = Opcode(C.su_aux_id) + Send = Opcode(C.su_send_id) + Envelope = Opcode(C.su_envelope_id) + Noise = Opcode(C.su_noise_id) + Oscillat = Opcode(C.su_oscillat_id) + Loadval = Opcode(C.su_loadval_id) + Receive = Opcode(C.su_receive_id) + In = Opcode(C.su_in_id) +) + +func (o Opcode) Stereo() Opcode { + return Opcode(byte(o) | 1) // set lowest bit +} + +func (o Opcode) Mono() Opcode { + return Opcode(byte(o) & 0xFE) // clear lowest bit +} + func (s *SynthState) Render(buffer []float32) int { fmt.Printf("Calling Render...\n") var ret = C.su_render_samples(s, C.int(len(buffer))/2, (*C.float)(&buffer[0])) @@ -17,7 +60,7 @@ func (s *SynthState) Render(buffer []float32) int { return int(ret) } -func (s *SynthState) SetCommands(c [2048]byte) { +func (s *SynthState) SetCommands(c [2048]Opcode) { pk := *((*[2048]C.uchar)(unsafe.Pointer(&c))) s.Commands = pk } diff --git a/bridge/bridge_test.go b/bridge/bridge_test.go index 13b30a9..9f6ef47 100644 --- a/bridge/bridge_test.go +++ b/bridge/bridge_test.go @@ -21,10 +21,8 @@ const su_max_samples = SAMPLES_PER_ROW * TOTAL_ROWS // const bufsize = su_max_samples * 2 func TestBridge(t *testing.T) { - commands := [2048]byte{ - 2, 2, 11, 0, // envelope mono, envelope mono, out stereo, advance - // TODO: pull these somehow from the C-side - } + commands := [2048]bridge.Opcode{ + bridge.Envelope, bridge.Envelope, bridge.Out.Stereo(), bridge.Advance} values := [16384]byte{64, 64, 64, 80, 128, // envelope 1 95, 64, 64, 80, 128, // envelope 2 128}