组合 2 个 wav 文件后生成的 wav 的采样率
我在 VS2010 中手动执行以下操作。 1. 读入 2 个波形文件,例如“1.wav”和“2.wav”。 2. 将2.wav 插入到1.wav 的中间。 3. 将结果波形流写入输出文件“out.wav”。
我现在可以使用以下结构成功读取波形文件
typedef struct {
char ChunkID[4]; /* RIFF Header */ //Magic header
unsigned long ChunkSize; /* RIFF Chunk Size */
char Format[4]; /* WAVE Header */
char Subchunk1ID[4]; /* FMT header */
unsigned long Subchunk1Size; /* Size of the fmt chunk */
unsigned short AudioFormat; /* Audio format 1=PCM,6=mulaw,7=alaw, 257=IBM Mu-Law, 258=IBM A-Law, 259=ADPCM */
unsigned short NumChannels; /* Number of channels 1=Mono 2=Sterio */
unsigned long SampleRate; /* Sampling Frequency in Hz */
unsigned long ByteRate; /* bytes per second */
unsigned short BlockAlign; /* 2=16-bit mono, 4=16-bit stereo */
unsigned short BitsPerSample; /* Number of bits per sample */
char Subchunk2ID[4]; /* "data" string */
unsigned long Subchunk2Size; /* Sampled data length */
BYTE Data[18000];
} WavFile;
,但是两个波形文件的一些参数不相同。例如,如果 1.wav 的 SampleRate 是 8000,2.wav 的 SampleRate 是 44100,那么 out.wav 的 SampleRate 是多少?
I'm doing the following in VS2010 manually.
1. Read in 2 wave files, say "1.wav" and "2.wav".
2. Insert 2.wav to the middle of 1.wav.
3. Write the result wave stream to an output file "out.wav".
I can now read in the wave files successfully using the following structure
typedef struct {
char ChunkID[4]; /* RIFF Header */ //Magic header
unsigned long ChunkSize; /* RIFF Chunk Size */
char Format[4]; /* WAVE Header */
char Subchunk1ID[4]; /* FMT header */
unsigned long Subchunk1Size; /* Size of the fmt chunk */
unsigned short AudioFormat; /* Audio format 1=PCM,6=mulaw,7=alaw, 257=IBM Mu-Law, 258=IBM A-Law, 259=ADPCM */
unsigned short NumChannels; /* Number of channels 1=Mono 2=Sterio */
unsigned long SampleRate; /* Sampling Frequency in Hz */
unsigned long ByteRate; /* bytes per second */
unsigned short BlockAlign; /* 2=16-bit mono, 4=16-bit stereo */
unsigned short BitsPerSample; /* Number of bits per sample */
char Subchunk2ID[4]; /* "data" string */
unsigned long Subchunk2Size; /* Sampled data length */
BYTE Data[18000];
} WavFile;
But some of the parameters of the 2 wave files are not the same. For example, if SampleRate of 1.wav is 8000, SampleRate of 2.wav is 44100, what will SampleRate of out.wav be?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
out.wav 的采样率是您必须明确定义的。在您的示例中,您可以选择 out.wav 为 44100,两者中较好的一个,但您需要通过插值或在中间添加零来对 1.wav 进行上采样。或者,您可以将其保持在 8000 并向下采样 2.wav,方法是通过低通滤波器运行它以滤除超过奈奎斯特(新采样率的一半)的频率,然后在中间丢弃样本。不管怎样,你必须明确决定你想做什么。
更多信息 - https://ccrma.stanford.edu/~jos/resample/
The sampling rate of out.wav is something that you will have to define explicitly. In your example, you could choose your out.wav to be 44100, the better of the two, but you will need to upsample 1.wav by interpolation or adding zeros in between. Alternatively, you could keep it at 8000 and downsample 2.wav by running it through a low-pass filter to filter out frequencies more than Nyquist (half of new sampling rate)and then dropping the samples in the middle. Eitherway, you will have to explicitly decide what you want to do.
More info - https://ccrma.stanford.edu/~jos/resample/