Skip to contentSkip to conversation

Line6 Toneport UX1 driver

DISCUSSION Stefano D'Angelo 2 participants 3 messages Jun 9, 2006 – Jun 10, 2006 1 message not in the archive

lore
Share & tools
lore
#0 lore raw

I just can't get it working... here's the code I've written:

static void snd_line6_tp_ux1_complete_playback_transfer (struct urb* urb,
struct pt_regs*
regs)
{
snd_pcm_substream_t *substream = (snd_pcm_substream_t *)(urb->context); struct snd_line6_tp_ux1 *chip = snd_pcm_substream_chip (substream); snd_pcm_runtime_t *runtime = substream->runtime;

urb->dev = chip->dev;
urb->transfer_dma = runtime->dma_addr;
urb->transfer_buffer = usb_buffer_alloc (urb->dev,
LINE6_TP_UX1_48000_16_PACKET_SIZE_OUT * 2, GFP_KERNEL, &urb->transfer_dma);
memcpy (urb->transfer_buffer, runtime->dma_area + chip->playback_pos *
2, LINE6_TP_UX1_48000_16_PACKET_SIZE_OUT * 2);
urb->transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP;

   usb_submit_urb (urb, GFP_ATOMIC);

chip->playback_pos += LINE6_TP_UX1_48000_16_PACKET_SIZE_OUT * 2 / 4; snd_pcm_period_elapsed (substream);
}

don't care about freeing, etc. The problem is that it gives me a kind of beep sound for anything I play. No underruns, etc., just that sound! URBs' data seems to be correct and also the transfer seems to happen with no particular problem. (no error checking right now however). Another thing is this: I've seen that you decrement the hardware pointer when it reaches the end of a period, but when I try to do this, it gives me back garbage values, how is this possible?
What do you think I should do?

_______________________________________________
Alsa-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/alsa-devel

#1 lore raw
Quoted 1 line · Stefano D'Angelo
   urb->transfer_dma = runtime->dma_addr;

This will always play the data at the beginning of the buffer.

Quoted 2 lines
   urb->transfer_buffer = usb_buffer_alloc (urb->dev,

LINE6_TP_UX1_48000_16_PACKET_SIZE_OUT * 2, GFP_KERNEL, &urb->transfer_dma);

This buffer should be allocated when the URB is allocated.

Quoted 2 lines
   memcpy (urb->transfer_buffer, runtime->dma_area + chip->playback_pos *

2, LINE6_TP_UX1_48000_16_PACKET_SIZE_OUT * 2);

I hope the buffer size is a multiple of PACKET_SIZE_OUT * 2.

Quoted 1 line
   urb->transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP;

Why the NO_TRANSFER_DMA_MAP? You shouldn't need to do such optimizations in the first version of the driver.

Quoted 1 line
   snd_pcm_period_elapsed (substream);

What is the period size?

Regards,
Clemens

A message that is not in the archive (sent off-list or not yet received): [email protected]

#3 lore raw

2006/6/9, Clemens Ladisch <[email protected]>:

Quoted 5 lines
Quoted 1 line · Stefano D'Angelo
   urb->transfer_dma = runtime->dma_addr;

This will always play the data at the beginning of the buffer.

fixed

Quoted 5 lines
   urb->transfer_buffer = usb_buffer_alloc (urb->dev,
Quoted 1 line

LINE6_TP_UX1_48000_16_PACKET_SIZE_OUT * 2, GFP_KERNEL,

&urb->transfer_dma);

This buffer should be allocated when the URB is allocated.

fixed

Quoted 4 lines
   memcpy (urb->transfer_buffer, runtime->dma_area + chip->playback_pos *
Quoted 1 line

2, LINE6_TP_UX1_48000_16_PACKET_SIZE_OUT * 2);

I hope the buffer size is a multiple of PACKET_SIZE_OUT * 2.

it is

Quoted 4 lines
   urb->transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP;

Why the NO_TRANSFER_DMA_MAP? You shouldn't need to do such optimizations in the first version of the driver.

ok

Quoted 3 lines
   snd_pcm_period_elapsed (substream);

What is the period size?

period size is 96 = LINE6_TP_UX1_48000_16_PACKET_SIZE_OUT * 2 (double buffering) / 2 (16 bit data), so everytime an urb is sent a period is elapsed.

Here is how I'm doing right now but I still got the same beep for everything I play (when I used the copy () callback it kind of worked, is perphaps possible that the soundcard doesn't support dma transfers?):

static void snd_line6_tp_ux1_complete_playback_transfer (struct urb* urb,
struct pt_regs*
regs)
{
snd_pcm_substream_t *substream = (snd_pcm_substream_t *)(urb->context); struct snd_line6_tp_ux1 *chip = snd_pcm_substream_chip (substream); snd_pcm_runtime_t *runtime = substream->runtime;

   chip->playback_pos += LINE6_TP_UX1_48000_16_PACKET_SIZE_OUT * 2 / 2;
   if (chip->playback_pos == runtime->buffer_size) {
       chip->playback_pos -= runtime->buffer_size;

   }

memcpy (urb->transfer_buffer, runtime->dma_area + chip->playback_pos *
2, LINE6_TP_UX1_48000_16_PACKET_SIZE_OUT * 2);

   snd_pcm_period_elapsed (substream);

usb_submit_urb (urb, GFP_ATOMIC);
}

static int snd_line6_tp_ux1_pcm_trigger (snd_pcm_substream_t *substream,
int cmd)

{
struct snd_line6_tp_ux1 *chip = snd_pcm_substream_chip (substream); snd_pcm_runtime_t *runtime = substream->runtime;
static struct urb* urb;

   switch (cmd) {
   case SNDRV_PCM_TRIGGER_START:
       urb = usb_alloc_urb (2, GFP_ATOMIC);
       urb->dev = chip->dev;
       urb->pipe = usb_sndisocpipe (urb->dev, 1);
       urb->complete = snd_line6_tp_ux1_complete_playback_transfer;
       urb->context = substream;
       urb->transfer_dma = runtime->dma_addr;
       urb->transfer_buffer = usb_buffer_alloc (urb->dev,
                LINE6_TP_UX1_48000_16_PACKET_SIZE_OUT * 2, GFP_ATOMIC,
                &urb->transfer_dma);
       memcpy (urb->transfer_buffer, runtime->dma_area,
                           LINE6_TP_UX1_48000_16_PACKET_SIZE_OUT * 2);

       urb->transfer_flags = URB_ISO_ASAP; // | URB_NO_TRANSFER_DMA_MAP;
       urb->interval = 1;
       urb->number_of_packets = 2;
       urb->iso_frame_desc[0].offset = 0;
       urb->iso_frame_desc[0].length = urb->iso_frame_desc[1].offset =
       urb->iso_frame_desc[1].length =
                                LINE6_TP_UX1_48000_16_PACKET_SIZE_OUT;
       chip->playback_pos = 0;
       usb_submit_urb (urb, GFP_KERNEL);
           break;
   case SNDRV_PCM_TRIGGER_STOP:
       usb_buffer_free (chip->dev,

                        LINE6_TP_UX1_48000_16_PACKET_SIZE_OUT * 2,
                        urb->transfer_buffer, urb->transfer_dma);
       usb_free_urb (urb);
           break;
   default:
           return -EINVAL;
       break;

}

return 0;
}

Thanks,
Stefano

_______________________________________________
Alsa-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/alsa-devel