Fwd: ALSA queries

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



---------- Forwarded message ---------
From: Chakravarthi Pradeep <doubleq7@xxxxxxxxx>
Date: Sun 5 Aug, 2018, 14:19
Subject: Re:  ALSA queries
To: <tiwai@xxxxxxx>


Hello Takashi,

Thanks for your reply.

 periods_min = the minimal number of periods
 period_bytes_min = the minimal size of bytes for one period
 period_bytes_max = the maximal size of bytes for one period


periods_min = the minimal number of periods :  what is meaning of
periods , is it minimal number of interrupts ?
period_bytes_min = the minimal size of bytes for one period : it
means, minimal size of bytes per interrupt in case of device, Is it
correct ?
what about period_max ?

It's most likely the ALSA PCM core's safety stop; your driver seem to
have missed snd_pcm_period_elapsed() calls, so the hwptr isn't
updated, resulting in XRUN.  ALSA PCM core checks such XRUN condition
with the own timer.

I'm attaching my driver thread along with this mail. Can you please
let me know if I have missed something in audio thread. ?. How to make
sure in driver that, trigger stop should be called only when stop
command is sent from application.

I'm getting cut cut cut ... noise along with audio in VLC application.
Initially for 2 or 4 seconds, cut cut cut noise is not heard in VLC
application, However after almost after 5 sec ,I can hear cut cut cut
noise in VLC application. With my analysis, hwptr is getting updated
properly however I have doubt in app_ptr. I'm attaching the excl sheet
with hw_ptr,app_ptr and buf_pos values.

How to remove the cut cut cut ... noise in audio ?

Regards,
Chakravarthi

On Fri, Aug 3, 2018 at 1:05 PM Takashi Iwai <tiwai@xxxxxxx> wrote:
>
> On Thu, 02 Aug 2018 16:31:13 +0200,
> Chakravarthi Pradeep wrote:
> >
> > I'm working on ALSA driver for PCIe card. My ALSA driver and it's
> > initializing struct snd_pcm_hardware with below parameter.
> >
> > /************************ code  start
> > ************************************************/
> > static struct snd_pcm_hardware audio_pcm_hardware = {
> > .info = (SNDRV_PCM_INFO_INTERLEAVED  | SNDRV_PCM_INFO_MMAP |
> > SNDRV_PCM_INFO_MMAP_VALID |
> > SNDRV_PCM_INFO_BLOCK_TRANSFER |
> > SNDRV_PCM_INFO_RESUME ),
> > .formats  =       (SNDRV_PCM_FORMAT_S16_LE | SNDRV_PCM_FORMAT_S24_LE),
> > .rates  = (SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 |
> > SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_192000),
> > .rate_min  = 44100,
> > .rate_max  = 192000,
> > .channels_min  = 2,
> > .channels_max  = 8,
> > .buffer_bytes_max  = 76800, /*75 kbytes */
> > .period_bytes_min  = 512,//4410, /* (channel (2) * sample_rate (44100)
> > * bit width (24)) / (60 * 8)  */
> > .period_bytes_max  = 16*1024,
> > .periods_min  = 10,
> > .periods_max  = 255,
> >
> > };
> > /************************ code  end
> > ************************************************/
> >
> > 1) I did not understand what is significance of periods_min ,
> > period_bytes_min ,  period_bytes_max and periods_max. Can you please
> > tell me what is importance of these parameter and what value should be
> > mentioned according into ALSA.
>
> These three defines the values your hardware may accept:
>  periods_min = the minimal number of periods
>  period_bytes_min = the minimal size of bytes for one period
>  period_bytes_max = the maximal size of bytes for one period
>
> > 2) snd_pcm_ops trigger callback is getting called in the driver when
> > application sends "start" command. But ALSA driver is stopping by
> > itself after one frame is copied to ALSA framework, without waiting
> > for "stop" command.
> >
> > For instance:
> > In trigger callback , I'm getting these logs after one frame is copied.
> > Trigger:Start (When Play button is selected/clicked in application,
> > Start command is sent to ALSA driver)
> > Dma transfer is completed.
> > Trigger:Stop. (When Stop button is selected/clicked in application,
> > Stop command is sent to ALSA driver. But stop button is not clicked in
> > this case)
>
> It's most likely the ALSA PCM core's safety stop; your driver seem to
> have missed snd_pcm_period_elapsed() calls, so the hwptr isn't
> updated, resulting in XRUN.  ALSA PCM core checks such XRUN condition
> with the own timer.
>
>
> Takashi



-- 
Thanks and Regards
Chakravarthi Pradeep.K
Ph: 91 9980434900
static int uhdc_audio_thread(void *data)
{
	char *audio_frame = NULL;
	int count = 0;
	uhdc_t3_card_driver *drv = (uhdc_t3_card_driver *)data;
	struct snd_pcm_runtime *runtime = drv->substream->runtime;

	
	audio_frame = kmalloc(MAX_AUDIO_SIZE, GFP_DMA);	
	if(!audio_frame)
	{
		return -ENOMEM;
	}
	while(1)
	{

		if (kthread_should_stop())
		{
			dbg_alsa( "###### %s %d\n",__FUNCTION__,__LINE__);
			break;
		}
		dbg_alsa( "###### Waiting for audio signal %s_%d\n",__FUNCTION__,__LINE__);
		wait_event_interruptible (audio_interrupt, (atomic_read (&audio_data_ready)));
		atomic_set (&audio_data_ready, 0);
		g_count = get_audio_size(g_temp_lro);
		count = g_count;
		printk( "######audio signal received and audio size:%d runtime->period_size:%d  %s_%d\n",g_count,runtime->period_size,__func__,__LINE__);		
		
		/* dma read is done here */
		/* audio_frame contains audio data */
		memcpy(drv->substream->runtime->dma_area + drv->buf_pos ,audio_frame,count);

		/* update the buf_pos */
		// here the (auto)increase of buf_pos is handled
		drv->buf_pos += count;
		drv->buf_pos %= drv->pcm_buffer_size;
	
		
		printk("\n\n\n hwptr=%d appl=%d pos=%d\n",
			(int)frames_to_bytes(runtime,runtime->status->hw_ptr),(int)frames_to_bytes(runtime, runtime->control->appl_ptr),drv->buf_pos);
		/* Below line needs to be uncommented for pointer to be updated in the alsa lib */
		snd_pcm_period_elapsed(drv->substream);
		
		try_to_freeze();

	}

	kfree(audio_frame);
	audio_frame = NULL;
	
	return 0 ;

}

Attachment: hwptr_app_ptr_buf_pos_analysis.xlsx
Description: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet

_______________________________________________
Alsa-devel mailing list
Alsa-devel@xxxxxxxxxxxxxxxx
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

[Index of Archives]     [ALSA User]     [Linux Audio Users]     [Kernel Archive]     [Asterisk PBX]     [Photo Sharing]     [Linux Sound]     [Video 4 Linux]     [Gimp]     [Yosemite News]

  Powered by Linux