分析.WAV 文件
analyzing .WAV files
我目前正在使用 .WAV 文件,我有一个问题。
我解决这个问题的方法是创建一个包含信息的结构:
typedef struct header_file{
char chunk_id[4];
int chunk_size;
char format[4];
char subchunk1_id[4];
int subchunk1_size;
short int audio_format;
short int num_channels;
int sample_rate;
int byte_rate;
short int block_align;
short int bits_per_sample;
char subchunk2_id[4];
int subchunk2_size;
}header;
typedef struct header_file* wav_p;
现在,我尝试像下面这样运行 WAV 文件:
ofstream myFile;
myFile.open("file.txt");
FILE * file = fopen("file.wav", "rb");
const int BUFFSIZE = 256;
int count = 0;
short int buff[BUFFSIZE];
wav_p wav = (wav_p)malloc(sizeof(header));
int nb;
if (file)
{
fread(wav, 1, sizeof(header), file);
while (!feof(file)){
nb = fread(buff, 1, BUFFSIZE, file);
count++;
for (int i = 0; i<BUFFSIZE; i += 1){
//the following part i found on the internet so i'm not sure if it is good
int h = (signed char)buff[i + 1];
int c = (h << 8) | buff[i];
double t = c / 32768.0;
myFile << t << endl;
if(abs(t)>1){
//checking that a value is between -1 to 1
}
}
}
}
fclose(file);
myFile.close();
我的问题是:内在for
是否正确? file.txt
我所有的值都在 -1 到 1 之间,所以我认为这很好,但我不确定,我是否正确地浏览了.wav文件,以及我将其放入"file.txt"的方式是否良好("file.txt"是否包含文件函数的"y 轴"值, 其中"x 轴"是时间(
你的代码基本上是正确的。 您没有检查 wav 标头以验证波形文件是否实际包含 16 位样本。
您对 16 位值的计算是错误的,因为buff
是一个short int
数组。 如果buff
是一个char
数组,你使用的计算是正确的(但你必须i
递增 2(。
使用short int
阵列,您可以说int c = buff[i];
,除非您的系统是大端系统。
abs(t) > 1
是不必要的,因为 -1.0 <= c
<1.0。
相关文章:
- 尝试使用来自 Win32 WASAPI C++的"捕获流"创建 wav 文件
- 如何从wav文件中获取采样率?
- 写入 wav 文件时定期创建静音
- 在不打开应用程序的情况下在MinGW c++中播放声音(.wav)文件
- 如何使用curl c ++源代码发布wav文件数据,如何使用c ++使用--data-binary?
- 为什么 XAudio2 仅在系统暂停时播放.wav文件?
- 处理文件期间输出失真.wav
- webRTC : 如何通过从WAV文件获得的样本将webRTC的VAD应用于音频
- WAV文件停止功能
- 如何从特定点播放.WAV文件(例如30秒)
- 通过C(或C )中的WAV文件循环
- 开放式阅读WAV文件lib
- 使用C++ / Python的wav文件的FFT
- 在mbed中打开的wav文件数量是否有限制
- 音频编程 SDL - 如何使用 wav 文件在命令行中指定频率切割
- 无法使用两种不同的频率填充 *.wav 文件的缓冲区
- 禁用在使用QAudioRecorder时创建wav文件
- 无论如何,我可以从WAV文件中打印Sox即可打印幅度值
- WAV文件的数据在-1和1之间,C ,SNDFILE
- 在黑莓10(原生)上分割音频文件(wav)