diff mbox

[RESEND] Use correct sampling rate for TV/FM radio

Message ID 200904142048.14713.oldium.pro@seznam.cz (mailing list archive)
State Changes Requested
Headers show

Commit Message

Oldřich Jedlička April 14, 2009, 6:48 p.m. UTC
Here is the fix for using the 32kHz sampling rate for TV and FM radio (ALSA).
The TV uses 32kHz anyway (mode 0; 32kHz demdec on), radio works only with
32kHz (mode 1; 32kHz baseband). The ALSA wrongly reported 32kHz and 48kHz for
everything (TV, radio, LINE1/2).

Now it should be possible to just use the card without the need to change the
capture rate from 48kHz to 32kHz. Enjoy :-)

Now without word-wrapping.

Signed-off-by: Oldřich Jedlička <oldium.pro@seznam.cz>
---
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Comments

Oldřich Jedlička May 19, 2009, 5:54 p.m. UTC | #1
On Tuesday 14 of April 2009 at 20:48:14, Oldrich Jedlicka wrote:
> Here is the fix for using the 32kHz sampling rate for TV and FM radio
> (ALSA). The TV uses 32kHz anyway (mode 0; 32kHz demdec on), radio works
> only with 32kHz (mode 1; 32kHz baseband). The ALSA wrongly reported 32kHz
> and 48kHz for everything (TV, radio, LINE1/2).
>
> Now it should be possible to just use the card without the need to change
> the capture rate from 48kHz to 32kHz. Enjoy :-)
>

Hi Mauro,

are there some comments for/against this patch? It is rather long time when I 
sent it, so I would like to know some opinions.

The reason behind this patch is that the code uses 32kHz for TV and for radio 
(the radio cannot use other frequency as far as I know). ALSA then reports 
both 32kHz and 48kHz for TV/radio, but 48kHz cannot be used.

Thanks!

Cheers,
Oldrich.

> Now without word-wrapping.
>
> Signed-off-by: Oldřich Jedlička <oldium.pro@seznam.cz>
> ---
> diff -r dba0b6fae413 linux/drivers/media/video/saa7134/saa7134-alsa.c
> --- a/linux/drivers/media/video/saa7134/saa7134-alsa.c	Thu Apr 09 08:21:42
> 2009 -0300 +++ b/linux/drivers/media/video/saa7134/saa7134-alsa.c	Mon Apr
> 13 23:07:22 2009 +0200 @@ -465,6 +465,29 @@
>  	.periods_max =		1024,
>  };
>
> +static struct snd_pcm_hardware snd_card_saa7134_capture_32kHz_only =
> +{
> +	.info =                 (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED
> | +				 SNDRV_PCM_INFO_BLOCK_TRANSFER |
> +				 SNDRV_PCM_INFO_MMAP_VALID),
> +	.formats =		SNDRV_PCM_FMTBIT_S16_LE | \
> +				SNDRV_PCM_FMTBIT_S16_BE | \
> +				SNDRV_PCM_FMTBIT_S8 | \
> +				SNDRV_PCM_FMTBIT_U8 | \
> +				SNDRV_PCM_FMTBIT_U16_LE | \
> +				SNDRV_PCM_FMTBIT_U16_BE,
> +	.rates =		SNDRV_PCM_RATE_32000,
> +	.rate_min =		32000,
> +	.rate_max =		32000,
> +	.channels_min =		1,
> +	.channels_max =		2,
> +	.buffer_bytes_max =	(256*1024),
> +	.period_bytes_min =	64,
> +	.period_bytes_max =	(256*1024),
> +	.periods_min =		4,
> +	.periods_max =		1024,
> +};
> +
>  static void snd_card_saa7134_runtime_free(struct snd_pcm_runtime *runtime)
>  {
>  	snd_card_saa7134_pcm_t *pcm = runtime->private_data;
> @@ -651,7 +674,13 @@
>  	pcm->substream = substream;
>  	runtime->private_data = pcm;
>  	runtime->private_free = snd_card_saa7134_runtime_free;
> -	runtime->hw = snd_card_saa7134_capture;
> +
> +	if (amux == TV || &card(dev).radio == dev->input) {
> +		/* TV uses 32kHz sampling, AM/FM radio is locked to 32kHz */
> +		runtime->hw = snd_card_saa7134_capture_32kHz_only;
> +	} else {
> +		runtime->hw = snd_card_saa7134_capture;
> +	}
>
>  	if (dev->ctl_mute != 0) {
>  		saa7134->mute_was_on = 1;
> --
> To unsubscribe from this list: send the line "unsubscribe linux-media" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html


--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Oldřich Jedlička May 23, 2009, 5:09 p.m. UTC | #2
On Tuesday 19 of May 2009 at 19:54:18, Oldrich Jedlicka wrote:
> On Tuesday 14 of April 2009 at 20:48:14, Oldrich Jedlicka wrote:
> > Here is the fix for using the 32kHz sampling rate for TV and FM radio
> > (ALSA). The TV uses 32kHz anyway (mode 0; 32kHz demdec on), radio works
> > only with 32kHz (mode 1; 32kHz baseband). The ALSA wrongly reported 32kHz
> > and 48kHz for everything (TV, radio, LINE1/2).
> >
> > Now it should be possible to just use the card without the need to change
> > the capture rate from 48kHz to 32kHz. Enjoy :-)
>

Hi Mauro,

I put you on CC in my previous mail, but maybe it would be better to send it 
directly. So do you have any opinions about the approach described 
above/below?

Thanks!

Cheers,
Oldrich.

> Hi Mauro,
>
> are there some comments for/against this patch? It is rather long time when
> I sent it, so I would like to know some opinions.
>
> The reason behind this patch is that the code uses 32kHz for TV and for
> radio (the radio cannot use other frequency as far as I know). ALSA then
> reports both 32kHz and 48kHz for TV/radio, but 48kHz cannot be used.
>
> Thanks!
>
> Cheers,
> Oldrich.
>
> > Now without word-wrapping.
> >
> > Signed-off-by: Oldřich Jedlička <oldium.pro@seznam.cz>
> > ---
> > diff -r dba0b6fae413 linux/drivers/media/video/saa7134/saa7134-alsa.c
> > --- a/linux/drivers/media/video/saa7134/saa7134-alsa.c	Thu Apr 09
> > 08:21:42 2009 -0300 +++
> > b/linux/drivers/media/video/saa7134/saa7134-alsa.c	Mon Apr 13 23:07:22
> > 2009 +0200 @@ -465,6 +465,29 @@
> >  	.periods_max =		1024,
> >  };
> >
> > +static struct snd_pcm_hardware snd_card_saa7134_capture_32kHz_only =
> > +{
> > +	.info =                 (SNDRV_PCM_INFO_MMAP |
> > SNDRV_PCM_INFO_INTERLEAVED
> >
> > | +				 SNDRV_PCM_INFO_BLOCK_TRANSFER |
> >
> > +				 SNDRV_PCM_INFO_MMAP_VALID),
> > +	.formats =		SNDRV_PCM_FMTBIT_S16_LE | \
> > +				SNDRV_PCM_FMTBIT_S16_BE | \
> > +				SNDRV_PCM_FMTBIT_S8 | \
> > +				SNDRV_PCM_FMTBIT_U8 | \
> > +				SNDRV_PCM_FMTBIT_U16_LE | \
> > +				SNDRV_PCM_FMTBIT_U16_BE,
> > +	.rates =		SNDRV_PCM_RATE_32000,
> > +	.rate_min =		32000,
> > +	.rate_max =		32000,
> > +	.channels_min =		1,
> > +	.channels_max =		2,
> > +	.buffer_bytes_max =	(256*1024),
> > +	.period_bytes_min =	64,
> > +	.period_bytes_max =	(256*1024),
> > +	.periods_min =		4,
> > +	.periods_max =		1024,
> > +};
> > +
> >  static void snd_card_saa7134_runtime_free(struct snd_pcm_runtime
> > *runtime) {
> >  	snd_card_saa7134_pcm_t *pcm = runtime->private_data;
> > @@ -651,7 +674,13 @@
> >  	pcm->substream = substream;
> >  	runtime->private_data = pcm;
> >  	runtime->private_free = snd_card_saa7134_runtime_free;
> > -	runtime->hw = snd_card_saa7134_capture;
> > +
> > +	if (amux == TV || &card(dev).radio == dev->input) {
> > +		/* TV uses 32kHz sampling, AM/FM radio is locked to 32kHz */
> > +		runtime->hw = snd_card_saa7134_capture_32kHz_only;
> > +	} else {
> > +		runtime->hw = snd_card_saa7134_capture;
> > +	}
> >
> >  	if (dev->ctl_mute != 0) {
> >  		saa7134->mute_was_on = 1;
> > --
> > To unsubscribe from this list: send the line "unsubscribe linux-media" in
> > the body of a message to majordomo@vger.kernel.org
> > More majordomo info at  http://vger.kernel.org/majordomo-info.html
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-media" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html


--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Mauro Carvalho Chehab May 27, 2009, 7:05 p.m. UTC | #3
Em Sat, 23 May 2009 19:09:12 +0200
Oldrich Jedlicka <oldium.pro@seznam.cz> escreveu:

> On Tuesday 19 of May 2009 at 19:54:18, Oldrich Jedlicka wrote:
> > On Tuesday 14 of April 2009 at 20:48:14, Oldrich Jedlicka wrote:
> > > Here is the fix for using the 32kHz sampling rate for TV and FM radio
> > > (ALSA). The TV uses 32kHz anyway (mode 0; 32kHz demdec on), radio works
> > > only with 32kHz (mode 1; 32kHz baseband). The ALSA wrongly reported 32kHz
> > > and 48kHz for everything (TV, radio, LINE1/2).
> > >
> > > Now it should be possible to just use the card without the need to change
> > > the capture rate from 48kHz to 32kHz. Enjoy :-)
> >
> 
> Hi Mauro,
> 
> I put you on CC in my previous mail, but maybe it would be better to send it 
> directly. So do you have any opinions about the approach described 
> above/below?

I did a look at saa713x datasheet. In thesis, it could be possible to program
the audio sampling rate divider for several rates including 32 kHz, 44.1 kHz
and 48 kHz.

However, I suspect that only MONO is supported with rates different than 32
kHz, since it is said there that AM/FM requires a nominal audio sample of
32 kHz, and that NICAM nominal audio sample rate is 32 kHz.

So, IMO, the right patch is just to allow samplings at 32 kHz



Cheers,
Mauro
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Oldřich Jedlička May 28, 2009, 4:47 p.m. UTC | #4
On Wednesday 27 of May 2009 at 21:05:35, Mauro Carvalho Chehab wrote:
> Em Sat, 23 May 2009 19:09:12 +0200
>
> Oldrich Jedlicka <oldium.pro@seznam.cz> escreveu:
> > On Tuesday 19 of May 2009 at 19:54:18, Oldrich Jedlicka wrote:
> > > On Tuesday 14 of April 2009 at 20:48:14, Oldrich Jedlicka wrote:
> > > > Here is the fix for using the 32kHz sampling rate for TV and FM radio
> > > > (ALSA). The TV uses 32kHz anyway (mode 0; 32kHz demdec on), radio
> > > > works only with 32kHz (mode 1; 32kHz baseband). The ALSA wrongly
> > > > reported 32kHz and 48kHz for everything (TV, radio, LINE1/2).
> > > >
> > > > Now it should be possible to just use the card without the need to
> > > > change the capture rate from 48kHz to 32kHz. Enjoy :-)
> >
> > Hi Mauro,
> >
> > I put you on CC in my previous mail, but maybe it would be better to send
> > it directly. So do you have any opinions about the approach described
> > above/below?
>
> I did a look at saa713x datasheet. In thesis, it could be possible to
> program the audio sampling rate divider for several rates including 32 kHz,
> 44.1 kHz and 48 kHz.
>
> However, I suspect that only MONO is supported with rates different than 32
> kHz, since it is said there that AM/FM requires a nominal audio sample of
> 32 kHz, and that NICAM nominal audio sample rate is 32 kHz.
>
> So, IMO, the right patch is just to allow samplings at 32 kHz

Hi Mauro,

I'm not good in programming the SAA7134, but I also have the SAA713x 
manual :-).

I don't know if the NICAM mode is used for LINE1/LINE2, but if not - and if it 
uses the Video-lock mode - it can (or could) operate in 44.1kHz and 48kHz 
too.

The manual talks about Video-mode and here is the note, that the FM/AM sound 
decoring requires a nominal audio sample rate of 32kHz. The code 
(saa7134-alsa.c) sets to use 32kHz for radio, it is not configurable - so 
this is where my patch applies.

The Video-lock mode can use 32kHz, 44.1kHz and 48kHz. The NICAM can use only 
the 32kHz. From the code (again the saa7134-alsa.c) the TV sets to use the 
DEMDEC 32kHz mode and is not configurable - again my patch applies.

So my only question is about the LINE1/LINE2, I do not understand the coding 
of SAA713x as much to be able to say anything about the mode of operation for 
LINE1/LINE2. Maybe somebody wants to use the 48kHz whenever possible on 
LINE1/LINE2 (quality reasons), so maybe limiting it there isn't good - I 
don't know, if it is possible to use it.
 
Cheers,
Oldrich.
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
hermann pitton May 28, 2009, 11:49 p.m. UTC | #5
Hi,

just some short notes.

Am Donnerstag, den 28.05.2009, 18:47 +0200 schrieb Oldrich Jedlicka:
> On Wednesday 27 of May 2009 at 21:05:35, Mauro Carvalho Chehab wrote:
> > Em Sat, 23 May 2009 19:09:12 +0200
> >
> > Oldrich Jedlicka <oldium.pro@seznam.cz> escreveu:
> > > On Tuesday 19 of May 2009 at 19:54:18, Oldrich Jedlicka wrote:
> > > > On Tuesday 14 of April 2009 at 20:48:14, Oldrich Jedlicka wrote:
> > > > > Here is the fix for using the 32kHz sampling rate for TV and FM radio
> > > > > (ALSA). The TV uses 32kHz anyway (mode 0; 32kHz demdec on), radio
> > > > > works only with 32kHz (mode 1; 32kHz baseband). The ALSA wrongly
> > > > > reported 32kHz and 48kHz for everything (TV, radio, LINE1/2).
> > > > >
> > > > > Now it should be possible to just use the card without the need to
> > > > > change the capture rate from 48kHz to 32kHz. Enjoy :-)
> > >
> > > Hi Mauro,
> > >
> > > I put you on CC in my previous mail, but maybe it would be better to send
> > > it directly. So do you have any opinions about the approach described
> > > above/below?
> >
> > I did a look at saa713x datasheet. In thesis, it could be possible to
> > program the audio sampling rate divider for several rates including 32 kHz,
> > 44.1 kHz and 48 kHz.
> >
> > However, I suspect that only MONO is supported with rates different than 32
> > kHz, since it is said there that AM/FM requires a nominal audio sample of
> > 32 kHz, and that NICAM nominal audio sample rate is 32 kHz.
> >
> > So, IMO, the right patch is just to allow samplings at 32 kHz
> 
> Hi Mauro,
> 
> I'm not good in programming the SAA7134, but I also have the SAA713x 
> manual :-).

If you have the programming manual, not what is for free download but
under NDA, you should find exact register settings for 48kHZ stereo over
DMA TV sound, if possible at all.

> I don't know if the NICAM mode is used for LINE1/LINE2, but if not - and if it 
> uses the Video-lock mode - it can (or could) operate in 44.1kHz and 48kHz 
> too.

NICAM, on all TV standards that support it, is always at the second
soundcarrier. So input must be SIF to isolate the SSIF and decode it
from there with the nicam decoder. (amux TV)

> The manual talks about Video-mode and here is the note, that the FM/AM sound 
> decoring requires a nominal audio sample rate of 32kHz. The code 
> (saa7134-alsa.c) sets to use 32kHz for radio, it is not configurable - so 
> this is where my patch applies.

For all analog audio out from tuner the sampling rate is 32 kHz. That is
correct.

> The Video-lock mode can use 32kHz, 44.1kHz and 48kHz. The NICAM can use only 
> the 32kHz. From the code (again the saa7134-alsa.c) the TV sets to use the 
> DEMDEC 32kHz mode and is not configurable - again my patch applies.
> 
> So my only question is about the LINE1/LINE2, I do not understand the coding 
> of SAA713x as much to be able to say anything about the mode of operation for 
> LINE1/LINE2. Maybe somebody wants to use the 48kHz whenever possible on 
> LINE1/LINE2 (quality reasons), so maybe limiting it there isn't good - I 
> don't know, if it is possible to use it.

Gerd had working 48kHz audio sampling rate from external audio LINE
inputs on his saa7134-oss, at least on the saa7134 chip.

This is not working anymore on saa7134-alsa.

He was also the opinion, that 48kHz stereo TV sound is not possible over
DMA too. IIRC, on broadcast level 32kHz is already up sampled.

A limiting factor might also be, that we can't differentiate between
saa7133, saa7135 and saa7131e. There are such chip comparing tables I
don't have at hand at the moment.

Cheers,
Hermann




--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Oldřich Jedlička May 29, 2009, 7:06 a.m. UTC | #6
Hi,

On Friday 29 of May 2009 at 01:49:50, hermann pitton wrote:
> Hi,
>
> just some short notes.
>
> Am Donnerstag, den 28.05.2009, 18:47 +0200 schrieb Oldrich Jedlicka:
> > On Wednesday 27 of May 2009 at 21:05:35, Mauro Carvalho Chehab wrote:
> > > Em Sat, 23 May 2009 19:09:12 +0200
> > >
> > > Oldrich Jedlicka <oldium.pro@seznam.cz> escreveu:
> > > > On Tuesday 19 of May 2009 at 19:54:18, Oldrich Jedlicka wrote:
> > > > > On Tuesday 14 of April 2009 at 20:48:14, Oldrich Jedlicka wrote:
> > > > > > Here is the fix for using the 32kHz sampling rate for TV and FM
> > > > > > radio (ALSA). The TV uses 32kHz anyway (mode 0; 32kHz demdec on),
> > > > > > radio works only with 32kHz (mode 1; 32kHz baseband). The ALSA
> > > > > > wrongly reported 32kHz and 48kHz for everything (TV, radio,
> > > > > > LINE1/2).
> > > > > >
> > > > > > Now it should be possible to just use the card without the need
> > > > > > to change the capture rate from 48kHz to 32kHz. Enjoy :-)
> > > >
> > > > Hi Mauro,
> > > >
> > > > I put you on CC in my previous mail, but maybe it would be better to
> > > > send it directly. So do you have any opinions about the approach
> > > > described above/below?
> > >
> > > I did a look at saa713x datasheet. In thesis, it could be possible to
> > > program the audio sampling rate divider for several rates including 32
> > > kHz, 44.1 kHz and 48 kHz.
> > >
> > > However, I suspect that only MONO is supported with rates different
> > > than 32 kHz, since it is said there that AM/FM requires a nominal audio
> > > sample of 32 kHz, and that NICAM nominal audio sample rate is 32 kHz.
> > >
> > > So, IMO, the right patch is just to allow samplings at 32 kHz
> >
> > Hi Mauro,
> >
> > I'm not good in programming the SAA7134, but I also have the SAA713x
> > manual :-).
>
> If you have the programming manual, not what is for free download but
> under NDA, you should find exact register settings for 48kHZ stereo over
> DMA TV sound, if possible at all.

I have something that is called "SAA7133; SAA7135 PCI audio and video 
broadcast decoder", Preliminary version, 2003 Sep 09. I've found it on the 
internet in 2006.

> > I don't know if the NICAM mode is used for LINE1/LINE2, but if not - and
> > if it uses the Video-lock mode - it can (or could) operate in 44.1kHz and
> > 48kHz too.
>
> NICAM, on all TV standards that support it, is always at the second
> soundcarrier. So input must be SIF to isolate the SSIF and decode it
> from there with the nicam decoder. (amux TV)
>
> > The manual talks about Video-mode and here is the note, that the FM/AM
> > sound decoring requires a nominal audio sample rate of 32kHz. The code
> > (saa7134-alsa.c) sets to use 32kHz for radio, it is not configurable - so
> > this is where my patch applies.
>
> For all analog audio out from tuner the sampling rate is 32 kHz. That is
> correct.
>
> > The Video-lock mode can use 32kHz, 44.1kHz and 48kHz. The NICAM can use
> > only the 32kHz. From the code (again the saa7134-alsa.c) the TV sets to
> > use the DEMDEC 32kHz mode and is not configurable - again my patch
> > applies.
> >
> > So my only question is about the LINE1/LINE2, I do not understand the
> > coding of SAA713x as much to be able to say anything about the mode of
> > operation for LINE1/LINE2. Maybe somebody wants to use the 48kHz whenever
> > possible on LINE1/LINE2 (quality reasons), so maybe limiting it there
> > isn't good - I don't know, if it is possible to use it.
>
> Gerd had working 48kHz audio sampling rate from external audio LINE
> inputs on his saa7134-oss, at least on the saa7134 chip.
>
> This is not working anymore on saa7134-alsa.
>
> He was also the opinion, that 48kHz stereo TV sound is not possible over
> DMA too. IIRC, on broadcast level 32kHz is already up sampled.
>
> A limiting factor might also be, that we can't differentiate between
> saa7133, saa7135 and saa7131e. There are such chip comparing tables I
> don't have at hand at the moment.

I cannot find anything specific to setting the DMA for TV in the document, 
only about the audio clock generation. In NICAM mode (whatever it means) the 
nominal sample rate is 32kHz. The frequency 32kHz can operate in two modes - 
with/without DEMDEC enabled (I don't know what the DEMDEC is). The code for 
TV in saa7134-alsa.c (I only guess, because the register address is 
completely different) uses the 32kHz with DEMDEC enabled (0x00 for 
SIF_SAMPLE_FREQ). The LINE1/LINE2 code sets the frequency to 32kHz+DEMDEC 
disabled (0x01) or 48kHz (0x03). There should be a possibility to set 44.1kHz 
(0x02) too, but it is not used.

One of the lines (LINE1/LINE2) captures the radio, but the radio requires 
32kHz (it is the LINE1/LINE2 branch in code - it uses mode 0x01, I don't know 
if the mode 0x00 can be used).

I tried to use the 48kHz for the composite input (digital camera) and it 
doesn't work for me too.

The rest is covered in a big cloud, I don't know much about DMA programming 
nor about the SAA713x programming. The document is not clear to me, it has a 
lot of tables and not much text in between.

But if the frequency other than 32kHz simply doesn't work, ALSA should report 
only 32kHz (at least for now). I can provide a simple patch for that, if 
nobody complains.

Cheers,
Oldrich.
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
hermann pitton May 31, 2009, 3:11 a.m. UTC | #7
Am Freitag, den 29.05.2009, 09:06 +0200 schrieb Oldrich Jedlicka: 
> Hi,
> 
> On Friday 29 of May 2009 at 01:49:50, hermann pitton wrote:
> > Hi,
> >
> > just some short notes.
> >
> > Am Donnerstag, den 28.05.2009, 18:47 +0200 schrieb Oldrich Jedlicka:
> > > On Wednesday 27 of May 2009 at 21:05:35, Mauro Carvalho Chehab wrote:
> > > > Em Sat, 23 May 2009 19:09:12 +0200
> > > >
> > > > Oldrich Jedlicka <oldium.pro@seznam.cz> escreveu:
> > > > > On Tuesday 19 of May 2009 at 19:54:18, Oldrich Jedlicka wrote:
> > > > > > On Tuesday 14 of April 2009 at 20:48:14, Oldrich Jedlicka wrote:
> > > > > > > Here is the fix for using the 32kHz sampling rate for TV and FM
> > > > > > > radio (ALSA). The TV uses 32kHz anyway (mode 0; 32kHz demdec on),
> > > > > > > radio works only with 32kHz (mode 1; 32kHz baseband). The ALSA
> > > > > > > wrongly reported 32kHz and 48kHz for everything (TV, radio,
> > > > > > > LINE1/2).
> > > > > > >
> > > > > > > Now it should be possible to just use the card without the need
> > > > > > > to change the capture rate from 48kHz to 32kHz. Enjoy :-)
> > > > >
> > > > > Hi Mauro,
> > > > >
> > > > > I put you on CC in my previous mail, but maybe it would be better to
> > > > > send it directly. So do you have any opinions about the approach
> > > > > described above/below?
> > > >
> > > > I did a look at saa713x datasheet. In thesis, it could be possible to
> > > > program the audio sampling rate divider for several rates including 32
> > > > kHz, 44.1 kHz and 48 kHz.
> > > >
> > > > However, I suspect that only MONO is supported with rates different
> > > > than 32 kHz, since it is said there that AM/FM requires a nominal audio
> > > > sample of 32 kHz, and that NICAM nominal audio sample rate is 32 kHz.
> > > >
> > > > So, IMO, the right patch is just to allow samplings at 32 kHz
> > >
> > > Hi Mauro,
> > >
> > > I'm not good in programming the SAA7134, but I also have the SAA713x
> > > manual :-).
> >
> > If you have the programming manual, not what is for free download but
> > under NDA, you should find exact register settings for 48kHZ stereo over
> > DMA TV sound, if possible at all.
> 
> I have something that is called "SAA7133; SAA7135 PCI audio and video 
> broadcast decoder", Preliminary version, 2003 Sep 09. I've found it on the 
> internet in 2006.
> 
> > > I don't know if the NICAM mode is used for LINE1/LINE2, but if not - and
> > > if it uses the Video-lock mode - it can (or could) operate in 44.1kHz and
> > > 48kHz too.
> >
> > NICAM, on all TV standards that support it, is always at the second
> > soundcarrier. So input must be SIF to isolate the SSIF and decode it
> > from there with the nicam decoder. (amux TV)
> >
> > > The manual talks about Video-mode and here is the note, that the FM/AM
> > > sound decoring requires a nominal audio sample rate of 32kHz. The code
> > > (saa7134-alsa.c) sets to use 32kHz for radio, it is not configurable - so
> > > this is where my patch applies.
> >
> > For all analog audio out from tuner the sampling rate is 32 kHz. That is
> > correct.
> >
> > > The Video-lock mode can use 32kHz, 44.1kHz and 48kHz. The NICAM can use
> > > only the 32kHz. From the code (again the saa7134-alsa.c) the TV sets to
> > > use the DEMDEC 32kHz mode and is not configurable - again my patch
> > > applies.
> > >
> > > So my only question is about the LINE1/LINE2, I do not understand the
> > > coding of SAA713x as much to be able to say anything about the mode of
> > > operation for LINE1/LINE2. Maybe somebody wants to use the 48kHz whenever
> > > possible on LINE1/LINE2 (quality reasons), so maybe limiting it there
> > > isn't good - I don't know, if it is possible to use it.
> >
> > Gerd had working 48kHz audio sampling rate from external audio LINE
> > inputs on his saa7134-oss, at least on the saa7134 chip.
> >
> > This is not working anymore on saa7134-alsa.
> >
> > He was also the opinion, that 48kHz stereo TV sound is not possible over
> > DMA too. IIRC, on broadcast level 32kHz is already up sampled.
> >
> > A limiting factor might also be, that we can't differentiate between
> > saa7133, saa7135 and saa7131e. There are such chip comparing tables I
> > don't have at hand at the moment.
> 
> I cannot find anything specific to setting the DMA for TV in the document, 
> only about the audio clock generation. In NICAM mode (whatever it means) the 
> nominal sample rate is 32kHz. The frequency 32kHz can operate in two modes - 
> with/without DEMDEC enabled (I don't know what the DEMDEC is). The code for 
> TV in saa7134-alsa.c (I only guess, because the register address is 
> completely different) uses the 32kHz with DEMDEC enabled (0x00 for 
> SIF_SAMPLE_FREQ). The LINE1/LINE2 code sets the frequency to 32kHz+DEMDEC 
> disabled (0x01) or 48kHz (0x03). There should be a possibility to set 44.1kHz 
> (0x02) too, but it is not used.

NCIAM is digital audio at SSIF and locked with 32kHz sample size to
video at broadcast level. Needs DEMDEC/SIF input to the NICAM decoder.

DemDec is demodulation decoding/decimation at SIF level using
appropriate filters etc. to recover the audio subcarriers. Type of audio
is signaled by pilot tones. In saa7134-tvaudio runs a kernelthread for
auto detecting the type of broadcast. It is different for saa7134 and
saa7133/35/31e. The saa7133 for System M can do only 32kHz from SIF for
sure and that is one more reason for your patch.

> One of the lines (LINE1/LINE2) captures the radio, but the radio requires 
> 32kHz (it is the LINE1/LINE2 branch in code - it uses mode 0x01, I don't know 
> if the mode 0x00 can be used).

Radio stereo sound comes from the tuners to one of the LINE in pairs.
The saa7133/35/31e can decode also the radio IF, but a different radio
IF filter at 7.5 MHz is used. We do this on cards having amux TV for
radio. The saa7134 can't do that. The saa7130 can also not decode TV
sound from SIF input and has only mono from tuners.

> I tried to use the 48kHz for the composite input (digital camera) and it 
> doesn't work for me too.

:(

On saa7134-oss rate=48000 was an insmod option and propagated through
put_user. If an app calls for 48000 on saa7134-alsa it seems to do
exactly nothing. 

That 0x02 44.1 kHz was left away, likely has a very simple explanation.
You can down sample easily by software to it. One can also up sample
from 32 kHz, but that will of course not add the missing spectrum.

> The rest is covered in a big cloud, I don't know much about DMA programming 
> nor about the SAA713x programming. The document is not clear to me, it has a 
> lot of tables and not much text in between.

You seem to have the more interesting part of the documentation and
after Gerd Hartmut had the NDAs and did the fixes, currently not active,
but since very old, it also might contain bugs.

> But if the frequency other than 32kHz simply doesn't work, ALSA should report 
> only 32kHz (at least for now). I can provide a simple patch for that, if 
> nobody complains.

All fine, but we should not start to hide bugs/uncertainties we obviously have.

So, until then, for me it seems better to keep it buggy for now.

Cheers,
Hermann
 

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff -r dba0b6fae413 linux/drivers/media/video/saa7134/saa7134-alsa.c
--- a/linux/drivers/media/video/saa7134/saa7134-alsa.c	Thu Apr 09 08:21:42 2009 -0300
+++ b/linux/drivers/media/video/saa7134/saa7134-alsa.c	Mon Apr 13 23:07:22 2009 +0200
@@ -465,6 +465,29 @@ 
 	.periods_max =		1024,
 };
 
+static struct snd_pcm_hardware snd_card_saa7134_capture_32kHz_only =
+{
+	.info =                 (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
+				 SNDRV_PCM_INFO_BLOCK_TRANSFER |
+				 SNDRV_PCM_INFO_MMAP_VALID),
+	.formats =		SNDRV_PCM_FMTBIT_S16_LE | \
+				SNDRV_PCM_FMTBIT_S16_BE | \
+				SNDRV_PCM_FMTBIT_S8 | \
+				SNDRV_PCM_FMTBIT_U8 | \
+				SNDRV_PCM_FMTBIT_U16_LE | \
+				SNDRV_PCM_FMTBIT_U16_BE,
+	.rates =		SNDRV_PCM_RATE_32000,
+	.rate_min =		32000,
+	.rate_max =		32000,
+	.channels_min =		1,
+	.channels_max =		2,
+	.buffer_bytes_max =	(256*1024),
+	.period_bytes_min =	64,
+	.period_bytes_max =	(256*1024),
+	.periods_min =		4,
+	.periods_max =		1024,
+};
+
 static void snd_card_saa7134_runtime_free(struct snd_pcm_runtime *runtime)
 {
 	snd_card_saa7134_pcm_t *pcm = runtime->private_data;
@@ -651,7 +674,13 @@ 
 	pcm->substream = substream;
 	runtime->private_data = pcm;
 	runtime->private_free = snd_card_saa7134_runtime_free;
-	runtime->hw = snd_card_saa7134_capture;
+
+	if (amux == TV || &card(dev).radio == dev->input) {
+		/* TV uses 32kHz sampling, AM/FM radio is locked to 32kHz */
+		runtime->hw = snd_card_saa7134_capture_32kHz_only;
+	} else {
+		runtime->hw = snd_card_saa7134_capture;
+	}
 
 	if (dev->ctl_mute != 0) {
 		saa7134->mute_was_on = 1;