Difference between revisions of "HackerHotel2019Badge/audio"
Jump to navigation
Jump to search
Line 1: | Line 1: | ||
== HackerHotel2019 Badge Audio API == | == HackerHotel2019 Badge Audio API == | ||
+ | |||
+ | ===Audio API=== | ||
Enjoying audio is easy. | Enjoying audio is easy. | ||
− | < | + | <nowiki>import audio |
audio.volume(11) | audio.volume(11) | ||
− | audio.play_mp3_stream('https://badge.team/RoccoW_-_06_-_Pumped.mp3')</ | + | audio.play_mp3_stream('https://badge.team/RoccoW_-_06_-_Pumped.mp3')</nowiki> |
For streaming audio, a wifi connection is of-course needed. | For streaming audio, a wifi connection is of-course needed. | ||
Line 18: | Line 20: | ||
<nowiki>audio.mixer_ctl_0(-128, 0) | <nowiki>audio.mixer_ctl_0(-128, 0) | ||
audio.mixer_ctl_1(128, 128)</nowiki> | audio.mixer_ctl_1(128, 128)</nowiki> | ||
+ | |||
+ | ===Full audio API=== | ||
+ | |||
+ | <nowiki>audio.play_mp3_file('/media/icq.mp3') play a local mp3 file. | ||
+ | audio.play_mp3_stream('http://streams.pinguinradio.com/PinguinRadio320.mp3') play a remote mp3 file or stream. | ||
+ | audio.is_playing() returns True when audio is playing. | ||
+ | audio.stop() stops audio from playing. | ||
+ | audio.volume() returns current volume level (0-128). | ||
+ | audio.volume(n) sets the current volume level. | ||
+ | audio.mixer_ctl_0(n, m) configures the right audio signal. | ||
+ | audio.mixer_ctl_0(n, m) configures the left audio signal.</nowiki> |
Revision as of 15:35, 11 February 2019
HackerHotel2019 Badge Audio API
Audio API
Enjoying audio is easy.
import audio audio.volume(11) audio.play_mp3_stream('https://badge.team/RoccoW_-_06_-_Pumped.mp3')
For streaming audio, a wifi connection is of-course needed.
Mixer ctl
Since the audio jack is reversed on the badges, and we don't want to force you to do a hardware modification, in software we "invert" channel 0 and add left and right to channel 1, this fixes the audio issue for passive headphones.
NB: This is automatically done by the firmware after the day 0 OTA. You can chose to disable this mod or use the mixer_ctl api for other effects like balance between left and right, or swapping channels.
audio.mixer_ctl_0(-128, 0) audio.mixer_ctl_1(128, 128)
Full audio API
audio.play_mp3_file('/media/icq.mp3') play a local mp3 file. audio.play_mp3_stream('http://streams.pinguinradio.com/PinguinRadio320.mp3') play a remote mp3 file or stream. audio.is_playing() returns True when audio is playing. audio.stop() stops audio from playing. audio.volume() returns current volume level (0-128). audio.volume(n) sets the current volume level. audio.mixer_ctl_0(n, m) configures the right audio signal. audio.mixer_ctl_0(n, m) configures the left audio signal.