Add Opcode type to bridge, and pull the opcodes from the cgo side.

This commit is contained in:
Veikko Sariola 2020-10-22 23:29:37 +03:00
parent af75dd38aa
commit 896e7e70b1
2 changed files with 46 additions and 5 deletions

View File

@ -10,6 +10,49 @@ import "C"
type SynthState = C.SynthState 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 { func (s *SynthState) Render(buffer []float32) int {
fmt.Printf("Calling Render...\n") fmt.Printf("Calling Render...\n")
var ret = C.su_render_samples(s, C.int(len(buffer))/2, (*C.float)(&buffer[0])) 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) return int(ret)
} }
func (s *SynthState) SetCommands(c [2048]byte) { func (s *SynthState) SetCommands(c [2048]Opcode) {
pk := *((*[2048]C.uchar)(unsafe.Pointer(&c))) pk := *((*[2048]C.uchar)(unsafe.Pointer(&c)))
s.Commands = pk s.Commands = pk
} }

View File

@ -21,10 +21,8 @@ const su_max_samples = SAMPLES_PER_ROW * TOTAL_ROWS
// const bufsize = su_max_samples * 2 // const bufsize = su_max_samples * 2
func TestBridge(t *testing.T) { func TestBridge(t *testing.T) {
commands := [2048]byte{ commands := [2048]bridge.Opcode{
2, 2, 11, 0, // envelope mono, envelope mono, out stereo, advance bridge.Envelope, bridge.Envelope, bridge.Out.Stereo(), bridge.Advance}
// TODO: pull these somehow from the C-side
}
values := [16384]byte{64, 64, 64, 80, 128, // envelope 1 values := [16384]byte{64, 64, 64, 80, 128, // envelope 1
95, 64, 64, 80, 128, // envelope 2 95, 64, 64, 80, 128, // envelope 2
128} 128}