Audio Generation + WINC1500 + Multithreading

Discussions around product based on ARM Cortex M7 core.

Moderator: nferre

Posts: 4
Joined: Thu Sep 10, 2015 5:44 pm

Audio Generation + WINC1500 + Multithreading

Tue Dec 15, 2015 5:59 pm


My project consists of generating sounds on the fly, like pure tones or band noises, and receiving parameters through a webssocket (I have implemented a tcp server and decoded the messages following the standard). For example, one possibility could be changing the frequency of the pure tone using a slider in a web app and being able to hear the changes at the same time you move the slider. I am using a winc1500 and a samv71 Xplained Board.
The main loop, where the problem occurs, is the following:

while (1) {
/* Handle pending events from network controller. */

if (wifi_connected == M2M_WIFI_CONNECTED) {
if (tcp_server_socket < 0) {
//Open TCP server socket
if ((tcp_server_socket = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
//printf("main: failed to create TCP server socket error!\r\n");

//Bind service
bind(tcp_server_socket, (struct sockaddr *)&addr, sizeof(struct sockaddr_in));

PlayGeneration is the function that fills the buffer which will be used by the SSC interrupt method to send the new values to the audio codec. As my sample rate is 48000 Hz, PlayGeneration should be called every 20 uSeconds and finish it task before that time.
The problem arises when messages are being exchanged in the web socket as it takes a lot of time. So, weird noises are noticeable when that happens. I have measured how much time it takes to receive a socket message and send an echo response and it was 20 ms in its worst case.

How can I overcome this problem?

I have thought two possible solutions to this:
1- I could move playGeneration to the SSC_Handler routine but the device will be most of the time inside the ISR which is not desirable. Though, it's the highest priority task... I think this may work.
2- Using two threads/tasks with the help of FreeRTOS for example. One would consist only of this line:


(to handle incoming websocket messages)

The other task will be fired by the ISR of the SSC and will not yield until it ends the calculations. It will only have: playGeneration();

What do you think? Am I missing something in the first task?
I am unsure about having to modify inner layers of the winc1500 host driver...

Thanks in advance.

Return to “SAM Cortex-M7 MCU”

Who is online

Users browsing this forum: No registered users and 2 guests