I am writing a program that generates a WAV file that contains a smoothly changing sound from the frequency seq1 to seq1 , the sample rate sampleRate = 44100 and a length of n seconds. It is necessary to find a formula by which to calculate the frequency of the current segment with a length of one complete oscillation of sound, as well as the total number of segments of the frame.

The current frequency is seq = k1 * x + seq1 , where k1 is the growth rate of the frequency, x is the ordinal number of the segment into one complete oscillation;

The number of samples per segment is spt = sampleRate/seq = sampleRate/(k1*x+b);

PS In principle, it can be simplified by discarding the initial frequency, and calculated by the formula spt=(sampleRate/k1)/x

As I understand it, the number of segments and the frequency increment from segment to segment should be derived from the equation

\ int_ {0} ^ {frame} \ frac {sampleRate} {k1 * x + b} dx

But I'm not exactly sure.

Please help extract the number of segments and the rate of increase in frequency.

 int main() { ofstream out("test.wav", ios::binary); int time = 30; waveHeaderInit(2, 44100, 16, time); waveData = new char[waveHeader.subchunk2Size]; int sequence = 100; volatile float phase; volatile int16_t sample; int maxAmplitude = pow(2, waveHeader.bitsPerSample - 1) - 1; for (int i = 0; i < time * waveHeader.sampleRate; i++) { int spt = waveHeader.sampleRate / sequence; phase = (i % spt) / float(spt); sample = sin(PI*phase)*maxAmplitude; for (int channel = 0; channel < waveHeader.numChannels; channel++) { ((int16_t*)waveData)[i*waveHeader.numChannels + channel] = sample; } } out.write((char*)&waveHeader, sizeof(waveHeader)); out.write(waveData, waveHeader.subchunk2Size); out.close(); return 0; } 
  • So you want to build a sound from scratch, or add effects to the finished one? - nick_n_a
  • Try not to ask "double" questions. - nick_n_a
  • f (frequency, Hz) = 1 / T (T is the period in seconds). - nick_n_a
  • Roughly, you can write f (t) = f0 + (f1 - f0) * ((t - t0) / (t1 - t0)) as a line equation if you want to increase the frequency linearly. (from the general equation of the line). - nick_n_a
  • one
    Yes. Because it will not fall into tact and will be torn. It is very difficult to describe the formula that would get into the contact (I can not imagine how). - nick_n_a

1 answer 1

Increase the frequency slowly at an exponential rate. Monotone sound is A*sin(2Pi*B*t) . Replace the constant B with the exponent B:=C*Exp[D*t] .

 C*Exp[D*t0]==seq0 C*Exp[D*t1]==seq1 --- D=Ln[seq1/seq0]/(t1-t0) C=seq0*((seq0/seq1)^(t0/(t1-t0))) 

We A*sin(2Pi*C*Exp[D*t]*t) . Simplify t0=0, t1=T Result:

  A*sin(2Pi*seq0*((seq1/seq0)^(t/T))*t)