-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
formatting: Add CPP files to uncrustify check
*.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
1 parent
177caff
commit 1403a5b
Showing
9 changed files
with
1,747 additions
and
1,497 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
379 changes: 208 additions & 171 deletions
379
applications/object_detection/ml_interface.cc
100755 → 100644
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
*/ | ||
|
@@ -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; | ||
} | ||
|
@@ -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 ); | ||
} | ||
} | ||
|
||
|
Oops, something went wrong.