Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Playing Music Using a Loop
- bustedthumbs
-
100+ posts
Playing Music Using a Loop
Alright, I'm a bit stuck - https://scratch.mit.edu/projects/129375022/#editor
The idea of the project is to be able to play several lines of music at once using clones of the ‘Music Player’ sprite. I found earlier that trying to do this without some sort of synchronization lead to the various lines of music getting out of sync.
To get started, click Twinkle Twinkle Little Star then click on the piano.
Inside Stage this starts a loop, much like a game loop that tries to tick as quickly as it can with a broadcast.
Inside Music Player look for the handling of the Prep Tick. This reads the next note from some data if necessary. It then checks if the note should be played and if so calls another broadcast to play the note. I used the second broadcast because I don't want the loop waiting for the note to complete playing before looping again.
I isolated it down so that only one line of music is playing, but the loop is still alarmingly slow and there is a weird warble in the note being played. Any ideas why? I have checked that each note is only played once (show the Debug Message variable to see this).
The idea of the project is to be able to play several lines of music at once using clones of the ‘Music Player’ sprite. I found earlier that trying to do this without some sort of synchronization lead to the various lines of music getting out of sync.
To get started, click Twinkle Twinkle Little Star then click on the piano.
Inside Stage this starts a loop, much like a game loop that tries to tick as quickly as it can with a broadcast.
Inside Music Player look for the handling of the Prep Tick. This reads the next note from some data if necessary. It then checks if the note should be played and if so calls another broadcast to play the note. I used the second broadcast because I don't want the loop waiting for the note to complete playing before looping again.
I isolated it down so that only one line of music is playing, but the loop is still alarmingly slow and there is a weird warble in the note being played. Any ideas why? I have checked that each note is only played once (show the Debug Message variable to see this).
Last edited by bustedthumbs (Nov. 23, 2016 16:34:15)
- asivi
-
1000+ posts
Playing Music Using a Loop
Hi, try allowing sreen refresh in your custom “Play Note”.
- bustedthumbs
-
100+ posts
Playing Music Using a Loop
Does it less often, but it still happens.
I'm thinking of adjusting my strategy here. Perhaps I let all of the voices play one measure of music then use a global notification to say when it is time to start the next measure. If they are drifting slowly this approach will bring them all back together frequently enough it should not be noticeable.
I'm thinking of adjusting my strategy here. Perhaps I let all of the voices play one measure of music then use a global notification to say when it is time to start the next measure. If they are drifting slowly this approach will bring them all back together frequently enough it should not be noticeable.
- Discussion Forums
- » Help with Scripts
-
» Playing Music Using a Loop