3

キャプチャしたRaw16kHzPCM16ビットファイルを16ビットWAVに変換するプログラムをCで作成しようとしています。

私はいくつかの投稿を読み、人々はを使用することをお勧めしlibsoxます。それをインストールして、今私はマンページを理解するのに本当に苦労しています。

これまでのところ(ソースdistの例を読んで)私は次のことを理解しましたstructs

  • sox_format_t
  • sox_signalinfo_t

おそらく、入力しているデータを説明するために使用できます。どういうわけかそれが必要な場合、私はまた、私が処理している情報(時間)の量を知っていますか?

いくつかのガイダンスをいただければ幸いです。

4

2 に答える 2

5

さて、質問に答えるとうまくいきました。ただし、ここにコードを投稿して、人々がコードを分析したり、自分のプロジェクトで使用したりできるようにします。

「simonc」と「NickolayO」の両方によって提供されるリンク。使われた。個々のフィールドの詳細については、Webを検索してください。

struct wavfile
{
    char        id[4];          // should always contain "RIFF"
    int     totallength;    // total file length minus 8
    char        wavefmt[8];     // should be "WAVEfmt "
    int     format;         // 16 for PCM format
    short     pcm;            // 1 for PCM format
    short     channels;       // channels
    int     frequency;      // sampling frequency, 16000 in this case
    int     bytes_per_second;
    short     bytes_by_capture;
    short     bits_per_sample;
    char        data[4];        // should always contain "data"
    int     bytes_in_data;
};

//Writes a header to a file that has been opened (take heed that the correct flags
//must've been used. Binary mode required, then you should choose whether you want to 
//append or overwrite current file
void write_wav_header(char* name, int samples, int channels){
    struct wavfile filler;
    FILE *pFile;
    strcpy(filler.id, "RIFF");
    filler.totallength = (samples * channels) + sizeof(struct wavfile) - 8; //81956
    strcpy(filler.wavefmt, "WAVEfmt ");
    filler.format = 16;
    filler.pcm = 1;
    filler.channels = channels;
    filler.frequency = 16000;
    filler.bits_per_sample = 16;
    filler.bytes_per_second = filler.channels * filler.frequency * filler.bits_per_sample/8;
    filler.bytes_by_capture = filler.channels*filler.bits_per_sample/8;
    filler.bytes_in_data = samples * filler.channels * filler.bits_per_sample/8;    
    strcpy(filler.data, "data");
    pFile = fopen(name, "wb");
    fwrite(&filler, 1, sizeof(filler), pFile);
    fclose(pFile);
}
于 2013-01-03T11:20:25.837 に答える
2

WAVヘッダーとデータを手動で書き込むことをお勧めします。PCMの場合は非常に簡単です: https ://web.archive.org/web/20080706175634/https://ccrma.stanford.edu/courses/422/projects/WaveFormat //

更新:元のリンクhttps://ccrma.stanford.edu/courses/422/projects/WaveFormat/が無効になりました。

于 2012-12-14T16:34:56.883 に答える