-
Notifications
You must be signed in to change notification settings - Fork 3
audio: add timestamp to raw files #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
ce5ea5d
4baa3f0
500f23f
066050f
47dc01a
c5e737c
480d3cc
a7e7e0b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,7 @@ | |
| #include "storage.h" | ||
| #include "audio_switch.h" | ||
| #include "sampling_lib.h" | ||
| #include "systick_lib.h" | ||
|
|
||
| ret_code_t err_code; | ||
|
|
||
|
|
@@ -29,13 +30,13 @@ nrf_pdm_mode_t local_mode; | |
| uint32_t local_freq; | ||
| uint8_t local_gain_l; | ||
| uint8_t local_gain_r; | ||
|
|
||
| uint64_t timestamp_buffer[PDM_BUF_NUM] = {0}; | ||
|
|
||
| int16_t subsampled[PDM_BUF_SIZE/DECIMATION]; | ||
| float filter_weight[DECIMATION]; | ||
| static uint64_t recording_start_timestamp; | ||
|
|
||
|
|
||
| static void process_audio_buffer(void) | ||
| static void process_audio_buffer(uint8_t buffer_index) | ||
| { | ||
| switch (audio_switch_position) | ||
| { | ||
|
|
@@ -47,6 +48,7 @@ static void process_audio_buffer(void) | |
| { | ||
| data_source_info.data_source = AUDIO; | ||
| data_source_info.audio_source_info.audio_buffer_length = PDM_BUF_SIZE*2; | ||
| data_source_info.audio_source_info.buffer_index = buffer_index; | ||
| err_code = app_sched_event_put(&data_source_info, sizeof(data_source_info), sd_write); | ||
| APP_ERROR_CHECK(err_code); | ||
| } | ||
|
|
@@ -69,6 +71,7 @@ static void process_audio_buffer(void) | |
| } | ||
|
|
||
| data_source_info.data_source = AUDIO; | ||
| data_source_info.audio_source_info.buffer_index = buffer_index; | ||
| data_source_info.audio_source_info.audio_buffer = subsampled; | ||
| data_source_info.audio_source_info.audio_buffer_length = (PDM_BUF_SIZE/DECIMATION)*2; //sizeof(subsampled); | ||
| err_code = app_sched_event_put(&data_source_info, sizeof(data_source_info), sd_write); | ||
|
|
@@ -101,8 +104,19 @@ static void drv_audio_pdm_event_handler(nrfx_pdm_evt_t const * const p_evt) | |
| { | ||
| pdm_buf[l].released = true; | ||
| data_source_info.audio_source_info.audio_buffer = &pdm_buf[l].mic_buf; | ||
| if (l == 0 && timestamp_buffer[l] == 0) { | ||
| // First buffer, set timestamp to recording start timestamp | ||
| timestamp_buffer[l] = recording_start_timestamp; | ||
| } else { | ||
| // Subsequent buffers | ||
| // t_rec_i = t_release_i - (PDM_BUF_SIZE / effective_sampling_rate) * 1000 | ||
| const uint32_t base_sample_rate = 20000; // 20kHz | ||
| uint64_t current_time = systick_get_millis(); | ||
| uint32_t buffer_duration = (PDM_BUF_SIZE / base_sample_rate) * 1000; | ||
|
Comment on lines
+113
to
+115
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sample rate can be a compile-time constant, and the result from the operation Not functionally different but I would expect that to yield better performance by a slight margin. You could also take advantage that this now supports C23 and constexpr can be used |
||
| timestamp_buffer[l] = current_time - buffer_duration; | ||
| } | ||
| NRF_LOG_INFO("pdm buf %d", pdm_buf[l].mic_buf[0]); | ||
| process_audio_buffer(); | ||
| process_audio_buffer(l); | ||
| break; | ||
| } | ||
| } | ||
|
|
@@ -123,9 +137,11 @@ static void drv_audio_pdm_event_handler(nrfx_pdm_evt_t const * const p_evt) | |
| } | ||
| } | ||
|
|
||
| ret_code_t drv_audio_init(nrf_pdm_mode_t mode) | ||
| ret_code_t drv_audio_init(nrf_pdm_mode_t mode, uint64_t timestamp) | ||
| { | ||
|
|
||
| recording_start_timestamp = timestamp; | ||
|
|
||
| switch (mode) | ||
| { | ||
| case 0: //stereo | ||
|
|
@@ -165,6 +181,7 @@ ret_code_t drv_audio_init(nrf_pdm_mode_t mode) | |
| //! position. The HW in the uC is designed for this frequency but Nordic | ||
| //! does not support it oficially as it's not considered tested enough | ||
| //! https://devzone.nordicsemi.com/f/nordic-q-a/15150/single-pdm-microphone-at-higher-pcm-sampling-rate | ||
| //! NOTE: Change the clock frequency in the `drv_audio_pdm_event_handler` function if this is changed. | ||
| pdm_cfg.clock_freq = 0x0A000000UL; | ||
| local_freq = pdm_cfg.clock_freq; | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.