This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2007-06-12 04:20:38

mohlar
Scratcher
Registered: 2007-05-24
Posts: 100+

A couple of questions about SOUND

I'm working on a few experiments with Sound loops in Scratch, using rhythm tracks, melody sequences and extracts from midi files converted to .wav  Although the first tests work quite well, I'd like to know if the following are possible.

------------------------------------------- Query 1 -------------------------------------------

IS THERE A WAY TO AVOID 'WAIT' WHEN USING 'FOREVER' TO CONTROL A SOUND LOOP?
The effect I want is for any one of several loops to play once whilst a key is pressed and to then repeat until the key is released. At present I'm using this code, but there is always a tiny lag between the end and the time when a loop restarts.

    when b key pressed
        forever if key "b" pressed?
            play sound "Tuareg2" and wait
    end

In my test project I have nine such loops and everything is fine and more than one loop can play simultaneously (up to 3 sounds best) - EXCEPT for having to have that tiny pause. Is there a 'work-round'?

------------------------------------------- Query 2 -------------------------------------------

EVEN BETTER - IS THERE A WAY TO AVOID HAVING TO KEEP KEYS PRESSED DOWN?
Is there a way to press a key, start a loop so that it automatically keeps on repeating UNTIL the same key is pressed again - thus stopping the loop from re-starting?

The experimental project I mentioned is here, so you can see what ideas I'm playing with:
http://scratch.mit.edu/projects/mohlar/12631

Thanks for any suggestions on those queries.

Last edited by mohlar (2007-06-12 04:23:57)

Offline

 

#2 2007-06-12 07:05:09

Jens
Scratcher
Registered: 2007-06-04
Posts: 1000+

Re: A couple of questions about SOUND

I just experimented a little bit with your project. Here's my solution for both of your questions:

1. instead of using "play sound and wait" just use "play sound". Then insert a "wait" block indicating the length of your sequence. 2.01 secs. worked fine for me with your "tuareg" sound.

2. create a local variable indicating if the sequence should be playing or not (a "flag"), I'm calling it "on".

Then code your "toggle" like this:

when the green flag is pressed
   set on to 0
   forever if on = 1
      play sound tuareg
      wait 2.01 secs

when a key pressed
   if on = 1
      set on to 0
      stop all sounds
   else
      set on to 1

This works fine on my computer and should probably do the trick for you.

Nice idea btw.
- Jens

Last edited by Jens (2007-06-12 07:16:48)


Jens Mönig

Offline

 

#3 2007-06-12 10:48:15

mohlar
Scratcher
Registered: 2007-05-24
Posts: 100+

Re: A couple of questions about SOUND

Thanks Jens, I'll have a look at those suggestions. Did you get the 2.01secs by experimenting to find the length of the loop as it played from inside Scratch? I wonder if that timing works OK on all machines, irrespective of their processors?

I just checked the lengths of the 9 samples that I used and they came out at as follows. Which one did you use?

If that's what you did, it would be an easy matter to do the same for all of them.

The 'Tuareg' sounds
A  1.97
B  1.89
C  1.99
D  2.00
E  1.84
F  1.99

The drum rhythms
G  3.97
H  1.97

The Abba riff 
7.43

Thanks again for the ideas. I'll play with those and put together a 'Technobean v.2'

Offline

 

#4 2007-06-12 13:40:49

Jens
Scratcher
Registered: 2007-06-04
Posts: 1000+

Re: A couple of questions about SOUND

I used the "A" sound, and just experimented around, I'm sure you'll get better results if you use your 'real' values. Don't know about different hardware. It'll probably slow down and get somewhat out of sync if a lot of sounds are played all at once.

Looking foreward to your "production version".


Jens Mönig

Offline

 

#5 2007-06-12 15:07:40

mohlar
Scratcher
Registered: 2007-05-24
Posts: 100+

Re: A couple of questions about SOUND

Thanks again Jens.
I've tried your ideas and they work - but for my purposes, I may stick to my original solution as the differences are fairly minimal and I'd like the result to be as readable to 'newbies' as possible so that they can take my ideas and do their own thing. (Having said that, I'm a 'newbie' myself).

My next task is to create and assemble a good bank of compatible and bpm-matched samples and loops for the full creative experience.

Thanks for your help.

Offline

 

Board footer