stm32f769/stm32f769i-disco/Src/pv_audio_rec.c
Go to the documentation of this file.
1 /*
2  Copyright 2021 Picovoice Inc.
3 
4  You may not use this file except in compliance with the license. A copy of the license is located in the "LICENSE"
5  file accompanying this source.
6 
7  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
8  an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
9  specific language governing permissions and limitations under the License.
10 */
11 
12 #include <stdbool.h>
13 #include <stdint.h>
14 #include <stdlib.h>
15 
17 
18 #include "picovoice.h"
19 
20 #define PV_INT16_MAX (32767)
21 #define PV_INT16_MIN (-32767 - 1)
22 
23 #define pv_int32_to_int16(N) (((N)<(PV_INT16_MIN))?(PV_INT16_MIN):(((N)>(PV_INT16_MAX))?(PV_INT16_MAX):(N)))
24 
25 __IO uint32_t SdmmcTest = 0;
26 __IO uint32_t SdramTest = 0;
27 
28 #define PV_AUDIO_REC_AUDIO_FREQUENCY (16000U)
29 #define PV_AUDIO_REC_CHANNEL_NUMBER (2)
30 #define PV_AUDIO_REC_RECORD_BUFFER_SIZE (512)
31 #define PV_AUDIO_REC_VOLUME_LEVEL (100)
32 
33 #define AUDIO_IN_PCM_BUFFER_SIZE (PV_AUDIO_REC_RECORD_BUFFER_SIZE)
34 #define AUDIO_IN_PDM_BUFFER_SIZE (AUDIO_IN_PCM_BUFFER_SIZE / 4)
35 
39 
40 static int32_t last_read_index = -1;
41 static int32_t read_index = 1;
42 static int32_t write_index = 0;
43 static int32_t buffer_index = 0;
44 
45 struct {
46  uint32_t channel_number;
47  uint32_t audio_frequency;
49  uint16_t *record_pcm_buffer;
52 } pv_audio_rec;
53 
57  pv_audio_rec.record_buffer_size = PV_AUDIO_REC_RECORD_BUFFER_SIZE;
58  pv_audio_rec.record_pcm_buffer = record_pcm_buffer;
59  pv_audio_rec.filter_old_output = 0;
60 
63  }
65  return PV_STATUS_SUCCESS;
66 }
67 
72  }
73  pv_audio_rec.is_recording = true;
74  return PV_STATUS_SUCCESS;
75 }
76 
78  if (BSP_AUDIO_IN_Stop() != AUDIO_OK) {
80  }
81  pv_audio_rec.is_recording = false;
82  return PV_STATUS_SUCCESS;
83 }
84 
85 const int16_t *pv_audio_rec_get_new_buffer(void) {
86  if (read_index == -1) {
87  return NULL;
88  }
89 
90  if (last_read_index == read_index) {
91  return NULL;
92  }
93 
95 
97 }
98 
99 static inline int16_t pv_hpf(int16_t s_int16, int16_t s_old_int16) {
100  //0xFC and 0x100 are the tuning parameters come from st for high pass filter
101  pv_audio_rec.filter_old_output = (0xFC * (pv_audio_rec.filter_old_output + (int32_t) s_int16 - (int32_t) s_old_int16)) / 0x100;
102  return (int16_t)pv_int32_to_int16(pv_audio_rec.filter_old_output);
103 }
104 
106  for (uint32_t i = 0; i < AUDIO_IN_PCM_BUFFER_SIZE / 4; i++) {
109  record_pcm_buffer[(AUDIO_IN_PCM_BUFFER_SIZE / 2) + (i - 1) * 2]);
110  }
111 
114  write_index = 1 - write_index;
115  buffer_index = 0;
116  }
117 }
118 
121  for (uint32_t i = 1; i < AUDIO_IN_PCM_BUFFER_SIZE / 4; i++) {
123  record_pcm_buffer[i * 2],
124  record_pcm_buffer[(i - 1) * 2]);
125  }
128  write_index = 1 - write_index;
129  buffer_index = 0;
130  }
131 }
132 
134  while (1);
135 }
136 
140 }
141 
__IO
#define __IO
Definition: imxrt1050/imxrt1050-evkb/CMSIS/core_cm7.h:237
write_index
static int32_t write_index
Definition: stm32f769/stm32f769i-disco/Src/pv_audio_rec.c:42
record_buffer_size
uint32_t record_buffer_size
Definition: stm32f769/stm32f769i-disco/Src/pv_audio_rec.c:48
pv_audio_rec_stop
pv_status_t pv_audio_rec_stop(void)
Definition: stm32f769/stm32f769i-disco/Src/pv_audio_rec.c:77
ping_pong_buffer
static int16_t ping_pong_buffer[2][PV_AUDIO_REC_RECORD_BUFFER_SIZE]
Definition: psoc062s2/src/pv_audio_rec.c:49
NULL
#define NULL
Definition: porcupine/demo/c/dr_libs/tests/external/miniaudio/extras/speex_resampler/thirdparty/resample.c:92
BSP_AUDIO_IN_Stop
uint8_t BSP_AUDIO_IN_Stop(void)
Stops audio recording.
Definition: stm32f4_discovery_audio.c:754
PV_STATUS_INVALID_STATE
@ PV_STATUS_INVALID_STATE
Definition: porcupine/include/picovoice.h:40
BSP_AUDIO_IN_TransferComplete_CallBack
void BSP_AUDIO_IN_TransferComplete_CallBack(void)
User callback when record buffer is filled.
Definition: stm32f769/stm32f769i-disco/Src/pv_audio_rec.c:105
audio_frequency
uint32_t audio_frequency
Definition: stm32f769/stm32f769i-disco/Src/pv_audio_rec.c:47
BSP_AUDIO_IN_DeInit
void BSP_AUDIO_IN_DeInit(void)
Deinit the audio IN peripherals.
Definition: stm32469i_discovery_audio.c:1036
BSP_AUDIO_IN_Init
uint8_t BSP_AUDIO_IN_Init(uint32_t AudioFreq, uint32_t BitRes, uint32_t ChnlNbr)
Initializes wave recording.
Definition: stm32f4_discovery_audio.c:705
channel_number
uint32_t channel_number
Definition: stm32f769/stm32f769i-disco/Src/pv_audio_rec.c:46
PV_AUDIO_REC_CHANNEL_NUMBER
#define PV_AUDIO_REC_CHANNEL_NUMBER
Definition: stm32f769/stm32f769i-disco/Src/pv_audio_rec.c:29
pv_audio_rec_start
pv_status_t pv_audio_rec_start(void)
Definition: stm32f769/stm32f769i-disco/Src/pv_audio_rec.c:68
PV_AUDIO_REC_RECORD_BUFFER_SIZE
#define PV_AUDIO_REC_RECORD_BUFFER_SIZE
Definition: stm32f769/stm32f769i-disco/Src/pv_audio_rec.c:30
SdmmcTest
__IO uint32_t SdmmcTest
Definition: stm32f769/stm32f769i-disco/Src/pv_audio_rec.c:25
is_recording
bool is_recording
Definition: stm32f769/stm32f769i-disco/Src/pv_audio_rec.c:50
record_pcm_buffer
uint16_t * record_pcm_buffer
Definition: stm32f769/stm32f769i-disco/Src/pv_audio_rec.c:49
pv_audio_rec_init
pv_status_t pv_audio_rec_init(void)
Definition: stm32f769/stm32f769i-disco/Src/pv_audio_rec.c:54
PV_STATUS_SUCCESS
@ PV_STATUS_SUCCESS
Definition: porcupine/include/picovoice.h:34
filter_old_output
int32_t filter_old_output
Definition: stm32f769/stm32f769i-disco/Src/pv_audio_rec.c:51
pv_status_t
pv_status_t
Definition: porcupine/include/picovoice.h:33
buffer_index
static int32_t buffer_index
Definition: stm32f769/stm32f769i-disco/Src/pv_audio_rec.c:43
pv_int32_to_int16
#define pv_int32_to_int16(N)
Definition: stm32f769/stm32f769i-disco/Src/pv_audio_rec.c:23
last_read_index
static int32_t last_read_index
Definition: stm32f769/stm32f769i-disco/Src/pv_audio_rec.c:40
BSP_AUDIO_IN_Record
uint8_t BSP_AUDIO_IN_Record(uint16_t *pbuf, uint32_t size)
Starts audio recording.
Definition: stm32f4_discovery_audio.c:737
AUDIO_IN_PCM_BUFFER_SIZE
#define AUDIO_IN_PCM_BUFFER_SIZE
Definition: stm32f769/stm32f769i-disco/Src/pv_audio_rec.c:33
pv_audio_rec_deinit
void pv_audio_rec_deinit(void)
Definition: stm32f769/stm32f769i-disco/Src/pv_audio_rec.c:137
BSP_AUDIO_IN_AllocScratch
uint8_t BSP_AUDIO_IN_AllocScratch(int32_t *pScratch, uint32_t size)
Allocate channel buffer scratch.
Definition: stm32f769i_discovery_audio.c:1204
AUDIO_IN_PDM_BUFFER_SIZE
#define AUDIO_IN_PDM_BUFFER_SIZE
Definition: stm32f769/stm32f769i-disco/Src/pv_audio_rec.c:34
PV_AUDIO_REC_AUDIO_FREQUENCY
#define PV_AUDIO_REC_AUDIO_FREQUENCY
Definition: stm32f769/stm32f769i-disco/Src/pv_audio_rec.c:28
pv_hpf
static int16_t pv_hpf(int16_t s_int16, int16_t s_old_int16)
Definition: stm32f769/stm32f769i-disco/Src/pv_audio_rec.c:99
record_pdm_buffer
static uint16_t record_pdm_buffer[AUDIO_IN_PDM_BUFFER_SIZE]
Definition: stm32f407/stm32f407g-disc1/Src/pv_audio_rec.c:28
DEFAULT_AUDIO_IN_BIT_RESOLUTION
#define DEFAULT_AUDIO_IN_BIT_RESOLUTION
Definition: stm32f4_discovery_audio.h:155
AUDIO_OK
#define AUDIO_OK
Definition: stm32f4_discovery_audio.h:149
ALIGN_32BYTES
ALIGN_32BYTES(static int32_t record_pdm_buffer[AUDIO_IN_PDM_BUFFER_SIZE])
pv_audio_rec
struct @542 pv_audio_rec
pv_audio_rec_get_new_buffer
const int16_t * pv_audio_rec_get_new_buffer(void)
Definition: stm32f769/stm32f769i-disco/Src/pv_audio_rec.c:85
read_index
static int32_t read_index
Definition: stm32f769/stm32f769i-disco/Src/pv_audio_rec.c:41
BSP_AUDIO_IN_HalfTransfer_CallBack
void BSP_AUDIO_IN_HalfTransfer_CallBack(void)
Manages the DMA Half Transfer complete event.
Definition: stm32f769/stm32f769i-disco/Src/pv_audio_rec.c:119
BSP_AUDIO_IN_Error_CallBack
void BSP_AUDIO_IN_Error_CallBack(void)
Audio IN Error callback function.
Definition: stm32f769/stm32f769i-disco/Src/pv_audio_rec.c:133
SdramTest
__IO uint32_t SdramTest
Definition: stm32f769/stm32f769i-disco/Src/pv_audio_rec.c:26
stm32f769i_discovery_audio.h
This file contains the common defines and functions prototypes for the stm32f769i_discovery_audio....


picovoice_driver
Author(s):
autogenerated on Fri Apr 1 2022 02:14:50