gpt4 book ai didi

python - c++中的这些python函数?

转载 作者:塔克拉玛干 更新时间:2023-11-03 08:26:33 24 4
gpt4 key购买 nike

<分区>

我基本上有一些我想了解的 python 源代码(不是我自己的)。这是一个抗锯齿异或音频振荡器。我根本不懂 python - 但除了一些事情外,它的可读性很强:

首先 - 完整代码:

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

一切看起来都非常简单 - 除了我假设为缓冲区的内容外,我只需要知道 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):

我打算实时使用它。其余的看起来就像简单的数学。非常感谢任何帮助!

安德鲁

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com