Channels ▼
RSS

Embedded Systems

Radios, Cell Phones, & Java

Source Code Accompanies This Article. Download It Now.


Tuner Range And Region

The minimum and maximum frequency of a modulation supported by the cell phone's radio can be retrieved using TunerControl's getMinFreq() and getMaxFreq() methods. Keep in mind that the frequency returned is in units of 100 Hertz. To convert it to MHz, divide the value by 10,000; for instance, 879,000 in 100 Hertz ~ 87.9 MHz:


int minFreq = 
   tunerControl.getMinFreq
   (TunerControl.MODULATION_FM);
int maxFreq = 
   tunerControl.getMaxFreq
   (TunerControl.MODULATION_FM);

Similarly for AM modulation:


int minFreq = 
   tunerControl.getMinFreq
   (TunerControl.MODULATION_AM);
int maxFreq = 
   tunerControl.getMaxFreq
   (TunerControl.MODULATION_AM);


Some applications may need to know which region the radio is equipped for:


if ((minFreq<=879000) && 
   (maxFreq>=1079000))
   tuningRegion= "US";
if ((minFreq<=879000) && 
   (maxFreq>=1080000))
   tuningRegion="Europe";
if ((minFreq<=760000) && 
   (maxFreq>=900000))
   tuningRegion="Japan";


Low-Signal Strength

There may be times when radio reception is substandard, such as when users go underground or between buildings. In such cases, radio reception can be hazy and the audio fuzzy. Luckily, there are parameters you can control to make the reception clearer and more audible. However, you first need to detect the signal strength. Fortunately, this information is easily obtained using TunerControl's getSignalStrength(). The signal strength indicator ranges from 0-100, with 0 being no reception and 100 being the best. For instance, to trigger corrective measures when the signal strength falls below 50 percent:


if (tunerControl
   .getSignalStrength()<50)
{
   ...
}

When the application determines that the reception is not acceptable, you can switch the stereo reception off and go to mono. This prevents the "wobbling" effect as the left and right channels drop off alternately. Do the switch using TunerControl's setStereoMode() method with the parameter TunerControl.MONO:


tunerControl.setStereoMode
   (TunerControl.MONO);

When the reception is weak, the volume tends to fade and becomes soft as well. To counteract this, you can have the application boost the volume. There are two basic approaches you can take—boosting the volume to the maximum, or incrementing it from the current volume setting. In either case, the first thing you have to do is get the MMAPI volume control of the radio player if it was not created earlier:


VolumeControl volumeControl = 
  (VolumeControl)radioplayer.
   getControl"VolumeControl");

Once you have the volume control, you can read the current volume level. This ranges from 0-100 with 100 being the loudest and 0 being mute. Thus, to increment the volume, you add a positive numeric value to the current volume level:

int currentVolume = 
   volumeControl.getLevel();
currentVolume = 
   volumeControl.setLevel
   (currentVolume + 10);

Or if we are just setting the volume to maximum:


int currentVolume = volumeControl.setLevel(100);

Combining all the previous actions, the end result is:


if (tunerControl.
   getSignalStrength()<50)
{
   tunerControl.setStereoMode
   (TunerControl.MONO);
   int currentVolume = 
   volumeControl.getLevel();
   currentVolume = 
   volumeControl.setLevel
   (currentVolume + 10);
}


Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.
 

Video