Skip to content
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

[Web] Fix audio issues with samples and GodotPositionReportingProcessor #102163

Merged
merged 1 commit into from
Jan 31, 2025

Conversation

adamscott
Copy link
Member

This PR pools the GodotPositionReportingProcessor worklets created instead of creating new worklets every time. This seems to prevent an escalation in memory usage over time.

Fixes #98731.

Copy link
Member

@rburing rburing left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixes the issue in my project, cf. #98731 (comment). Thanks!

@Repiteo Repiteo merged commit a7e5469 into godotengine:master Jan 31, 2025
19 checks passed
@Repiteo
Copy link
Contributor

Repiteo commented Jan 31, 2025

Thanks!

this.lastPostTime = currentTime;
this.port.postMessage({ 'type': 'position', 'data': this.position });
}

return true;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the spec https://developer.mozilla.org/en-US/docs/Web/API/AudioWorkletProcessor/process - returning true will force the AudioWorkletNode to remain active. I.e. I think this will keep processing even after it's been disconnected. Instead of adding a pool wouldn't it be easier to just return false here when it's disconnected?

i.e. something like this:

this._positionWorklet.port.postMessage('stop'); // tell the processor to stop
this._positionWorklet.disconnect();
class GodotPositionReportingProcessor extends AudioWorkletProcessor {
	constructor() {
		super();
		this.position = 0;
		this.running = true;
		this.port.onmessage = (event) => {
			if (event.data === 'stop') {
				this.running = false;
			}
		};
	}

	process(inputs, _outputs, _parameters) {
		if (inputs.length > 0) {
			const input = inputs[0];
			if (input.length > 0) {
				this.position += input[0].length;
				this.port.postMessage({ 'type': 'position', 'data': this.position });
				return true;
			}
		}
		if (!this.running) {
			this.port.onmessage = null;
		}
		return this.running;
	}
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll test it out! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

v4.4 Sound quickly regresses on the Web: freezes, noises, crackles
4 participants