コード例 #1
0
def blend():
    blend = []
    for i in range(882000):
        t = i / 44100
        s = (math.sin(math.pi * f * t))**6
        y = ((1 - s) * brown_v[i] + s * white[i])
        blend.append(y)
        print(blend)
    stdaudio.playSamples(blend)
    stdaudio.wait()
コード例 #2
0
    curve(x0, y0, xm, ym + delta, var / beta, beta, n - 1)
    curve(xm, ym + delta, x1, y1, var / beta, beta, n - 1)


import stdaudio
import math

SAMPLE_RATE = 44100
CONCERT_A = 440
DURATION = 5

# generate an array with 5 seconds of the A tone
# 44100 * 5 = 220500 samples

num_samples = SAMPLE_RATE * DURATION

# array of samples
samples = []
for i in range(num_samples):
    # time in seconds
    t = i / SAMPLE_RATE
    semitone = math.floor(t)
    f = CONCERT_A * (2**(semitone / 12.0))
    y = math.sin(2.0 * math.pi * f * t)
    samples += [y]

print(samples)
stdaudio.playSamples(samples)
stdaudio.wait()
help(stdaudio)
コード例 #3
0
import math
import stdio  # this is new!
import stdaudio

SPS = 44100
CONCERT_A = 440.0
NOTES_ON_SCALE = 12.0

while not stdio.isEmpty():
    pitch = stdio.readInt()
    duration = stdio.readFloat()
    hz = CONCERT_A * (2.0**(pitch / NOTES_ON_SCALE))
    n = int(SPS * duration)
    note = [0.0] * (n + 1)
    for i in range(n + 1):
        note[i] = math.sin(2.0 * math.pi * i * hz / SPS)
    stdaudio.playSamples(note)

stdaudio.wait()
コード例 #4
0
ファイル: playthattune.py プロジェクト: davidhuizhou/python
# standard audio.

SPS = 44100
CONCERT_A = 440.0
NOTES_ON_SCALE = 12.0

while not stdio.isEmpty():

    pitch = stdio.readInt()
    duration = stdio.readFloat()
    hz = CONCERT_A * (2.0 ** (pitch / NOTES_ON_SCALE))
    n = int(SPS * duration)
    note = stdarray.create1D(n+1, 0.0)
    for i in range(n+1):
        note[i] = math.sin(2.0 * math.pi * i * hz / SPS)
    stdaudio.playSamples(note)

stdaudio.wait()

#-----------------------------------------------------------------------

# python playthattune.py < elise.txt

# python playthattune.py < ascale.txt

# python playthattune.py < entertainer.txt

# python playthattune.py < firstcut.txt

# python playthattune.py < freebird.txt
コード例 #5
0
def tone(hz, duration):
    n = int(44100 * duration)
    note = [0.0] * (n + 1)
    for i in range(n + 1):
        note[i] = math.sin(2.0 * math.pi * i * hz / 44100)
    stdaudio.playSamples(note)
コード例 #6
0
    a = tone(hz, t)
    hi = tone(2*hz, t)
    lo = tone(hz/2, t)
    h = superpose(hi, lo, .5, .5)
    return superpose(a, h, .5, .5)

#-----------------------------------------------------------------------

# Read sound samples from standard input, add harmonics, and play
# the resulting the sound to standard audio.

while not stdio.isEmpty():
    pitch = stdio.readInt()
    duration = stdio.readFloat()
    a = note(pitch, duration)
    stdaudio.playSamples(a)
stdaudio.wait()

#-----------------------------------------------------------------------

# python playthattunedeluxe.py < ascale.txt

# python playthattunedeluxe.py < elise.txt

# python playthattunedeluxe.py < entertainer.txt

# python playthattunedeluxe.py < firstcut.txt

# python playthattunedeluxe.py < freebird.txt

# python playthattunedeluxe.py < looney.txt
コード例 #7
0
ファイル: oceanWaves.py プロジェクト: ShehabSN/Ocean-Waves
    recur(arr, i0, tm, new_variance, scale)
    recur(arr, tm, i1, new_variance, scale)

    return arr


arr = [0] * 882000
variance = 0.05

counter = 1
for i in range(20):
    recur(arr, i * 44099, 44099 * counter, variance, hurst)
    counter += 1

whitearr = []


def generate_white():
    for i in range(882000):
        whitearr.append(random.uniform(float(-0.25), float(0.25)))
    return (whitearr)


whitearr = generate_white()
waves = 882000 * [0]
for i in range(882000):
    blend = (math.sin(math.pi * 0.20 * i / 44100)**6)
    waves[i] = ((1 - blend) * arr[i] + blend * whitearr[i])

stdaudio.playSamples(waves)
コード例 #8
0
    hi = tone(2 * hz, t)
    lo = tone(hz / 2, t)
    h = superpose(hi, lo, .5, .5)
    return superpose(a, h, .5, .5)


#-----------------------------------------------------------------------

# Read sound samples from standard input, add harmonics, and play
# the resulting the sound to standard audio.

while not stdio.isEmpty():
    pitch = stdio.readInt()
    duration = stdio.readFloat()
    a = note(pitch, duration)
    stdaudio.playSamples(a)
stdaudio.wait()

#-----------------------------------------------------------------------

# python playthattunedeluxe.py < ascale.txt

# python playthattunedeluxe.py < elise.txt

# python playthattunedeluxe.py < entertainer.txt

# python playthattunedeluxe.py < firstcut.txt

# python playthattunedeluxe.py < freebird.txt

# python playthattunedeluxe.py < looney.txt
コード例 #9
0
from p3 import GuitarString
import stdaudio
a_string = GuitarString(440.00)
b = a_string.pluck()
print(b)
c = a_string.tick()
print(c)
stdaudio.playSamples(100)
コード例 #10
0
	def play(self):
		stdaudio.playSamples(samples)
コード例 #11
0
b0=0
b1=last
w0=0
w1=last

hurst_exp=0.5
variance=0.05
scale=2.0**(2.0*hurst_exp)
frequency=0.25
amplitude=0.25

white(white_noise, w0, w1, amplitude)

#separate it into 10 pieces (each one is 88200 length long)
bridge(brown_noise, 0, 88200, variance, scale)
bridge(brown_noise, 88200, 176400, variance, scale)
bridge(brown_noise, 176400, 264600, variance, scale)
bridge(brown_noise, 264600, 352800, variance, scale)
bridge(brown_noise, 352800, 441000, variance, scale)
bridge(brown_noise, 441000, 529200, variance, scale)
bridge(brown_noise, 529200, 617400, variance, scale)
bridge(brown_noise, 617400, 705600, variance, scale)
bridge(brown_noise, 705600, 793800, variance, scale)
bridge(brown_noise, 793800, 881999, variance, scale)
#check and makesure the values are right

final(final_array)


stdaudio.playSamples(final_array)
stdaudio.wait()