-
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
Conversation
Era-Dorta
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great start!
a4d69d6 to
6e9fe9e
Compare
Era-Dorta
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Neat!
Era-Dorta
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, a few more questions. This is a very sensitive change, so I want to make sure that we get it right.
|
@Josfemova , can you please also review this PR? |
| 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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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 PDM_BUF_SIZE / base_sample_rate) * 1000 could be too due to const evaluation if this calc was in a macro instead.
Not functionally different but I would expect that to yield better performance by a slight margin.
Perhaps the calculation of these can be combined with this calculation: https://docs.nordicsemi.com/bundle/ps_nrf5340/page/pdm.html
you could move the value for pdfm_cfg.clock_freq in drv_audio_pdm.c to a define.
You could also take advantage that this now supports C23 and constexpr can be used
microphone/drv_audio_pdm.c
Outdated
| if (current_time >= buffer_duration) { | ||
| timestamp_buffer[l] = current_time - buffer_duration; | ||
| } else { | ||
| timestamp_buffer[l] = current_time; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure why the false case is needed here. If this is a second entry the current_time would be by definition at least 2 buffers duration's in value wouldn't it? Could you elaborate, perhaps I'm missing something
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- @Era-Dorta This got me thinking, wouldn't it be nice to have an endpoint to tell a midge what the current time is? to have a reference to compare the timestamps against?
IDK if you would consider that useful but came to mind while reviewing this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you elaborate
It's for potential timer wrap-arounds. If the timer was about 0xFFFFFFF0and it wraps around to 0x0 then the initial condition will be false and you'd get nonsense values. It shouldn't really happen though because the midge won't be running that long.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was the main reason I initially thought but in practical terms, a Midge will never be ON for enough time for a 64bit msec value to overflow. I think we can safely assume the wrap-around case will never be executed
Josfemova
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
Era-Dorta
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm too, I had one comment that I forgot to click send on but feel free to merge as is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Answered in the comment, all good to merge.
Record the initial timestamp when microphone receives the record command and subsequent timestamps with an offset based on sample rate.
736f86c to
a7e7e0b
Compare
Fix #9
Creates a new file with a
.Dextension containing the following data per audio sample.