-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Paul Guyot <pguyot@kallisys.net>
- Loading branch information
Showing
11 changed files
with
130 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
.rebar3 | ||
_build | ||
_checkouts | ||
_vendor | ||
.eunit | ||
*.o | ||
*.beam | ||
*.plt | ||
*.swp | ||
*.swo | ||
.erlang.cookie | ||
ebin | ||
log | ||
erl_crash.dump | ||
.rebar | ||
logs | ||
.idea | ||
*.iml | ||
rebar3.crashdump | ||
*~ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
play_mp3_i2s | ||
===== | ||
|
||
Sample code to plan an MP3 sound on an I2S card. | ||
|
||
It was tested with an esp32c3 card connected to a MAX98357A module. | ||
|
||
The MAX98357A module is connected to the following esp32c3 gpios: | ||
|
||
- LRCLK: gpio 7 | ||
- BCLK: gpio 6 | ||
- DIN: gpio 5 | ||
|
||
The MAX98357A module doesn't require any MCLK, so this example doesn't | ||
configure a gpio for it. | ||
|
||
Build and flash | ||
--------------- | ||
|
||
$ rebar3 atomvm esp32_flash -p /dev/cu.usbmodem* |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{erl_opts, [debug_info]}. | ||
{deps, []}. | ||
|
||
{shell, [ | ||
% {config, "config/sys.config"}, | ||
{apps, [play_mp3_i2s]} | ||
]}. | ||
{plugins, [ | ||
atomvm_rebar3_plugin | ||
]}. | ||
{profiles, [ | ||
{check, [ | ||
{plugins, [erlfmt]} | ||
]} | ||
]}. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[]. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{application, play_mp3_i2s, [ | ||
{description, "AtomVM MP3 player"}, | ||
{vsn, "0.1.0"}, | ||
{registered, []}, | ||
{applications, [ | ||
kernel, | ||
stdlib | ||
]}, | ||
{env, []}, | ||
{modules, []}, | ||
|
||
{licenses, ["MIT"]}, | ||
{links, []} | ||
]}. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
%%%------------------------------------------------------------------- | ||
%% @doc Example code to play an MP3 file over i2s | ||
%% @end | ||
%%%------------------------------------------------------------------- | ||
|
||
-module(play_mp3_i2s). | ||
|
||
-export([start/0]). | ||
|
||
%% GPIO configuration | ||
|
||
-define(I2S_LRC_GPIO, 7). | ||
-define(I2S_BCLK_GPIO, 6). | ||
-define(I2S_DIN_GPIO, 5). | ||
|
||
start() -> | ||
io:format("Play MP3 using AtomVM ESP ADF\n"), | ||
|
||
AudioPipeline = esp_adf_audio_pipeline:init([]), | ||
|
||
MP3File = atomvm:read_priv(?MODULE, "adf_music.mp3"), | ||
|
||
io:format("MP3File: ~B bytes\n", [byte_size(MP3File)]), | ||
|
||
MP3Decoder = esp_adf_mp3_decoder:init([]), | ||
ok = esp_adf_audio_element:set_read_binary(MP3Decoder, MP3File), | ||
ok = esp_adf_audio_pipeline:register(AudioPipeline, MP3Decoder, <<"mp3">>), | ||
|
||
I2SOutput = esp_adf_i2s_output:init([ | ||
{gpio_bclk, ?I2S_BCLK_GPIO}, {gpio_lrclk, ?I2S_LRC_GPIO}, {gpio_dout, ?I2S_DIN_GPIO} | ||
]), | ||
ok = esp_adf_audio_pipeline:register(AudioPipeline, I2SOutput, <<"i2s">>), | ||
|
||
ok = esp_adf_audio_pipeline:link(AudioPipeline, [<<"mp3">>, <<"i2s">>]), | ||
|
||
ok = esp_adf_audio_pipeline:run(AudioPipeline), | ||
|
||
timer:sleep(5000), | ||
|
||
ok = esp_adf_audio_pipeline:stop(AudioPipeline), | ||
ok = esp_adf_audio_pipeline:wait_for_stop(AudioPipeline), | ||
ok = esp_adf_audio_pipeline:terminate(AudioPipeline), | ||
ok = esp_adf_audio_pipeline:unregister(AudioPipeline, MP3Decoder), | ||
ok = esp_adf_audio_pipeline:unregister(AudioPipeline, I2SOutput), | ||
|
||
ok. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
{erl_opts, [debug_info]}. | ||
{deps, []}. | ||
{plugins, [atomvm_rebar3_plugin]}. | ||
{profiles, [ | ||
{check, [ | ||
{plugins, [erlfmt]} | ||
]} | ||
]}. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters