Thursday, July 23, 2026

Modification for AudioSource module (together with native) – Cocos Creator


Hello Mr @zhangxm and @mr.kylin ,

I’m engaged on audio supply adjustment (including parameter for pitch). Any suggestion which file(s) I ought to modify so It will probably implement effectively in native platform particularly for home windows.

I’ve tried to change these recordsdata:

  1. CocosEnginenativecocosaudiooalsoftAudioEngine-soft.h / .cpp
  2. CocosEnginenativecocosaudiooalsoftAudioPlayer.h / .cpp

however ultimately, when I attempt to compile simulator app utilizing command “gulp gen-simulator”, It provides empty construct (no .exe)

@westdragoneye what’s your cocos creator model?

Hello Mr @zhangxm , Thanks for repy.

It’s 3.8.0 sir

Is that this a warning, not an error? Are there another errors?

I’ve look total log when I’m operating gulp command however there is no such thing as a “error” message. And primarily based on my ss high there that’s the one one appears to be like sus.

however the level of this matter, it’s not about which log error is. I need to know which file(s) I ought to modify if we need to add new parameter to exist module.

For instance: If person of this engine wanna add pitch parameter for audio supply, Which file(s) ought to comply with for modification. I wager the one who is aware of this case is cocos group proper?

hello Mr. @zhangxm any replace but?

You’ll be able to work on the .ts recordsdata, as said on 3.8 right here Cocos Creator 3.8 Handbook – Engine Customization Workflow

C:ProgramDatacocoseditorsCreator3.8.1resourcesresources3denginecocosaudioaudio-source.ts
Right here I looked for ‘quantity’, then copy/paste/renamed to ‘pitch’ each occurence (all however @tooltip('i18n:audio.quantity') which is right here C:ProgramDatacocoseditorsCreator3.8.1resourcesresources3dengineeditori18n[langCode]localization.js when you could).

C:ProgramDatacocoseditorsCreator3.8.1resourcesresources3dengine@typespalaudio.d.ts
On this one I fastened the errors from the opposite file modifications (constructor, getter and setter, loadOneShotAudio).

C:ProgramDatacocoseditorsCreator3.8.1resourcesresources3denginebin.declarationscc.d.ts
And at last added the pitch variable getter and setter to the AudioSource class.

Complile the engine (Developer->Compile the engine) and reload (Developer->Reload).

This will provide you with the pitch subject within the element inspector and also you’ll have the ability to entry it through code (this.node.getComponent(AudioSource).pitch) to work from there.
image

Wow thanks @coimbra , It is a new information for me. I didn’t notice there may be …engine@typespalaudio.d.ts.

Give me a couple of minutes I’ll let you recognize my progress.



1 Like

Hello @coimbra , I’ve implement all steps that you just given to me however it provides none pitch impact and I believe there’s something must do with OpenAL scripts.

Like I point out earlier than I added OpenAL API (for pitch management) in :

…EnginenativecocosaudiooalsoftAudioEngine-soft.h / .cpp
additionally in …EnginenativecocosaudiooalsoftAudioPlayer.h / .cpp

Are there any cpp scripts beside that two scritps that must deal with?

These steps have been solely so as to add a variable to the element. I’m nonetheless attempting to determine how one can apply it to the pitch, since in enginenativecocosaudiooalsoftAudioPlayer.cpp we have already got a line for the pitch, however with a hardcoded worth alSourcef(_alSource, AL_PITCH, 1.0F);
I’ve run via a bunch of recordsdata attempting to make it work with a _pitch variable, however i’m misplaced on this maze. Nonetheless wanting although.



1 Like

Guess i’m caught virtually in the identical spot as you have been. Gulp appears to builds, however my editor crashes after. Eliminated and reinstalled nodejs; tried a couple of instances with totally different engine variations; however all the time ends in the identical: builds, then crashes. Can’t even inform you if the modifications utilized.



1 Like

take it simple @coimbra , you aren’t alone to really feel that. That’s why I like open supply :rofl:

I’ll attempt to replace cocos supply into 3.8.2 after which lets see the consequence



1 Like

Howdy everybody. I’ve figured it out to some extent.

You’ll be able to see modifications on this fork on github: lampysprites/cocos-engine/commit/b6040f08c1cc24b935e1cfc067e9d1157f453d4a (i cannot publish hyperlinks!). The patch provides pitch property to AudioSource element.

At present, solely play technique on openal-soft platform works correctly. I didn’t change playOneShot, and it broke from receiving pitch == 0. I plan to repair it will definitely.

It’d be nice if somebody contributed assist to html5, android and apple platforms so it may be thought-about for merging. For html5, there appear to be an current patch in the primary repo PR’s which isn’t but merged (i cannot publish hyperlinks!). I can maybe do html5, however have little or no expertise with cell growth.



1 Like

Alrighty I’ve fastened one shot and (very crudely) merged html5 code from pr#9751, which works in browser a minimum of -leaving solely android and apple unfinished. It’s in the identical repository’s audio-pitch department.



2 Likes

I recognize your assist bro, I’m going to see your work. Thanks @extendable-arms

Hello, I adopted your hyperlink and it’s the samplerate change of the audio. I don’t assume I can discover the forked repo that you just talked about. Is it closed?
THX

I discovered it in the primary repo at Audio playrate – assist oalsoft, replace html5 by lampysprites · Pull Request #16764 · cocos/cocos-engine · GitHub
Be aware this was two+ years, and a significant model in the past so likelihood is it received’t merge.
I’ve no vitality for fixing it, hope you perceive.

thnaks very a lot.
I’m not on-line final week. I simply transfer to fmod and add it to the projetc, lol.
however thanks in your replying.



1 Like

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisement -spot_img

Latest Articles