+2 votes

Hi everyone!
I've been trying to make some kind of a music game on Godot for some time now, and I'm really stuck on something, so for short:
I have a sample player that... well... plays a sample, that part is fine,
the problem is,
when I try to change the sample player volume, the change doesn't apply until the sample player plays again, not while the sample is being played.
I've noted that it is possible to change the stream player volume on the fly (with StreamPlayer.setvolumedb), but I'm not able to do so with the sample player (with SamplePlayer.setvolumedb), and both classes have methods to change the volume.

My question is: Can I change the volume of the sample player on the fly by any means?
Is there a function/method I'm missing to work that out?

Also, but not that important for now:
I've experienced problems with sound while having LLMS(Linux Multi Media Studio) open, being more specific, having the audio settings for outputlatency under 30 or something makes all the audio output to be fuzzy and noise-like, but closing LMMS or, in some extreme cases, restarting pulseaudio from terminal seems to fix the problem.
Right now I have the output_latency on 15 and I have no problems, without opening LMMS.
I don't know if this is something related to drivers or not, I haven't tested it on windows for now, but it should work just fine.

BTW: I'm using Godot 2.0 Stable, on Ubuntu 15.04 64 bits

Sorry for my English and Thanks in advance!!!

in Engine by (40 points)

2 Answers

+2 votes
Best answer

Santiago, the most efficient way to work with samples in Godot (latency-wise and detailed control-wise speaking, but not so comfy way, unfortunately) is to actually plug straight into AudioServer interface that stands behind SamplePlayer anyway.

It allows you to operate all audio parameters in a smooth, detailed way that as far as my experience goes (mainly audio related applications) is not possible when using just a SamplePlayer node.

It is more complicated, because you basically have to create everything from scratch - you have to put in code things that SamplePlayer node takes care of for you - but that kind of low level access gives more control and better latency.

So, if you want to have smooth, instant changes of the volume of the already playing sample, use AudioServer and it's function voice_set_volume.
It will work like a charm.

by (721 points)
selected by

Thank you for your answer, Freeman, and sorry for replying so late. I will try to use AudioServer. Thanyou you all!

Hello again, I've tried using AudioServer but somehow, after I set the voice volume, and I play the sample again, the volume is restored to the default.

I've used the methods described here: http://godotengine.org/qa/2314/delay-in-sound-effects-from-sampleplayer2d

I don't know what I'm doing wrong :(

Congrats on making the AudioServer working. ;)
I don't know what's in your code, but to remember the voice volume adjustments, you could use a global variable
http://docs.godotengine.org/en/latest/tutorials/step_by_step/singletons_autoload.html?highlight=singleton

and let the adjustment value of the volume be "remembered" there and recalled when creating new voice to play a sample again.

Sorry to bother you again with this, but I've tried everything I could think of but... still no luck with that.

this link has the project in which I've been playing with the sample player, I honestly don't know what I'm doing wrong :(

I think I should just move on and work on other projects but I really would like to know how to change a sample's volume dynamically.

Extra data: The version 2.0.2 of godot crashes when I try to play a sample from the sample library window on the editor, but the version 2.0 work just fine.

Thank you for all the help!!

How are you getting to AudioServer ? AudioServer isn't a node. It's not a method of AudioStreamPlayer3D. Where/how do you access AudioServer?

0 votes

Hi.

First off, I would make sure you are using either .wav files or .ogg files directly (as opposed to Godot-specific sound formats).

If the sound still glitches and if you can prove this happens in very simple cases, I would open an issue on Godot's github page as it may be a bug.

by (138 points)

Hi there! I'm using ogg files for streaming and the godot sample format for the sample player, and both glitches at the same time when LMMS is open. When I open the ubuntu sound options and go to the applications tab(or something like that) the icon for the godot application blinks endlessly while the sound glitches.

Does it only glitch when LMMS is open or does it also happen with other applications open? Does it glitch when Godot is the only thing open?

If the answer to the latter is no, then it may or may not be an issue with Ubuntu then, I don't use Linux myself though so I can't say for sure.

It doesn't glitch when Godot is the only thing open, no matter the output_latency value, I can go as low as 5 ms and the program runs fine.
I tried to capture my desktop while running the program but the two screen capture programs I've used so far don't record any sound.
I have to say that I had issues with the audio no ubuntu in the past, in general, so I suppose that this is just driver/hardware related.

Now talking about dynamic volume change on the sample player, do you have any Idea on what can I do?
I've noted that the method to getvolumedb also give me some errors.

this link --> http://www.mediafire.com/download/67dfwsrb24fq8bc/SampleTest.zip has a simple test I've made to show the error Godot gives me when I try to change the sample player volume with the method setvolumedb. Also, the line with the method getvolumedb for the sample player is commented as it doesn't work.

The Debugger shows me this:
Type:Error
Description:
Time 0:00:00:0469
C Error: Condition '!v.active' is true. returned: 0
C Source: scene/audio/sampleplayer.cpp:411
C Function: get
volumedb

something similar appears to happen with setvolume_db.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.