Skip to main content

Code sample - FM radio and TV tuning

Delphi and C# (ActiveX) sample code.

Get the list of available TV Tuners

for I := 0 to VideoCapture1.TVTuner_Devices_GetCount - 1 do
cbTVTuner.Items.Add(VideoCapture1.TVTuner_Devices_GetItem(i));
for (int i = 0; i < VideoCapture1.TVTuner_Devices_GetCount(); i++)
cbTVTuner.Items.Add(VideoCapture1.TVTuner_Devices_GetItem(i));

Get the list of available TV formats

for I := 0 to VideoCapture1.TVTuner_TVFormats_GetCount - 1 do
cbTVSystem.Items.Add(VideoCapture1.TVTuner_TVFormats_GetItem(i));
for (int i = 0; i < VideoCapture1.TVTuner_TVFormats_GetCount(); i++)
cbTVSystem.Items.Add(VideoCapture1.TVTuner_TVFormats_GetItem(i));

Get the list of countries

for I := 0 to VideoCapture1.TVTuner_Countries_GetCount - 1 do
cbTVCountry.Items.Add(VideoCapture1.TVTuner_Countries_GetItem(i));
for (int i = 0; i < VideoCapture1.TVTuner_Countries_GetCount(); i++)
cbTVCountry.Items.Add(VideoCapture1.TVTuner_Countries_GetItem(i));

Select TV Tuner

VideoCapture1.TVTuner_Name := cbTVTuner.Items[cbTVTuner.ItemIndex];
VideoCapture1.TVTuner_Name = cbTVTuner.Text;

Read TV Tuner settings

VideoCapture1.TVTuner_Read;
VideoCapture1.TVTuner_Read();

Get the list of available TV modes

for I := 0 to VideoCapture1.TVTuner_Modes_GetCount - 1 do
cbTVMode.Items.Add(VideoCapture1.TVTuner_Modes_GetItem(i));
for (int i = 0; i < VideoCapture1.TVTuner_Modes_GetCount(); i++)
cbTVMode.Items.Add(VideoCapture1.TVTuner_Modes_GetItem(i));

Get current audio and video frequencies.

edVideoFreq.Text := IntToStr(VideoCapture1.TVTuner_VideoFrequency);
edAudiofreq.Text := IntToStr(VideoCapture1.TVTuner_AudioFrequency);
edVideoFreq.Text = Convert.ToString(VideoCapture1.TVTuner_VideoFrequency);
edAudioFreq.Text = Convert.ToString(VideoCapture1.TVTuner_AudioFrequency);

Select signal source

cbTVInput.ItemIndex := cbTVInput.Items.IndexOf(VideoCapture1.TVTuner_InputType);
cbTVInput.SelectedIndex = cbTVInput.Items.IndexOf(VideoCapture1.TVTuner_InputType);

Select work mode

cbTVMode.ItemIndex := cbTVMode.Items.IndexOf(VideoCapture1.TVTuner_Mode);
cbTVMode.SelectedIndex = cbTVMode.Items.IndexOf(VideoCapture1.TVTuner_Mode);

Select TV system (PAL, NTSC, SECAM, etc.)

cbTVSystem.ItemIndex := cbTVSystem.Items.IndexOf(VideoCapture1.TVTuner_TVFormat);
cbTVSystem.SelectedIndex = cbTVSystem.Items.IndexOf(VideoCapture1.TVTuner_TVFormat);

Select country

cbTVCountry.ItemIndex := cbTVCountry.Items.IndexOf(VideoCapture1.TVTuner_Country);
cbTVCountry.SelectedIndex = cbTVCountry.Items.IndexOf(VideoCapture1.TVTuner_Country);

Write TVTuner_TuneChannels event code.

procedure TForm1.VideoCapture1TVTunerTuneChannels(SignalPresent: Boolean; Channel, Frequency, Progress: Integer);
begin
pbChannels.Position := Progress;

if SignalPresent then
cbTVChannel.Items.Add(IntToStr(Channel));

if Channel = -1 then
begin
pbChannels.Position := 0;
ShowMessage('AutoTune complete');
end;
end;
private void VideoCapture1_OnTVTunerTuneChannels(
object sender,
AxVisioForge_Video_Capture_3.IVFVideoCaptureXEvents_OnTVTunerTuneChannelsEvent e)
{
pbChannels.Value = e.progress;

if (e.signalPresent)
cbTVChannel.Items.Add(e.channel.ToString());

if (e.channel == -1)
{
pbChannels.Value = 0;
MessageBox.Show("AutoTune complete");
};
}

Start tune process

const KHz = 1000;
const MHz = 1000000;

VideoCapture1.TVTuner_Read;
cbTVChannel.Items.Clear;

//If you select FM Tuning, you can specify the initial frequencies and the scanning pitch

if ( (cbTVMode.ItemIndex <> -1) and (cbTVMode.Items[cbTVMode.ItemIndex] = 'FM Radio') ) then
begin
VideoCapture1.TVTuner_FM_Tuning_StartFrequency := 100 * Mhz;
VideoCapture1.TVTuner_FM_Tuning_StopFrequency := 110 * MHz;
VideoCapture1.TVTuner_FM_Tuning_Step := 100 * KHz;
end;

VideoCapture1.TVTuner_TuneChannels_Start;
const int KHz = 1000;
const int MHz = 1000000;

VideoCapture1.TVTuner_Read();
cbTVChannel.Items.Clear();

//If you select FM Tuning, you can specify the initial frequencies and the scanning pitch

if ( (cbTVMode.SelectedIndex != -1) && (cbTVMode.Text == "FM Radio") )
{
VideoCapture1.TVTuner_FM_Tuning_StartFrequency = 100 * MHz;
VideoCapture1.TVTuner_FM_Tuning_StopFrequency = 110 * MHz;
VideoCapture1.TVTuner_FM_Tuning_Step = 100 * KHz;};

Once each channel is found, the event will be called and the channel will be added to the combo-box. Also, you can specify the frequency and number of each channel manually.

Set channels by number

VideoCapture1.TVTuner_Channel := StrToInt(edChannel.Text);
VideoCapture1.TVTuner_Apply;
VideoCapture1.TVTuner_Channel = Convert.ToInt32(edChannel.Text);
VideoCapture1.TVTuner_Apply();

Set radio frequency

VideoCapture1.TVTuner_Channel := -1; // must be -1 to use frequency
VideoCapture1.TVTuner_Frequency := StrToInt(edChannel.Text);
VideoCapture1.TVTuner_Apply;
VideoCapture1.TVTuner_Channel = -1; // must be -1 to use frequency
VideoCapture1.TVTuner_Frequency = Convert.ToInt32(edChannel.Text);
VideoCapture1.TVTuner_Apply();

Please contact support to get help with this tutorial. Visit our GitHub page to get more code samples.