I am working on audio source adjustment (adding parameter for pitch). Any suggestion which file(s) I should modify so It can implement well in native platform especially for windows.
but the point of this topic, it is not about which log error is. I want to know which file(s) I should modify if we want to add new parameter to exist module.
For example: If user of this engine wanna add pitch parameter for audio source, Which file(s) should follow for modification. I bet the one who knows this case is cocos team right?
C:\ProgramData\cocos\editors\Creator\3.8.1\resources\resources\3d\engine\cocos\audio\audio-source.ts
Here I searched for ‘volume’, then copy/paste/renamed to ‘pitch’ every occurence (all but @tooltip('i18n:audio.volume') which is here C:\ProgramData\cocos\editors\Creator\3.8.1\resources\resources\3d\engine\editor\i18n[langCode]\localization.js if you may).
C:\ProgramData\cocos\editors\Creator\3.8.1\resources\resources\3d\engine@types\pal\audio.d.ts
In this one I fixed the errors from the other file modifications (constructor, getter and setter, loadOneShotAudio).
C:\ProgramData\cocos\editors\Creator\3.8.1\resources\resources\3d\engine\bin.declarations\cc.d.ts
And finally added the pitch variable getter and setter to the AudioSource class.
Complile the engine (Developer->Compile the engine) and reload (Developer->Reload).
This will give you the pitch field in the component inspector and you’ll be able to access it via code (this.node.getComponent(AudioSource).pitch) to work from there.
Hi @coimbra , I have implement all steps that you given to me but it gives none pitch effect and I think there is something need to do with OpenAL scripts.
Like I mention before I added OpenAL API (for pitch control) in :
…\Engine\native\cocos\audio\oalsoft\AudioEngine-soft.h / .cpp
also in …\Engine\native\cocos\audio\oalsoft\AudioPlayer.h / .cpp
Are there any cpp scripts beside that two scritps that need to handle?
Those steps were only to add a variable to the component. I’m still trying to figure out how to apply it to the pitch, since in engine\native\cocos\audio\oalsoft\AudioPlayer.cpp we already have a line for the pitch, but with a hardcoded value alSourcef(_alSource, AL_PITCH, 1.0F);
I’ve run through a bunch of files trying to make it work with a _pitch variable, but i’m lost in this maze. Still looking though.
Guess i’m stuck almost in the same spot as you were. Gulp seems to builds, but my editor crashes after. Removed and reinstalled nodejs; tried a few times with different engine versions; but always ends in the same: builds, then crashes. Can’t even tell you if the changes applied.
Hello everyone. I’ve figured it out to some degree.
You can see changes in this fork on github: lampysprites/cocos-engine/commit/b6040f08c1cc24b935e1cfc067e9d1157f453d4a (i can not post links!). The patch adds pitch property to AudioSource component.
Currently, only play method on openal-soft platform works properly. I did not change playOneShot, and it broke from receiving pitch == 0. I plan to fix it eventually.
It’d be great if someone contributed support to html5, android and apple platforms so it can be considered for merging. For html5, there seem to be an existing patch in the main repo PR’s which is not yet merged (i can not post links!). I can perhaps do html5, but have very little experience with mobile development.
Alrighty I’ve fixed one shot and (very crudely) merged html5 code from pr#9751, which works in browser at least -leaving only android and apple unfinished. It’s in the same repository’s audio-pitch branch.