Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When delay is used more than twice in the function, the bytecode will not generate "SHIFTSTATE" correctly #101

Open
tomoyanonymous opened this issue Nov 20, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@tomoyanonymous
Copy link
Collaborator

minimal example

fn twodelay(x,y){
    (delay(1000,x,1.0),delay(2000,y,2.0))
}
fn dsp(){
    let (x1,y1) = twodelay(0.0,0.0)
    let (x2,y2) = twodelay(1.0,1.0)
    (x1+x2,y1+y2)
}

and bytecode. In "twodelay" , "SHIFTSTATE" should be called but not.

_mimium_global
nparams:0 nret: 0
upindexes: []  state_size: 0  
constants:  []
instructions:
  ret0
twodelay
nparams:2 nret: 2
upindexes: []  state_size: 3006  
constants:  []
instructions:
  mov        4 0
  movimmF    5 1
  delay      4 4 5
  mov        2 4
  mov        4 1
  movimmF    5 2
  delay      4 4 5
  mov        3 4
  ret        2 2
dsp
nparams:0 nret: 2
upindexes: []  state_size: 6012  
constants:  [1]
instructions:
  movimmF    2 0
  movimmF    3 0
  movc       4 0
  mov        5 4
  mov        6 2
  mov        7 3
  call       5 2 2
  mov        0-1 5-6
  movimmF    4 1
  movimmF    5 1
  shiftsttpos 3006
  movc       6 0
  mov        7 6
  mov        8 4
  mov        9 5
  call       7 2 2
  mov        2-3 7-8
  mov        6 0
  mov        7 2
  addf       6 6 7
  mov        4 6
  mov        6 1
  mov        7 3
  addf       6 6 7
  mov        5 6
  shiftsttpos -3006
  ret        4 2
ext_fun:
""
globals:
[]strings:  []
@tomoyanonymous tomoyanonymous added the bug Something isn't working label Nov 20, 2024
@tomoyanonymous
Copy link
Collaborator Author

Other examples.

fn fbdelay(input,time,fb,mix){
    input*mix + (1.0-mix) * delay(40001.0,(input+self*fb),time)
}

fn dsp(){
    let l = fbdelay(0.0,40000.0,0.9,0.5)
    let r = fbdelay(1.0,10000.0,0.2,0.6)
    (l,r)
}

Bytecode. Order of negative& positive offsets in "dsp" are weird. And where the number 25531 came from?

_mimium_global
nparams:0 nret: 0
upindexes: []  state_size: 0  
constants:  []
instructions:
  ret0
fbdelay
nparams:4 nret: 1
upindexes: []  state_size: 40005  
constants:  []
instructions:
  getstate   4 1
  mov        5 0
  mov        6 3
  mulf       5 5 6
  movimmF    6 1
  mov        7 3
  subf       6 6 7
  mov        7 0
  mov        8 4
  mov        9 2
  mulf       8 8 9
  addf       7 7 8
  mov        8 1
  shiftsttpos 1
  delay      7 7 8
  mulf       6 6 7
  addf       5 5 6
  shiftsttpos -1
  getstate   6 1
  setstate   5 1
  ret        6 1
dsp
nparams:0 nret: 2
upindexes: []  state_size: 80010  
constants:  [4606281698874543309, 1, 4596373779694328218, 4603579539098121011]
instructions:
  movimmF    1 0
  movimmF    2 40000
  movc       3 0
  movimmF    4 0.5
  movc       5 1
  mov        6 5
  mov        7 1
  mov        8 2
  mov        9 3
  mov        10 4
  call       6 4 1
  mov        0 6
  movimmF    2 1
  movimmF    3 10000
  movc       4 2
  movc       5 3
  shiftsttpos -25531
  movc       6 1
  mov        7 6
  mov        8 2
  mov        9 3
  mov        10 4
  mov        11 5
  call       7 4 1
  mov        1 7
  mov        4 0
  mov        2 4
  mov        4 1
  mov        3 4
  shiftsttpos 25531
  ret        2 2
ext_fun:
""
globals:
[]strings:  []

@tomoyanonymous
Copy link
Collaborator Author

tomoyanonymous commented Nov 20, 2024

Ah, this 25531 came from the limit of the offset size, which is represented as i16...
I merged popstate/pushstate into shiftstate in Bytecode but we should split this again to maximize the max delay size.
If we can use unsigned 24bit integer for push/popstate, the maximum size of the delay is 16777216, which is about 175 seconds in 96kHz. I think this is sufficient value.

@tomoyanonymous
Copy link
Collaborator Author

u24 can be represented with uX crate. https://github.com/rust-ux/uX

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant