Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
ESP32-audioI2S
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
ESP32-audioI2S
Commits
b5ffed41
Unverified
Commit
b5ffed41
authored
Jan 04, 2022
by
Wolle
Committed by
GitHub
Jan 04, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add files via upload
parent
8b1b4a98
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
106 additions
and
68 deletions
+106
-68
examples/OwnAudioTask/separate_audiotask.ino
examples/OwnAudioTask/separate_audiotask.ino
+106
-68
No files found.
examples/OwnAudioTask/separate_audiotask.ino
View file @
b5ffed41
...
...
@@ -7,62 +7,81 @@
#define I2S_BCLK 27
#define I2S_LRC 26
/* We create 10 structures and 10 memory areas for the queues.
* Only the pointer to a structure is transferred to the queue.
* The queue therefore only takes up a small amount of memory.
* Since the command is executed with a time delay, the structure cannot be overwritten prematurely.
* However, you can work cyclically. Then a check for a full queue is not necessary. */
Audio
audio
;
struct
audioMessage
{
uint8_t
cmd
;
char
*
txt
;
uint32_t
value
;
}
audioTxMessage
[
10
],
audioRxMessage
;
String
ssid
=
"******"
;
String
password
=
"******"
;
//****************************************************************************************
// A U D I O _ T A S K *
//****************************************************************************************
enum
:
uint8_t
{
SET_VOLUME
,
GET_VOLUME
,
CONNECTTOHOST
,
CONNECTTOFS
};
struct
audioMessage
{
uint8_t
cmd
;
const
char
*
txt
;
uint32_t
value
;
uint32_t
ret
;
}
audioTxMessage
,
audioRxMessage
;
enum
:
uint8_t
{
SET_VOLUME
,
GET_VOLUME
,
CONNECTTOHOST
,
CONNECTTOSD
};
QueueHandle_t
audioSetQueue
=
NULL
;
QueueHandle_t
audioGetQueue
=
NULL
;
void
CreateQueues
(){
audioSetQueue
=
xQueueCreate
(
10
,
sizeof
(
struct
audioMessage
));
audioGetQueue
=
xQueueCreate
(
10
,
sizeof
(
struct
audioMessage
));
}
Audio
audio
;
String
ssid
=
"*****"
;
String
password
=
"*****"
;
void
audioTask
(
void
*
parameter
)
{
CreateQueues
();
if
(
!
audioSetQueue
||
!
audioGetQueue
){
log_e
(
"queues are not initialized"
);
while
(
true
){;}
// endless loop
}
void
AudioPlayer_Task
(
void
*
parameter
)
{
struct
audioMessage
audioRxTaskMessage
;
struct
audioMessage
audioTxTaskMessage
[
10
];
struct
audioMessage
audioTxTaskMessage
;
audio
.
setPinout
(
I2S_BCLK
,
I2S_LRC
,
I2S_DOUT
);
audio
.
setVolume
(
15
);
// 0...21
while
(
true
){
if
(
audioSetQueue
!=
NULL
){
if
(
xQueueReceive
(
audioSetQueue
,
&
audioRxTaskMessage
,
0
)
==
pdPASS
)
{
if
(
audioRxTaskMessage
.
cmd
==
SET_VOLUME
){
log_i
(
"set volume to %d"
,
audioRxTaskMessage
.
value
);
audio
.
setVolume
(
audioRxTaskMessage
.
value
);
}
if
(
audioRxTaskMessage
.
cmd
==
CONNECTTOHOST
){
log_i
(
"new url is %s"
,
audioRxTaskMessage
.
txt
);
audio
.
connecttohost
(
audioRxTaskMessage
.
txt
);
}
if
(
audioRxTaskMessage
.
cmd
==
GET_VOLUME
){
audioTxTaskMessage
[
0
].
cmd
=
GET_VOLUME
;
audioTxTaskMessage
[
0
].
value
=
audio
.
getVolume
();
xQueueSend
(
audioGetQueue
,
&
audioTxTaskMessage
[
0
],
0
);
}
if
(
xQueueReceive
(
audioSetQueue
,
&
audioRxTaskMessage
,
1
)
==
pdPASS
)
{
if
(
audioRxTaskMessage
.
cmd
==
SET_VOLUME
){
audioTxTaskMessage
.
cmd
=
SET_VOLUME
;
audio
.
setVolume
(
audioRxTaskMessage
.
value
);
audioTxTaskMessage
.
ret
=
1
;
xQueueSend
(
audioGetQueue
,
&
audioTxTaskMessage
,
portMAX_DELAY
);
}
else
if
(
audioRxTaskMessage
.
cmd
==
CONNECTTOHOST
){
audioTxTaskMessage
.
cmd
=
CONNECTTOHOST
;
audioTxTaskMessage
.
ret
=
audio
.
connecttohost
(
audioRxTaskMessage
.
txt
);
xQueueSend
(
audioGetQueue
,
&
audioTxTaskMessage
,
portMAX_DELAY
);
}
else
if
(
audioRxTaskMessage
.
cmd
==
CONNECTTOSD
){
audioTxTaskMessage
.
cmd
=
CONNECTTOSD
;
audioTxTaskMessage
.
ret
=
audio
.
connecttoSD
(
audioRxTaskMessage
.
txt
);
xQueueSend
(
audioGetQueue
,
&
audioTxTaskMessage
,
portMAX_DELAY
);
}
else
if
(
audioRxTaskMessage
.
cmd
==
GET_VOLUME
){
audioTxTaskMessage
.
cmd
=
GET_VOLUME
;
audioTxTaskMessage
.
ret
=
audio
.
getVolume
();
xQueueSend
(
audioGetQueue
,
&
audioTxTaskMessage
,
portMAX_DELAY
);
}
else
{
log_i
(
"error"
);
}
}
audio
.
loop
();
if
(
!
audio
.
isRunning
())
vTaskDelay
(
10
);
// yield
}
}
void
AudioPlayer_Init
(
void
)
{
void
audioInit
()
{
CreateQueues
();
xTaskCreatePinnedToCore
(
AudioPlayer_Task
,
/* Function to implement the task */
"
audioplay"
,
/* Name of the task */
audioTask
,
/* Function to implement the task */
"
vs1053play"
,
/* Name of the task */
5000
,
/* Stack size in words */
NULL
,
/* Task input parameter */
2
|
portPRIVILEGE_BIT
,
/* Priority of the task */
...
...
@@ -71,51 +90,70 @@ void AudioPlayer_Init(void) {
);
}
void
CreateQueues
(){
audioSetQueue
=
xQueueCreate
(
10
,
sizeof
(
struct
audioMessage
));
audioGetQueue
=
xQueueCreate
(
10
,
sizeof
(
struct
audioMessage
));
audioMessage
transmitReceive
(
audioMessage
msg
){
xQueueSend
(
audioSetQueue
,
&
msg
,
portMAX_DELAY
);
if
(
xQueueReceive
(
audioGetQueue
,
&
audioRxMessage
,
portMAX_DELAY
)
==
pdPASS
){
if
(
msg
.
cmd
!=
audioRxMessage
.
cmd
){
log_e
(
"wrong reply from message queue"
);
}
}
return
audioRxMessage
;
}
void
audioSetVolume
(
uint8_t
vol
){
audioTxMessage
.
cmd
=
SET_VOLUME
;
audioTxMessage
.
value
=
vol
;
audioMessage
RX
=
transmitReceive
(
audioTxMessage
);
}
uint8_t
audioGetVolume
(){
audioTxMessage
.
cmd
=
GET_VOLUME
;
audioMessage
RX
=
transmitReceive
(
audioTxMessage
);
return
RX
.
ret
;
}
bool
audioConnecttohost
(
const
char
*
host
){
audioTxMessage
.
cmd
=
CONNECTTOHOST
;
audioTxMessage
.
txt
=
host
;
audioMessage
RX
=
transmitReceive
(
audioTxMessage
);
return
RX
.
ret
;
}
bool
audioConnecttoSD
(
const
char
*
filename
){
audioTxMessage
.
cmd
=
CONNECTTOSD
;
audioTxMessage
.
txt
=
filename
;
audioMessage
RX
=
transmitReceive
(
audioTxMessage
);
return
RX
.
ret
;
}
//****************************************************************************************
// S E T U P *
//****************************************************************************************
void
setup
()
{
Serial
.
begin
(
115200
);
WiFi
.
begin
(
ssid
.
c_str
(),
password
.
c_str
());
while
(
WiFi
.
status
()
!=
WL_CONNECTED
)
delay
(
1500
);
audio
.
setPinout
(
I2S_BCLK
,
I2S_LRC
,
I2S_DOUT
);
CreateQueues
();
AudioPlayer_Init
();
int
i
=
0
;
audioTxMessage
[
i
].
cmd
=
CONNECTTOHOST
;
audioTxMessage
[
i
].
txt
=
"http://mp3.ffh.de/radioffh/hqlivestream.mp3"
;
audioTxMessage
[
i
].
value
=
0
;
xQueueSend
(
audioSetQueue
,
&
audioTxMessage
[
i
],
0
);
i
++
;
audioTxMessage
[
i
].
cmd
=
SET_VOLUME
;
audioTxMessage
[
i
].
txt
=
NULL
;
audioTxMessage
[
i
].
value
=
10
;
xQueueSend
(
audioSetQueue
,
&
audioTxMessage
[
i
],
0
);
i
++
;
audioTxMessage
[
i
].
cmd
=
GET_VOLUME
;
audioTxMessage
[
i
].
txt
=
NULL
;
audioTxMessage
[
i
].
value
=
0
;
xQueueSend
(
audioSetQueue
,
&
audioTxMessage
[
i
],
0
);
audioInit
();
audioConnecttohost
(
"http://mp3.ffh.de/radioffh/hqlivestream.mp3"
);
audioSetVolume
(
15
);
log_i
(
"current volume is: %d"
,
audioGetVolume
());
}
void
loop
(){
if
(
audioGetQueue
!=
NULL
){
if
(
xQueueReceive
(
audioGetQueue
,
&
audioRxMessage
,
(
TickType_t
)
0
)
==
pdPASS
)
{
if
(
audioRxMessage
.
cmd
==
GET_VOLUME
){
log_i
(
"current volume is %d"
,
audioRxMessage
.
value
);
}
}
}
//****************************************************************************************
// L O O P *
//****************************************************************************************
void
loop
(){
// your own code here
}
//*****************************************************************************************
// E V E N T S *
//*****************************************************************************************
void
audio_info
(
const
char
*
info
){
Serial
.
print
(
"info "
);
Serial
.
println
(
info
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment