Hi everyone,
I am using a SK-S7G2 board with E2studio 6.2.0 and SSP 1.2.0 to play I2S samples. I manage to play the samples but I would like to know when playback is over before playing other samples. I was planning on using a callback function and the I2S_EVENT_TX_EMPTY event to detect that, but the callback is never called.
Is that the right way to detect when the playback is over, and if yes, why isn't the callback called?
Thanks !
This is my thread configuration:
This is my code, with the callback that never gets called:
#include "song_thread.h"
#include "math.h"
#define FREQUENCY1 400 // frequency of sine wave in Hz
#define AMPLITUDE 1000 // amplitude of sine wave
#define SAMPLERATE 44100 // sample rate in Hz
#define PI 3.14159265
int still_writing;
void song_thread_entry(void)
{
ssp_err_t err;
int16_t *p_buffer1 ;
uint32_t sizebuf=0;
still_writing = 0;
int16_t buff1[SAMPLERATE / FREQUENCY1];
sizebuf = sizeof(buff1);
for (uint16_t s=0; s < (SAMPLERATE / FREQUENCY1); s++){
buff1[s] =(int16_t)( sin(2.0 * PI * s / (SAMPLERATE/FREQUENCY1)) * AMPLITUDE); //filling of the PCM sample for a La
}
p_buffer1= buff1;
err = g_sf_audio_playback_hw0.p_api->open(g_sf_audio_playback_hw0.p_ctrl,g_sf_audio_playback_hw0.p_cfg);
if(SSP_SUCCESS!=err){
tx_thread_sleep(10);
}
err= g_sf_audio_playback_hw0.p_api->start( g_sf_audio_playback_hw0.p_ctrl);
if(SSP_SUCCESS!=err){
tx_thread_sleep(10);
}
while (1)
{
if(still_writing != 1) // if the previous write operation has completed...
{
still_writing = 1; // start another writing*/
err=g_sf_audio_playback_hw0.p_api-> play(g_sf_audio_playback_hw0.p_ctrl,p_buffer1,sizebuf );
if(SSP_SUCCESS!=err)
{
tx_thread_sleep(10);
}
}
else // if the previous write operation is still ongoing...
{
tx_thread_sleep (10); // wait for 10 ticks before making another attempt
}
tx_thread_sleep (0);
}
}
void i2s_callback(i2s_callback_args_t * p_args)
{
switch(p_args->event)
{
case I2S_EVENT_TX_EMPTY:
still_writing = 0;
break;
default:
break;
}
}