ほとんどのSOといくつかのフォーラムを検索しましたが、わかりません。これをゼロからコーディングしたわけではありません。コードを取得し、要件に従って変更しようとしています。
したがって、最初に元のコーダーの功績を認めます。私はこれを参照しています: http://www3.nd.edu/~dthain/courses/cse20211/fall2013/wavfile/
ここでは、わずか 1 秒間だけ正弦波を作成しています。しかし、私はこの点を超えることができません。少なくとも 20 秒間再生する必要があります。
これが私のコードです。ポインター/ヘルプが得られることを願っています。前もって感謝します。元のコーダーに感謝します。
WAVFILE_SAMPLES_PER_SECOND = 44100
example.c ファイル
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <errno.h>
#include "wavfile.h"
const int NUM_SAMPLES = (WAVFILE_SAMPLES_PER_SECOND*2);
int main()
{
unsigned long waveform[NUM_SAMPLES*4]; // here I am changing it to 4
double frequency = 440;
int volume = 255;
unsigned long int length = NUM_SAMPLES*4; // here I am changing it to 4
// For one second the length = 88200
unsigned long int i;
for(i=0;i<length;i++) {
long double t = (long double) i / WAVFILE_SAMPLES_PER_SECOND;
waveform[i] = volume*sin(frequency*t*2*M_PI);
}
printf("length=%d\n",length);
FILE * f = wavfile_open("sound.wav");
if(!f) {
printf("couldn't open sound.wav for writing: %s",strerror(errno));
return 1;
}
wavfile_write(f,waveform,length);
wavfile_close(f);
return 0;
}
wave.h ファイル
#ifndef WAVFILE_H
#define WAVFILE_H
#include <stdio.h>
#include <inttypes.h>
FILE * wavfile_open( const char *filename );
void wavfile_write( FILE *file, short data[], int length );
void wavfile_close( FILE * file );
#define WAVFILE_SAMPLES_PER_SECOND 44100
#endif
ファイルが正常に作成されました。しかし、どのプレーヤーでも再生できません。誰でも助けることができますか?再度、感謝します