ikbencasdoei / godot-voip

godot-voip is a Godot Engine addon which makes it very easy to setup a real-time voice-chat system in your Godot game. This addon also includes a demo project.
https://godotengine.org/asset-library/asset/425
MIT License
196 stars 13 forks source link

[Off-Topic] - How to make a beat detection? #8

Closed Gamemap closed 3 years ago

Gamemap commented 3 years ago

This is off topic! If you do not want this, please delete this issue!

I don't want to create too many accounts for forums, so I want to ask you if you can help/explain me how to create a music beat detection in godot. I want a pattern to move to the next step to a beat in the music. (Is this possiblein Godot?)

I hope you can help me with that, Gamemap

Here is an example for an pattern (later as an Animationplayer in Godot)

https://user-images.githubusercontent.com/71942164/109418456-c5918300-79c8-11eb-8801-6b06a0bdd282.mp4

ikbencasdoei commented 3 years ago

I'm not an expert but I think this is certainly possible in Godot. But I really think it is better if you ask this in Godot Q&A, Godot Discord server, Godot subreddit, etc. I maybe can help you there and others can help as well.

Gamemap commented 3 years ago

Ok, I think i will make an account at Godot Q&A.

Gamemap commented 3 years ago

I will look at you Input threshold.https://github.com/casbrugman/godot-voip/commit/e2e78b29cd1d944ca501f93eccd87c054ceeba37 Maybe something like that is what I need.

Gamemap commented 3 years ago

Somehow you send the audio data only when the input sensitivity is lower than the sound. Could you shortly explain how you did that and if it is possible to get a signal when the music is "louder"?

Edit: Have you used the new effect capture for that? https://github.com/casbrugman/godot-voip/blob/e2e78b29cd1d944ca501f93eccd87c054ceeba37/addons/godot-voip/scripts/voip_instance.gd#L60

ikbencasdoei commented 3 years ago

Yes I use the capture effect to get the microphone input for the plugin. See:

    var stereo_data = _effect_capture.get_buffer(_effect_capture.get_frames_available())

    #Loop over the array to get the highest value.
    var max_value = 0.0
    for i in range(stereo_data.size()):
      var value = (stereo_data[i].x + stereo_data[i].y) / 2.0
      max_value = max(value, max_value)

    #If value is lower than the threshold stop
    if max_value < input_threshold:
      return

After that the logic you want to run when the threshold is reached.

Gamemap commented 3 years ago

Thank you! I will try to implement this in the next few days. Would the audio capture also work with music files or only with a mic?

ikbencasdoei commented 3 years ago

Yes, you just have to add the capture effect to the same audio bus you play your music in and you will be able to capture it.

Gamemap commented 3 years ago

I'm glad to tell you that the beat detection works :) Thanks a lot for this code!

I have not done any fine tuning yet.

Here is an example (with audio):

https://user-images.githubusercontent.com/71942164/109793866-7e4c0200-7c15-11eb-947c-6add51a47891.mp4