You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
## Low level sample access and direct audio playback
547
+
548
+
You can access the audio input (`AUDIO_IN0/1`) sample buffer per frame (on Tulip Desktop, Web, and future devices with audio input support), and you can also set two external audio channels (`AUDIO_EXT0/1`) from Python. This lets you synthesize audio in Python, or do things like stream WAV files from disk to the audio output.
549
+
550
+
To do so, you need to register an AMY frame callback in Tulip. In this example, we open a WAV file and read it 256 frames per block, and set those frames to the EXT0/1 oscillators, which we initialize as AMY oscillators 0 and 1, with their pan set to left and right.
551
+
552
+
```python
553
+
# Play a wav file through AMY, streaming from disk
554
+
import amy_wave
555
+
f = amy_wave.open(wav_filename,'rb')
556
+
557
+
defcb(x):
558
+
frames = f.readframes(256)
559
+
if(len(frames)!=1024): # file done. stop the AMY frame callback.
560
+
frames =bytes(1024)
561
+
tulip.amy_block_done_callback()
562
+
# Sets the stereo channel buffer EXT0/EXT1 from the frames bytes
563
+
tulip.amy_set_external_input_buffer(frames)
564
+
565
+
amy.reset()
566
+
amy.send(osc=0,wave=amy.AUDIO_EXT0, pan=0, vel=1)
567
+
amy.send(osc=1,wave=amy.AUDIO_EXT1, pan=1, vel=1)
568
+
tulip.amy_block_done_callback(cb)
569
+
```
570
+
571
+
To sample incoming audio (on devices that support it), use `tulip.amy_get_input_buffer`:
572
+
573
+
```python
574
+
buf =bytes()
575
+
tick_start =0
576
+
ms =2000
577
+
578
+
defsample(x):
579
+
global buf
580
+
buf = buf + tulip.amy_get_input_buffer()
581
+
# stop "recording" to buf after ms
582
+
if(tulip.ticks_ms() > tick_start + ms):
583
+
tulip.amy_block_done_callback()
584
+
play()
585
+
586
+
tick_start = tulip.ticks_ms()
587
+
print("Recording for 2s. Make sure audio input is on!")
588
+
tulip.amy_block_done_callback(sample)
589
+
# Then buf will have stereo frames of audio to do whatever you want with.
590
+
```
591
+
592
+
Please note: on Tulip CC hardware, you do not have much compute time left per block to do much. Reading files, saving to memory or doing simple synthesis works, but most anything more complicated you should write your effects / synthesis code in C, as part of AMY.
593
+
546
594
## Music sequencer
547
595
548
596
Tulip is always running AMY's live sequencer, which allows you to have multiple music programs running sharing a common clock.
0 commit comments