Audio recording - and irq_handler


#1

Hello,

I tried to write an application which records an audio input in aPCM Sample array.
But it didnt works. The ListenLowIrqHandler is never called also the AudioEventHandler.
For my confusion the PCM Record and Play Sample works fine, but i cannot find the big difference?

#include "adl_global.h"

// ----------------------------------------------------------------------------
// constants
// ----------------------------------------------------------------------------

const u16 wm_apmCustomStackSize         = 1024;
const u32 wm_apmIRQLowLevelStackSize    = 1024;
const u32 wm_apmIRQHighLevelStackSize   = 1024;

#define AT_CMD_START    "AT+START"


// ----------------------------------------------------------------------------
// local variables
// ----------------------------------------------------------------------------

s32 appListenLowIrqHandle   = 0;
s32 appListenAudioResource  = 0;

void* StreamBuffer          = NULL;
u32   StreamBufferSize      = 0;

// ----------------------------------------------------------------------------
// local functions
// ----------------------------------------------------------------------------
void AudioEventHandler( s32 audioResource, adl_audioEvents_e event );

bool ListenLowIrqHandler( adl_irqID_e source,
                          adl_irqNotificationLevel_e notificationLevel,
                          adl_irqEventData_t* data );

void AtStartCmdHandler( adl_atCmdPreParser_t* params );

// ----------------------------------------------------------------------------
// main function
// ----------------------------------------------------------------------------

void adl_main ( adl_InitType_e InitType )
{
    TRACE (( 1, "AudioTest2 : Enter Main" ));
    TRACE (( 1, __DATE__ ));
    TRACE (( 1, __TIME__ ));
    
    // subscribe to low-level irq
    appListenLowIrqHandle = adl_irqSubscribe( ListenLowIrqHandler, 
                            ADL_IRQ_NOTIFY_LOW_LEVEL,
                            ADL_IRQ_PRIORITY_LOW_LEVEL,
                            1 );
                      
    if( appListenLowIrqHandle < 0 )
    {
        TRACE (( 2, "ERROR -> appListenLowIrqHandle = %d", appListenLowIrqHandle ));
        return;
    }
    
    // subscribe audio resource for listening
    appListenAudioResource = adl_audioSubscribe( ADL_AUDIO_MICROPHONE, 
                             (adl_audioEventHandler_f) AudioEventHandler,
                             ADL_AUDIO_RESOURCE_OPTION_FORBID_PREEMPTION );
                             
    if( appListenAudioResource < 0 )
    {
        TRACE (( 2, "ERROR -> appListenAudioResource = %d", appListenAudioResource ));
        return;
    }  
    
    // subscribe at command for recording
    s32 sRet;
    sRet = adl_atCmdSubscribe( AT_CMD_START, 
                               (adl_atCmdHandler_t)AtStartCmdHandler, 
                               ADL_CMD_TYPE_ACT );
    
    if( sRet != OK )
    {
        TRACE (( 2, "ERROR -> adl_atCmdSubscribe returns %d", sRet ));
        return;
    }
    
    TRACE (( 1, "AudioTest2 : Leave Main" ));
}


// ----------------------------------------------------------------------------
// implementation of local functions
// ----------------------------------------------------------------------------

void AudioEventHandler( s32 audioResource, adl_audioEvents_e event )
{
    TRACE (( 1, "AudioTest2 : Enter AudioEventHandler" ));
    
    TRACE (( 1, "AudioTest2 : Leave AudioEventHandler" ));
}


bool ListenLowIrqHandler( adl_irqID_e source,
                          adl_irqNotificationLevel_e notificationLevel,
                          adl_irqEventData_t* data )
{
    TRACE (( 1, "AudioTest2 : Enter ListenLowIrqHandler" ));
    
    DUMP ( 4, StreamBuffer, StreamBufferSize );

    TRACE (( 1, "AudioTest2 : Leave ListenLowIrqHandler" ));
    
    return FALSE;
}


void AtStartCmdHandler( adl_atCmdPreParser_t* params )
{
    TRACE (( 1, "AudioTest2 : Enter AtStartCmdHandler" ));
    
    adl_audioGetOption( appListenAudioResource, 
                        ADL_AUDIO_PCM_8K_16B_MONO_BUFFER_SIZE,
                        &StreamBufferSize);
    TRACE (( 3, "StreamBufferSize = %d", StreamBufferSize ));
    
    StreamBuffer = adl_memGet( StreamBufferSize );
    
    s32 sRet = 0;
    sRet = adl_audioStreamListen( appListenAudioResource, 
                                  ADL_AUDIO_PCM_MONO_8K_16B, 
                                  appListenLowIrqHandle,
                                  0,
                                  StreamBuffer );                               
    if( sRet != OK )
        TRACE (( 2, "ERROR -> adl_audioStreamListen returns %d", sRet ));                                
    
    TRACE (( 1, "AudioTest2 : Leave AtStartCmdHandler" ));    
}