def _initialize_audio(self): if self._audio is None: self._audio = audioio.AudioOut(board.A1) self._mixer = audioio.Mixer(voice_count=VOICE_COUNT, sample_rate=16000, channel_count=1, bits_per_sample=16, samples_signed=True) self._audio.play(self._mixer)
wav = audioio.WaveFile(f) print("%d channels, %d bits per sample, %d Hz sample rate " % (wav.channel_count, wav.bits_per_sample, wav.sample_rate)) # Audio playback object - we'll go with either mono or stereo depending on # what we see in the first file if wav.channel_count == 1: audio = audioio.AudioOut(board.A0) elif wav.channel_count == 2: # audio = audioio.AudioOut(board.A0, right_channel=board.A0) audio = audioio.AudioOut(board.A0) else: raise RuntimeError("Must be mono or stereo waves!") mixer = audioio.Mixer(voice_count=4, sample_rate=wav.sample_rate, channel_count=wav.channel_count, bits_per_sample=wav.bits_per_sample, samples_signed=True) audio.play(mixer) samples = [] # Read the 4 wave files, convert to stereo samples, and store # (show load status on neopixels and play audio once loaded too!) for v in VOICES: wave_file = open(v, "rb") print(v) # OK we managed to open the wave OK sample = audioio.WaveFile(wave_file) # debug play back on load! mixer.play(sample, voice=0) while mixer.playing:
notes = {} WAVE_TYPES = ["sine", "square", "sawtooth", "triangle"] current_wave_type = "sine" for wave_type in WAVE_TYPES: for octave in range(3, 6): for note_letter in note_letters: cur_note = "%s%s" % (note_letter, octave) notes["%s%s" % (wave_type, cur_note)] = audioio.WaveFile( open("notes/%s/%s.wav" % (wave_type, cur_note), "rb")) print(notes) audio = audioio.AudioOut(left_channel=board.A0, right_channel=board.A1) mixer = audioio.Mixer(voice_count=7, sample_rate=8000, channel_count=2, bits_per_sample=16, samples_signed=True) audio.play(mixer) for i, color in enumerate(colors): trellis.pixels[i, 0] = color trellis.pixels[i, 1] = color trellis.pixels[i, 2] = color prev_pressed = [] trellis.pixels[7, 0] = (255, 255, 255) while True: #print(trellis.pressed_keys) cur_keys = trellis.pressed_keys
# Parse the first file to figure out what format its in wave_format = parse_wav(VOICES[0]) print(wave_format) # Audio playback object - we'll go with either mono or stereo depending on # what we see in the first file if wave_format['channels'] == 1: audio = audioio.AudioOut(board.A1) elif wave_format['channels'] == 2: audio = audioio.AudioOut(board.A1, right_channel=board.A0) else: raise RuntimeError("Must be mono or stereo waves!") mixer = audioio.Mixer(voice_count=4, sample_rate=wave_format['sample_rate'], channel_count=wave_format['channels'], bits_per_sample=16, samples_signed=True) audio.play(mixer) samples = [] # Read the 4 wave files, convert to stereo samples, and store # (show load status on neopixels and play audio once loaded too!) for v in range(4): trellis.pixels[(v, 0)] = DRUM_COLOR[v] wave_file = open(VOICES[v], "rb") # OK we managed to open the wave OK for x in range(1, 4): trellis.pixels[(v, x)] = DRUM_COLOR[v] sample = audioio.WaveFile(wave_file) # debug play back on load!
sample_rate = wav.sample_rate print('%d channels, %d bits per sample, %d Hz sample rate ' % (wav.channel_count, wav.bits_per_sample, wav.sample_rate)) # Audio playback object - we'll go with either mono or stereo depending on # what we see in the first file if wav.channel_count == 1: audio = audioio.AudioOut(board.A1) elif wav.channel_count == 2: audio = audioio.AudioOut(board.A1, right_channel=board.A0) else: raise RuntimeError('Must be mono or stereo waves!') mixer = audioio.Mixer(voice_count=2, sample_rate=sample_rate, channel_count=channel_count, bits_per_sample=bits_per_sample, samples_signed=True) audio.play(mixer) # Clear all pixels trellis.pixels.fill(0) # Light up button with a valid sound file attached for i, v in enumerate(SAMPLES): filename = SAMPLE_FOLDER + v[0] try: with open(filename, 'rb') as f: wav = audiocore.WaveFile(f) print( filename,
# Setup and load sound files to be used during the game audiofiles = [ "background_music.wav", "tackle_sound.wav", "firstdown_sound.wav", "referee_whistle_sound.wav", "delay_of_game_sound.wav", "referee_touchdown_sound.wav", "crowd_touchdown_sound.wav" ] wave_f1 = audioio.WaveFile(open(audiofiles[0], "rb")) wave_f2 = audioio.WaveFile(open(audiofiles[1], "rb")) wave_f3 = audioio.WaveFile(open(audiofiles[2], "rb")) wave_f4 = audioio.WaveFile(open(audiofiles[3], "rb")) wave_f5 = audioio.WaveFile(open(audiofiles[4], "rb")) wave_f6 = audioio.WaveFile(open(audiofiles[5], "rb")) wave_f7 = audioio.WaveFile(open(audiofiles[6], "rb")) mixer = audioio.Mixer(voice_count=3, sample_rate=22050, channel_count=1, bits_per_sample=16, samples_signed=True) audio = audioio.AudioOut(board.SPEAKER) #mixer.play(wave_f1, voice=0, loop=True) #mixer.play(wave_f1, voice=0) #Function Modules that generate certain states of the game # Play out of time sound def OutofTime(): audio.play(wave_f4) time.sleep(1) audio.play(wave_f5)
# test all buttons print("Test Buttons") for index, button in enumerate(buttons): print("Push Button " + str(index)) while button.value: pass print(str(i)) print("Button " + str(index) + " works.") print("All buttons work.") # create mixer object with the number of voices required mixer = audioio.Mixer(voice_count=VOICE_COUNT, sample_rate=SAMPLE_RATE, channel_count=1, bits_per_sample=BIT_DEPTH, samples_signed=True) # start outputing the mixer to the DAC audio_pin.play(mixer) was_released = [] for i in buttons: was_released.append(True) # main body loop # check buttons and play sample in mixer while True: for index, button in enumerate(buttons): if not button.value and was_released[index]: