将短裤数组转换为双打数组 [英] Converting an array of shorts to an array of doubles
本文介绍了将短裤数组转换为双打数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在C / C ++中将short类型的数组转换为double类型的数组?
How I could convert array of type short to array of type double in C/C++?
我有代码从wav文件中读取音频数据,并且输出为array类型短。因此,现在我想将此数据用于FFT(我不想使用库)。
I have code to read audio data from wav file and output is array of type short. So now I want to use this data for FFT (I don't want use libraries).
有任何技巧或想法吗?
推荐答案
您无法转换该数组;不过,您可以使用转换后的值创建新数组:
You can't convert the array; you can however create a new array with the converted values:
#include <iterator>
#include <algorithm>
short src[10] = ...;
double dst[sizeof(src)/sizeof(short)];
std::copy(std::begin(src), std::end(src), dst); // generic, C++11
std::copy(src, src + 10, dst); // a bit more hackish
最好使用 std ::数组< float,10> src;
等。
如果您的数组实际上是动态数据结构,则变得更加容易:
If your "arrays" are really dynamic data structures, it becomes even easier:
std::vector<float> src = ... ;
std::vector<double> dst(src.begin(), src.end());
这篇关于将短裤数组转换为双打数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文