Comments (8)
We have no expectation that behavior seen using tools other than Scratch will represent the behavior using Scratch. Can you experience this behavior using Scratch?
from scratch-audio.
Okay, I put the project playing for 2 hours in the vanilla Scratch to see how the behavior is noticable, and here's the result.
2021-01-29_19-46-00.mp4
from scratch-audio.
I made a test for a quick reproduction of the behaviour: https://scratch.mit.edu/projects/481050174/
It became slower and slower until the page reloaded again.
However, when the audio assets removed and the same audio reuploaded again, it became more responsive again.
from scratch-audio.
Here's an even more minimal version of @Kouzeru's project. It no longer makes much noise, but it still calls "set pitch effect" as fast as it can. You can watch the "set effect calls per second" drop very quickly after startup. Stopping the project and starting it again does not restore initial performance, but reloading the page does.
sound effects per second.sb3.zip
from scratch-audio.
Here's GarboMuffin's approach upon tackling this problem by doing optimisation upon sound effect changes
TurboWarp/scratch-vm@bffe350
from scratch-audio.
When is this fixed? Is anyone allowed to contribute?
from scratch-audio.
Hello, from testing, this actually appears to be an issue with your code. Since loops without a screen update have zero delay at the end of the loop, it will take an indeterminate amount of time, anything you run in the loop will eat into that loop (so it takes longer to loop). It is jot regulated to take some specific amount of time because that would break frequently and often if it was.
The biggest problem is the if statement where you check the time. Since this would end up running each time you run the loop (for example 1,000s to 10,000s of times per second. Conditional statements (not maths) cause a higher amount of CPU time than other instructions. To not have this random delay, you should instead use the "repeat until" block, which only checks every reasonable amount of time. But that will be too fast (1/10,000 usually) so you should do something like this instead
when green flag clicked
set [thisFrameNo v] to (0)
forever
change [thisFrameNo v] by (1)
show // do something that updates the screen
end
end
when green flag clicked
start sound [mySound.ogg v]
set [lastFrameNo v] to (0)
set [changesPerSecond v] to (0)
forever
set [nextTick v] to (round (timer + 0.5))
repeat until <not (timer) < (nextTick)> // greater than or equal to
repeat until <not <lastFrameNo = thisFrameNo>>
change pitch by (1 / 512)
change [changesPerSecond v] by (1)
wait (1 / 2000)
end
end
say (changesPerSecond)
set [changesPerSecond v] to (0)
end
end
from scratch-audio.
Cwilisf already got the issue right. The purpose of the quick loop in the project is only to hasten the effect, so you don't need to wait for the performance drops to build up.
You see you got the 10000 loops per secs at the initial, then it drops lower. And resetting the project does not restore the performance.
This seems to have an insignificant effect for simple projects that don't use the sound blocks intensively. This however causes some problems for the complex project of mine, and the others.
from scratch-audio.
Related Issues (20)
- Notes initially ignore volume HOT 2
- The ADPCM decoder uses too much memory HOT 1
- RIFFVtWAVEfmt Wave Files don't load in 3.0
- The instruments could use some tweaks HOT 1
- Invalid content error in Firefox on one project
- Handle Chrome audio autoplay policy change HOT 5
- Repeatedly changing the volume (e.g. fade-out) causes bitsy effect HOT 1
- Audio on a particular project can't be decoded successfully HOT 1
- Set volume to in a forever loop causes audio to stutter on Firefox HOT 2
- First time a sound plays it starts at full volume even if volume is set lower
- Pan left/right doesn't effect extension blocks HOT 1
- Extend the pitch effects limit HOT 3
- "The AudioContext was not allowed to start. It must be resumed (or created) after a user gesture on the page." are displayed in chrome console when scratch is started. HOT 1
- npm-published packages should follow semver
- To remove the sound pitch limit completely HOT 1
- Dependency Dashboard
- module is not defined HOT 1
- Migrate from travis-after-all to Travis Stages
- Audio still clicks when restarting after a rest block HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from scratch-audio.