|
hi
The Sound.playTone method always return immediatly. It seems that it
only puts the information in a queue, which is then played in
background. This can be good but can also be a problem to control the
program behavior.
For instance, i want to implement a sirene with light and sound. Howto
synchronize the sound with the light? The light is attached to output A.
I use a sinosoid to make the effect.
1.
The following code would work if playTone only returned after the sound
is played. But what happens is that the loop finishes immedialtly
and the sound continues to play...:
for (x=0; x<100; x+=0.1) {
Motor.A.setPower(7*sin(x));
playTone(1000+100*sin(x),10) // 100 miliseconds
}
2.
I could do a call to sleep after the playTone, but the argument should
be calculated with precision. If i simple use 100 miliseconds there
would be a delay between the light and the sound:
for (x=0; x<100; x+=0.1) {
Motor.A.setPower(7*sin(x));
playTone(1000+100*sin(x),10) // 100 miliseconds
// calculate X
Thread.sleep(X);
}
Is there an easier way?
daniel
|
|
Message has 1 Reply:  | | Re: Sound.playTone
|
| Hi Daniel, (...) True (...) This does not seem to be a problem with my code; Motor.A.forward(); for (float x=0; x<1000; x+=0.1f) { int sx = (int)(Math.sin(x)*10.../calculate sine once Motor.A.setPower(3+3...0);//avoid negative power (...) (22 years ago, 21-May-03, to lugnet.robotics.rcx.java)
|
3 Messages in This Thread:     
- Entire Thread on One Page:
- Nested:
All | Brief | Compact | Dots
Linear:
All | Brief | Compact
|
|
|
|