Help me developping this code

define function slice ( array , start , final )
begin
set dur = final - start
set sequence = make-array (  dur )
set i = 0
loop
repeat dur
set sequence[i] = array[start + i]
set i = i + 1
end
return sequence
end

define function slice_replace ( array , start , final , chunk  )
begin
set dur = final - start
set i = 0
loop
repeat dur
set array[ start + i ] = chunk[ i ]
set i = i + 1
end
return array
end

define function slice_add ( array , start , final , chunk  )
begin
set dur = final - start
set i = 0
loop
repeat dur
set array[ start + i ] = array[ start + i ] + chunk[ i ]
set i = i + 1
end
return array
end



define function band ( sound , freq ,ran )
begin
set out = sound
loop
repeat 20
set out = reson ( out ,  freq , ran , 1)
end
return out
end

set len = snd-length ( *track* ,  48000 * 10000000  ) 
set audio = make-array ( len )
set i = 0
loop
repeat len
set audio [i] = 0
set i = i + 1
end

set tbands = 7
;set spectre = make-array ( tbands )
set steps = 100


set nsamples = snd-stop-time ( *track* ) * snd-srate( *track* )
set i = 0
loop
repeat tbands
set freq = 500 + (i * 1000)
set shift = ( 7500 - freq ) / freq
set spectre =  band ( *track* , freq  , 1000 )

set n = 0
set chunk = len / steps
set s = 0
loop
repeat steps
set spectre = pitshift ( spectre, shift / steps , 1 ) 
set spectre_array = snd-samples (spectre , len )
set spectre_array [0] = chunk
set spectre_array [1] = len
set spectre_array [2] = len / steps
set spectre_array [3] = steps
set sequence = slice ( spectre_array , n , n + chunk )
set audio = slice_add ( audio , n , n + chunk , sequence )
set s = s + 1
set n = n + chunk
end
set i = i + 1
end    

return snd-from-array ( audio , snd-t0 ( *track* ) , snd-srate( *track* ), len )

Why am I getting this error?:

error: bad argument type - #(6629 662977 6629 700 0 0 0 ... 0 0 0)
Call traceback:
    MAIN() at line 91

Mister Nyquist, just give me back my sound and stop asking for password-alike parameters I don’t care about!

Sorry, I don’t speak SAL.

Are you a bot? It’s the same than lisp but with less (), and that’s why i use it.

Ha ha, no I’m not a bot. I was one of the developers / support / documentation people working on Audacity for 15 years. I was working with Nyquist from before SAL was invented. I retired after muse group took over Audacity. I still drop by the forum from time to time.

1 Like

Don’ you think it’s time for a python implementation of nyquist? way slower, but much more functional. A simple wrapper at least.

I wouldn’t say a Python implementation would be more functional than the current Lisp version (unless, of course, it actually included more functionality than the Lisp version, but if that functionality is needed then why wouldn’t it just be added to the Lisp version?).

Lisp itself is a very powerful and expressive language, and it can be very enlightening to learn it (I sometimes joke that other programming languages keep getting closer to Lisp, but it’s actually true to a point). Nyquist is based on XLISP which is close to Common Lisp, so if you learn Common Lisp you’ll do well with Nyquist.

The arguments for snd-from-array in the final line should be:
snd-from-array(t0, sr, array)

See: Nyquist Functions