#ifdef MY_CODE
/*
* Allocate static stack buffers inside the high-speed DTCM section.
* Increased input (microphone) stack to 3072 bytes for safe Speex-16 encoding execution.
*/
#define PA_OUT_STACK_SIZE 2048
#define PA_IN_STACK_SIZE 3072
static uint8_t __aligned(4) pa_out_dtcm_stack[PA_OUT_STACK_SIZE] __attribute__((section(".dtcm_data")));
static uint8_t __aligned(4) pa_in_dtcm_stack[PA_IN_STACK_SIZE] __attribute__((section(".dtcm_data")));
#endif
pthread_attr_init(&pa_stream->threadAttr);
#ifdef MY_CODE
/*
* Dynamically map the appropriate fast DTCM stack memory pointer
* based on whether the thread acts as an audio input or output stream.
*/
if (outputParameters) {
ret = pthread_attr_setstack(&pa_stream->threadAttr,
pa_out_dtcm_stack,
PA_OUT_STACK_SIZE);
} else {
ret = pthread_attr_setstack(&pa_stream->threadAttr,
pa_in_dtcm_stack,
PA_IN_STACK_SIZE);
}
if (ret != 0) {
printf("[POSIX_STACK] ERROR: Failed to assign DTCM memory to thread attributes: %d\n", ret);
return -1;
}
#else
pthread_attr_setstacksize(&pa_stream->threadAttr, 2048);
#endif
ret = pthread_create(&pa_stream->pa_thread, &pa_stream->threadAttr,
outputParameters ? pa_thread_hnd_out : pa_thread_hnd_in,
pa_stream);