adjusted buffers
This commit is contained in:
parent
16497b25c0
commit
f9495e0736
1 changed files with 25 additions and 31 deletions
|
|
@ -3,6 +3,7 @@
|
||||||
# SPDX-License-Identifier: MIT
|
# SPDX-License-Identifier: MIT
|
||||||
# Ambient Machine inspired by Yuri Suzuki https://www.yurisuzuki.com/projects/the-ambient-machine
|
# Ambient Machine inspired by Yuri Suzuki https://www.yurisuzuki.com/projects/the-ambient-machine
|
||||||
import os
|
import os
|
||||||
|
import gc
|
||||||
import board
|
import board
|
||||||
import busio
|
import busio
|
||||||
import audiocore
|
import audiocore
|
||||||
|
|
@ -26,8 +27,6 @@ for p in (8,9,10,11,12,4,3,2,1,0):
|
||||||
pin.switch_to_input(pull=Pull.UP)
|
pin.switch_to_input(pull=Pull.UP)
|
||||||
switches.append(Debouncer(pin))
|
switches.append(Debouncer(pin))
|
||||||
|
|
||||||
switch_states = [False] * 20 # list of switch states
|
|
||||||
|
|
||||||
wav_files = []
|
wav_files = []
|
||||||
|
|
||||||
for filename in os.listdir('/samples/'): # on board flash
|
for filename in os.listdir('/samples/'): # on board flash
|
||||||
|
|
@ -36,62 +35,57 @@ for filename in os.listdir('/samples/'): # on board flash
|
||||||
print(filename)
|
print(filename)
|
||||||
|
|
||||||
wav_files.sort() # put in alphabetical/numberical order
|
wav_files.sort() # put in alphabetical/numberical order
|
||||||
|
gc.collect()
|
||||||
# Metro M7 pins for the I2S amp:
|
# Metro M7 pins for the I2S amp:
|
||||||
lck_pin, bck_pin, dat_pin = board.D9, board.D10, board.D12
|
lck_pin, bck_pin, dat_pin = board.D9, board.D10, board.D12
|
||||||
|
|
||||||
audio = audiobusio.I2SOut(bit_clock=bck_pin, word_select=lck_pin, data=dat_pin)
|
audio = audiobusio.I2SOut(bit_clock=bck_pin, word_select=lck_pin, data=dat_pin)
|
||||||
mixer = audiomixer.Mixer(voice_count=len(wav_files), sample_rate=22050, channel_count=1,
|
mixer = audiomixer.Mixer(voice_count=len(wav_files), sample_rate=22050, channel_count=1,
|
||||||
bits_per_sample=16, samples_signed=True, buffer_size=8192)
|
bits_per_sample=16, samples_signed=True, buffer_size=2048)
|
||||||
audio.play(mixer)
|
audio.play(mixer)
|
||||||
|
|
||||||
for i in range(10): # start playing all wavs on loop w levels down
|
for i in range(10): # start playing all wavs on loop w levels down
|
||||||
wave = audiocore.WaveFile(open(wav_files[i], "rb"))
|
wave = audiocore.WaveFile(wav_files[i], bytearray(1024))
|
||||||
mixer.voice[i].play(wave, loop=True)
|
mixer.voice[i].play(wave, loop=True)
|
||||||
mixer.voice[i].level = 0.0
|
mixer.voice[i].level = 0.0
|
||||||
|
|
||||||
|
LOW_VOL = 0.2
|
||||||
|
HIGH_VOL = 0.5
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
for i in range(len(switches)):
|
for i in range(len(switches)):
|
||||||
switches[i].update()
|
switches[i].update()
|
||||||
if i < 5: # first row plays five samples
|
switch_row = i // 5
|
||||||
|
if switch_row == 0: # first row plays five samples
|
||||||
if switches[i].fell:
|
if switches[i].fell:
|
||||||
if switch_states[i+5] is True: # check volume switch
|
if switches[i+5].value is False: # check vol switch (pull-down, so 'False' is 'on')
|
||||||
mixer.voice[i].level = 0.4 # if up
|
mixer.voice[i].level = HIGH_VOL # if up
|
||||||
else:
|
else:
|
||||||
mixer.voice[i].level = 0.2 # if down
|
mixer.voice[i].level = LOW_VOL # if down
|
||||||
switch_states[i] = not switch_states[i]
|
|
||||||
if switches[i].rose:
|
if switches[i].rose:
|
||||||
mixer.voice[i].level = 0.0
|
mixer.voice[i].level = 0.0
|
||||||
switch_states[i] = not switch_states[i]
|
|
||||||
|
|
||||||
elif 4 < i < 10: # second row adjusts volume of first row
|
if switch_row == 1: # second row adjusts volume of first row
|
||||||
if switches[i].fell:
|
if switches[i].fell:
|
||||||
if switch_states[i-5] is True: # raise volume if it is on
|
if switches[i-5].value is False: # raise volume if it is on
|
||||||
mixer.voice[i-5].level = 0.4
|
mixer.voice[i-5].level = HIGH_VOL
|
||||||
switch_states[i] = not switch_states[i]
|
|
||||||
if switches[i].rose:
|
if switches[i].rose:
|
||||||
if switch_states[i-5] is True: # lower volume if it is on
|
if switches[i-5].value is False: # lower volume if it is on
|
||||||
mixer.voice[i-5].level = 0.2
|
mixer.voice[i-5].level = LOW_VOL
|
||||||
switch_states[i] = not switch_states[i]
|
|
||||||
|
|
||||||
elif 9 < i < 15: # third row plays five different samples
|
if switch_row == 2: # third row plays five different samples
|
||||||
if switches[i].fell:
|
if switches[i].fell:
|
||||||
if switch_states[i+5] is True:
|
if switches[i+5].value is False:
|
||||||
mixer.voice[i-5].level = 0.4
|
mixer.voice[i-5].level = HIGH_VOL
|
||||||
else:
|
else:
|
||||||
mixer.voice[i-5].level = 0.2
|
mixer.voice[i-5].level = LOW_VOL
|
||||||
switch_states[i] = not switch_states[i]
|
|
||||||
if switches[i].rose:
|
if switches[i].rose:
|
||||||
mixer.voice[i-5].level = 0.0
|
mixer.voice[i-5].level = 0.0
|
||||||
switch_states[i] = not switch_states[i]
|
|
||||||
|
|
||||||
elif 14 < i < 20: # fourth row adjust volumes of third row
|
if switch_row == 3: # fourth row adjust volumes of third row
|
||||||
if switches[i].fell:
|
if switches[i].fell:
|
||||||
if switch_states[i-5] is True:
|
if switches[i-5].value is False:
|
||||||
mixer.voice[i-10].level = 0.4
|
mixer.voice[i-10].level = HIGH_VOL
|
||||||
switch_states[i] = not switch_states[i]
|
|
||||||
if switches[i].rose:
|
if switches[i].rose:
|
||||||
if switch_states[i-5] is True:
|
if switches[i-5].value is False:
|
||||||
mixer.voice[i-10].level = 0.2
|
mixer.voice[i-10].level = LOW_VOL
|
||||||
switch_states[i] = not switch_states[i]
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue