All of lore.kernel.org
 help / color / mirror / Atom feed
* ALSA: Updating Sample Rates in sound/core/pcm_native.c
@ 2012-04-18 23:51 Jeremy Torres
  2012-04-19  5:56 ` Clemens Ladisch
  2012-04-19  6:02 ` Takashi Iwai
  0 siblings, 2 replies; 5+ messages in thread
From: Jeremy Torres @ 2012-04-18 23:51 UTC (permalink / raw)
  To: alsa-devel

Hello,

I have updated pcm.h in the linux kernel to allow for new sample
rates.  For example, I have added 128000 and 144000 sample rates.  Per
the documentation in pcm.h, I also updated pcm_native.c (the rates
table).  However when I try and use the "default" device for the
sample rates:

1.  For 128000: plug conversion occurs for 128K, but the slave is
configured to 96K;
2.  For 144000: plug conversion is attempted at the 176400 rate;

Note that:
a) I have snd_pcm_hw_resample set to FALSE in my application; however,
I've been using aplay/arecord to test as well with repeatable results.
b) I do not have an asoundrc setup for plug conversion, etc.  I only
have the default /usr/share/alsa/alsa.conf;
c) When I try the the device "hw:0,0", I get a (proper) warning that
the sample rate requested is not being honored (i.e., 96K instead of
128K).

I have placed debug in pcm_lib.c,  and pcm_native.c and my sample rate
constraints are set.  My understanding is if I define a specific rate
and it can be matched in the "rates" table, it should be honored.

Environment Info:
ALSA lib/driver version 1.0.20
SOC Driver

Any help would be greatly appreciated!

Regards,
Jeremy

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: ALSA: Updating Sample Rates in sound/core/pcm_native.c
  2012-04-18 23:51 ALSA: Updating Sample Rates in sound/core/pcm_native.c Jeremy Torres
@ 2012-04-19  5:56 ` Clemens Ladisch
       [not found]   ` <843008328967385249@unknownmsgid>
  2012-04-19  6:02 ` Takashi Iwai
  1 sibling, 1 reply; 5+ messages in thread
From: Clemens Ladisch @ 2012-04-19  5:56 UTC (permalink / raw)
  To: Jeremy Torres, alsa-devel

Jeremy Torres wrote:
>I have updated pcm.h in the linux kernel to allow for new sample
>rates.
>However when I try and use the "default" device for the
>sample rates:
>
>1.  For 128000: plug conversion occurs for 128K, but the slave is
>configured to 96K;
>2.  For 144000: plug conversion is attempted at the 176400 rate;

You must keep the symbols in pcm.h and a sound.h
synchronized, and you must not change the value
of any existing symbols.


Regards,
Clemens

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: ALSA: Updating Sample Rates in sound/core/pcm_native.c
  2012-04-18 23:51 ALSA: Updating Sample Rates in sound/core/pcm_native.c Jeremy Torres
  2012-04-19  5:56 ` Clemens Ladisch
@ 2012-04-19  6:02 ` Takashi Iwai
  1 sibling, 0 replies; 5+ messages in thread
From: Takashi Iwai @ 2012-04-19  6:02 UTC (permalink / raw)
  To: Jeremy Torres; +Cc: alsa-devel

At Wed, 18 Apr 2012 19:51:18 -0400,
Jeremy Torres wrote:
> 
> Hello,
> 
> I have updated pcm.h in the linux kernel to allow for new sample
> rates.

No, don't do that unless rates are commonly used by many drivers.
Use snd_pcm_hw_constraint_list() instead.

>  For example, I have added 128000 and 144000 sample rates.  Per
> the documentation in pcm.h, I also updated pcm_native.c (the rates
> table).  However when I try and use the "default" device for the
> sample rates:
> 
> 1.  For 128000: plug conversion occurs for 128K, but the slave is
> configured to 96K;
> 2.  For 144000: plug conversion is attempted at the 176400 rate;

If the problem still happens even with the explicit rate list,
it's easier to debug when you give the patch.


Takashi

> Note that:
> a) I have snd_pcm_hw_resample set to FALSE in my application; however,
> I've been using aplay/arecord to test as well with repeatable results.
> b) I do not have an asoundrc setup for plug conversion, etc.  I only
> have the default /usr/share/alsa/alsa.conf;
> c) When I try the the device "hw:0,0", I get a (proper) warning that
> the sample rate requested is not being honored (i.e., 96K instead of
> 128K).
> 
> I have placed debug in pcm_lib.c,  and pcm_native.c and my sample rate
> constraints are set.  My understanding is if I define a specific rate
> and it can be matched in the "rates" table, it should be honored.
> 
> Environment Info:
> ALSA lib/driver version 1.0.20
> SOC Driver
> 
> Any help would be greatly appreciated!
> 
> Regards,
> Jeremy
> _______________________________________________
> Alsa-devel mailing list
> Alsa-devel@alsa-project.org
> http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: ALSA: Updating Sample Rates in sound/core/pcm_native.c
       [not found]       ` <CAEA5knsd3NtVCCdufvWm1C6rqLkB2vwarpQVu_TTUw7U5i_JGA@mail.gmail.com>
@ 2012-04-19 17:06         ` Clemens Ladisch
  2012-04-27 20:54           ` Jeremy Torres
  0 siblings, 1 reply; 5+ messages in thread
From: Clemens Ladisch @ 2012-04-19 17:06 UTC (permalink / raw)
  To: Jeremy Torres; +Cc: alsa-devel

Jeremy Torres wrote:
> Thanks for the quick reply!  So, I followed Takashi's advice and added
> the constraint list for the new sample rates and no longer changed
> pcm.h/pcm_native.c.  I can record/play at the new sample rates;
> however, ALSA is performing rate conversion.  For example, to run at
> 144K, the slave is configured to run 192K, even though my hardware can
> be configured to support 144K.

This sounds like a bug in the driver.

Unfortunately, my crystal ball is out of order, so you have to actually
show the source code for me to be able to help you.


Regards,
Clemens

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: ALSA: Updating Sample Rates in sound/core/pcm_native.c
  2012-04-19 17:06         ` Clemens Ladisch
@ 2012-04-27 20:54           ` Jeremy Torres
  0 siblings, 0 replies; 5+ messages in thread
From: Jeremy Torres @ 2012-04-27 20:54 UTC (permalink / raw)
  To: Clemens Ladisch; +Cc: alsa-devel

Clemens,

Per your request, the following is the source code I've changed in an
attempt to get additional sample rates that my hardware CODEC can
natively support.

The intent is to use the "hardware" device only (no "plug") with NO
rate conversion for the new sample rates (e.g., 144Khz).  Currently,
if I attempt to use 144Khz, the hardware "slave" samples at 192K, and
ALSA rate converts to 144Khz.

>From linux-2.6.31/sound/soc/davinci/davinci-pcm.c:

static struct snd_pcm_hardware davinci_pcm_hardware = {
	.info = (SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER |
		 SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID |
		 SNDRV_PCM_INFO_PAUSE),
	.formats = (SNDRV_PCM_FMTBIT_S16_LE),
	.rates = (SNDRV_PCM_RATE_8000_192000 | SNDRV_PCM_RATE_KNOT),
	.rate_min = 7200,  // Changed to support new rate
	.rate_max = 192000,
	.channels_min = 1,//2,
	.channels_max = 2,
	.buffer_bytes_max = 256 * 1024,
	.period_bytes_min = 32,
	.period_bytes_max = 8 * 1024,
	.periods_min = 16,
	.periods_max = 255,
	.fifo_size = 0,
};

// ADDED: to support rates not defined in sound/pcm.h
static unsigned int rates[] = { 7200, 8000, 9600, 12000, 16000, 44100,
48000, 64000,
                                96000, 128000, 144000, 192000 };
static struct snd_pcm_hw_constraint_list constraints_rates = {
          .count = ARRAY_SIZE(rates),
          .list = rates,
          .mask = 0,
  };

static int davinci_pcm_open(struct snd_pcm_substream *substream)
{
	struct snd_pcm_runtime *runtime = substream->runtime;
	struct davinci_runtime_data *prtd;
	int ret = 0;

	snd_soc_set_runtime_hwparams(substream, &davinci_pcm_hardware);

	// ADDED: to support rates not supported in sound/pcm.h

	ret = snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
					  &constraints_rates);
	if (ret < 0)
	  {
	    printk(KERN_ERR "ERROR: unable to set HW constraint list!\n");
	    return -1;
	  }

	prtd = kzalloc(sizeof(struct davinci_runtime_data), GFP_KERNEL);
	if (prtd == NULL)
		return -ENOMEM;

	spin_lock_init(&prtd->lock);

	runtime->private_data = prtd;

	ret = davinci_pcm_dma_request(substream);
	if (ret) {
		printk(KERN_ERR "davinci_pcm: Failed to get dma channels\n");
		kfree(prtd);
	}
	
	return ret;
}



Thanks,
Jeremy

On Thu, Apr 19, 2012 at 1:06 PM, Clemens Ladisch <clemens@ladisch.de> wrote:
> Jeremy Torres wrote:
>> Thanks for the quick reply!  So, I followed Takashi's advice and added
>> the constraint list for the new sample rates and no longer changed
>> pcm.h/pcm_native.c.  I can record/play at the new sample rates;
>> however, ALSA is performing rate conversion.  For example, to run at
>> 144K, the slave is configured to run 192K, even though my hardware can
>> be configured to support 144K.
>
> This sounds like a bug in the driver.
>
> Unfortunately, my crystal ball is out of order, so you have to actually
> show the source code for me to be able to help you.
>
>
> Regards,
> Clemens

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2012-04-27 20:54 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-18 23:51 ALSA: Updating Sample Rates in sound/core/pcm_native.c Jeremy Torres
2012-04-19  5:56 ` Clemens Ladisch
     [not found]   ` <843008328967385249@unknownmsgid>
     [not found]     ` <4F902B74.7070603@ladisch.de>
     [not found]       ` <CAEA5knsd3NtVCCdufvWm1C6rqLkB2vwarpQVu_TTUw7U5i_JGA@mail.gmail.com>
2012-04-19 17:06         ` Clemens Ladisch
2012-04-27 20:54           ` Jeremy Torres
2012-04-19  6:02 ` Takashi Iwai

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.