mirror of
https://github.com/vsariola/sointu.git
synced 2026-02-08 00:30:18 -05:00
Implement sample-based oscillators, with sample import from gm.dls.
This commit is contained in:
@ -136,6 +136,13 @@ su_op_oscillat_normalized:
|
||||
fadd dword [WRK+su_osc_wrk.phase]
|
||||
fst dword [WRK+su_osc_wrk.phase]
|
||||
fadd dword [edx+su_osc_ports.phaseofs]
|
||||
%ifdef INCLUDE_SAMPLES
|
||||
test al, byte SAMPLE
|
||||
jz short su_op_oscillat_not_sample
|
||||
call su_oscillat_sample
|
||||
jmp su_op_oscillat_shaping ; skip the rest to avoid color phase normalization and colorloading
|
||||
su_op_oscillat_not_sample:
|
||||
%endif
|
||||
fld1
|
||||
fadd st1, st0
|
||||
fxch
|
||||
@ -168,6 +175,7 @@ su_op_oscillat_not_pulse:
|
||||
jmp su_op_oscillat_gain ; skip waveshaping as the shape parameter is reused for gateshigh
|
||||
su_op_oscillat_not_gate:
|
||||
%endif
|
||||
su_op_oscillat_shaping:
|
||||
; finally, shape the oscillator and apply gain
|
||||
fld dword [edx+su_osc_ports.shape]
|
||||
call su_waveshaper
|
||||
@ -285,6 +293,42 @@ SECT_DATA(suconst)
|
||||
|
||||
%endif
|
||||
|
||||
; SAMPLES
|
||||
%ifdef INCLUDE_SAMPLES
|
||||
|
||||
SECT_TEXT(suoscsam)
|
||||
|
||||
su_oscillat_sample: ; p
|
||||
pushad ; edx must be saved, eax & ecx if this is stereo osc
|
||||
push edx
|
||||
mov al, byte [VAL-4] ; reuse "color" as the sample number
|
||||
lea edi, [MANGLE_DATA(su_sample_offsets) + eax*8] ; edi points now to the sample table entry
|
||||
fmul dword [c_samplefreq_scaling] ; p*r
|
||||
fistp dword [esp]
|
||||
pop edx ; edx is now the sample number
|
||||
movzx ebx, word [edi + su_sample_offset.loopstart] ; ecx = loopstart
|
||||
sub edx, ebx ; if sample number < loop start
|
||||
jl su_oscillat_sample_not_looping ; then we're not looping yet
|
||||
mov eax, edx ; eax = sample number
|
||||
movzx ecx, word [edi + su_sample_offset.looplength] ; edi is now the loop length
|
||||
xor edx, edx ; div wants edx to be empty
|
||||
div ecx ; edx is now the remainder
|
||||
su_oscillat_sample_not_looping:
|
||||
add edx, ebx ; sampleno += loopstart
|
||||
add edx, dword [edi + su_sample_offset.start]
|
||||
fild word [MANGLE_DATA(su_sample_table) + edx*2]
|
||||
fdiv dword [c_32767]
|
||||
popad
|
||||
ret
|
||||
|
||||
SECT_DATA(suconst)
|
||||
%ifndef C_32767
|
||||
c_32767 dd 32767.0
|
||||
%define C_32767
|
||||
%endif
|
||||
|
||||
%endif
|
||||
|
||||
;-------------------------------------------------------------------------------
|
||||
; LOADVAL opcode
|
||||
;-------------------------------------------------------------------------------
|
||||
|
||||
@ -64,6 +64,7 @@ endstruc
|
||||
%endif
|
||||
%endmacro
|
||||
|
||||
%define SAMPLE 0x80 ; in this case, all the rest of the bits is the sample index
|
||||
%define SINE 0x40
|
||||
%define TRISAW 0x20
|
||||
%define PULSE 0x10
|
||||
@ -95,6 +96,9 @@ endstruc
|
||||
%if (%8) & GATE == GATE
|
||||
%define INCLUDE_GATE
|
||||
%endif
|
||||
%if (%8) & SAMPLE == SAMPLE
|
||||
%define INCLUDE_SAMPLES
|
||||
%endif
|
||||
%endmacro
|
||||
|
||||
struc su_osc_ports
|
||||
@ -119,9 +123,39 @@ endstruc
|
||||
%define GATESLOW(val) val
|
||||
%define GATESHIGH(val) val
|
||||
%define COLOR(val) val
|
||||
%define SAMPLENO(val) val
|
||||
%define SHAPE(val) val
|
||||
%define FLAGS(val) val
|
||||
|
||||
;-------------------------------------------------------------------------------
|
||||
; Sample related defines
|
||||
;-------------------------------------------------------------------------------
|
||||
|
||||
%macro SU_BEGIN_SAMPLE_OFFSETS 0
|
||||
SECT_DATA(susamoff)
|
||||
|
||||
EXPORT MANGLE_DATA(su_sample_offsets)
|
||||
%endmacro
|
||||
|
||||
%macro SAMPLE_OFFSET 3
|
||||
dd %1
|
||||
dw %2
|
||||
dw %3
|
||||
%endmacro
|
||||
|
||||
%define START(val) val
|
||||
%define LOOPSTART(val) val
|
||||
%define LOOPLENGTH(val) val
|
||||
|
||||
%define SU_END_SAMPLE_OFFSETS
|
||||
|
||||
struc su_sample_offset ; length conveniently 8, so easy to index
|
||||
.start resd 1
|
||||
.loopstart resw 1
|
||||
.looplength resw 1
|
||||
.size
|
||||
endstruc
|
||||
|
||||
;-------------------------------------------------------------------------------
|
||||
; NOISE structs
|
||||
;-------------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user