AudioStreamSample in Godot 4: Identifier "AudioStreamSample" not declared

By Eduardo Orellana · Updated

AudioStreamSample is called AudioStreamWAV in Godot 4. Replace the class name; its data, format, mix_rate, stereo and loop properties keep their names, but the loop mode constant LOOP_PING_PONG is now LOOP_PINGPONG.

AppImage, x86_64. Ubuntu 22.04, Debian 12, Fedora 39 or newer.

Intel or AMD Chromebook, with Linux turned on.

Download for macOSDownload for Windows

What Godot is checking

When GDScript loads a script it resolves every identifier. AudioStreamSample is not a class in Godot 4, so the analyzer stops with Identifier not declared in the current scope and none of the script runs.

When the project setting debug/gdscript/warnings/renamed_in_godot_4_hint is on, the analyzer looks the name up in the Godot 3 to 4 rename table and appends Did you mean to use with the new name. That table carries AudioStreamSample to AudioStreamWAV.

The same table's enum renames carry LOOP_PING_PONG to LOOP_PINGPONG, marked for AudioStreamWAV. The class reference lists the LoopMode constants as LOOP_DISABLED, LOOP_FORWARD, LOOP_PINGPONG and LOOP_BACKWARD.

The analyzer reports every use of the old name, not only the first. On 4.7.2 the repro prints the same parse error for lines 4, 5 and 7, the three lines that name AudioStreamSample, and then Failed to load script.

More on this: Physics2DServerSW in Godot 4: Identifier "Physics2DServerSW" not declared

Reproduce it

A Godot 3 script that builds a short 16-bit tone in an AudioStreamSample and plays it, in a Godot 4 project. The scene is one AudioStreamPlayer with this script.

extends AudioStreamPlayer

func _ready():
	var sample = AudioStreamSample.new()
	sample.format = AudioStreamSample.FORMAT_16_BITS
	sample.mix_rate = 22050
	sample.loop_mode = AudioStreamSample.LOOP_PING_PONG
	stream = sample
	play()

What Godot 4.7.2 prints

Godot Engine v4.7.2.stable.mono.official.ed1daf0bf - https://godotengine.org

SCRIPT ERROR: Parse Error: Identifier "AudioStreamSample" not declared in the current scope. Did you mean to use "AudioStreamWAV"?
   at: GDScript::reload (res://answers/audiostreamsample-in-godot-4/repro.gd:4)
SCRIPT ERROR: Parse Error: Identifier "AudioStreamSample" not declared in the current scope. Did you mean to use "AudioStreamWAV"?
   at: GDScript::reload (res://answers/audiostreamsample-in-godot-4/repro.gd:5)
SCRIPT ERROR: Parse Error: Identifier "AudioStreamSample" not declared in the current scope. Did you mean to use "AudioStreamWAV"?
   at: GDScript::reload (res://answers/audiostreamsample-in-godot-4/repro.gd:7)
ERROR: Failed to load script "res://answers/audiostreamsample-in-godot-4/repro.gd" with error "Parse error".
   at: load (modules/gdscript/gdscript_resource_format.cpp:46)

Fix it

Use AudioStreamWAV and LOOP_PINGPONG. The script fills 0.1 seconds of a 440 Hz sine as signed 16-bit little-endian PCM, sets the loop points, and prints what the stream reports.

extends AudioStreamPlayer

func _ready() -> void:
	var rate := 22050
	var frames := rate / 10
	var pcm := PackedByteArray()
	pcm.resize(frames * 2)
	for i in frames:
		var s := int(sin(TAU * 440.0 * i / rate) * 16000.0)
		pcm.encode_s16(i * 2, s)

	var wav := AudioStreamWAV.new()
	wav.format = AudioStreamWAV.FORMAT_16_BITS
	wav.mix_rate = rate
	wav.stereo = false
	wav.data = pcm
	wav.loop_mode = AudioStreamWAV.LOOP_PINGPONG
	wav.loop_begin = 0
	wav.loop_end = frames
	stream = wav

	print("class: ", wav.get_class())
	print("bytes: ", wav.data.size())
	print("length: ", wav.get_length())
	print("loop mode is pingpong: ", wav.loop_mode == AudioStreamWAV.LOOP_PINGPONG)
	print("AudioStreamSample in ClassDB: ", ClassDB.class_exists("AudioStreamSample"))

What the fixed script prints

Godot Engine v4.7.2.stable.mono.official.ed1daf0bf - https://godotengine.org

class: AudioStreamWAV
bytes: 4410
length: 0.1
loop mode is pingpong: true
AudioStreamSample in ClassDB: false

Verified on Godot 4.7.2

Both scripts on this page were run headless on Godot 4.7.2 (4.7.2.stable.mono.official.ed1daf0bf) on 6 October 2026, and the output above is what Godot printed, unedited.

Where the check lives in Godot's source: [gdscript_analyzer.cpp lines 4679 to 4687, the message and the rename hint](https://github.com/godotengine/godot/blob/4.7.2-stable/modules/gdscript/gdscript_analyzer.cpp#L4679), [renames_map_3_to_4.cpp line 1483, AudioStreamSample to AudioStreamWAV](https://github.com/godotengine/godot/blob/4.7.2-stable/editor/project_upgrade/renames_map_3_to_4.cpp#L1483), [renames_map_3_to_4.cpp line 117, LOOP_PING_PONG to LOOP_PINGPONG](https://github.com/godotengine/godot/blob/4.7.2-stable/editor/project_upgrade/renames_map_3_to_4.cpp#L117), [AudioStreamWAV class reference](https://github.com/godotengine/godot/blob/4.7.2-stable/doc/classes/AudioStreamWAV.xml).

Questions

Is AudioStreamSample still in ClassDB under its old name?
No. On 4.7.2, ClassDB.class_exists("AudioStreamSample") prints false. Only AudioStreamWAV exists.
What is LOOP_PING_PONG called in Godot 4?
LOOP_PINGPONG. The LoopMode constants on AudioStreamWAV are LOOP_DISABLED, LOOP_FORWARD, LOOP_PINGPONG and LOOP_BACKWARD.
How do I load a WAV file at runtime in Godot 4?
Call the static AudioStreamWAV.load_from_file(path, options), or AudioStreamWAV.load_from_buffer(bytes, options) for WAV data already in a PackedByteArray. The option keys match the properties of ResourceImporterWAV.
What format does the data property expect?
Raw samples in the format the format property names. With FORMAT_8_BITS it expects signed 8-bit PCM, so subtract 128 from each unsigned byte; with FORMAT_QOA it expects a whole QOA file. The fix fills FORMAT_16_BITS data with PackedByteArray.encode_s16.