New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Design: Add ability to create sound from string buffer (DEF-1967) #3289
Comments
Starting working on this... |
@britzl, does it make sense to support OGG raw data, or is it only about WAV ? |
@otsakir for an MVP I'd say only WAV but I think we'd like support for both. |
ok. MVP ? |
Minimum Viable Product. The least amount of functionality that we can release with. If the feature is released with .wav support only it would still be useful. Adding .ogg support could be done in a second step. |
@britzl , @JCash , before discussing details of the implementation, the summary of my plan is the following:
Having all these set up, should theoretically allow us to play the sound with Does this make any sense to you ? Any easier approach ? I also checked Thanks |
Sounds good.
Although there is no actual file representing this dynamic sound, I believe it should go through our resource system.
For an example of how to create resources, checkout res_sound.cpp, and also script_resource.cpp (SetTexture). Also, if we have the sound as a proper resource, we can use the dynamic sound data interchangeably with the other code. (i.e. no need for another type dmGameSystem::Sound). See comp_sprite.cpp (GetMaterial) for an example of this.
I think it's reasonable to expect to have a sound component in order to play the sounds.
While I agree, we also have our paradigm of just unloading a collection. This is how things are designed. Given the fire-and-forget nature of our sounds, I wonder how we handle the refcounting/destruction on those resources when we unload a collection when the sounds are still playing. Overall, I think what you have here is a good strategy moving forwards. |
@JCash, thanks for the suggestiong. I went through them and resource related code. I also tried to better understand defold's bootstrapping wrt resources using gdb on a simple project with a sample ogg sound. Let me describe the mechanism as i've observed and understood it. I think it will save us some time later from clearing up misunderstandings.
Having that in place, and after considering your suggestions i'm sharing my view on the obstacles i'm facing:
Instead, wrt to the core of the implementation i'm suggesting the following approach:
https://github.com/defold/defold/blob/dev/engine/resource/src/resource.cpp#L1101
I won't get into the details of the rest of the implementation now. I believe we can settle these later as the feature gets together. JCash, tell me if this makes any sense to you. cc @britzl |
Hi @otsakir !
I think this is a good summary of how we're dealing with resources
The The
Correct. Our current example is
Yes. We'll require the developer to add a sound component in the editor, then use our Lua script and perhaps extension to create and update the sound data resource. |
@JCash, thanks. Updating an existing sound So, as far as i understand, the developer will be required to create a sound component and provide some sort of sound for it initially. Then, he/she will be able to update it using some sort of new lua api call like One final point. The update will affect the data of the Thoughts ? |
Btw, I was wondering about the actual format of the raw data provided by the user in the lua api call when updating the wavc/oggc resource content. From my understanding it should follow the format of a valid .wav/.ogg file. Does this stand ? |
Yes, the data should be in the format of a wav or ogg file |
Correct. We currently have no way to specify "no resource", and I'm not sure we want it (it's a bit of a separate discussion).
Correct. The path is required to update a resource. Example is To get the path of a resource, we need to implement it in the sound component type. See
As @britzl mentioned, the raw data we want in our case is .wav/.ogg. It may be beneficial however to know that most often our internal formats need to be stored in our own data formats. |
@JCash , thanks for the feedback. I've already created sample code that updates the sound resource on the fly and seems to work. Let me draft the implementation, based on the texture example presented here: https://defold.com/ref/resource/#resource.set_texture:path-table-buffer Lua apiBelow, a preview of the lua code that updates the internal .wav resource of a sound component.
Implementationscript_resource.cppNew comp_sound.cpp:GetSoundGetPropertyProvide support for a new property named ConcernsA sound component that initially has a 'wavc' resource bound to it, will throw a decoder error if it's updated to an 'oggc' type of resource. Are we ok with that ? Maybe do some forward check and provide a more informative error message to the developer. |
* 'Published' sound resource property in sound component. Now accessible from lua resource.get() * Support for sound-data resource update from lua string
Still needs minor tweaking
…3289 Commit: "More robust test for dynamic sound update - ref defold#3289" This reverts commit 9a57d6a.
* Update sound resource from buffer - ref defold#3289 * 'Published' sound resource property in sound component. Now accessible from lua resource.get() * Support for sound-data resource update from lua string * Test case for stringbuffer sound update - ref defold#3289
Similarly to what can be done with loading textures dynamically using gui.new_texture it would be nice to be able to do sound.new_sound
Requested on the forum: (LINK REMOVED)
The text was updated successfully, but these errors were encountered: