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:

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:

m2m_wifi_handle_events(NULL);

(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...