Skip to content

Commit

Permalink
Add MFB to MIVisisonX
Browse files Browse the repository at this point in the history
  • Loading branch information
swetha097 committed Mar 25, 2024
1 parent dba24ba commit dc4200b
Show file tree
Hide file tree
Showing 7 changed files with 309 additions and 10 deletions.
1 change: 1 addition & 0 deletions amd_openvx_extensions/amd_rpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ list(APPEND SOURCES
source/tensor/WarpAffine.cpp
source/tensor/SequenceRearrange.cpp
source/tensor/PreemphasisFilter.cpp
source/tensor/MelFilterBank.cpp
source/kernel_rpp.cpp
source/internal_publishKernels.cpp
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ vx_status WarpAffine_Register(vx_context);
vx_status SequenceRearrange_Register(vx_context);
vx_status PreemphasisFilter_Register(vx_context);
vx_status Spectrogram_Register(vx_context);
vx_status MelFilterBank_Register(vx_context);

// kernel names
#define VX_KERNEL_RPP_NOPBATCHPD_NAME "org.rpp.NopbatchPD"
Expand Down Expand Up @@ -283,5 +284,6 @@ vx_status Spectrogram_Register(vx_context);
#define VX_KERNEL_RPP_SEQUENCEREARRANGE_NAME "org.rpp.SequenceRearrange"
#define VX_KERNEL_RPP_PREEMPHASISFILTER_NAME "org.rpp.PreemphasisFilter"
#define VX_KERNEL_RPP_SPECTROGRAM_NAME "org.rpp.Spectrogram"
#define VX_KERNEL_RPP_MELFILTERBANK_NAME "org.rpp.MelFilterBank"

#endif //_AMDVX_EXT__PUBLISH_KERNELS_H_
3 changes: 2 additions & 1 deletion amd_openvx_extensions/amd_rpp/include/kernels_rpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ extern "C"
VX_KERNEL_RPP_VIGNETTE = VX_KERNEL_BASE(VX_ID_AMD, VX_LIBRARY_RPP) + 0x72,
VX_KERNEL_RPP_WARPAFFINE = VX_KERNEL_BASE(VX_ID_AMD, VX_LIBRARY_RPP) + 0x73,
VX_KERNEL_RPP_PREEMPHASISFILTER = VX_KERNEL_BASE(VX_ID_AMD, VX_LIBRARY_RPP) + 0x74,
VX_KERNEL_RPP_SPECTROGRAM = VX_KERNEL_BASE(VX_ID_AMD, VX_LIBRARY_RPP) + 0x75
VX_KERNEL_RPP_SPECTROGRAM = VX_KERNEL_BASE(VX_ID_AMD, VX_LIBRARY_RPP) + 0x75,
VX_KERNEL_RPP_MELFILTERBANK = VX_KERNEL_BASE(VX_ID_AMD, VX_LIBRARY_RPP) + 0x76,
};

#ifdef __cplusplus
Expand Down
30 changes: 24 additions & 6 deletions amd_openvx_extensions/amd_rpp/include/vx_ext_rpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -1881,23 +1881,41 @@ extern "C"
/*! \brief [Graph] Produces a spectrogram from a 1D signal.
* \ingroup group_amd_rpp
* \param [in] graph The handle to the graph.
* \param [in] pSrc The input tensor in <tt>\ref VX_TYPE_UINT8</tt> or <tt>\ref VX_TYPE_FLOAT32</tt> or <tt>\ref VX_TYPE_FLOAT16</tt> or <tt>\ref VX_TYPE_INT8</tt> format data.
* \param [in] pSrcLength The input tensor of batch size in <tt>unsigned int<tt> containing the roi values for the input in xywh/ltrb format.
* \param [out] pDst The output tensor (begin) in <tt>\ref VX_TYPE_UINT8</tt> or <tt>\ref VX_TYPE_FLOAT32</tt> or <tt>\ref VX_TYPE_FLOAT16</tt> or <tt>\ref VX_TYPE_INT8</tt> format data.
* \param [in] pSrc The input tensor in <tt>\ref VX_TYPE_FLOAT32</tt> format data.
* \param [in] pSrcRoi The input tensor of batch size in <tt>unsigned int<tt> containing the roi values for the input in xywh (w- samples, h - channels) format.
* \param [out] pDst The output tensor (begin) in <tt>\ref VX_TYPE_FLOAT32</tt> format data.
* \param [in] pDstDims The input tensor of batch size in <tt>unsigned int<tt> containing the roi values for the output tensor in xywh/ltrb format.
* \param [in] windowFn The input array in <tt>\ref VX_TYPE_FLOAT32</tt> format containing the samples of the window function that will be multiplied to each extracted window when calculating the STFT.
* \param [in] centerWindow The input scalar in <tt>\ref VX_TYPE_BOOL</tt> format containing indicates whether extracted windows should be padded so that the window function is centered at multiples of window_step.
* \param [in] reflectPadding The input scalar in <tt>\ref VX_TYPE_BOOL</tt> format containing indicates the padding policy when sampling outside the bounds of the signal.
* \param [in] centerWindow The input scalar in <tt>\ref VX_TYPE_BOOL</tt> format indicating whether extracted windows should be padded so that the window function is centered at multiples of window_step.
* \param [in] reflectPadding The input scalar in <tt>\ref VX_TYPE_BOOL</tt> format indicating the padding policy when sampling outside the bounds of the signal.
* \param [in] spectrogramLayout The input scalar in <tt>\ref VX_TYPE_INT32</tt> format containing the Output spectrogram layout.
* \param [in] power The input scalar in <tt>\ref VX_TYPE_INT32</tt> format containing the exponent of the magnitude of the spectrum.
* \param [in] nfft The input scalar in <tt>\ref VX_TYPE_INT32</tt> format containing the size of the FFT.
* \param [in] windowLength The input scalar in <tt>\ref VX_TYPE_INT32</tt> format containing Window size in number of samples.
* \param [in] windowStep The input array in <tt>\ref VX_TYPE_INT32</tt> format containing the step between the STFT windows in number of samples.
* \return A node reference <tt>\ref vx_node</tt>. Any possible errors preventing a successful creation should be checked using <tt>\ref vxGetStatus</tt>.
*/
SHARED_PUBLIC vx_node VX_API_CALL vxExtRppSpectrogram(vx_graph graph, vx_tensor pSrc, vx_tensor pSrcLength, vx_tensor pDst, vx_tensor pDstDims, vx_array windowFn, vx_scalar centerWindow, vx_scalar reflectPadding, vx_scalar spectrogramLayout,
SHARED_PUBLIC vx_node VX_API_CALL vxExtRppSpectrogram(vx_graph graph, vx_tensor pSrc, vx_tensor pSrcRoi, vx_tensor pDst, vx_tensor pDstDims, vx_array windowFn, vx_scalar centerWindow, vx_scalar reflectPadding, vx_scalar spectrogramLayout,
vx_scalar power, vx_scalar nfft, vx_scalar windowLength, vx_scalar windowStep);

/*! \brief [Graph] Produces a mel-spectrogram from spectrogram on applying a bank of triangular filters
* \ingroup group_amd_rpp
* \param [in] graph The handle to the graph.
* \param [in] pSrc The input tensor in <tt>\ref VX_TYPE_FLOAT32</tt> format data.
* \param [in] pSrcRoi The input tensor of batch size in <tt>unsigned int<tt> containing the roi values for the input in xywh (w- samples, h - channels) format.
* \param [out] pDst The output tensor (begin) in <tt>\ref VX_TYPE_FLOAT32</tt> format data.
* \param [in] pDstRoi The input tensor of batch size in <tt>unsigned int<tt> containing the roi values for the input in xywh (w- samples, h - channels) format.
* \param [in] freqHigh The input array in <tt>\ref VX_TYPE_FLOAT32</tt> format containing the maximum frequency.
* \param [in] freqLow The input scalar in <tt>\ref VX_TYPE_FLOAT32</tt> format containing the minimum frequency.
* \param [in] melFormula The input scalar in <tt>\ref VX_TYPE_INT32</tt> format indicates the formula used to convert frequencies from hertz to mel and vice versa.
* \param [in] nfilter The input scalar in <tt>\ref VX_TYPE_INT32</tt> format containing the number of mel filters.
* \param [in] normalize The input scalar in <tt>\ref VX_TYPE_BOOL</tt> format to determine weather to normalize the triangular filter weights by the width of the frequecny bands.
* \param [in] sampleRate The input scalar in <tt>\ref VX_TYPE_FLOAT32</tt> format containing the sampling rate of the audio data.
* \return A node reference <tt>\ref vx_node</tt>. Any possible errors preventing a successful creation should be checked using <tt>\ref vxGetStatus</tt>.
*/
SHARED_PUBLIC vx_node VX_API_CALL vxExtRppMelFilterBank(vx_graph graph, vx_tensor pSrc, vx_tensor pSrcRoi, vx_tensor pDst, vx_tensor pDstRoi, vx_scalar freqHigh,
vx_scalar freqLow, vx_scalar melFormula, vx_scalar nfilter, vx_scalar normalize, vx_scalar sampleRate);

#ifdef __cplusplus
}
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ vx_status get_kernels_to_publish()
STATUS_ERROR_CHECK(ADD_KERNEL(WarpAffine_Register));
STATUS_ERROR_CHECK(ADD_KERNEL(PreemphasisFilter_Register));
STATUS_ERROR_CHECK(ADD_KERNEL(Spectrogram_Register));
STATUS_ERROR_CHECK(ADD_KERNEL(MelFilterBank_Register));

return status;
}
Expand Down
30 changes: 27 additions & 3 deletions amd_openvx_extensions/amd_rpp/source/kernel_rpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2559,7 +2559,7 @@ VX_API_ENTRY vx_node VX_API_CALL vxExtRppPreemphasisFilter(vx_graph graph, vx_te
return node;
}

VX_API_ENTRY vx_node VX_API_CALL vxExtRppSpectrogram(vx_graph graph, vx_tensor pSrc, vx_tensor pSrcLength, vx_tensor pDst, vx_tensor pDstDims, vx_array windowFn, vx_scalar centerWindows, vx_scalar reflectPadding, vx_scalar spectrogramLayout,
VX_API_ENTRY vx_node VX_API_CALL vxExtRppSpectrogram(vx_graph graph, vx_tensor pSrc, vx_tensor pSrcRoi, vx_tensor pDst, vx_tensor pDstRoi, vx_array windowFn, vx_scalar centerWindows, vx_scalar reflectPadding, vx_scalar spectrogramLayout,
vx_scalar power, vx_scalar nfft, vx_scalar windowLength, vx_scalar windowStep) {
vx_node node = NULL;
vx_context context = vxGetContext((vx_reference)graph);
Expand All @@ -2568,9 +2568,9 @@ VX_API_ENTRY vx_node VX_API_CALL vxExtRppSpectrogram(vx_graph graph, vx_tensor p
vx_scalar deviceType = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_UINT32, &devtype);
vx_reference params[] = {
(vx_reference)pSrc,
(vx_reference)pSrcLength,
(vx_reference)pSrcRoi,
(vx_reference)pDst,
(vx_reference)pDstDims,
(vx_reference)pDstRoi,
(vx_reference)windowFn,
(vx_reference)centerWindows,
(vx_reference)reflectPadding,
Expand All @@ -2585,6 +2585,30 @@ VX_API_ENTRY vx_node VX_API_CALL vxExtRppSpectrogram(vx_graph graph, vx_tensor p
return node;
}

VX_API_ENTRY vx_node VX_API_CALL vxExtRppMelFilterBank(vx_graph graph, vx_tensor pSrc, vx_tensor pSrcRoi, vx_tensor pDst, vx_tensor pDstRoi, vx_scalar freqHigh, vx_scalar freqLow, vx_scalar melFormula,
vx_scalar nfilter, vx_scalar normalize, vx_scalar sampleRate) {
vx_node node = NULL;
vx_context context = vxGetContext((vx_reference)graph);
if (vxGetStatus((vx_reference)context) == VX_SUCCESS) {
vx_uint32 devtype = getGraphAffinity(graph);
vx_scalar deviceType = vxCreateScalar(vxGetContext((vx_reference)graph), VX_TYPE_UINT32, &devtype);
vx_reference params[] = {
(vx_reference)pSrc,
(vx_reference)pSrcRoi,
(vx_reference)pDst,
(vx_reference)pDstRoi,
(vx_reference)freqHigh,
(vx_reference)freqLow,
(vx_reference)melFormula,
(vx_reference)nfilter,
(vx_reference)normalize,
(vx_reference)sampleRate,
(vx_reference)deviceType};
node = createNode(graph, VX_KERNEL_RPP_MELFILTERBANK, params, 11);
}
return node;
}

RpptDataType getRpptDataType(vx_enum vxDataType) {
switch(vxDataType) {
case vx_type_e::VX_TYPE_FLOAT32:
Expand Down
Loading

0 comments on commit dc4200b

Please sign in to comment.