C 通用加法综合程序
我正在尝试编写一个通用的加法合成c程序,该程序将生成一个复杂的正弦波,该正弦波由任意频率的纯正弦波序列在单个包络之后生成。 输入文件将具有这种性质C 通用加法综合程序,c,audio,synthesis,C,Audio,Synthesis,我正在尝试编写一个通用的加法合成c程序,该程序将生成一个复杂的正弦波,该正弦波由任意频率的纯正弦波序列在单个包络之后生成。 输入文件将具有这种性质 F0 P0 // a list of up to 100 floats indicating frequencies and F1 P1 // % contribution of this frequency to the sound F2 P2 ...
F0 P0 // a list of up to 100 floats indicating frequencies and
F1 P1 // % contribution of this frequency to the sound
F2 P2
....
-1 // sentinal value to indicate end of frequency list
B0 A0 // first breakpoint
B1 A1
... // There can be an arbitary number of breakpoints
我希望我的程序生成一个WAV文件,直到最后一个断点,所有正弦波都将以给定的频率生成,按所列的百分比比例缩放,并加在一起生成最终的声音
我尝试过一些c编程,但我不是一个天生的c编程者,所以这就是我到目前为止所做的:
#include <stdio.h>
#include <stdlib.h>
#include <portsf.h>
#include <math.h>
#ifndef M_PI
#define M_PI (3.141592654)
#endif
// Additive Synthesis
PSF_PROPS props;
props.srate = 44100;
props.chans = 2;
props.samptype = PSF_SAMP_IEEE_FLOAT;
props.format = PSF_STDWAVE;
props.chformat = STDWAVE;
float* frame;
int sampleNumber;
double angleIncrement;
double frequency;
double sampleRate;
int i;
int twopi = 2.0 * M_PI;
ofd = psf_sndCreate(argv[2],&props,0,0,PSF_CREATE_RDWR);
int main (int argc, char* argv[]) {
sampleNumber = 0;
angleIncrement = twopi * frequency/sampleRate;
while (i < sampleNumber) {
frame[0] = frame[1] = sin(sampleNumber * angleIncrement);
sampleNumber++;
if (fwrite(&sampleout,sizeof(float),1,rawfile) !=1) {
printf("Error writing to output file.\n");
return 1;
}
if (i <=1000)
fprintf(bpfile, "%ld\t%f\n", i, frame);
phase += angleIncrement;
if (phase >= twopi)
phase -= twopi;
}
phase_offset = -1 * PI / 2;
sample_buffer = (float*) malloc(samples * sizeof(float));
// sample_buffer set back to 0
memset(sample_buffer, 0, sizeof(float)*sampleNumber);
// go through the number of harmonics
for (i = 1; i <= NHARMS; i++) {
amp = 1.0 / i;
// go through number of sinusoid components
for (n = 0; n < sampleNumber; n++) {
sample_buffer[n] += amp * cos(i * angleIncrement * n + phase_offset);
}
}
}
#包括
#包括
#包括
#包括
#伊夫德夫·穆皮
#定义M_PI(3.141592654)
#恩迪夫
//加性合成
PSF_道具;
props.srate=44100;
props.chans=2;
props.samptype=PSF\u SAMP\u IEEE\u FLOAT;
props.format=PSF\u STDWAVE;
props.chformat=STDWAVE;
浮动*帧;
int sampleNumber;
双角度增量;
双频;
双采样器;
int i;
int-twopi=2.0*M_-PI;
ofd=psf_sndCreate(argv[2],&props,0,0,psf_CREATE_RDWR);
int main(int argc,char*argv[]){
sampleNumber=0;
角度增量=twopi*频率/采样率;
而(i 对于(i=1;i随着我开始注意到越来越多的小细节,这些评论开始让人讨厌(但请确保您仍然回答我的Hello World编译问题),因此我将它们合并到这个答案中,并在看到更多信息时进行更新:
到目前为止,频率
只使用了一次,而且当时只有0.0
一次。这就是你想要的吗
i
被初始化为0
,而sampleNumber
也在0
启动。因此while
条件(i
将永远不会执行
i
永远不会递增,但如果(i我同意AKA4749,还有一件事你应该做:添加样本时剪辑样本,否则会出现失真:
if ( sample[i] > 1 ) sample[i] = 1;
else if ( sample[i] < -1 ) sample[i] = -1;
如果(样本[i]>1)样本[i]=1;
如果(样本[i]<-1)样本[i]=-1;
您遇到的错误是什么?@AK4749我得到的是一个没有这样的文件或目录gcc:没有输入文件
,但除此之外,我不完全确定我是否真的正确处理了这个问题。我们可以慢慢地一次解决一个问题,但首先我觉得您的gcc设置不正确你能编译一个简单的hello world程序吗?+1用于制作一个加法合成器。我的gcc出了点问题,但这已经解决了,所以我可以运行hello world问题。我已经解决了一些问题,但仍然收到很多错误。有没有一封电子邮件可以发送给你,因为这条评论是正确的ead可能会来回一段时间,发送一封电子邮件给这个:显然没有括号,我会通过那里给你更好的联系信息-这是一个高知名度的网站,不想发布我真正的电子邮件哈哈。它将开放24小时。