Symbian
Symbian OS Library

SYMBIAN OS V9.3

[Index] [Spacer] [Previous] [Next]



How to use the Tuner API


Overview

The Tuner API is an abstract API for receiving radio broadcasts such as FM or DAB (provided that the necessary hardware is present on the phone). It provides a consistent API that is independent of the underlying implementation and hardware specifics.

The Tuner API can be used to perform tasks such as:

[Top]


Getting started


Initialization

Applications wishing to use the Tuner API must include the <tuner/tuner.h> header for access to the relevant declarations and link against tuner.lib. To begin using the tuner API, an instance of CMMTunerUtility must be created using CMMTunerUtility::NewL(). This requires:


Shutting down

When an application has finished using the Tuner API it must delete the CMMTunerUtility instance. The destructor takes care of stopping any ongoing recording or playback activity and powering down the tuner hardware if no other clients need it. The following code shows an example of the normal usage pattern:

CMMTunerUtility* iTunerUtil = CMMTunerUtility::NewL( … );

CleanupStack::PushL( iTunerUtil );

// add extra observers, configure tuner utility options

// tune / playback / record

CleanupStack::PopAndDestroy( iTunerUtil );

If the Tuner utility is to be reused at a later point then CMMTunerUtility::Close() can be used to free up resources and the tuner hardware without actually destroying the Tuner utility.


The Tuner Change Observer

Applications may need to receive notifications when the tuner’s state changes. The MMMTunerChangeObserver interface exists for this purpose. The client receives notifications when:

To observe any of these notifications, CMMTunerUtility::NotifyChange() must be called and passed to an implementation of the MMMTunerChangeObserver interface.


The Signal Strength Observer

Applications can optionally implement the MMMSignalStrengthObserver interface to monitor changes in signal reception. The interface contains one function:

The MMMSignalStrengthObserver can then be registered with the Tuner utility via CMMTunerUtility::NotifySignalStrength(). To stop receiving signal strength notifications call CMMTunerUtility::CancelNotifySignalStrength().


The Stereo Observer

Applications can optionally implement the MMMTunerStereoObserver interface to monitor when reception switches from mono to stereo sound and vice-versa (as can happen with FM radio). The interface contains two functions:

The MMMTunerStereoObserver can then be registered with the Tuner utility via CMMTunerUtility::NotifyStereoChange(). To stop receiving signal strength notifications call CMMTunerUtility::CancelNotifyStereoChange().

[Top]


Tuning


Gaining control of the tuner

Applications must request control of a tuner before using it to tune into a particular station. This is to prevent multiple applications trying to control the same tuner simultaneously. To gain control of a tuner, call CMMTunerUtility::RequestTunerControl().

Control of the tuner is kept until it is explicitly released using CMMTunerUtility::ReleaseTunerControl() or it is revoked. If control is revoked, a callback to MMMTunerObserver::MToTunerEvent() with an event type of MMMTunerObserver::EControlEvent and an error of KErrAccessDenied occurs.


Manual tuning

To tune to a particular frequency the CMMTunerUtility::Tune() function is used. The required frequency and band are specified by a TFrequency object which represents the frequency in Hertz and a value from the CMMTunerUtility::TTunerBand enum respectively.

For example, to tune to 100MHz FM:

const TInt KFreqHundredMHz = 100 * 1000000; // 100MHz

User::LeaveIfError( iTunerUtil->RequestTunerControl() );

TFrequency myFreq( KFreqHundredMHz );

iTunerUtil->Tune( myFreq, ETunerBandFM );

iTunerUtil->ReleaseTunerControl();

This is an asynchronous command and ultimately results in a callback to MMMTunerObserver::MToTuneComplete(). Additionally, MMMTunerChangeObserver::MTcoFrequencyChanged() is called if a change observer has been registered (for more information, see The Tuner Change Observer).

If no error has occurred then the error code passed to the callback function is KErrNone, if control of the tuner cannot be granted at present KErrAccessDenied is passed, otherwise one of the other system-wide errors is passed.

If the client does not currently have control of the tuner, a request for control is made (in the preceding example, the call to CMMTunerUtility::RequestTunerControl() could have been omitted). If control of the tuner is granted then MMMTunerObserver::MToTunerEvent() is invoked with an event type of MMMTunerObserver::EControlEvent and an error of KErrNone.

Once control of the tuner has been granted, it is retained until either a call to CMMTunerUtility::ReleaseTunerControl() is made or the session is pre-empted, in which case there is a callback to MToTunerEvent with an event type MMMTunerObserver::EControlEvent and an error value KErrAccessDenied.

A re-tune currently in progress can be interrupted by calling CMMTunerUtility::CancelRetune(). If CMMTunerUtility::CancelRetune() is called, the normal callbacks do not occur. If no tune or seek operation is in progress, this function has no effect.


Seeking for stations

The Tuner utility also allows searching for stations using the asynchronous function CMMTunerUtility::StationSeek(). Searching for the next station signal starts from a given starting frequency and stops when a station is found or when all frequencies have been searched and nothing is found. When the next station is found (or nothing is found) a callback to MMMTunerObserver::MToTuneComplete() occurs with the appropriate error value (KErrNotFound if nothing is found).

If the application needs to be notified of the frequency of the found station, a tuner change observer must be registered. For more information, see The Tuner Change Observer.

Control of the tuner must be requested, likewise, control is not released once a station has been found. This is done via CMMTunerUtility::ReleaseTunerControl() when no further control is required.

During a search, background noise may be heard at frequencies between stations. Squelching mutes this noise and is enabled or disabled by calling CMMTunerUtility::SetSquelch().

An ongoing seek operation can be interrupted using CMMTunerUtility::CancelRetune().


The Tuner Scanner utility

The CMMTunerScannerUtility class augments CMMTunerUtility to provide enhanced station scanning functionality. CMMTunerScannerUtility searches the frequency spectrum, pausing for a specified amount of time when a station is found.

A CMMTunerScannerUtility instance is created by using the CMMTunerUtility::GetTunerScannerUtilityL() function of an instantiated Tuner utility. This function is passed an implementation of MMMTunerObserver which is used by the scanner utility. Only one CMMTunerScannerUtility instance may be created per CMMTunerUtility.

Tip: We recommend reusing the tuner observer passed to the CMMTunerUtility to avoid having to check for re-tune notifications in several places.

The scanner utility provides two methods:

[Top]


Playback

The CMMTunerAudioPlayerUtility class is used to play audio from the tuner. It is created by calling the CMMTunerUtility::GetTunerAudioPlayerUtilityL() function of an instantiated Tuner utility. This requires an implementation of the MMMTunerAudioPlayerObserver interface to monitor callbacks from the player utility. Only one audio player utility may be created per Tuner utility.

Before playing an audio signal, the player utility must be initialized by calling CMMTunerAudioPlayerUtility::InitializeL(). This requires:

The priority and preference can be changed at any time using CMMTunerAudioPlayerUtility::SetPriority().

Once initialization has completed (successfully or otherwise) the audio player observer receives a MMMTunerAudioPlayerObserver::MTapoInitializeComplete() callback. Audio playback can then be commenced using the utility’s Play() function and stopped with Stop().

The CMMTunerAudioPlayerUtility provides methods to:

To register for notifications of when control of the audio resource is lost or regained, use an implementation of the MMMFAudioResourceNotificationCallback interface.

[Top]


Recording

The CMMTunerAudioRecorderUtility class is used to record audio from the tuner. It is created using the CMMTunerUtility::GetTunerAudioRecorderUtilityL() function and an implementation of the MMMTunerAudioRecorderObserver interface. Only one instance of a recorder utility may be created per Tuner utility.

Before use the recorder utility must be initialized using CMMTunerAudioRecorderUtility::InitializeL(). This requires:

The CMMTunerAudioRecorderUtility provides functions for:

Note: Some recording settings cannot be changed once the recording has started.

[Top]


Accessing RDS data


Basic functionality

RDS is the European standard for broadcasting data about a radio station within the FM frequency band (it is not supported by other frequency bands or broadcast systems). RDS data can be used to provide information such as the station name and the type of programme currently being broadcast. Its North American equivalent is RBDS.

The CMMRdsTunerUtility class provides methods to access the RDS capabilities of the tuner device. It supports both RDS and RBDS standards.

To make use of the RDS capabilities of the tuner, construct a CMMRdsTunerUtility object using CMMTunerUtility::GetRdsTunerUtilityL(). Only one instance of CMMRdsTunerUtility may be created per instance of CMMTunerUtility.

RDS has a number of features, these include:

To find which RDS features are supported by the current tuner call CMMRdsTunerUtility::GetRdsCapabilities().


Setting the RDS features

RDS features can be set on or off by calling the relevant Set functions of CMMRdsTunerUtility. For example, CMMRdsTunerUtility::SetTrafficAnnouncement() sets the traffic announcement feature on or off.

Respective Get functions exist for querying which features are currently enabled.


Setting the callbacks

Whenever an RDS feature changes, it causes a callback on a specific method of the MMMRdsStateChangeObserver class, for example, changes to the announcement volume offset causes a callback on MMMRdsStateChangeObserver::MrscoTrafficAnnouncementChanged().

To receive these change notifications an observer class must be set up and associated with the CMMRdsTunerUtility object. This is done by calling CMMRdsTunerUtility::NotifyRdsStateChange() with a reference to an MMMRdsStateChangeObserver object that can receive the notifications.

There are similar observer objects and associated notification request methods (for example, CMMRdsTunerUtility::NotifyAlternativeFrequencies()) for other aspects of the RDS Tuner utility’s operation.


Using RDS to search for a station

CMMRdsTunerUtility has a number of methods that use RDS information to search for a radio station, using the following search criteria:

For example, to search for a radio station with a traffic programme:

myRdsTunerUtility->StationSearchByTrafficProgramme(ETrue, iFrequency,
                              ETunerBandFm, SearchDirectionUp , ETrue);

This returns the next radio station with a traffic programme. The scanning starts at the frequency iFrequency in the FM frequency band, in the direction of increasing frequency. Because the parameter aCircularSeek is set to ETrue, when the end of the band is reached, the search will loop back to the beginning of the band.

[Top]


Custom commands

The API of the Tuner utility can be extended in the following ways:

Note: Details of any such extensions will be provided by the suppliers of the tuner implementation(s).

[Top]


See also