Thursday 3 December 2009

Radio sets

The TAvionics class is a single instance, one client, one avionics suite. If you leave a vehicle, this class is dumped (along with all the MFDs, HUDs and everything else it hosts followed by a good garbage collection). Enter a new vehicle and it's re-loaded, along with all the memory required for the instrument display buffers etc.

A radio has two channels, a main and a standby, (an AH-64D Apache Helicopter has several radio sets which we will go into later). We will use the ActiveChannel field to index these. If you're familiar with Microsoft Flight Simulator or have any of those RadioStack hardware panels you will be familiar with the "Active" and "Standby" principle of the radio set.

In Sandbox, now Leadwerks Editor, any models of class "radiosource" have keys for two frequencies and file for a radio source. The scene loader populates a TMap of radio-sources. The TRadio class by default loads in a sound file of radio static, turn on the radio and all you hear is shhhhhhhhhhhhhhhhshhhhhhshhh.



Fortunately each can be squelched independently. Using units of 0.0 to 1.0 we assume a background noise has a weak strength, say 0.3 and we'll set the default squelch to 0.2, so we can hear something when we turn the radio on.

And using Audacity we generated two radiohiss.ogg files simply using the "generate noise" function of the program. We used a low-pass filter to give it a more radio set feel. We'll adjust the pitch of the hiss pseudo-randomly when we step through frequencies and no other signal source is present.








Type TRadio


Field Enabled:Int;
Field Band:Int;
Field ActiveChannel:Int; ' 0 = FREQUENCY1 1=FREQUENCY2
Field Frequency:Float[] {hidden}; ' CHANNEL INDEX
Field AudioFile:TSound[] ; ' CHANNEL INDEX
Field Strength:Float[] ; ' CHANNEL INDEX
Field Squelch:Float[] ; ' CHANNEL INDEX
Field Volume:Float;
Field source:TSource; ' SET EXTERNALLY, NORMALLY BY TAVIONICS


Method New()
Self.AudioFile = New TSound[2] ;
Self.Frequency = New Float[2] ;
Self.Strength = New Float[2] ;
Self.Squelch = New Float[2] ;
Self.Enabled = True;
Self.Volume = 1.0;
Self.AudioFile[0] = LoadSound("abstract::radiohiss.ogg") ;
Self.AudioFile[1] = LoadSound("abstract::radiohiss2.ogg") ;
Self.source = Null;
Self.ActiveChannel = 0;
Self.Squelch[0] = 0.2;
Self.Squelch[1] = 0.2;
Self.Strength[0] = 0.3;
Self.Strength[1] = 0.3;
End Method


Method SwitchOn(audiosrc:TSource)
If audiosrc Then
Self.source = audiosrc;
Self.source.SetVolume(0.4) ;
Self.source.SetPitch(Rnd(0.2, 0.9)) ;
If (Self.Enabled) And (Self.Strength[ActiveChannel] > Self.Squelch[ActiveChannel]) Then
PlaySource(Self.source) ;
End If
End If
End Method

Method SetFrequency(tuner:Float, channel:Int = 0)
Frequency[channel] = tuner;
UpdateRadioSources();

End Method

End Type


This is enough for an example. The Update method periodically steps through the TMap of radio-sources, and if they are in range; 
  • Sets the signal strength in the radio class
  • Loads the sound file specified in the entityclass info into the appropriate AudioFile channel.
  • Sets the volume of the sound file based on strength.
The TSource is created in the parent class (TAvionics). We only want one source to listen for radio transmissions so we pass this to each radio we create.

Our Apache has two radio sets for voice communication (a total of four channels), in addition there is a radio used for navigation. The Band field indicates if the radio UHF, VHF or NDB, VOR. Radio instruments used for navigation will query the NavRadio reciever for signal strength and bearing (bearing comes from the entity position of the radio-source relative to the player_vehicle entity).




What can I say. It works well enough. Our cockpit does not yet have any radio controls except for a few key-presses to turn the active channel and set vol. and squelch.


Finally, it is with deep regret that my wife's father passed away this morning at the age of 79 in Victoria BC. A survivor of the atomic bombing of Hiroshima, he was sponsored into the United States and became an influential scentist shaping our understanding of deep ocean currents and many years later, fibre-optics. He had a most interesting life and a devoted Quaker spending much of his time helping others. Mike, you will be missed.



No comments:

Post a Comment