Skip to content

Commit 4e870dc

Browse files
committed
fixing amyboard examples
1 parent 1ed23ed commit 4e870dc

1 file changed

Lines changed: 4 additions & 95 deletions

File tree

tulip/amyboardweb/static/examples.js

Lines changed: 4 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ midi.config.add_synth(synth.PatchSynth(6, 256))
1212
'c':`
1313
# some stuart dempster in your browser
1414
import music, tulip
15-
amy.load_sample(tulip.root_dir()+'sys/ex/bcla3.wav', patch=50)
16-
s = synth.OscSynth(wave=amy.PCM, patch=50)
15+
amy.load_sample(tulip.root_dir()+'sys/ex/bcla3.wav', preset=50)
16+
s = synth.OscSynth(wave=amy.PCM, preset=50)
1717
for i,note in enumerate(music.Chord('F:min7').midinotes()):
1818
s.note_on(note+24, 1, time=i*4000)
1919
s.note_off(note+24, time=20000)
@@ -72,96 +72,5 @@ js.fetch(url).then(lambda r: r.text()).then(lambda x: json.loads(x)).then(lambda
7272
amy.send(osc=30, pan=0, wave=amy.AUDIO_IN0, vel=1)
7373
amy.send(osc=31, pan=1, wave=amy.AUDIO_IN1, vel=1)
7474
amy.echo(level=1, delay_ms=400, max_delay_ms=1500, feedback=0.8, filter_coef=None)
75-
`},{
76-
't':'music',
77-
'd':'Directly play a wav file',
78-
'c':`
79-
# wav.py
80-
# plays a wavfile from amy external audio
81-
82-
import amy_wave
83-
f = None
84-
try:
85-
f = amy_wave.open(wav_filename,'rb')
86-
except:
87-
print("Upload a wav file and type >>> wav_filename='file.wav' first.")
88-
89-
def cb(x):
90-
frames = f.readframes(256)
91-
if(len(frames)!=1024):
92-
frames = bytes(1024)
93-
tulip.amy_block_done_callback()
94-
tulip.amy_set_external_input_buffer(frames)
95-
96-
if(f is not None):
97-
amy.reset()
98-
amy.send(osc=0,wave=amy.AUDIO_EXT0, pan=0, vel=1)
99-
amy.send(osc=1,wave=amy.AUDIO_EXT1, pan=1, vel=1)
100-
tulip.amy_block_done_callback(cb)
101-
`},{
102-
't':'music',
103-
'd':'Sample audio in and play it as an instrument',
104-
'c':`
105-
# sample.py
106-
# try sampling audio to pcm memorypcm
107-
108-
import tulip, amy, synth, music
109-
110-
buf = bytes()
111-
t = 0
112-
tick_start = 0
113-
ms = 2000
114-
syn = None
115-
116-
def play():
117-
amy.send(reset=amy.RESET_TIMEBASE+amy.RESET_ALL_OSCS)
118-
amy.load_sample_bytes(buf, stereo=True, patch=50, loopstart=0, loopend=int(amy.AMY_SAMPLE_RATE*(ms/1000.0)))
119-
syn = synth.OscSynth(wave=amy.PCM, patch=50)
120-
for i,note in enumerate(music.Chord('F:min7').midinotes()):
121-
syn.note_on(note+24, 1, time=i*1000)
122-
syn.note_off(note+24, time=5000)
123-
124-
def sample(x):
125-
global buf, syn
126-
buf = buf + tulip.amy_get_input_buffer()
127-
if(tulip.ticks_ms() > tick_start + ms):
128-
tulip.amy_block_done_callback()
129-
play()
130-
131-
tick_start = tulip.ticks_ms()
132-
print("Recording for 2s. Make sure audio input is on!")
133-
tulip.amy_block_done_callback(sample)
134-
`
135-
},{
136-
'd':'Generate audio buffers in Python',
137-
't':'music',
138-
'c':`
139-
# makes a sine wave. obviously, it's easier to do this in AMY directly!
140-
# but just showing how to do it for any audio synthesis in python
141-
from ulab import numpy as np
142-
import ulab
143-
freq = 440.0
144-
amp = 32767
145-
lut_size = 512
146-
count = 0
147-
lut = np.array(amp * np.sin(np.linspace(0,2*np.pi,lut_size,endpoint=False)), dtype=np.int16)
148-
# freq/2 because we send stereo buffer in this example
149-
step_size = ((freq/2.0) * lut_size) / float(amy.AMY_SAMPLE_RATE)
150-
index = 0
151-
152-
def cb(x):
153-
global count
154-
t = np.array(np.arange(count*512,count*512+512)*step_size)
155-
samples = ulab.user.arraymodlut(lut, t);
156-
tulip.amy_set_external_input_buffer(samples.tobytes())
157-
if(count==1000): # stop
158-
tulip.amy_block_done_callback()
159-
amy.reset()
160-
count = count + 1
161-
162-
amy.reset()
163-
amy.send(osc=0,wave=amy.AUDIO_EXT0, pan=0, vel=1)
164-
amy.send(osc=1,wave=amy.AUDIO_EXT1, pan=1, vel=1)
165-
tulip.amy_block_done_callback(cb)
166-
`
167-
}]
75+
`}
76+
]

0 commit comments

Comments
 (0)