Coder Social home page Coder Social logo

gdscriptaudioimport's People

Contributors

4321ba avatar eamonnmr avatar gianclgar avatar guysoft avatar l4vo5 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

gdscriptaudioimport's Issues

mp3 support

Thank you very much for this!
Now that Godot 3.2.4 supports mp3, it would be easy to add mp3 support, it seems to work fine just like with ogg.
I tried this in RC4 and it seems to work just fine:
insert after the ogg part:

#if file is mp3
elif filepath.ends_with(".mp3"):
	var newstream = AudioStreamMP3.new()
	newstream.loop = true #set to false or delet this line if you dont want to loop
	newstream.data = bytes
	return newstream 

It'd be wise to wait until 3.2.4 comes out though. I'll make a pr.

In-memory based parsing and some appreciation.

Appreciation

Thanks for your efforts developing GDScriptAudioImport! I was glad to find this project existed when I discovered Godot unexpectedly didn't handle parsing WAV files at run time!

Modification to support in-memory (non file-based) parsing

A couple of suggestions if you or anyone else happens to develop the code any further:

  • Consider extracting the WAV parsing code into a separate function so that it can be used with WAV files from non-file sources (e.g. HTTP request).
    I very hackily modified the code to do this when I re-used it here: lightly modified GDScriptAudioImport.gd.
    (Also, FWIW, removed the debug print statements too--although it'd probably be more useful to enable them to be able to be toggled on/off for development purposes.)
  • When reading from a file consider using the get_* family of functions for the parsing data types rather than implementing the byte/offset handling "manually": https://docs.godotengine.org/en/stable/classes/class_file.html#class-file-method-get-16
    Edited to add: Forgot to mention, it's potentially possible to easily convert the code to get_* functions based on changing the set_* operations in Godot's WAV save implementation to get_* operations. :D (Or, indeed, some of the code in the WAV resource importer, e.g. here.)
  • If changing to use a separate function to parse a non-file-based PoolByteArray in memory, it's still possible to use get_* family style parsing methods but it's not at all obvious how...
    The solution is to use the extremely un-intuitively named & under-documented StreamPeerBuffer class which also supports the get_*/set_* data type parsing methods--but this isn't immediately obvious because the methods are actually implemented on the StreamPeer class from which it inherits.
    Here's an example of StreamPeerBuffer class in use.
    And some more notes about StreamPeerBuffer.
    Which includes this summary: :D

    The...ah..."un-intuitively"-named StreamPeerBuffer is un-intuitively named because it has no Peer :) and it's not a Stream. It's just a Buffer...with some useful helper methods.

    The naming is because it's based on a class that is used by the family of classes that do have Peer(s) & are Streams.

I would be inclined to make the modifications myself just to tidy up the implementation a bit but given this functionality will hopefully be (re-)implemented in engine at some point* it's not obvious that it's worth spending the time refining the existing code further.

Anyway, thanks again & hope some of these notes are useful to someone along the way. :)

Add some tags to the project to make it easier to find via GitHub search

I had some trouble finding the project again after discovering it last week. I know realise this might be because of the missing tags.

I would expect to be able to find the project for example like this: https://github.com/search?o=desc&q=godot+audio&s=stars&type=Repositories

Ideas for fitting tags:

  • godot
  • audio
  • gdscript
  • music

Possibly some other tags from the other projects you can see in the list, but I think those are the main ones. I hope that works, I am not 100% familiar with how the GitHub search works.

I am aware that the search is definitely able to access the desription: https://github.com/search?q=A+script+in+GDScript+for+importing+.wav+and+.ogg+audio+files+at+runtime&type=Repositories so if adding the tags does not work maybe somehow add Godot in the description. But hopefully adding the tags is enough.

Update for godot 4

Godot 4 came out recently. All code except .ogg can easily be translated to godot 4 mostly by applying the name changes (File > fIleAccess, PoolByteArray -> PackedByteArray, etc.).
Don't know if there is some magic for loading .ogg in godot 4 at runtime at this time, but the remainder should be updated.

wrong calculations of loop_end (assuming 4 bytes per sample)

In line 143 the samplenum for setting loop_end is calculated wrong. It assumes 4 bytes per sample, which isn't always correct and hence causes the loop to start earlier in some cases (e.g. 16 bit per sample / mono). As the bits_per_sample is calculated above it should be used to calculate the correct samplenum instead.

OLD: var samplenum = newstream.data.size() / 4 (line 143)
NEW: var samplenum = newstream.data.size() / (bits_per_sample / 8)

Note, that the bits_per_sample is initialized with 0. Hence this might result in a division by 0. Hence, I suggest something like assert(bits_per_sample != 0) as done above in the code... or do some other error handling. Thanks!

unable to put newstream.data into $AudioStreamPlayer.stream and play it manually

unable to put newstream.data into $AudioStreamPlayer.stream and play it manually.

BTW,

func _on_openmusic_file_selected(path):
var file = File.new()
file.open(path, File.READ)
$AudioStreamPlayer.stream = file.get_current_file()

Idk why this doesn't work with wav mp3 or ogg files.
But if I use your code,
I can't even hear anything or manually control it.
Just asking, should I put your code into the $audiostreamplayer or it's ok to put it in the main node?

thanks for answering!

Found a WAV file that doesn't play

As the title suggest: I found a wav file that doesn't play.
I can't send it as it's too large, but the data starts at ~byte 700, and it contains artist names + a junk chunk
changing the loop to go to that causes it to make weird glitchy sound.
I don't really know how to solve this one sadly, but it works fine when imported with the normal audio importer: https://github.com/godotengine/godot/blob/master/editor/import/resource_importer_wav.cpp

Example file: https://mega.nz/file/tFdXlSiL#YWdCsuFSaRtWa8felZX1FWsVer247oAjGyEXPFV34Yk

The parsed format code is 3, so it doesn't work

Hey, first, thank you for providing such script.

I've tried to load a .wav file (too big to send here), and the format code that was parsed was 3, so it's not 8_BITS, 16_BITS or IMA_ADPCM.

I'm not sure why, but I can provide you with more information or the file if you want to try.

ogg doesn't always start

With ogg files, they sometimes click or make another noise before they start playing normally, or don't start at all. This doesn't seem to depend on the file and happens at random, and importing it via the in-engine importer it works fine.

Adding a 300 millisecond delay before playing the file makes this issue occur less frequent.

I'm thinking this has to do with the engine still decoding the data, as the in-engine importer does the same as your code for loading ogg files.

Edit: formatting

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.