godot: Cannot record audio on Linux when compiled with -fPIC

Godot version

3.4.stable

System information

Linux 5.15.4-arch1-1

Issue description

The following code captures audio from a mic and plays it back:

extends Node

var capture := AudioEffectCapture.new()
var playback: AudioStreamGeneratorPlayback

func _ready():
	var idx := AudioServer.get_bus_count()
	AudioServer.add_bus(idx)
	AudioServer.set_bus_mute(idx, true)
	AudioServer.add_bus_effect(idx, capture)

	var mic := AudioStreamPlayer.new()
	mic.stream = AudioStreamMicrophone.new()
	mic.bus = AudioServer.get_bus_name(idx)
	add_child(mic)
	mic.play()

	var player := AudioStreamPlayer.new()
	player.stream = AudioStreamGenerator.new()
	playback = player.get_stream_playback()
	add_child(player)
	player.play()

func _physics_process(_delta: float):
	var n := capture.get_frames_available()
	var recorded := capture.get_buffer(n)
	var maxval := 0.0
	for i in range(n):
		playback.push_frame(recorded[i])

	capture.clear_buffer()

In godot 3.3.4, it works as expected. In godot 3.4, I hear nothing.

Steps to reproduce

  1. Run the example project with godot 3.3.4
  2. Talk into your mic
  3. Verify you hear your voice played back
  4. Run the example project with Godot 3.4
  5. Talk into your mic
  6. Hear nothing played back

Minimal reproduction project

example.zip

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Reactions: 1
  • Comments: 15 (11 by maintainers)

Most upvoted comments

I’m getting extrememly confused. This problem seems specific to the godot 3.4 PKGBUILD for ArchLinux. If I download that PKGBUILD and run makepkg -s, the resulting godot binary cannot capture audio. If I unpack the source .tgz and compile with the same flags, it seems to work fine:

scons -j16 bits=64 colored=yes platform=x11 pulseaudio=yes system_certs_path=/etc/ssl/certs/ca-certificates.crt target=release_debug tools=yes use_llvm=no CFLAGS=-fPIC -Wl,-z,relro,-z,now CXXFLAGS=-fPIC -Wl,-z,relro,-z,now builtin_bullet=no builtin_certs=no builtin_freetype=no builtin_libpng=no builtin_libvorbis=no builtin_libwebp=no builtin_miniupnpc=no builtin_pcre2=no builtin_zlib=no builtin_zstd=no

I’ll keep investigating, but it seems like this is probably an Arch-specific packaging issue and not a Godot bug.

@extremety1989 if you’re asking about this issue in particular, n is nonzero but the data from capture.get_frames_available() is all 0 (if compiled with -fPIC).

If you’re asking for general help, this issue isn’t the place. Check out some of the community resources, the docs, the godot-voip plugin, or the audio recording demo

I just double-checked and confirmed – removing -fPIC from https://github.com/archlinux/svntogit-community/blob/packages/godot/trunk/PKGBUILD#L49-L50 fixes the issue. Is this a bug in Godot or in the Arch packaging? It seems like compiling with -fPIC should work, though I also see this line https://github.com/archlinux/svntogit-community/blob/packages/godot/trunk/PKGBUILD#L23 messing with the automatically-added pie flags.

The issue seems to be -fPIC in the CFLAGS and CXXFLAGS