Game Development Community

Adjusting volume on car radio

by RedCore · in Torque Game Engine · 12/11/2003 (4:36 pm) · 6 replies

The title says it all.. I'm trying to create a volume control for my radio..

While were on the topic.. how would i create a actual station(or simulate it) so that if you switch station and then came back to a previus station.. it will keep playing like a real radio station..

i was thinking about creating the stations then just when one is selected adjust the volume of the others.. so you dont hear them..and again i run into the adjusting volume problem.. i'm not sure how i'd set all that up..

also, how would i could some sort of graphical display that pulses according to the sound coming out(similar to modern day sound systems..)


Thank,
RedCore

#1
12/11/2003 (7:36 pm)
I've already told you on IRC where to look at for adjusting volumes, you just like to ignore and keep asking until someone throws code at you, and I won't. As to playing all the sounds at the same time that's not possible since streaming many files at the same time will mean a high load to the cpu and to the hard disk since you are constantly accessing it.
#2
12/12/2003 (3:04 pm)
You said i couldnt do it while its playing.. so i'm asking for other idea's..

And you obviusly dont know what your talking about, I dont want code.. i want to know the methods i could use..
#3
12/12/2003 (9:18 pm)
I told you where to search for real-time modification of volume. Now stop being lazy, I wont tell you what file and line to look into, neither post the code for you. GO DO IT
#4
12/12/2003 (10:55 pm)
Keep track of the start time of the stations and then use that to cue the sounds when people switch stations.

I assume you can hook into the audio decode stuff to get a realtime volume value.
#5
12/13/2003 (4:52 am)
Xavier if he is bothering you by posting questions that you already gave him answers to then don't reply to his thread. Maybe someone is willing to write the code for him. It's not worth your time to reply and not worth his time to read your reply.
#6
12/13/2003 (6:14 am)
Is adjusting volume really what you want do? I can't see a good way to achieve this with volume settings.

How about this:

Each station is in a separate MP3/OGG file (whatever format, shouldn't matter). They should be roughly the same length, so the system works nicely. For each station you have a torque variable that stores the 'current time'. When you start a round in your game, your current time will be set to 0 (it's not the time as in looking at the clock, it's always 'elapsed time' from a certain point). This time is ticked up as you play, and is basically a real-time clock. Load the first station audio file, and start it playing.

Now, if you change to station 2, it's a simple case of:

Stopping the current audio file
Playing an 'interference/scramble' sample (explained below)
Loading the next radio station audio file
Fast forward it to the 'current time'
Start it playing from there

The interference sample achieves two things - it makes sure you don't have audio silence, which is never a good thing in games. It also attempts to mask any delay you have from loading a new audio file. For the interference sample, you could even record the real thing and use that. If you have an analogue tuned radio, spin the dial and change channels real quickly and record the result to a WAV :-) You could even play that WAV backwards when you tune the dial to the left ;-)

If you then changed back to station 1, you would repeat the exact same steps. The fast forward is the important part - I'm sure you can do this, and you will need a time that is an offset from 0:0:0. Another important thing, to keep your code and the effect clean, would be to monitor when the MP3 file ends - you'll want to reset it to the beggining like it's on repeat, but you'll also want to reset your internal timer for the 'current time' back to 0:0:0. This ensures that if you've listened to 2:41 of the current station, you will always start at 2:41 (well, maybe 2:42 or 2:43, depending on load times) on the station you change over to.

How does that sound? Not massively elegant, but I think a simple way to achieve what you're looking for?

-Darren.