From owner-freebsd-multimedia@FreeBSD.ORG Wed Feb 27 23:43:33 2008 Return-Path: Delivered-To: freebsd-multimedia@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 5EB1410670A1 for ; Wed, 27 Feb 2008 23:43:33 +0000 (UTC) (envelope-from danny@ricin.com) Received: from smtpq1.tilbu1.nb.home.nl (smtpq1.tilbu1.nb.home.nl [213.51.146.200]) by mx1.freebsd.org (Postfix) with ESMTP id A518D8FC19 for ; Wed, 27 Feb 2008 23:43:32 +0000 (UTC) (envelope-from danny@ricin.com) Received: from [213.51.146.188] (port=36652 helo=smtp3.tilbu1.nb.home.nl) by smtpq1.tilbu1.nb.home.nl with esmtp (Exim 4.60) (envelope-from ) id 1JUVvv-0001GZ-7z; Thu, 28 Feb 2008 00:43:31 +0100 Received: from cp1228410-a.dbsch1.nb.home.nl ([84.27.217.164]:50083 helo=desktop.homenet) by smtp3.tilbu1.nb.home.nl with smtp (Exim 4.60) (envelope-from ) id 1JUVvt-0008Lv-SM; Thu, 28 Feb 2008 00:43:31 +0100 Received: by desktop.homenet (sSMTP sendmail emulation); Thu, 28 Feb 2008 00:42:39 +0100 From: "Danny Pansters" To: Yuri Pankov Date: Thu, 28 Feb 2008 00:42:38 +0100 User-Agent: KMail/1.9.7 References: <200802270019.40771.danny@ricin.com> <20080227175555.GA92245@mail.irbisnet.ru> In-Reply-To: <20080227175555.GA92245@mail.irbisnet.ru> X-Face: (Zs+'ncTcchkOX|~t6{?Iii=O!G#WEK!+OD0|-F=i%1pvP5V_Sz4PaJC8o)=?utf-8?q?MiSnH/JMJFy=0A=09oBN-My?=, v":S7, (=?utf-8?q?mmkPm=27U=7BMgT+eM=2EBd=5Cp/P!dr=5DhOTXqpse21O!=25Ct=60SE=2EOodq?= =?utf-8?q?=5Dry=5E=23kU=5E=0A=09-?=GT.[8D}i$6P>=" =?utf-8?q?=23=0A=09*J+4d=7E?= MIME-Version: 1.0 Content-Type: Multipart/Mixed; boundary="Boundary-00=_vVfxHOoKAgM2InL" Message-Id: <200802280042.39186.danny@ricin.com> X-Spam-Score: 0.0 (/) X-Content-Filtered-By: Mailman/MimeDel 2.1.5 Cc: freebsd-multimedia@freebsd.org Subject: Re: kbtv2 sound saa.c X-BeenThere: freebsd-multimedia@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Multimedia discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 27 Feb 2008 23:43:33 -0000 --Boundary-00=_vVfxHOoKAgM2InL Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline On Wednesday 27 February 2008 18:55:56 you wrote: > thanks for the hints, but I must admit that I'm totally lost here - > where can I tweak sound carrier frequency? There doesn't seem to be a canned-in way (only for setting NTSC vs PAL), but Sidney's information gave me a second datapoint (for the actual value to be set to "audio_options.sao_siffreq1"). It stands to logic that it's not only a linear but also a proportional equation to convert the actual freq to the required registry value. In terms of numbers I made it work, and there seems to be a certain logic in terms of (audio) output frequency. I think the attached patch will work for you, as well as for PAL I (UK) and hopefully also for NTSC. The sif is switched when broadcast standard gets changed. Here (B/G) it used to be that with other PAL variants the sound would remain. With the current working version of the saa backend it gets noise (most cases mixed with the actual original sound) if I switch away from B/G to any other PAL type as well as if I switch to NTSC, then it gets a heavy pulse-like noise. Once I switch back to B/G sound is ok again. Please try attached patches (1.93 working version, not beta3 yet) to saa.c and saa.h. If you want/need to experiment in python with the saa module directly (from python prompt) please note that you need to "from Kbtv2.drivers.saa import saa" and then first init video and turn capture on, and after that init audio before tuner (viewer must be after video, may be last, mixer can probably be ignored for your purposes). Use dir(saa) to see the available functions. If you want/need to experiment in python with the AVCtrl (easier), you need to "from Kbtv2 import avctrl", then e.g. "avc = avctrl.AVCtrl('saa', 0)". dir(avc) shows all methods, with help(...) you can access the inline documentation (or see the html doc in DOCSDIR). > > BTW, I've found my old post - > http://lists.freebsd.org/pipermail/freebsd-multimedia/2007-January/005711.h >tml > > With those tda9887 settings driver "just worked" with bundled tvv > application (doesn't work for me anymore - I'm lacking xv extension with > NVIDIA 8600GT and xf86-video-nv). It may be that some of the B,C,E data may need to be tweaked here and there, but first of all I like to warn you that the mk3 and especially if init need to be tested after a *cold* boot. If you have for example used the card under windows or linux and then reboot into freebsd the tuner may not be in the same (uninitialized) state as after a cold boot. As you may know, saa doesn't use firmware or eeprom. On linux/windows they do use that. > > > TIA, > Yuri Cheers, Dan Because the ML scrubs attachments, the patches (diff -u) are copied-pasted below for ML readers. Make sure to re-tab if you copy-paste it. --- saa.h.orig 2008-02-01 00:14:40.000000000 +0100 +++ saa.h 2008-02-27 23:51:05.000000000 +0100 @@ -72,16 +72,19 @@ #define CMD_LO_TEMIC 0x02 #define CMD_MID_TEMIC 0x04 #define CMD_HI_TEMIC 0x01 +#define CMD_LO_MICROTUNE CMD_LO_PHILIPS +#define CMD_MID_MICROTUNE CMD_MID_PHILIPS +#define CMD_HI_MICROTUNE CMD_HI_PHILIPS #define FREQ_VIF_PAL 38.90 // Video IF (picture carrier) freq, MHz #define FREQ_VIF_PAL_LACCENT 33.95 #define FREQ_VIF_NTSC 45.75 #define FREQ_VIF_NTSC_JAPAN 58.75 -#define FREQ_SND_PAL_B_G 5.5 // Sound carrier frequency, MHz (not used) -#define FREQ_SND_PAL_I 6.0 -#define FREQ_SND_PAL_D_K_L 6.5 -#define FREQ_SND_NTSC 4.5 +#define FREQ_SND_PAL_B_G 55 // Sound carrier frequency, MHz * 10 +#define FREQ_SND_PAL_I 60 +#define FREQ_SND_PAL_D_K_L 65 +#define FREQ_SND_NTSC 45 #define FREQ_LOBAND_PAL 48.25 // Bands, MK3 spec followed for PAL #define FREQ_LOBAND_NTSC 55.25 @@ -112,7 +115,7 @@ #define TUNER_TEMIC 3 #define TUNER_ALPS 4 #define TUNER_LG 5 -#define TUNER_MICROTUNE 6 // Not supported (same as NONE) +#define TUNER_MICROTUNE 6 // Experimental #define TDA988X_ADDRESS 0x86 // IF and tuner address #define TUNER_ADDRESS 0xc0 @@ -164,6 +167,7 @@ int audio_get_source(); int audio_set_mute(int onoff); int audio_get_mute(); +int __set_sif(int freq); /// TUNER FUNCTIONS ////////////////////////////////////////////////////// @@ -181,6 +185,7 @@ int tuner_get_afc(); int __init_mk3(); int __init_if(); +int __init_mt(); // not implemented yet /// VIDEO FUNCTIONS ////////////////////////////////////////////////////// --- saa.c.orig 2008-02-20 02:05:42.000000000 +0100 +++ saa.c 2008-02-27 23:51:02.000000000 +0100 @@ -64,6 +64,7 @@ struct saa_video_opt vo; // saa video options structure struct saa_video_std std; // saa video standard structure struct saa_video_spec spec; // saa video specification structure +struct saa_audio_opt ao; // saa audio options caddr_t framebuffer; // framebuffer data caddr_t framebuffer_copy; // copy int mixer_devmask = 0; // mixer channel mask @@ -98,26 +99,33 @@ int bpp; int new_frame = 0; -static struct saa_audio_spec audio_spec = { +struct saa_audio_spec audio_spec = { // saa/tvv/FLTK/audioopt.c .sas_audsel = AUDSEL_SIF, .sas_sfs = SFS_SIF_32KHZ, .sas_icsch = 1, - .sas_cap_sampcount = 16384, + .sas_cap_sampcount = (SAA_ACAP_FRAME_MAX_SZ >> AUDFMT_AUSEL_SHIFT), .sas_audfmt = AUDFMT_16BIT, .sas_audsamp = AUDSAMP_STEREO, .sas_flag_samp2complement = 1, .sas_flags = 0, }; +// Audio siffreq note: +// sampcount = SAA_ACAP_FRAME_MAX_SZ >> AUDFMT_AUSEL_SHIFT = 16384 +// postfactor = (sampcount >> AUDFMT_SAMP_SHIFT) * 32 / 48 = sampcount * 25 / 3 +// siffreq should then be set to FREQ_SND_foo * sampcount * 25 / 3 +// That way only integers are required to get the anticipated register values +// I don't know if the 32/48 reasoning is correct but the produced numbers are + /// AUDIO FUNCTIONS ////////////////////////////////////////////////////// int audio_init(const char* adev) { if ((fda = open(adev, O_RDWR, 0)) < 0) return -1; // Init the DAC (source 0) if (ioctl(fda, ACAPTUREON, &audio_spec) < 0) return -2; - usleep(sleeptime); - if (ioctl(fda, ACAPTUREOFF, &empty) < 0) return -3; + if (ioctl(fda, GETAUDIOOPT, &ao) < 0) return -3; + if (ioctl(fda, ACAPTUREOFF, &empty) < 0) return -4; audio_set_mute(0); return 0; } @@ -162,6 +170,17 @@ return audio_muted; } +int __set_sif(int freq) { + if (freq == FREQ_SND_NTSC) audio_spec.sas_flags = ASPEC_FLAG_NTSC; + else audio_spec.sas_flags = 0; + if (ioctl(fda, ACAPTUREON, &audio_spec) < 0) return -1; + if (ioctl(fda, GETAUDIOOPT, &ao) < 0) return -2; + ao.sao_siffreq1 = (uint32_t) (freq * audio_spec.sas_cap_sampcount * 25 / 3); + if (ioctl(fda, SETAUDIOOPT, &ao) < 0) return -3; + if (ioctl(fda, ACAPTUREOFF, &empty) < 0) return -4; + return 0; +} + /// TUNER FUNCTIONS ////////////////////////////////////////////////////// /* TODO: update iic code to use the newer interface (iic.ko axed in CURRENT) */ @@ -212,12 +231,13 @@ int tuner_set_type(int ttype) { // Tuner types = 0 to 6: // TUNER_NONE, TUNER_PHILIPS, TUNER_PHILIPS_MK3, TUNER_TEMIC, TUNER_LG, - // TUNER_ALPS, TUNER_MICROTUNE (same as NONE) - if (ttype < 0 || ttype > 5) ttype = 0; + // TUNER_ALPS, TUNER_MICROTUNE + if (ttype < 0 || ttype > 6) ttype = 0; if (ttype == 0) { tuner_type = ttype; return 0; } + audio_set_mute(1); // Bandswitch commands if (ttype == TUNER_PHILIPS) { bsw_lo = CMD_LO_PHILIPS; @@ -239,15 +259,26 @@ bsw_mid = CMD_MID_ALPS; bsw_hi = CMD_HI_ALPS; } - else { + else if (ttype == TUNER_TEMIC) { bsw_lo = CMD_LO_TEMIC; bsw_mid = CMD_MID_TEMIC; bsw_hi = CMD_HI_TEMIC; } + // ChangeLog 20080223: hello microtune + else { + bsw_lo = CMD_LO_MICROTUNE; + bsw_mid = CMD_MID_MICROTUNE; + bsw_hi = CMD_HI_MICROTUNE; + } // Init MK3 if needed if (ttype == TUNER_PHILIPS_MK3) { val = __init_mk3(); - if (val < 0) return val - 10; // kludge + if (val < 0) return val - 20; // kludge + } + // Init MT if needed, ChangeLog 20080223 + if (ttype == TUNER_MICROTUNE) { + val = __init_mt(); + if (val < 0) return val - 60; // kludge } // IF init if needed if (got_tda988x) { @@ -257,6 +288,7 @@ // Re-tune! tuner_set_frequency(curfreq); tuner_type = ttype; + audio_set_mute(0); return 0; } @@ -273,6 +305,7 @@ // BSTD_PAL_B_G, BSTD_PAL_D_K, BSTD_PAL_I, BSTD_PAL_L, BSTD_PAL_LACCENT // BSTD_NTSC, BSTD_NTSC_JAPAN (B/G, D/K, L/L' are same for SECAM) if (tuner_type == 0) return 0; + audio_set_mute(1); if (bstd < 0) bstd = 0; else if (bstd > 6) bstd = 6; bcast_std = bstd; @@ -296,7 +329,12 @@ // MK3 (re-)init -- do this always if MK3 (ChangeLog 20080218) if (tuner_type == TUNER_PHILIPS_MK3) { val = __init_mk3(); - if (val < 0) return val - 10; // kludge + if (val < 0) return val - 20; // kludge + } + // Init MT if needed, ChangeLog 20080223 + else if (tuner_type == TUNER_MICROTUNE) { + val = __init_mt(); + if (val < 0) return val - 60; // kludge } // IF init if needed if (got_tda988x) { @@ -305,6 +343,14 @@ } // Re-tune! tuner_set_frequency(curfreq); + // Set audio IF frequency + if (bcast_std == BSTD_NTSC || bcast_std == BSTD_NTSC_JAPAN) { + __set_sif(FREQ_SND_NTSC); + } + else if (bcast_std == BSTD_PAL_B_G) __set_sif(FREQ_SND_PAL_B_G); + else if (bcast_std == BSTD_PAL_I) __set_sif(FREQ_SND_PAL_I); + else __set_sif(FREQ_SND_PAL_D_K_L); + audio_set_mute(0); return 0; } @@ -426,6 +472,11 @@ return 0; } +int __init_mt() { + // TODO + return 0; +} + /// VIDEO FUNCTIONS ////////////////////////////////////////////////////// int video_init(const char* vdev) { --Boundary-00=_vVfxHOoKAgM2InL Content-Type: text/x-diff; charset="iso-8859-1"; name="patch-saa.h" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="patch-saa.h" --- saa.h.orig 2008-02-01 00:14:40.000000000 +0100 +++ saa.h 2008-02-27 23:51:05.000000000 +0100 @@ -72,16 +72,19 @@ #define CMD_LO_TEMIC 0x02 #define CMD_MID_TEMIC 0x04 #define CMD_HI_TEMIC 0x01 +#define CMD_LO_MICROTUNE CMD_LO_PHILIPS +#define CMD_MID_MICROTUNE CMD_MID_PHILIPS +#define CMD_HI_MICROTUNE CMD_HI_PHILIPS #define FREQ_VIF_PAL 38.90 // Video IF (picture carrier) freq, MHz #define FREQ_VIF_PAL_LACCENT 33.95 #define FREQ_VIF_NTSC 45.75 #define FREQ_VIF_NTSC_JAPAN 58.75 -#define FREQ_SND_PAL_B_G 5.5 // Sound carrier frequency, MHz (not used) -#define FREQ_SND_PAL_I 6.0 -#define FREQ_SND_PAL_D_K_L 6.5 -#define FREQ_SND_NTSC 4.5 +#define FREQ_SND_PAL_B_G 55 // Sound carrier frequency, MHz * 10 +#define FREQ_SND_PAL_I 60 +#define FREQ_SND_PAL_D_K_L 65 +#define FREQ_SND_NTSC 45 #define FREQ_LOBAND_PAL 48.25 // Bands, MK3 spec followed for PAL #define FREQ_LOBAND_NTSC 55.25 @@ -112,7 +115,7 @@ #define TUNER_TEMIC 3 #define TUNER_ALPS 4 #define TUNER_LG 5 -#define TUNER_MICROTUNE 6 // Not supported (same as NONE) +#define TUNER_MICROTUNE 6 // Experimental #define TDA988X_ADDRESS 0x86 // IF and tuner address #define TUNER_ADDRESS 0xc0 @@ -164,6 +167,7 @@ int audio_get_source(); int audio_set_mute(int onoff); int audio_get_mute(); +int __set_sif(int freq); /// TUNER FUNCTIONS ////////////////////////////////////////////////////// @@ -181,6 +185,7 @@ int tuner_get_afc(); int __init_mk3(); int __init_if(); +int __init_mt(); // not implemented yet /// VIDEO FUNCTIONS ////////////////////////////////////////////////////// --Boundary-00=_vVfxHOoKAgM2InL--