我想找到,笔记是如何建立的。 乐器(小提琴或钢琴)的示例,音符LA4(A4)具有440Hz的主(或中心)频率FC,具有特定幅度AC,但它必须具有其他频率(谐波?)FH与其他幅度AH。 / p>
谐波的其他频率取决于主频率,幅度(几乎)小于主频率的幅度。
形成(构建)笔记
我想知道如何形成(建立)笔记(没有考虑时间)。
实施例: A4 = AC(FC)+ AH1(FH1)+ AH2(FH2)+ AH3(FH3)+ AH4(FH4)...... AHn(FHn) 也许,FH1 = 2 * FC,FH2 = 3 * FC,FH3 = 4 * FC,等等....
乐器之间的比较(小提琴和钢琴)
对于钢琴,Note LA4(A4)的主频FC为440Hz,和 也许,FC(钢琴)= FC(小提琴),FH1(钢琴)= FH1(小提琴),FH2(钢琴)= FH2(小提琴),依此类推....
但是,AC(钢琴)!= AC(小提琴),AH1(钢琴)!= AH1(小提琴),AH2(钢琴)!= AH2(小提琴),等等....
我的问题的例子是: http://www.phys.unsw.edu.au/jw/sound.spectrum.html
我想播放这个音符,避免使用MIDI格式,这可以用Java / C#(或其他语言编程)实现,以后可以更好地控制我的声音。
谢谢。
安娜
答案 0 :(得分:3)
我有这个......
int iTone = 40; //Tone to be interpreted
iSmplRate = 32000; //Sample Rate
int NumBytesPerSample = 16; // 8 or 16
int NumChannels = 2; //1 Mono, 2 Stereo
double Duration = 6.5; //Seconds performing
Short sAmplit = 1200;
int iNumSmpl = (int)(SampleRate*Duration);
NumTotalBytes = (int)(SampleRate*Duration*NumBytesPerSample*NumChannels);
ByteBuffer bbWav = ByteBuffer.allocate(NumTotalBytes);
double dMaxInstr = (double)Short.MIN_VALUE;
double dMinInstr = (double)Short.MAX_VALUE;
//Amplitude for violin's armonics
double[] violAmps = {1.0, 0.286699025, 0.150079537, 0.042909002,
0.203797365, 0.229228698, 0.156931925,
0.115470898, 0.0, 0.097401803, 0.087653465,
0.052331036, 0.052922462, 0.038850593,
0.053554676, 0.053697434, 0.022270261,
0.013072562, 0.008585879, 0.005771505,
0.004343925, 0.002141371, 0.005343231,
0.000530244, 0.004711017, 0.009014153};
//Amplitude for piano's armonics
double[] pianAmps = {1.0, 0.399064778, 0.229404484, 0.151836061,
0.196754229, 0.093742264, 0.060871957,
0.138605419, 0.010535002, 0.071021868,
0.029954614, 0.051299684, 0.055948288,
0.066208224, 0.010067391, 0.00753679,
0.008196947, 0.012955577, 0.007316738,
0.006216476, 0.005116215, 0.006243983,
0.002860679, 0.002558108, 0.0, 0.001650392};
double[] operator = {1.0};
if (instrument.equals("violin")) {
operator = violAmps;
}
if (instrument.equals("piano")) {
operator = pianAmps;
}
double dFreq = 440.0*Math.pow(2.0, (iTone-69)/12.0;
double dFreqRel = iSmplRate/dFreq;
Integer iSampleInstrument = null;
double PI2 = 2*Math.PI;
int[] iSamplesInstr = new int[iNumSmpl];
for (int i = 0;i < iNumSmpl; i++) {
Double Angle = i*PI2/dFreqRel;
Double dInstrument = 0.0;
for (int a = 1; a <=operator.length; a++) {
dInstrument += operator[a-1]*Math.sin((double)a*Angle);
}
dMaxInstr = (dInstrument>dMaxInstr)?dInstrument:dMaxInstr;
dMinInstr = (dInstrument<dMinInstr)?dInstrument:dMinInstr;
iSampleInstrument = (int)(sAmplit*dInstrument);
if (instrument.equals("violin")) {
double FreqEnvV = iSmplRate/6.0;
double FracEnvV = 35.0;
double dEnvViolin = sAmplit*DStepperExt(Math.sin(1.0*i*PI2/FreqEnvV),4)/FracEnvV;
iSampleInstrument = (int)(iSampleInstrument+dEnvViolin);
}
if (instrument.equals("piano")) {
double FracEnvP = 8.0/10.0;
double AngP = (double)i/(iSmplRate*FracEnvP);
double EnvPiano = 1.0/Math.exp(AngP);
iSampleInstrument = (int)(iSampleInstrument*EnvPiano);
}
dMxSmplInstr = (iSampleInstrument>dMxSmplInstr)?iSampleInstrument:dMxSmplInstr;
dMnSmplInstr = (iSampleInstrument<dMnSmplInstr)?iSampleInstrument:dMnSmplInstr;
iSamplesInstr[i] = iSampleInstrument;
}
double dMaxAbs =
(Math.abs(dMaxInstr)>Math.abs(dMinInstr))?Math.abs(dMaxInstr):Math.abs(dMinInstr);
double dMxAbsSmpl =
(Math.abs(dMxSmplInstr)>Math.abs(dMnSmplInstr))?Math.abs(dMxSmplInstr):Math.abs(dMnSmplInstr);
double dNormal = 1.0;
if (dMxAbsSmpl > 32768.0) {
dNormal = 32768.0/dMxAbsSmpl;
}
for (int i = 0;i < iNumSmpl; i++) {
short sSampleInst = (short)(iSamplesInstr[i]*dNormal);
try {
if (iNumByteSmpl == 2) {
bbWav.put((byte)((sSampleInst >> 0) & 0xFF));
bbWav.put((byte)((sSampleInst >> 8) & 0xFF));
if (iNumChnnls == 2) {
bbWav.put((byte)((sSampleInst >> 0) & 0xFF));
bbWav.put((byte)((sSampleInst >> 8) & 0xFF));
}
} else {
byte ByteSample = (byte)((sSampleInst >> 8) & 0xFF);
short ShrtSample = (short)(ByteSample & 0xFF);
ShrtSample += 128;
bbWav.put((byte)(ShrtSample & 0xFF));
if (iNumChnnls == 2) {
bbWav.put((byte)(ShrtSample & 0xFF));
}
}
} catch (Exception e) {
System.out.println(e.getMessage());
}
此代码用于小提琴乐器:
private Double DStepperExt(Double Val, Integer Steps) {
//Return a value inside in range defined by step
//Divide [-1.0,1.0]/(Steps-1), retorning the value according to the range
//The value must be between 0.0 and 1.0
if (Steps <= 0.0) {
return 0.0;
}
if (Val != -1.0 && Val != 1.0) {
Val = Val - Val.intValue();
}
Double sDouble = new Double(Steps-1);
Double bdStep = 2.0/sDouble;
Double bdRef = bdStep/2.0;
bdRef = bdRef - 1.0;
Double bdInit = -1.0;
Double bdRet = null;
for (int c = 0; c<=sDouble;c++) {
if (Val < bdRef) {
bdRet = bdInit;
break;
} else {
bdInit = bdInit+bdStep;
bdRef = bdRef+bdStep;
}
}
return Math.min(bdRet.doubleValue(),1.0);
}
试试这段代码,我的声音并不完美,但非常相似。
答案 1 :(得分:2)
请注意,您正在进行的是巨大任务。如果您的目标是创建自己的合成器,听起来像钢琴,小提琴等,通过将谐波与特定振幅相加,那么创造一种逼真的声音是非常困难的。声学乐器的谐波以复杂的方式随时间变化。正如guidot所说,声音的攻击和延迟部分将会非常不同。如果你试着在一段时间内测量一个真实乐器的相对振幅,然后合成正弦曲线,那么你所能达到的最好就是听起来就像一个孩子的玩具。
如果这是你想要做的,那么你需要分析你想要模仿的声音随时间的频谱。我建议最简单的方法是使用Matlab,Octave或Scipy之类的东西。如果您想要可视化,请尝试使用Sonic Visualiser或Marsyas。
如果您想要创建逼真的播放,那么您有两个选择。一个是使用Wavetable synthesis,这是多少便宜的合成器(尤其是PC声卡上的合成器)的工作原理。另一个是研究Physical Modelling Synthesis,它模拟了乐器的物理特性,以创造逼真的声音。
答案 2 :(得分:0)
如果我理解正确,你正在尝试进行傅立叶综合,希望能得到类似于原始乐器的东西。我认为成功的可能性非常小:
我会推荐John Pierce,音乐之声科学作为介绍。