Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 367
Module api conversion of math functions and mfcc module, and cmocka fixes#10293
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
3c3c03f2aba590eb7c7c630ffeb8b567aa4eb7d6f0b17aaab562f7e6ab08569098a097b85e9391a4c8fa2556bc8731d3629090979fd4f807File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -4,6 +4,7 @@ | ||
| // | ||
| // Author: Seppo Ingalsuo <seppo.ingalsuo@linux.intel.com> | ||
| #include <sof/audio/module_adapter/module/generic.h> | ||
| #include <sof/audio/format.h> | ||
| #include <rtos/alloc.h> | ||
| #include <sof/math/auditory.h> | ||
| @@ -85,7 +86,7 @@ int16_t psy_mel_to_hz(int16_t mel) | ||
| return hz; | ||
| } | ||
| int psy_get_mel_filterbank(struct psy_mel_filterbank *fb) | ||
| int mod_psy_get_mel_filterbank(struct processing_module *mod, struct psy_mel_filterbank *fb) | ||
| { | ||
| int32_t up_slope; | ||
| int32_t down_slope; | ||
| @@ -200,8 +201,7 @@ int psy_get_mel_filterbank(struct psy_mel_filterbank *fb) | ||
| } | ||
| fb->data_length = &fb->scratch_data2[base_idx] - &fb->scratch_data2[0]; | ||
| fb->data = rzalloc(SOF_MEM_FLAG_USER, | ||
| sizeof(int16_t) * fb->data_length); | ||
| fb->data = mod_zalloc(mod, sizeof(int16_t) * fb->data_length); | ||
| if (!fb->data) | ||
| return -ENOMEM; | ||
| @@ -210,3 +210,8 @@ int psy_get_mel_filterbank(struct psy_mel_filterbank *fb) | ||
| fb->scratch_data2, sizeof(int16_t) * fb->data_length); | ||
| return 0; | ||
| } | ||
| int mod_psy_free_mel_filterbank(struct processing_module *mod, struct psy_mel_filterbank *mel_fb) | ||
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. is this ever used outside of the module destruction path? ContributorAuthor 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. As I mentioned earlier, the cmocka tests to not implement the resource tracking and everything has to be freed manually in order to make Valgrind happy. And of course due to recent turn of events, the resource tracking has taken a step back in any case. ContributorAuthor 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. Of course there probably is one or two places in mfcc where this function should be called, but that is another story. Once I get my per module resource tracking ready, the mfcc is one module that should take it into use among the first ones. | ||
| { | ||
| return mod_free(mod, mel_fb->data); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -4,6 +4,7 @@ | ||
| // | ||
| // Author: Seppo Ingalsuo <seppo.ingalsuo@linux.intel.com> | ||
| #include <sof/audio/module_adapter/module/generic.h> | ||
| #include <sof/audio/format.h> | ||
| #include <sof/math/matrix.h> | ||
| #include <sof/math/dct.h> | ||
| @@ -31,7 +32,7 @@ | ||
| * multiply with the returned matrix. | ||
| * \param[in,out] dct In input provide DCT type and size, in output the DCT matrix | ||
| */ | ||
| int dct_initialize_16(struct dct_plan_16 *dct) | ||
| int mod_dct_initialize_16(struct processing_module *mod, struct dct_plan_16 *dct) | ||
| { | ||
| int16_t dct_val; | ||
| int32_t arg; | ||
| @@ -51,7 +52,7 @@ int dct_initialize_16(struct dct_plan_16 *dct) | ||
| if (dct->num_in > DCT_MATRIX_SIZE_MAX || dct->num_out > DCT_MATRIX_SIZE_MAX) | ||
| return -EINVAL; | ||
| dct->matrix = mat_matrix_alloc_16b(dct->num_in, dct->num_out, 15); | ||
| dct->matrix = mod_mat_matrix_alloc_16b(mod, dct->num_in, dct->num_out, 15); | ||
| if (!dct->matrix) | ||
| return -ENOMEM; | ||
| @@ -77,3 +78,8 @@ int dct_initialize_16(struct dct_plan_16 *dct) | ||
| return 0; | ||
| } | ||
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. would it be possible to modify these functions in place without first adding new versions and then deleting original ones? E.g. in patch 1 modify function prototypes and add wrappers: then move all users one by one to use ContributorAuthor 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. Maybe, but I am not volunteering for the task. What whoud be the point? 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.
@jsarha the point would be not to duplicate code even intermittently, keeping all commits small and easily reviewable ContributorAuthor 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. I grant you the point obout being easier to review and to be sure the functions are still in essence the same. But I think our git repository can easily take the duplicated code. This was a result of my conversion method. Making mod api versions of all that I needed for mfcc and then remove the obsolte functions and see what breaks. I really hope you do not put to redo also this part of this PR series. Good thing of course is that by now I know almost by heart all the allocs and frees in all the module code. | ||
| int mod_dct_free_16(struct processing_module *mod, struct dct_plan_16 *dct) | ||
| { | ||
| return mod_free(mod, dct->matrix); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -5,6 +5,7 @@ | ||
| // Author: Amery Song <chao.song@intel.com> | ||
| // Keyon Jie <yang.jie@linux.intel.com> | ||
| #include <sof/audio/module_adapter/module/generic.h> | ||
| #include <sof/audio/buffer.h> | ||
| #include <sof/audio/format.h> | ||
| #include <sof/common.h> | ||
| @@ -63,6 +64,55 @@ struct fft_plan *fft_plan_new(void *inb, void *outb, uint32_t size, int bits) | ||
| return plan; | ||
| } | ||
| struct fft_plan *mod_fft_plan_new(struct processing_module *mod, void *inb, | ||
| void *outb, uint32_t size, int bits) | ||
| { | ||
| struct fft_plan *plan; | ||
| int lim = 1; | ||
| int len = 0; | ||
| int i; | ||
| if (!inb || !outb) | ||
| return NULL; | ||
| plan = mod_zalloc(mod, sizeof(struct fft_plan)); | ||
| if (!plan) | ||
| return NULL; | ||
| switch (bits) { | ||
| case 16: | ||
| plan->inb16 = inb; | ||
| plan->outb16 = outb; | ||
| break; | ||
| case 32: | ||
| plan->inb32 = inb; | ||
| plan->outb32 = outb; | ||
| break; | ||
| default: | ||
| return NULL; | ||
| } | ||
| /* calculate the exponent of 2 */ | ||
| while (lim < size) { | ||
| lim <<= 1; | ||
| len++; | ||
| } | ||
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. this can be done without a loop with ContributorAuthor 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. A good proposal, but the issue has nothing to do with this PR. | ||
| plan->size = lim; | ||
| plan->len = len; | ||
| plan->bit_reverse_idx = mod_zalloc(mod, plan->size * sizeof(uint16_t)); | ||
| if (!plan->bit_reverse_idx) | ||
| return NULL; | ||
| /* set up the bit reverse index */ | ||
| for (i = 1; i < plan->size; ++i) | ||
| plan->bit_reverse_idx[i] = (plan->bit_reverse_idx[i >> 1] >> 1) | | ||
| ((i & 1) << (len - 1)); | ||
| return plan; | ||
| } | ||
| void fft_plan_free(struct fft_plan *plan) | ||
| { | ||
| if (!plan) | ||
| @@ -71,3 +121,12 @@ void fft_plan_free(struct fft_plan *plan) | ||
| rfree(plan->bit_reverse_idx); | ||
| rfree(plan); | ||
| } | ||
| void mod_fft_plan_free(struct processing_module *mod, struct fft_plan *plan) | ||
| { | ||
| if (!plan) | ||
| return; | ||
| mod_free(mod, plan->bit_reverse_idx); | ||
| mod_free(mod, plan); | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
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.
mfcc_free_buffers()is only called frommfcc_free(). So we don't need explicitmod_free()calls? Alsomod_fft_plan_free()only callsmod_free()internallyThere 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.
It indeed appears so. But now that I am restoring all the clean up code anyway, this code is again needed.