Skip to content

Instantly share code, notes, and snippets.

@soyoil
Last active September 18, 2020 16:11
Show Gist options
  • Save soyoil/8f588b7a95bc150e1d853dd4a2ae20ef to your computer and use it in GitHub Desktop.
Save soyoil/8f588b7a95bc150e1d853dd4a2ae20ef to your computer and use it in GitHub Desktop.
ゲームボーイのノイズ音源の波形を表示するガバガバプログラム
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