SampleUp
Performs signal upsampling (a factor is used to increase the sample rate).
Specifically, upsampling is inserting (factor-1) zeros between elements in the source sampling sequence src. Therefore, in the sampling result sequence, factor elements form one block. phase indicates the sampling phase, which determines the position of the source sequence element in the result sequence. The value range is [0, factor-1].
The processing manner may be described by using the following formula:
;
;
.
The function interface declaration is as follows:
- Operations on integers:
HmppResultHMPPS_SampleUp_16s(const int16_t *src, int32_t srcLen, int16_t *dst, int32_t *dstLen, int32_t factor,int32_t *phase);
HmppResult HMPPS_SampleUp_16sc(const Hmpp16sc *src, int32_t srcLen, Hmpp16sc *dst, int32_t *dstLen, int32_t factor, int32_t *phase);
- Operations on floating-point numbers:
HmppResult HMPPS_SampleUp_32f(const float *src, int32_t srcLen, float *dst, int32_t *dstLen, int32_t factor, int32_t *phase);
HmppResult HMPPS_SampleUp_64f(const double *src, int32_t srcLen, double *dst, int32_t *dstLen, int32_t factor, int32_t *phase);
HmppResult HMPPS_SampleUp_32fc(const Hmpp32fc *src, int32_t srcLen, Hmpp32fc *dst, int32_t *dstLen, int32_t factor, int32_t *phase);
HmppResult HMPPS_SampleUp_64fc(const Hmpp64fc *src, int32_t srcLen, Hmpp64fc *dst, int32_t *dstLen, int32_t factor, int32_t *phase);
Parameters
Parameter |
Description |
Value Range |
Input/Output |
|---|---|---|---|
src |
Pointer to the source vector |
The value cannot be NULL. |
Input |
srcLen |
Sample size |
(0, INT_MAX] |
Input |
dst |
Pointer to the destination vector |
The value cannot be NULL. |
Output |
dstLen |
Sampling width |
The value cannot be NULL. |
Output |
factor |
Sampling factor |
(0, INT_MAX] |
Input |
phase |
Pointer to the sampling phase |
Not empty and within the range [0, factor) |
Input |
Return Value
- Success: HMPP_STS_NO_ERR
- Failure: An error code is returned.
Error Codes
Error Code |
Description |
|---|---|
HMPP_STS_NULL_PTR_ERR |
The value of src, dst, dstLen, or phase is NULL. |
HMPP_STS_SIZE_ERR |
The value of len is less than or equal to 0. |
HMPP_STS_SAMPLE_FACTOR_ERR |
The sampling factor is less than or equal to 0. |
HMPP_STS_SAMPLE_PHASE_ERR |
The sampling phase is less than 0 or greater than or equal to factor. |
Example
#define BUFFER_SIZE_S 9
void SampleUpExample(void)
{
Hmpp16sc src1[BUFFER_SIZE_S] = { 14761, -14761, -9981, 9381, 286, -7115, -15360, -7959, -26648, -13094,
-29344, -999, -12922, 8793, -21146, 12262, 1568, -6382 };
Hmpp16sc src2[BUFFER_SIZE_S] = { 30000, -30000, -9976, 9976, -848, -2080, -22268, -32406, 29451, 8620,
19416, -30118, -31166, -28113, -11331, -8179, -30595, 14322 };
Hmpp16sc dst[65] = { 0 };
int32_t dstLen1 = 0;
int32_t dstLen2 = 0;
int32_t factor = 4;
int32_t phase = 2;
HmppResult result;
result = HMPPS_SampleUp_16sc(src1, BUFFER_SIZE_S, dst, &dstLen1, factor, &phase);
result |= HMPPS_SampleUp_16sc(src2, BUFFER_SIZE_S, dst + dstLen1, &dstLen2, factor, &phase);
printf("result = %d\n", result);
if (result != HMPP_STS_NO_ERR) {
return;
}
int32_t i = 0;
printf("dstLen1 = %d\ndst1 =", dstLen1);
for(; i < dstLen1; ++i){
printf(" %d %d ", dst[i].re, dst[i].im);
}
printf("\ndstLen2 = %d\ndst2 =", dstLen1);
for(; i < dstLen1 + dstLen2; ++i){
printf(" %d %d ", dst[i].re, dst[i].im);
}
printf("\n");
}
Output:
result = 0 dstLen1 = 36 dst1 = 0 0 0 0 14761 -14761 0 0 0 0 0 0 -9981 9381 0 0 0 0 0 0 286 -7115 0 0 0 0 0 0 -15360 -7959 0 0 0 0 0 0 -26648 -13094 0 0 0 0 0 0 -29344 -999 0 0 0 0 0 0 -12922 8793 0 0 0 0 0 0 -21146 12262 0 0 0 0 0 0 1568 -6382 0 0 dstLen2 = 36 dst2 = 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -31166 -28113 0 0 0 0 0 0 -11331 -8179 0 0 0 0 0 0 -30595 14322 0 0