Skip to content

Commit

Permalink
formatting: Add CPP files to uncrustify check
Browse files Browse the repository at this point in the history
*.cc, and *.cpp files were not checked by uncrustify
code formatter tool, these files are now added to be
checked and styled according to uncrustify suggestions.

Signed-off-by: Ahmed Ismail <[email protected]>
  • Loading branch information
AhmedIsmail02 committed Sep 18, 2024
1 parent 177caff commit 1403a5b
Show file tree
Hide file tree
Showing 9 changed files with 1,747 additions and 1,497 deletions.
959 changes: 519 additions & 440 deletions applications/keyword_detection/ml_interface.cc

Large diffs are not rendered by default.

379 changes: 208 additions & 171 deletions applications/object_detection/ml_interface.cc
100755 → 100644

Large diffs are not rendered by default.

125 changes: 66 additions & 59 deletions applications/speech_recognition/dsp/src/dsp_interfaces.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright 2022-2023 Arm Limited and/or its affiliates
/* Copyright 2022-2024 Arm Limited and/or its affiliates
* <[email protected]>
* SPDX-License-Identifier: MIT
*/
Expand Down Expand Up @@ -31,85 +31,92 @@ extern "C" {

static float audio_timestamp = 0.0;

void vSetAudioTimestamp(float timestamp) {
void vSetAudioTimestamp( float timestamp )
{
taskENTER_CRITICAL();
audio_timestamp = timestamp;
taskEXIT_CRITICAL();
}

float xGetAudioTimestamp() {
float xGetAudioTimestamp()
{
taskENTER_CRITICAL();
float timestamp = audio_timestamp;
taskEXIT_CRITICAL();
return timestamp;
}

DspAudioSource::DspAudioSource(const int16_t* audiobuffer, size_t block_count ):
block_count{block_count},
audiobuffer{audiobuffer}
DspAudioSource::DspAudioSource( const int16_t * audiobuffer,
size_t block_count ) :
block_count{ block_count },
audiobuffer{ audiobuffer }
{

}

const int16_t *DspAudioSource::pxGetCurrentBuffer()
const int16_t * DspAudioSource::pxGetCurrentBuffer()
{
#ifndef AUDIO_VSI
// Update block ID
current_block = (current_block + 1) % block_count;
#endif
#ifndef AUDIO_VSI
/* Update block ID */
current_block = ( current_block + 1 ) % block_count;
#endif

return(audiobuffer + current_block*(AUDIO_BLOCK_SIZE/2));
return( audiobuffer + current_block * ( AUDIO_BLOCK_SIZE / 2 ) );
}

#ifdef AUDIO_VSI

void DspAudioSource::vWaitForNewBuffer()
{
xSemaphoreTake( this->semaphore, portMAX_DELAY );
}
void DspAudioSource::vWaitForNewBuffer()
{
xSemaphoreTake( this->semaphore, portMAX_DELAY );
}

void DspAudioSource::prvNewAudioBlockReceived(void* ptr)
{
auto* self = reinterpret_cast<DspAudioSource*>(ptr);
void DspAudioSource::prvNewAudioBlockReceived( void * ptr )
{
auto * self = reinterpret_cast<DspAudioSource *>( ptr );

// Update block ID
self->current_block = self->block_under_write;
self->block_under_write = ((self->block_under_write + 1) % self->block_count);
/* Update block ID */
self->current_block = self->block_under_write;
self->block_under_write = ( ( self->block_under_write + 1 ) % self->block_count );

if ( self->semaphore != NULL )
{
BaseType_t yield = pdFALSE;
// Wakeup task waiting
if(xSemaphoreGiveFromISR(self->semaphore, &yield) == pdTRUE)
if( self->semaphore != NULL )
{
portYIELD_FROM_ISR (yield);
BaseType_t yield = pdFALSE;

/* Wakeup task waiting */
if( xSemaphoreGiveFromISR( self->semaphore, &yield ) == pdTRUE )
{
portYIELD_FROM_ISR( yield );
}
}
}
};

#endif
#endif /* ifdef AUDIO_VSI */

static bool prvDspMlLock(SemaphoreHandle_t ml_fifo_mutex)
static bool prvDspMlLock( SemaphoreHandle_t ml_fifo_mutex )
{
if ( ml_fifo_mutex == NULL ) {
if( ml_fifo_mutex == NULL )
{
return false;
}

if ( xSemaphoreTake( ml_fifo_mutex, portMAX_DELAY ) != pdTRUE ) {
if( xSemaphoreTake( ml_fifo_mutex, portMAX_DELAY ) != pdTRUE )
{
LogError( ( "Failed to acquire ml_fifo_mutex" ) );
return false;
}

return true;
}

static bool prvDspMlUnlock(SemaphoreHandle_t ml_fifo_mutex)
static bool prvDspMlUnlock( SemaphoreHandle_t ml_fifo_mutex )
{
if ( ml_fifo_mutex == NULL ) {
if( ml_fifo_mutex == NULL )
{
return false;
}

if ( xSemaphoreGive( ml_fifo_mutex ) != pdTRUE ) {
if( xSemaphoreGive( ml_fifo_mutex ) != pdTRUE )
{
LogError( ( "Failed to release ml_fifo_mutex" ) );
return false;
}
Expand All @@ -118,50 +125,50 @@ static bool prvDspMlUnlock(SemaphoreHandle_t ml_fifo_mutex)
}


DSPML::DSPML(size_t bufferLengthInSamples ):nbSamples(bufferLengthInSamples)
DSPML::DSPML( size_t bufferLengthInSamples ) : nbSamples( bufferLengthInSamples )
{
bufferA=static_cast<int16_t*>(malloc(bufferLengthInSamples*sizeof(int16_t)));
bufferB=static_cast<int16_t*>(malloc(bufferLengthInSamples*sizeof(int16_t)));
bufferA = static_cast<int16_t *>( malloc( bufferLengthInSamples * sizeof( int16_t ) ) );
bufferB = static_cast<int16_t *>( malloc( bufferLengthInSamples * sizeof( int16_t ) ) );

dspBuffer = bufferA;
mlBuffer = bufferB;
}

DSPML::~DSPML()
{
free(bufferA);
free(bufferB);
free( bufferA );
free( bufferB );
}

void DSPML::vCopyToDSPBufferFrom(int16_t * buf)
void DSPML::vCopyToDSPBufferFrom( int16_t * buf )
{
prvDspMlLock(mutex);
memcpy(dspBuffer,buf,sizeof(int16_t)*nbSamples);
prvDspMlUnlock(mutex);

prvDspMlLock( mutex );
memcpy( dspBuffer, buf, sizeof( int16_t ) * nbSamples );
prvDspMlUnlock( mutex );
}

void DSPML::vCopyFromMLBufferInto(int16_t * buf)
void DSPML::vCopyFromMLBufferInto( int16_t * buf )
{
prvDspMlLock(mutex);
memcpy(buf,mlBuffer,sizeof(int16_t)*nbSamples);
prvDspMlUnlock(mutex);
prvDspMlLock( mutex );
memcpy( buf, mlBuffer, sizeof( int16_t ) * nbSamples );
prvDspMlUnlock( mutex );
}

void DSPML::vSwapBuffersAndWakeUpMLThread()
{
int16_t* tmp;
int16_t * tmp;

prvDspMlLock(mutex);
tmp=dspBuffer;
dspBuffer=mlBuffer;
mlBuffer=tmp;
prvDspMlUnlock(mutex);
prvDspMlLock( mutex );
tmp = dspBuffer;
dspBuffer = mlBuffer;
mlBuffer = tmp;
prvDspMlUnlock( mutex );

BaseType_t yield = pdFALSE;
if (xSemaphoreGiveFromISR(semaphore, &yield) == pdTRUE)

if( xSemaphoreGiveFromISR( semaphore, &yield ) == pdTRUE )
{
portYIELD_FROM_ISR (yield);
portYIELD_FROM_ISR( yield );
}
}

Expand Down
Loading

0 comments on commit 1403a5b

Please sign in to comment.