Skip to content

Instantly share code, notes, and snippets.

@vv111y
Created April 26, 2018 03:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vv111y/ec3ba9a299406a1d84deabd9477459ea to your computer and use it in GitHub Desktop.
Save vv111y/ec3ba9a299406a1d84deabd9477459ea to your computer and use it in GitHub Desktop.
def windowfn(X):
return X
def MDCT(X, blocksize=64):
originalN = len(X)
N = blocksize
# zero pad the signal right away. Calls within FFT functions will be
# effectively ignored.
nzeros, X = padData(X)
# Length of padded X
newN = len(X)
numBlocks = newN//blocksize
state = [0]*2*N
result = []
# for block in range(0,N,blocksize):
# for block in X[0:N:blocksize]:
for i in range(numBlocks):
temp = windowfn(X[i*N:(i+1)*N])
state = [0]*2*N
for i in range(N//2):
state[i] = -temp[N//2+i] - temp[N//2+i]
state[N//2+i] = state[N+i] - state[2*N-i-1]
for i in range(N):
state[N+i] = temp[i]
state = DCT4(state)
result.extend(state[:N])
return result
def iMDCT(X, blocksize=64):
# zero padding not done. It is assumed this came from an MDCT
# and will be correct size
N = blocksize
newN = len(X)
numBlocks = newN//blocksize
# right now assuming sin windowfn
normalfactor = N
state = [0]*2*N
result = []
for i in range(numBlocks):
temp = windowfn(X[i*N:(i+1)*N])
for i in range(N//2):
state[i] = -state[N + N//2 -i -1]
state[N//2 + i] = -state[N + i]
for i in range(N):
state[N+i] = temp[i]
# ? should this be iDCT4, or just DCT4
state = iDCT4(state)
for i in range(N//2):
state[i] = (state[i] + state[N + N//2 +1]) / normalfactor
state[N//2 + i] = (state[N//2 + i] + state[2*N - i - 1]) / normalfactor
result.extend(state[:N])
return result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment