From 7a977b833fed49f67a74636addb590f078d12636 Mon Sep 17 00:00:00 2001 From: Jens Arnold Date: Sat, 28 May 2005 01:09:19 +0000 Subject: [PATCH] Avoid radio interference from the MAS internal clock on devices with the Samsung tuner (FM recorder, old Ondio FM) by slightly shifting it away when necessary. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@6531 a1c6a512-1295-4272-9138-f99709370657 --- firmware/export/mpeg.h | 3 +++ firmware/mpeg.c | 16 ++++++++++++++++ firmware/tuner_samsung.c | 25 +++++++++++++++++++++++++ 3 files changed, 44 insertions(+) diff --git a/firmware/export/mpeg.h b/firmware/export/mpeg.h index ca0de1f823..71e61a08c9 100644 --- a/firmware/export/mpeg.h +++ b/firmware/export/mpeg.h @@ -50,6 +50,9 @@ void mpeg_set_recording_options(int frequency, int quality, int source, int channel_mode, bool editable, int prerecord_time); void mpeg_set_recording_gain(int left, int right, bool use_mic); +#if CONFIG_TUNER & S1A0903X01 +int mpeg_get_mas_pllfreq(void); +#endif unsigned long mpeg_recorded_time(void); unsigned long mpeg_num_recorded_bytes(void); void mpeg_pause_recording(void); diff --git a/firmware/mpeg.c b/firmware/mpeg.c index ff3f95ce0b..28bfa6201e 100644 --- a/firmware/mpeg.c +++ b/firmware/mpeg.c @@ -2382,6 +2382,22 @@ void mpeg_set_recording_gain(int left, int right, bool use_mic) mas_codec_writereg(0x0, shadow_codec_reg0); } +#if CONFIG_TUNER & S1A0903X01 +/* Get the (unpitched) MAS PLL frequency, for avoiding FM interference with the + * Samsung tuner. Zero means unknown. Currently handles recording from analog + * input only. */ +int mpeg_get_mas_pllfreq(void) +{ + if (mpeg_mode != MPEG_ENCODER) + return 0; + + if (rec_frequency_index == 0) /* 44.1 kHz / 22.05 kHz */ + return 22579000; + else + return 24576000; +} +#endif + /* try to make some kind of beep, also in recording mode */ void audio_beep(int duration) { diff --git a/firmware/tuner_samsung.c b/firmware/tuner_samsung.c index 632fb7561f..c024fceb9d 100644 --- a/firmware/tuner_samsung.c +++ b/firmware/tuner_samsung.c @@ -20,8 +20,11 @@ #include #include +#include "config.h" #include "tuner.h" /* tuner abstraction interface */ #include "fmradio.h" /* physical interface driver */ +#include "mpeg.h" +#include "sound.h" #define DEFAULT_IN1 0x100003 /* Mute */ #define DEFAULT_IN2 0x140884 /* 5kHz, 7.2MHz crystal */ @@ -49,6 +52,28 @@ void samsung_set(int setting, int value) case RADIO_FREQUENCY: { int pll_cnt; +#if CONFIG_HWCODEC == MAS3587F + /* Shift the MAS internal clock away for certain frequencies to + * avoid interference. */ + int pitch = 1000; + + /* 4th harmonic falls in the FM frequency range */ + int if_freq = 4 * mpeg_get_mas_pllfreq(); + + /* shift the mas harmonic >= 300 kHz away using the direction + * which needs less shifting. */ + if (value < if_freq) + { + if (if_freq - value < 300000) + pitch = 1003 - (if_freq - value) / 100000; + } + else + { + if (value - if_freq < 300000) + pitch = 997 + (value - if_freq) / 100000; + } + sound_set_pitch(pitch); +#endif /* We add the standard Intermediate Frequency 10.7MHz ** before calculating the divisor ** The reference frequency is set to 50kHz, and the VCO