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

Re: [pygame] Fwd: mixing sound files for engine noise



Chipperfield Kurt A wrote:
> Hi.  I am new to the list and have a question about sound.  I would like to
> write a driving simulator game with engine sounds that change as the speed
> of the engine changes.  This would allow you to hear the engine rev up as
> you accelerate.  I think I can just record a few engine noises (idle,
> mid-throttle, and full-throttle for example) and then mix them to get
> realistic engine noises for all engine speeds.  Does anyone know if this is
> possible and how to do it?  Thanks in advance.

your idea may work pretty well. if you only had 2 sounds (low and high) you 
would set it up something like this...



#load
lo_rpm_engine = Sound('lo_rpm.wav')
hi_rpm_engine = Sound('hi_rpm.wav')

#set initial volume
lo_rpm_engine.set_volume(0)
hi_rpm_engine.set_volume(0)

#loop forever and get channels
lo_channel = lo_rpm_engine.play(-1)
hi_channel = hi_rpm_engine.play(-1)

def modify_engine_sound(current_speed, max_speed):
     percent = float(current_speed) / max_speed
     if percent > 1.0: percent = 1.0 #just in case faster than max
     hi_channel.set_volume(percent)
     lo_channel.set_volume(1.0 - percent)



setting it to use more than one channel is a task left to the reader :]
also, using a linear interpolation like this may not sound right, as the 
engine will be loudest at about 50%. you could modify the percentage with 
something like this.

def smooth_percentage(percent):
     return  (1 - cos(min(val, 1.0) * pi)) * .5



____________________________________
pygame mailing list
pygame-users@seul.org
http://pygame.seul.org