Modification for AudioSource module (including native)

Hi Mr @zhangxm and @mr.kylin ,

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.

I’ve tried to modify these files:

  1. CocosEngine\native\cocos\audio\oalsoft\AudioEngine-soft.h / .cpp
  2. CocosEngine\native\cocos\audio\oalsoft\AudioPlayer.h / .cpp

but in the end, when I try to compile simulator app using command “gulp gen-simulator”, It gives empty build (no .exe)

@westdragoneye what’s your cocos creator version?

Hi Mr @zhangxm , Thank you for repy.

It is 3.8.0 sir

Is this a warning, not an error? Are there any other errors?

I’ve look entire log when I am running gulp command but there is no “error” message. And based on my ss top there that’s the only one looks sus.

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?

hi Mr. @zhangxm any update yet?

You can work on the .ts files, as stated on 3.8 here Cocos Creator 3.8 Manual - Engine Customization Workflow

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).

In this one I fixed the errors from the other file modifications (constructor, getter and setter, loadOneShotAudio).

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.

Wow thanks @coimbra , This is a new knowledge for me. I didn’t realize there is …\engine@types\pal\audio.d.ts.

Give me a few minutes I will let you know my progress.

1 Like

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.

1 Like

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.

1 Like

take it easy @coimbra , you are not alone to feel that. That’s why I love open source :rofl:

I will try to update cocos source into 3.8.2 and then lets see the result

1 Like

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.

1 Like

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.

1 Like

I appreciate your help bro, I am going to see your work. Thanks @extendable-arms