#include void downsample(const short *input, int inputSize, short *output, int outputSize) {int ratio = inputSize / outputSize;for (int i = 0; i < outputSize; ++i) {int start = i * ratio;int sum = 0;for (int j = start; j < start + ratio; ++j) {sum += input[j];}output[i] = sum / ratio;}}int main() {// 假设有一个原始音频数据 input,长度为 inputSizeshort input[] = { /* 原始音频数据 */ };int inputSize = sizeof(input) / sizeof(short);int outputSize = inputSize / 2;// 降低采样率为原来的一半short output[outputSize];downsample(input, inputSize, output, outputSize);// 输出降采样后的音频数据for (int i = 0; i < outputSize; ++i) {printf("%d ", output[i]);}return 0;}
import mathll = 3 # out put len, down sample lena=[10,9,3,4,5,2,11,45,90,17,12,49,32,40,53,32,11,45,90,17]b=[0]*llr= len(a)/llstart = 0ed =0for ni in range(ll):start = eded = round(ni*r+r)sm = 0cnt =0#print('stat',start,start+r)for oi in range(start,ed):print(oi)sm += a[oi]cnt = cnt +1#print(cnt,sm)b[ni]=int(sm/cnt)print(b)
保障每个样本都被用到了。