Simple tone generator?

My use case is fairly simple: I’d like to use the latest audio engine tools to generate a tone (sine wave) at a specific frequency and be able to change the frequency on the fly.

I’m comfortable in both BP and UMG, so wiring it up doesn’t scare me, I just have no idea where to start. I’m not at all familiar with DAWs, synths, filters, etc. and many of the tutorials out there seem to be geared towards people coming from an audio background.

Is this a fairly simple thing to do with the new audio engine?

Simple use case, as to generate a sine wave and adjust its tone is fairly easy and i’m sure with a few minutes of digging thru google, this topic or even youtube you will find the example for it. But once you start dig deeper in the rabbit hole you will require to have a certain amount of understanding it’s obviously the case here as well, just like with anything else in the engine. Audio is not different from any of the other technologies integrated in the engine, so you have to learn the basics first to know which tool you will want to use for your work. It’s not feature complete but rich, and that is good for setting up complex behavior too, tho you may find it less satisfactory for certain use cases. It’s no problem, and i mean not to complaints about the current state, since it is evolving pretty fast and have great improvements by the day you can see this on the github commits.

One thing that i think would be nice to put more time investment is the visual feedback of the setup, and perhaps better modularity to understand what is happening. For instance, i have found NI’s reaktor to be a good example of modular synthesis where i have learned a great ton of basics about how a synth can work, and it allowed me to setup very sophisticated builds for many use cases. Reaktor was never meant to be optimal for real time use (with multiple instances even) but at least you could have a straight idea of what is going on. You can take a look at tools like reaktor that should help. But of course you can go down the path with the basic VST’s as well in free DAW applications you can use them to experiment with the properties of similar functions you can find in the engine as well, since they are ready to use and simple to access.

I would also suggest you to try to setup simple synthesis projects you can test and evaluate the behavior of the engine system, that should give you a huge boost of practical experience too with the ue4 implementation. Start with a sine wave and a fequency modulation, just like the example you have mentioned.

If you create a New C++ class SynthComponent, it will code gen a simple sine tone generator with an example of a BP API function for changing pitch, starting, stopping, etc.

Watch Dan do it on stage live at GDC 2017 here: The Future of Audio in Unreal Engine | GDC 2017 | Unreal Engine - YouTube

Ah, this is perfect. Thank you!

I spent the last 6-8 hours searching and scouring the internet and this is the only reference I have found that mentions the generation of sound waves in the Unreal Engine. Does anyone have any other references for this? I went to that video above and all he did was show you how to create a new C++ SynthComponent…I guess there must be an extra step somewhere to get it to work because I tried using the Start function on beginplay and placed it in the scene and it doesn’t make any sound.

You probably haven’t activated the synth component - I always forget!! Add your synth component to an Actor Blueprint then add the Blueprint to the scene. Then in the actor blueprint either Activate the synth component with a BP node or set it to Auto Activate in the details panel. No need for anything else and it should work when you Play.

Yeah Idk, I did it like it showed me to but he had it connected to something else so I’m not sure what all he left out. I know next to nothing about synth components, I should probably look into learning more about them. I imagine I’m just not doing something right, I had it on a BP and even added it to the seen. I tried activate, and the start function but neither of them seemed to do anything. No sound would play when I started the level. No doubt it’s just my lack of understanding, if you do have any good sources though that break the SynthComponent down and explain it better please share. I would appreciate it.

Lol your funny, I’m not trying to build hardware. I’m into building software, that’s why I’m on an UnrealEngine forum not a tech forum.

1 Like

I just learnt from the UE code in the dsp library to see how it worked in UE4 but
I have done DSP coding before. I would recommend finding a book on Audio programming for C++ if you are serious about it. UE4 is pretty standard in how it implements DSP and has its own DSP library to help you so downloading the source is good. But I have never seen any step by step tutorials specific to UE4.

What C++ code did you add to your synth component to generate the sound in the OnGenerateAudio method? The Default synth component wont make any sound without a few modifications - to get the oscillator to work there is a #define that has to be set to 1 and the comment in the .h file tells you to add the dsp path to the project (I forgot exactly what because I never use that code and delete it immediately!). If you dont want to use their oscillator the simplest thing to do is generate noise - In the OnGenerateAudio method make the OutAudio[Sample] = a random number between -1.0 and +1.0 in the for loop and you will hear white noise.

Once you get it going you can control the frequency with a variable float from the output back to the input. As you adjust that variable it should change your frequency at the oscillator output. If you are wanting to get a constant output at one frequency lock the output with a RC filter. i would think a constant float would do that job nicely for the RC filter.

When you get this running i would be interested just seeing it work. Video would be sweet. I was thinking of trying to make a basic electronics learning game, but i do not think many would be interested in it. So i scrapped the idea. Looks like a fun little project you have going :slight_smile:

Ah thanks for the info, I’ll probably have to do that. UE4 I’ve found isn’t quite as straightforward in some areas as it would be coding it outside of the Engine. I was primarily just trying to get it up and running and understand how it all worked before actually trying to manipulate it to meet my needs.

Yeah, I might do that if I can get this figured out. I did it in Unity and it was so straight forward and simple. I just feel lost when it comes to trying to do the same thing in UE4.

i would do what the guys aboveSandyBeachSystem was saying and what he is saying to get it going. Once you have white noise you can start adjusting according. 1st thing to do is to get a oscillator running > basically a loop that does not stop that makes noise. Then solve what frequency your at < if you need to.

If you were using OnAudioFilterRead in Unity, OnGenerateAudio is works basically the same but is less of a fudge. TBH it took me ages to make any noise in UE4 but most was getting my head around how the Engine worked. But once you get any sound it gets easier very quickly and you can do anything.

In theory, this should work. As for me, now there are many different software that can provide work with an audio track and get a sound of a different range.

I was messing around yesterday with the audio set up stuff and there are many ways to do the sound stuff. I found the oscillator and the white noise items. I can see once i decide to hook up those in the proper set up, it all should work. I am working on a play the music and make the different colored lights light up at certain frequencies, like the christmas lights on the houses we see today is what i am after.
What makes this tough is it is done in code not actual electronic circuits. So it makes you think how the heck can i get this in code, but if it were actual electronic circuits it be a lot easier. Example is getting the frequencies from the audio track you play. Is there a function in UNREAL4 that will spit out the frequencies that are being played in the audio? Any ideas would be appreciated very much.

EDIT: Think i might have found ithttps://docs.unrealengine.com/en-US/BlueprintAPI/SoundVisualization/CalculateFrequencySpectrum/index.html

EDIT: Must watch video if you want to get frequencies
https://www.bing.com/videos/search?q=how+to+get+frequencies+from+audio&&view=detail&mid=78A9B5E3C05B44C4096878A9B5E3C05B44C40968&&FORM=VDRVRV

Eww no don’t use that old plugin for getting freqs! It is MUCH easier, better, and already built-in to later versions of Unreal! Check out tons of examples in my free project: Arthurs Audio BPs

sweet, thanks for the info. i will check that out right now :slight_smile:

EDIT: that is awesome man, good job on that.
Again, that it just plain badass! Thanks for your time you put into that. That is one hell of a setup it is just plain awesome. your the man.

1 Like

Thanks for the response, I’ll keep that in mind and just start working through some audio tutorials. I too found it quite easy too pull off in Unity with my limited knowledge of their system at the time. Unreal seems to lack many tutorials on specific things like this so I assume you really have to wrap your head around their system before you understand things like that.