音声ファイルを出力するには?


さかな  2004-07-15 05:19:15  No: 53986

前に投稿させていただいた者です。何度もすみません。
Cで.au形式の簡単な音声ファイルを作るプログラムなのですが、 
出力されたauファイルが開けません。
原因としては、このプログラムはbig endianのもので、
私のPCはlittle endianなので、開けないようです。
どなたか、big endianからlittle endianの変換の仕方を教えていただけないでしょうか?
ちなみにbig endianのプログラムです↓

#define MAXDATA 40000
#include <stdio.h>
#include <math.h>

typedef struct {
    int magic;
    int dataLocation;
    int dataSize;
    int dataFormat;
    int samplingRate;
    int channelCount;
    char info[4];
} SNDSoundStruct;

main(int argc, char *argv[]) {
    SNDSoundStruct hdr;
    FILE *fp;
    int frequency = 800;
    double step;
    int i;
    char x;
    
    if(argc != 2) {
        fprintf(stderr, "Usage: mysound <frequency>\n");
        exit(-1);
    }
    if (((frequency = atoi(argv[1])) <= 0) || (frequency > 4000)) {
        fprintf(stderr, "frequency should be between 0 to 4000 Hz\n");
        exit(-1);
    }
    
    fp = fopen("myfiling.au", "w");
   
    strcpy((char *)(&hdr.magic), "dns.");
    hdr.dataLocation = sizeof(hdr);
    hdr.dataSize = MAXDATA;
    hdr.dataFormat = 2;
    hdr.samplingRate = 8000;
    hdr.channelCount = 1;

    fwrite(&hdr, sizeof(hdr), 1, fp);
    for(i=0; i<MAXDATA; i++) {
        x = (char)(128.0 + 128.0 * sin(3.14 * 2 * frequency * i));
        fwrite(&x, 1, 1, fp);
    }

    fclose(fp);
}


.  2004-07-15 05:46:25  No: 53987

http://www2.realint.com/cgi-bin/tarticles.cgi?pointc+15514


※返信する前に利用規約をご確認ください。

※Google reCAPTCHA認証からCloudflare Turnstile認証へ変更しました。






  このエントリーをはてなブックマークに追加