How to generate a time dependent frequency wave?

0

I want to create a sound whose frequency is time-dependent, let's say that the frequency of time ms is timeHz, hence in 20 s you have all the audible frequencies. Just as an example, with ffmpeg you can use time variable (%T) to overlay the time of every frame on a video. I thought I could use %T variable to generate such a wave. I've tried

ffmpeg -f lavfi -i "sine=frequency=%T*1000:sample_rate=44100:duration=20" -c:a pcm_s16le allfreq.wav

but it seems sine filter must have a fixed frequency.

I tried to use ffmpeg but it doesn't matter what program you use as long as it's free (light downloads appreciated).

cdlvcdlv

Posted 2016-12-14T12:18:34.487

Reputation: 703

2

You can overlay every frame of a video and just all of a sudden switch to audio? As for the sine function what you're actually trying to do is only generate part of the sine. Otherwise you would have an increasing base frequency while the sine would still continue to be sine. Maybe you could use the Chirp Generator from Audacity.

– Seth – 2016-12-14T12:30:45.553

The chirp generator suits perfectly. It has got more options that I didn't think, but interesting nevertheless. You can write it in as answer. – cdlvcdlv – 2016-12-14T12:43:31.143

Answers

2

While you start out with talking about video it seems like you're really interested in audio. You idea about the sine function is correct that it requires a fixed frequency as you'd set the base frequency that way. It would still be sine "around" that frequency.

What you're actually trying to do is generate a part of a sine or more likely a linear function increasing the frequency constantly. To do this you could try to use a Program like Audacity and it's Chrip Generator which from what it sounds like, would be what you're looking for. It would allow you to generate a sound starting at frequency X and let it end at Y after time N.

Seth

Posted 2016-12-14T12:18:34.487

Reputation: 7 657

1You are right, my original question was written somewhat confusing. I've edited it to make it more clear to future readers. – cdlvcdlv – 2016-12-14T12:53:20.163

1

If using ffmpeg, you have the aevalsrc filter:

ffmpeg -f lavfi -i "aevalsrc='sin(1000*t*2*PI*t)':s=44100:d=20" -c:a pcm_s32le allfreq.wav

You should be able to emulate all the chirp generator parameters once you figure out the expression required :)

I've used 32-bit float as output format as that's what Audacity's working format is.

Gyan

Posted 2016-12-14T12:18:34.487

Reputation: 21 016

I didn't know the aevalsrc filter. I suppose ffmpeg may work but it doesn't with these options. The frequency of the sound generated by your command increases until 11.025 s; then begin to decrease. I can see a relation between variable t and frecuency, but not as expected. – cdlvcdlv – 2016-12-14T18:02:29.660

1Yeah, I see that. Likely due to the combination of two things: 1) the low sampling rate 2) the dithering of the filter frequency output once it reaches a quarter of the sampling rate. Use s=176400. – Gyan – 2016-12-14T18:12:45.003

There is one more problem: the formula inside the sin is wrong. With ffmpeg -f lavfi -i "aevalsrc='sin(1000*t*PI*t)':s=44100:d=20" -c:a pcm_s16le allfreq.wav the wave is right. – cdlvcdlv – 2016-12-14T18:24:08.417

1With that formula, you are only going upto 10 kHz base. One cycle of the sine wave is 2*PI, so 2*PI*t produces one wave in a second. 1000*2*PI*t produces 1000 in a second. You further multiply by t to vary the carrier. – Gyan – 2016-12-14T18:28:54.477

I see your point, but both Audition and Audacity show wave from ffmpeg -f lavfi -i "aevalsrc='sin(1000*t*2*PI*t)':s=176400:d=20" -c:a pcm_s32le allfreq.wav reaching 40kHz in spectral view. Maybe an ffmpeg bug? – cdlvcdlv – 2016-12-14T19:38:43.760

Possibly. Will look into this tomorrow. – Gyan – 2016-12-14T20:13:38.590