note wavelength one or less
This commit is contained in:
parent
db873683d3
commit
e16edef965
32
pgfw/Note.py
32
pgfw/Note.py
|
@ -1,8 +1,12 @@
|
|||
# adapted from Pythoven
|
||||
# https://github.com/phiresky/pythoven
|
||||
|
||||
from random import randint
|
||||
from math import sin, log, pi
|
||||
from array import array
|
||||
|
||||
from pygame.mixer import Sound, get_init, version
|
||||
from pygame import version
|
||||
from pygame.mixer import Sound, get_init
|
||||
|
||||
class Samples(Sound):
|
||||
|
||||
|
@ -17,7 +21,7 @@ class Samples(Sound):
|
|||
self.amplitude = (1 << (self.get_sample_width() * 8 - 1)) - 1
|
||||
|
||||
def get_sample_width(self):
|
||||
return abs(get_init()[1] / 8)
|
||||
return abs(int(get_init()[1] / 8))
|
||||
|
||||
def build(self):
|
||||
pass
|
||||
|
@ -89,32 +93,34 @@ class Note(Samples):
|
|||
|
||||
def store_triangle_wave(self, samples, period):
|
||||
amplitude = self.amplitude
|
||||
coefficient = 4 * amplitude / float(period - 1)
|
||||
for time in xrange(int(round(period / 2.0))):
|
||||
y = int((coefficient * time) - amplitude)
|
||||
samples[time] = y
|
||||
samples[-time - 1] = y
|
||||
if period > 1:
|
||||
coefficient = 4 * amplitude / float(period - 1)
|
||||
for time in range(int(round(period / 2.0))):
|
||||
y = int((coefficient * time) - amplitude)
|
||||
samples[time] = y
|
||||
samples[-time - 1] = y
|
||||
|
||||
def store_saw_wave(self, samples, period):
|
||||
amplitude = self.amplitude
|
||||
for time in xrange(period):
|
||||
samples[time] = int(2 * amplitude / float(period - 1) * time - \
|
||||
amplitude)
|
||||
if period > 1:
|
||||
for time in range(period):
|
||||
samples[time] = int(2 * amplitude / float(period - 1) * time - \
|
||||
amplitude)
|
||||
|
||||
def store_sine_wave(self, samples, period):
|
||||
amplitude = self.amplitude
|
||||
for time in xrange(period):
|
||||
for time in range(period):
|
||||
samples[time] = int(round(sin(time / (period / pi / 2)) * \
|
||||
amplitude))
|
||||
|
||||
def store_dirty_wave(self, samples):
|
||||
amplitude = self.amplitude
|
||||
for time in xrange(len(samples)):
|
||||
for time in range(len(samples)):
|
||||
samples[time] = randint(-amplitude, amplitude)
|
||||
|
||||
def store_square_wave(self, samples, period):
|
||||
amplitude = self.amplitude
|
||||
for time in xrange(period):
|
||||
for time in range(period):
|
||||
if time < period / 2:
|
||||
samples[time] = amplitude
|
||||
else:
|
||||
|
|
Loading…
Reference in New Issue