gpt4 book ai didi

audio - fscanf(文件指针, "%d\n%lg\n",sig_length,sample_rate);怎么解释呢?

转载 作者:行者123 更新时间:2023-11-30 18:51:28 25 4
gpt4 key购买 nike

我有一个从互联网之前存在的科学音频文件类型(称为 TFD v1)的音频格式转换为未压缩的简单原始样本值数组...在 this page 上的 get_signal() 函数中,我不知道样本值的格式如何,以及为什么我需要采样率来从数组中读取 256 个点?

  fscanf (filepointer         , "%d\n%lg\n" , sig_length,  fsam         );
fscanf (raw_audio_array_file, ?? , 256 , SRate_Float );


/*******************************************************
* function get_signal reads signal data into sig_re from
* the file pointed to by filepointer. If the file is a
* type 2 TFD file then the imaginary part is set too.
* If the signal is type 1, its hilbert transform is
* returned in the imaginary part (sig_im).
********************************************************/


void get_signal (filepointer, sig_re, sig_im, fsam, sig_length)
FILE *filepointer;
double sig_re[],
sig_im[],
*fsam;
int *sig_length;

{
register int i; /* counter variable */
int sigtype; /* data file type */
double dummy1,
dummy2; /* dummy temporary variables */


fscanf (filepointer, "%d\n", &sigtype);
if (sigtype == 1) { /* Type one TFD file */
fscanf (filepointer, "%d\n%lg\n", sig_length, fsam);
for (i = 0; i < *sig_length; i++) {
fscanf (filepointer, "%lg\n", &sig_re[i]);
}
analytic (sig_re, sig_im, *sig_length);
}
else {
if (sigtype == 2) { /* Type 2 TFD file */
fprintf(stderr,"Complex signal.\n");
fscanf (filepointer, "%d\n%lg\n", sig_length, fsam);
for (i = 0; i < *sig_length; i++) {
fscanf (filepointer, "(%lg,%lg)\n", &sig_re[i], &sig_im[i]);
printf("%lg\n",sig_re[i]);
}
}
else {
fprintf (stderr, "ccg : incorrect input format.\n");
exit (7);
}
fclose (filepointer);
}
} /* END OF FUNCTION get_signal */

最佳答案

fscanf (filepointer, "%d\n%lg\n", sig_length, fsam); 调用 C 函数 fscanf ,根据格式字符串从文件中读取格式化数据。

本例中的格式字符串为 "%d\n%lg\n" ,它分解为 %d (整数)、换行符、%lg(一个double),以及另一个换行符。因此,基本上,它从文件中读取两行,第一行应包含具有样本长度的整数,第二行包含采样率。

举个例子,使用现代采样率:

1
256
44100.0
1.0
0.98
0.96
...

其中第一行是 sigtype,第二行和第三行是信号长度(以样本为单位)和采样率,其余行是信号值。

关于audio - fscanf(文件指针, "%d\n%lg\n",sig_length,sample_rate);怎么解释呢?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36677112/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com