c - 从 C 中的 wav 文件中删除暂停

标签 c wav

我需要删除 wav 文件中的暂停(暂停 - 幅度<16且长度>N个样本的区域)。不太了解如何使用示例,以及如何从文件中逐个读取示例。下面是我的代码:

#include <stdio.h>
#include <stdlib.h>
#define BUFSIZE 4000

typedef struct header {
    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;
    short int extra_param_size;
    char subchunk2_id[4];
    int subchunk2_size;
} header;
typedef struct header* header_p;

void change_file(char * input, int N){
    FILE * infile = fopen(input, "rb");
    FILE * outfile = fopen("outfile.wav", "wb");
    short int inbuff16[BUFSIZE];
    header_p meta = (header_p)malloc(sizeof(header));

    if (infile) {
        fread(meta, 1, sizeof(header), infile);
        fwrite(meta, 1, sizeof(header), outfile);

        while (!feof(infile)) {
                fread(inbuff16, 1, BUFSIZE, infile);      
                //delete pause here
                fwrite(inbuff16, 1, BUFSIZE, outfile);
        }
    }
    if (infile) { fclose(infile); }
    if (outfile) { fclose(outfile); }
    if (meta) { free(meta); }
}

int main (int argc, char const *argv[]){
    char infile[] = "track.wav";
    change_file(infile, 20);
    return 0;
}

最佳答案

不得在 while 循环中使用 !feof(infile) 表达式。

详情:

Why is “while ( !feof (file) )” always wrong?

关于c - 从 C 中的 wav 文件中删除暂停,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30654808/

相关文章:

c - GStreamer 解决了从命令行转换为 C 代码时的过滤问题

c - realloc() 悬挂指针和未定义行为

c - 无法通过cmd运行C程序

java - 将 .wav 文件和 .ttf 字体文件添加到可执行 jar 文件中

c - MIPS 操作存储在数据中的数组

c - haskell FFI传入和传出C结构数组

c# - 用 HTML5 播放 wav

audio - 如何将 RAW/WAV 文件解码为数字列表?

iphone - iPhone 应用程序的声音格式

flash - 如何使用http播放wave文件?