godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.16k stars 97 forks source link

Make the API for loading audio files at run-time uniform across formats #8055

Open CsloudX opened 1 year ago

CsloudX commented 1 year ago

Describe the project you are working on

Music Player

Describe the problem or limitation you are having in your project

In 4.x, it has ability to load audio on runtime, but it not uniformed.

MP3

var file = FileAccess.open(path, FileAccess.READ)
var sound = AudioStreamMP3.new()
sound.data = file.get_buffer(file.get_length())

OGG

var sound = load_from_file(path)

WAV

No api, but I think it was simple to implement.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

uniform all api to static method load_from_file(path).

If possible, I wish all have load_from_buffer.(sometime I will get data from network)

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

/

If this enhancement will not be used often, can it be worked around with a few lines of script?

/

Is there a reason why this should be core and not an add-on in the asset library?

It is should be core.

Calinou commented 1 year ago
fire commented 1 year ago

Are you interested in making pr for this? I think making a new matching set of apis would help unify and allow the backwards compatibility change by marking as deprecated and then removing many versions later

marcinn1 commented 1 year ago

Should loading audio files work via ResourceLoader::load()? I see there is nothing like ResourceFormatLoaderAudio.

ResourceLoader::load can be a high level interface for loading any resources. Instead of detecting format of the file inside the app (MusicPlayer in this example), Godot can do this internally.

PS. I need audio files loading at runtime in my project. I can help with testing or making a patch.

fire commented 1 year ago

The load function in Godot Engine utilizes its internal format. Importers convert the original file into this internal format. An .imported/godot/file.res replaces the original file with the converted internal format, and then the "pointer" is saved in the .import file.

marcinn1 commented 1 year ago

Ok, so I'm confused again and I think I must be lucky with loading DDS by using ResourceLoader: https://github.com/godotengine/godot-proposals/issues/5748#issuecomment-1756301744