[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] MacPerl sings 'Camptown Races'



At 10:16 AM -0600 11/22/98, Greenblatt & Seay wrote:
...
>I wish I could have my program adjust the tempo automatically according to
>the processor speed of the computer it is running on. Perhaps I could put
>tempo controls in a menu or detect a certain keyDown event to control tempo
>during playback, say '+' for faster and '-' for slower. Maybe there's a
>better way to control the length of the note than a 'for loop'. Any
>suggestions?
...

David,

I made a couple of changes (below).  I use the Perl 4-argument
select() to sleep for a fractional number of seconds.  
I'm assuming select() will yield time to other tasks, so this
could change the way the script behaves when other programs 
are running.  But at least the timing should be more uniform
across processors.

I also use StopSpeech() to truncate any word that lasts
too long.  I sometimes got pitch changes during a word because
SetSpeechPitch got called with the pitch for the next word
while the previous word was still playing.

I've been considering using SetSpeechRate() to adjust the 
length of each word, but haven't worked it out yet.  

It looks like a two-pass scheme might be a good way to go:
first measuring the words and compiling a snd resource, then 
playing the resource. This would eliminate processor-dependant
delays between words.  

Ack!  Can multiple voices and accompaniment be far beyond?
Where did I put my Handel's Messiah score?

Thanks for a great diversion! :-)

Jim



Change:

$tempo = 85000; # increase the value if song is too fast or ends of words are clipped
 
to:

$tempo = 240; # quarter notes per minute, approx.
$tempo_factor = 60 / $tempo; # seconds per quarter note


and change:

			$d = int($tempo * $dur{$dur});
			for ($w = 0; $w < $d; $w++) { }

to:
			select(undef, undef, undef, $tempo_factor * $dur{$dur});
			StopSpeech $channel 	or die $^E;

--
Jim Miner          jfm@winternet.com

***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch