Last active
September 18, 2020 16:11
-
-
Save soyoil/8f588b7a95bc150e1d853dd4a2ae20ef to your computer and use it in GitHub Desktop.
ゲームボーイのノイズ音源の波形を表示するガバガバプログラム
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import matplotlib.pyplot as plt | |
def noize(shortFreq): | |
reg = 0xffff | |
output = 1 | |
fre = list() | |
for i in range(300): | |
if(reg == 0): | |
reg = 1 | |
reg += reg + (((reg >> (6 if shortFreq else 14)) ^ (reg >> (5 if shortFreq else 13))) & 1) | |
output = output ^ (reg & 1) | |
fre.append((output-0.5)*-1) | |
return fre | |
xmin = 0 | |
xmax = 300 | |
fig = plt.figure(figsize=(20, 3)) | |
axes1 = fig.add_subplot(1, 2, 1) | |
x=np.arange(xmin, xmax, 1) | |
y=noize(False) | |
plt.xlim(0, 300) | |
plt.ylim(-1, 1) | |
plt.xticks(color="None") | |
plt.yticks(color="None") | |
plt.tick_params(length=0) | |
axes1.plot(x, y, label="Long period noise") | |
plt.legend(loc='upper left') | |
axes1 = fig.add_subplot(1, 2, 2) | |
x=np.arange(xmin, xmax, 1) | |
y=noize(True) | |
plt.xlim(0, 300) | |
plt.ylim(-1, 1) | |
plt.xticks(color="None") | |
plt.yticks(color="None") | |
plt.tick_params(length=0) | |
axes1.plot(x, y, label="Short period noise") | |
plt.legend(loc='upper left') | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment