Skip to main content
Visitor II
December 17, 2022
Solved

Get an angle from Acoustic SL library?

  • December 17, 2022
  • 1 reply
  • 1278 views

Hello!

I am working on a project I have 4 mems microphones and I want to get an angle from these 4 microphones, I have 12 neopixel Leds which lit up according to the voice direction on the 4 microphones. I have the Stm32cubeide project for it, but I don't how can get the angle with it.

Here is the Code and I will also attach the files...

Please guide me!

/* USER CODE BEGIN Header */
/**
 ******************************************************************************
 * @file : main.c
 * @brief : Main program body
 ******************************************************************************
 * @attention
 *
 * Copyright (c) 2022 STMicroelectronics.
 * All rights reserved.
 *
 * This software is licensed under terms that can be found in the LICENSE file
 * in the root directory of this software component.
 * If no LICENSE file comes with this software, it is provided AS-IS.
 *
 ******************************************************************************
 */
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "cube_hal.h"
#include "com.h"
//#include "maino.h"
 
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
 
/* USER CODE END Includes */
 
/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */
 
/* USER CODE END PTD */
 
/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
/* USER CODE END PD */
 
/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */
 
/* USER CODE END PM */
 
/* Private variables ---------------------------------------------------------*/
//UART_HandleTypeDef huart2;
 
/* USER CODE BEGIN PV */
 
/* USER CODE END PV */
 
/* Private function prototypes -----------------------------------------------*/
//void SystemClock_Config(void);
//static void MX_GPIO_Init(void);
//static void MX_USART2_UART_Init(void);
/* USER CODE BEGIN PFP */
 
USBD_HandleTypeDef hUSBDDevice;
extern USBD_AUDIO_ItfTypeDef USBD_AUDIO_fops;
extern uint16_t PDM_Buffer[((((AUDIO_IN_CHANNELS * AUDIO_IN_SAMPLING_FREQUENCY) / 1000) * MAX_DECIMATION_FACTOR) / 16)*N_MS ];
CCA02M2_AUDIO_Init_t MicParams;
 
/* USER CODE END PFP */
 
/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
 
/* USER CODE END 0 */
 
/**
 * @brief The application entry point.
 * @retval int
 */
int main(void)
{
 /* STM32F4xx HAL library initialization:
 - Configure the Flash prefetch, instruction and Data caches
 - Configure the Systick to generate an interrupt each 1 msec
 - Global MSP (MCU Support Package) initialization
 */
 HAL_Init();
 /* Configure the system clock */
 SystemClock_Config();
 /* Initialize USB descriptor basing on channels number and sampling frequency */
 USBD_AUDIO_Init_Microphone_Descriptor(&hUSBDDevice, AUDIO_IN_SAMPLING_FREQUENCY, AUDIO_IN_CHANNELS);
 /* Init Device Library */
 USBD_Init(&hUSBDDevice, &AUDIO_Desc, 0);
 /* Add Supported Class */
 USBD_RegisterClass(&hUSBDDevice, &USBD_AUDIO);
 /* Add Interface callbacks for AUDIO Class */
 USBD_AUDIO_RegisterInterface(&hUSBDDevice, &USBD_AUDIO_fops);
 /* Start Device Process */
 USBD_Start(&hUSBDDevice);
 /*Init Uart Communication*/
 Uart_Init();
 
 /* Initialize all configured peripherals */
// MX_GPIO_Init();
// MX_USART2_UART_Init();
 /* USER CODE BEGIN 2 */
 
 /* Initialize microphone acquisition */
 MicParams.BitsPerSample = 16;
 MicParams.ChannelsNbr = AUDIO_IN_CHANNELS;
 MicParams.Device = AUDIO_IN_DIGITAL_MIC;
 MicParams.SampleRate = AUDIO_IN_SAMPLING_FREQUENCY;
 MicParams.Volume = AUDIO_VOLUME_INPUT;
 
 if (CCA02M2_AUDIO_IN_Init(CCA02M2_AUDIO_INSTANCE, &MicParams) != BSP_ERROR_NONE)
 {
 Error_Handler();
 }
 
 /* Initialize Acoustic_SL library */
 Audio_Libraries_Init();
 
 /* Initialize software interrupt tasks */
 SW_IRQ_Tasks_Init();
 
 /* Start audio acquisition */
 if (CCA02M2_AUDIO_IN_Record(CCA02M2_AUDIO_INSTANCE, (uint8_t *) PDM_Buffer, AUDIO_IN_BUFFER_SIZE) != BSP_ERROR_NONE)
 {
 Error_Handler();
 }
 
 
 /* USER CODE END 2 */
 
 /* Infinite loop */
 /* USER CODE BEGIN WHILE */
 while (1)
 {
 /* USER CODE END WHILE */
 
 /* USER CODE BEGIN 3 */
 }
 /* USER CODE END 3 */
}
 
#if 0
 
///**
// * @brief System Clock Configuration
// * @retval None
// */
//void SystemClock_Config(void)
//{
// RCC_OscInitTypeDef RCC_OscInitStruct = {0};
// RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
//
// /** Configure the main internal regulator output voltage
// */
// __HAL_RCC_PWR_CLK_ENABLE();
// __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE2);
//
// /** Initializes the RCC Oscillators according to the specified parameters
// * in the RCC_OscInitTypeDef structure.
// */
// RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
// RCC_OscInitStruct.HSIState = RCC_HSI_ON;
// RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
// RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
// RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
// RCC_OscInitStruct.PLL.PLLM = 16;
// RCC_OscInitStruct.PLL.PLLN = 336;
// RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4;
// RCC_OscInitStruct.PLL.PLLQ = 7;
// if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
// {
// Error_Handler();
// }
//
// /** Initializes the CPU, AHB and APB buses clocks
// */
// RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
// |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
// RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
// RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
// RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
// RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
//
// if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
// {
// Error_Handler();
// }
//}
 
/**
 * @brief USART2 Initialization Function
 * @param None
 * @retval None
 */
static void MX_USART2_UART_Init(void)
{
 
 /* USER CODE BEGIN USART2_Init 0 */
 
 /* USER CODE END USART2_Init 0 */
 
 /* USER CODE BEGIN USART2_Init 1 */
 
 /* USER CODE END USART2_Init 1 */
 huart2.Instance = USART2;
 huart2.Init.BaudRate = 115200;
 huart2.Init.WordLength = UART_WORDLENGTH_8B;
 huart2.Init.StopBits = UART_STOPBITS_1;
 huart2.Init.Parity = UART_PARITY_NONE;
 huart2.Init.Mode = UART_MODE_TX_RX;
 huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
 huart2.Init.OverSampling = UART_OVERSAMPLING_16;
 if (HAL_UART_Init(&huart2) != HAL_OK)
 {
 Error_Handler();
 }
 /* USER CODE BEGIN USART2_Init 2 */
 
 /* USER CODE END USART2_Init 2 */
 
}
 
/**
 * @brief GPIO Initialization Function
 * @param None
 * @retval None
 */
static void MX_GPIO_Init(void)
{
 GPIO_InitTypeDef GPIO_InitStruct = {0};
 
 /* GPIO Ports Clock Enable */
 __HAL_RCC_GPIOC_CLK_ENABLE();
 __HAL_RCC_GPIOH_CLK_ENABLE();
 __HAL_RCC_GPIOA_CLK_ENABLE();
 __HAL_RCC_GPIOB_CLK_ENABLE();
 
 /*Configure GPIO pin Output Level */
 HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, GPIO_PIN_RESET);
 
 /*Configure GPIO pin : B1_Pin */
 GPIO_InitStruct.Pin = B1_Pin;
 GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
 GPIO_InitStruct.Pull = GPIO_NOPULL;
 HAL_GPIO_Init(B1_GPIO_Port, &GPIO_InitStruct);
 
 /*Configure GPIO pin : LD2_Pin */
 GPIO_InitStruct.Pin = LD2_Pin;
 GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
 GPIO_InitStruct.Pull = GPIO_NOPULL;
 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
 HAL_GPIO_Init(LD2_GPIO_Port, &GPIO_InitStruct);
 
}
 
#endif
 
/* USER CODE BEGIN 4 */
 
/* USER CODE END 4 */
 
#ifdef USE_FULL_ASSERT
/**
 * @brief Reports the name of the source file and the source line number
 * where the assert_param error has occurred.
 * @param file: pointer to the source file name
 * @param line: assert_param error line source number
 * @retval None
 */
void assert_failed(uint8_t *file, uint32_t line)
{
 /* USER CODE BEGIN 6 */
 /* User can add his own implementation to report the file name and line number,
 ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
 /* USER CODE END 6 */
}
#endif /* USE_FULL_ASSERT */

    This topic has been closed for replies.
    Best answer by Eleon BORLINI

    Hi @Community member​ ,

    please consider this thread (LINK1) and this other thread (LINK2) and keep only those for any further requests.

    -Eleon

    1 reply

    ST Employee
    January 4, 2023

    Hi @Community member​ ,

    please consider this thread (LINK1) and this other thread (LINK2) and keep only those for any further requests.

    -Eleon

    VikiAuthor
    Visitor II
    January 5, 2023

    Thank you for the help...