#include <stdio.h>
#include <math.h>
#include <stdint.h>
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#define SAMPLE_RATE 44100
#define DURATION 2 // Duration in seconds
#define FREQUENCY 440 // Frequency in Hz
#define AMPLITUDE 32760 // Max amplitude for 16-bit audio
void write_wav_header(FILE *file, int sample_rate, int num_samples) {
uint32_t chunk_size = 36 + num_samples * 2;
uint16_t audio_format = 1; // PCM
uint16_t num_channels = 1;
uint16_t bits_per_sample = 16;
uint32_t byte_rate = sample_rate * num_channels * bits_per_sample / 8;
uint16_t block_align = num_channels * bits_per_sample / 8;
// RIFF chunk
fwrite("RIFF", 1, 4, file);
fwrite(&chunk_size,
C语言生成wav文件,写入sin波
最新推荐文章于 2024-11-01 12:24:48 发布