I basically have some source-code(not my own) in python that I would like to understand. It's an anti-aliased xor audio oscillator. I don't know python at all - but it's quite readable except for a few things:
Firstly - the full code:
f0 = 500.
fs = 44100.
T0 = f0/fs
P0 = fs/f0
t = arange(0,3*fs)
L = len(t)
imax = 2**16
# =============================================================================
# SIGNALS
# =============================================================================
# -----------------------------------------------------------------------------
#
def trivial_xor():
s = zeros(L)
sd1 = zeros(L)
sd2 = zeros(L)
s = zeros(L)
w = 0.5
p = 0
for n in range(0,L):
d1 = 2*p - 1
if p < w: d2 = 0
else: d2 = -0.5
x1 = int(d1 * imax) & 0xFFFF
x2 = int(d2 * imax) & 0xFFFF
y = (x1 ^ x2) / float(imax)
s[n] = 2*y - 1
sd1[n] = d1
sd2[n] = d2
p += T0
if p > 1: p -= 1
return s
# -----------------------------------------------------------------------------
#
def trivial_xor_withSources():
s = zeros(L)
sd1 = zeros(L)
sd2 = zeros(L)
s = zeros(L)
w = 0.5
p = 0
for n in range(0,L):
d1 = 2*p - 1
if p < w: d2 = 0
else: d2 = -0.5
x1 = int(d1 * imax) & 0xFFFF
x2 = int(d2 * imax) & 0xFFFF
y = (x1 ^ x2) / float(imax)
s[n] = 2*y - 1
sd1[n] = d1
sd2[n] = d2
p += T0
if p > 1: p -= 1
return s,sd1,sd2
# -----------------------------------------------------------------------------
#
def PTR1_xor():
s = trivial_xor() - 2*T0
#
T1 = 2*T0
P1 = 1/T1
cdc = 1 + T1
p0 = p1 = 0
#
for n in range(0,L):
if p0 < 0.5:
h = 0.5
if p1 < T1:
s[n] = p1*(2 - 2*h*P1) + 2*h - cdc
elif p0 < 0.75:
h = 0.5
if p1 < T1:
s[n] = p1*(2 - 2*h*P1) + 2*h - cdc + 1
else:
h = 1
pp = p1 - 0.5
if pp < T1:
s[n] = pp*(2 - 2*h*P1) + 2*h - cdc
#
p0 += T0
p1 += T1
if p0 > 1: p0 -= 1
if p1 > 1: p1 -= 1
return s
It all seems pretty straight forward - except for what I assume to be the buffers, all I need to know is what is these function(s) in c++?
////////////////////////////////
t = arange(0,3*fs)
L = len(t)
imax = 2**16
////////////////////////////////
def trivial_xor_withSources():
s = zeros(L)
sd1 = zeros(L)
sd2 = zeros(L)
s = zeros(L)
w = 0.5
p = 0
for n in range(0,L):
I'm planning on using this in real time. The rest just look like simple math. Any help greatly appreciated!
Andrew