* [PATCH]snd-usb-usx2y 0.8.7: Use macro usb_maxpacket() for portability
@ 2004-12-02 12:19 Karsten Wiese
2004-12-02 14:42 ` Takashi Iwai
0 siblings, 1 reply; 16+ messages in thread
From: Karsten Wiese @ 2004-12-02 12:19 UTC (permalink / raw)
To: Takashi Iwai; +Cc: alsa-devel
[-- Attachment #1: Type: text/plain, Size: 529 bytes --]
Hi
on the usb-devel list there is a similar patch by David Brownell:
http://marc.theaimsgroup.com/?i=<200411281314.50175.david-b%20()%20pacbell%20!%20net>
David's patch doesn't compile on current kernel, so I wrote this one.
regards,
Karsten
patch header:
>>>>
Summary: Use macro usb_maxpacket() for portability.
In future kernels struct usb_device won't have the epmaxpacketin/out members.
Use macro usb_maxpacket() instead of directly accessing those members.
Signed-off-by: Karsten Wiese <annabellesgarden@yahoo.de>
<<<<
[-- Attachment #2: snd-usb-usx2y.patch.0.8.7 --]
[-- Type: text/x-diff, Size: 2892 bytes --]
Index: alsa-kernel/usb/usx2y/usbusx2y.c
===================================================================
RCS file: /cvsroot/alsa/alsa-kernel/usb/usx2y/usbusx2y.c,v
retrieving revision 1.6
diff -U3 -r1.6 usbusx2y.c
--- alsa-kernel/usb/usx2y/usbusx2y.c 29 Nov 2004 14:09:49 -0000 1.6
+++ alsa-kernel/usb/usx2y/usbusx2y.c 2 Dec 2004 11:57:57 -0000
@@ -1,6 +1,10 @@
/*
* usbusy2y.c - ALSA USB US-428 Driver
*
+2004-12-02 Karsten Wiese
+ Version 0.8.7:
+ Use macro usb_maxpacket() for portability.
+
2004-10-26 Karsten Wiese
Version 0.8.6:
wake_up() process waiting in usX2Y_urbs_start() on error.
@@ -135,7 +139,7 @@
MODULE_AUTHOR("Karsten Wiese <annabellesgarden@yahoo.de>");
-MODULE_DESCRIPTION("TASCAM "NAME_ALLCAPS" Version 0.8.6");
+MODULE_DESCRIPTION("TASCAM "NAME_ALLCAPS" Version 0.8.7");
MODULE_LICENSE("GPL");
MODULE_SUPPORTED_DEVICE("{{TASCAM(0x1604), "NAME_ALLCAPS"(0x8001)(0x8005)(0x8007) }}");
Index: alsa-kernel/usb/usx2y/usbusx2yaudio.c
===================================================================
RCS file: /cvsroot/alsa/alsa-kernel/usb/usx2y/usbusx2yaudio.c,v
retrieving revision 1.6
diff -U3 -r1.6 usbusx2yaudio.c
--- alsa-kernel/usb/usx2y/usbusx2yaudio.c 27 Oct 2004 07:38:35 -0000 1.6
+++ alsa-kernel/usb/usx2y/usbusx2yaudio.c 2 Dec 2004 11:57:59 -0000
@@ -413,25 +413,23 @@
static int usX2Y_urbs_allocate(snd_usX2Y_substream_t *subs)
{
int i;
- unsigned int datapipe; /* the data i/o pipe */
+ unsigned int pipe;
int is_playback = subs == subs->usX2Y->subs[SNDRV_PCM_STREAM_PLAYBACK];
struct usb_device *dev = subs->usX2Y->chip.dev;
- if (is_playback) { /* allocate a temporary buffer for playback */
- datapipe = usb_sndisocpipe(dev, subs->endpoint);
- subs->maxpacksize = dev->epmaxpacketout[subs->endpoint];
+ pipe = is_playback ? usb_sndisocpipe(dev, subs->endpoint) :
+ usb_rcvisocpipe(dev, subs->endpoint);
+ subs->maxpacksize = usb_maxpacket(dev, pipe, is_playback);
+ if (!subs->maxpacksize)
+ return -EINVAL;
+
+ if (is_playback && NULL == subs->tmpbuf) { /* allocate a temporary buffer for playback */
+ subs->tmpbuf = kcalloc(nr_of_packs(), subs->maxpacksize, GFP_KERNEL);
if (NULL == subs->tmpbuf) {
- subs->tmpbuf = kcalloc(nr_of_packs(), subs->maxpacksize, GFP_KERNEL);
- if (NULL == subs->tmpbuf) {
- snd_printk(KERN_ERR "cannot malloc tmpbuf\n");
- return -ENOMEM;
- }
+ snd_printk(KERN_ERR "cannot malloc tmpbuf\n");
+ return -ENOMEM;
}
- } else {
- datapipe = usb_rcvisocpipe(dev, subs->endpoint);
- subs->maxpacksize = dev->epmaxpacketin[subs->endpoint];
}
-
/* allocate and initialize data urbs */
for (i = 0; i < NRURBS; i++) {
struct urb** purb = subs->urb + i;
@@ -453,7 +451,7 @@
}
}
(*purb)->dev = dev;
- (*purb)->pipe = datapipe;
+ (*purb)->pipe = pipe;
(*purb)->number_of_packets = nr_of_packs();
(*purb)->context = subs;
(*purb)->interval = 1;
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH]snd-usb-usx2y 0.8.7: Use macro usb_maxpacket() for portability
2004-12-02 12:19 [PATCH]snd-usb-usx2y 0.8.7: Use macro usb_maxpacket() for portability Karsten Wiese
@ 2004-12-02 14:42 ` Takashi Iwai
2004-12-06 22:15 ` Karsten Wiese
0 siblings, 1 reply; 16+ messages in thread
From: Takashi Iwai @ 2004-12-02 14:42 UTC (permalink / raw)
To: Karsten Wiese; +Cc: alsa-devel
At Thu, 2 Dec 2004 13:19:19 +0100,
Karsten Wiese wrote:
>
> Hi
>
> on the usb-devel list there is a similar patch by David Brownell:
> http://marc.theaimsgroup.com/?i=<200411281314.50175.david-b%20()%20pacbell%20!%20net>
> David's patch doesn't compile on current kernel, so I wrote this one.
Thanks, applied to CVS.
BTW, do you have the latest hwdep-pcm paptch to apply to CVS, too?
Takashi
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://productguide.itmanagersjournal.com/
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH]snd-usb-usx2y 0.8.7: Use macro usb_maxpacket() for portability
2004-12-02 14:42 ` Takashi Iwai
@ 2004-12-06 22:15 ` Karsten Wiese
2004-12-07 11:48 ` Takashi Iwai
0 siblings, 1 reply; 16+ messages in thread
From: Karsten Wiese @ 2004-12-06 22:15 UTC (permalink / raw)
To: Takashi Iwai; +Cc: alsa-devel
[-- Attachment #1: Type: text/plain, Size: 938 bytes --]
Am Donnerstag 02 Dezember 2004 15:42 schrieb Takashi Iwai:
>
> BTW, do you have the latest hwdep-pcm paptch to apply to CVS, too?
This is it.
Karsten
patch header:
>>>>
Summary: hwdep interface for pcm data.
Implements "rawusb" pcm data transfer through hwdep interface:
The usb_hcd reads/writes pcm data from/into dma-memory.
That memory is mmaped by jack's usx2y driver.
Jack's usx2y driver is the first/last to read/write pcm data.
Read/write is a combination of power of 2 period shaping and float/int conversation.
Compared to standard alsa/jack we leave out power of 2 period shaping
inside snd-usb-usx2y which needs memcpy() and additional buffers.
As a side effect possible unwanted pcm-data coruption resulting of
standard alsa's snd-usb-usx2y period shaping scheme falls away.
Result is sane jack operation at buffering schemes down to 128frames, 2 periods.
Signed-off-by: Karsten Wiese <annabellesgarden@yahoo.de>
<<<<
[-- Attachment #2: snd-usb-usx2y+hwdep_pcm.patch.0.8.7.bz2 --]
[-- Type: application/x-bzip2, Size: 7527 bytes --]
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH]snd-usb-usx2y 0.8.7: Use macro usb_maxpacket() for portability
2004-12-06 22:15 ` Karsten Wiese
@ 2004-12-07 11:48 ` Takashi Iwai
2004-12-07 22:01 ` Karsten Wiese
0 siblings, 1 reply; 16+ messages in thread
From: Takashi Iwai @ 2004-12-07 11:48 UTC (permalink / raw)
To: Karsten Wiese; +Cc: alsa-devel
[-- Attachment #1: Type: text/plain, Size: 1412 bytes --]
At Mon, 6 Dec 2004 23:15:01 +0100,
Karsten Wiese wrote:
>
> Am Donnerstag 02 Dezember 2004 15:42 schrieb Takashi Iwai:
> >
> > BTW, do you have the latest hwdep-pcm paptch to apply to CVS, too?
>
> This is it.
A part of patches seems missing. I got:
usx2yhwdeppcm.c: In function `usX2Y_usbpcm_urb_capt_retire':
usx2yhwdeppcm.c:77: error: structure has no member named `hwdep_pcm_shm'
...
The code looks almost fine. I found some strange coding style
occasinally (e.g. unnecessary block in a function or a goto-jump into
the if-branch). The fixed usx2yhwdeppcm.c is attached below. Also,
the patch file which would be needed for alsa-driver tree is below,
too.
In addition, two things I'd like to request you to change.
1. handling of pcm streams in usX2Y_reset() and
snd_usX2Y_hwdep_pcm_open()
It's quite hacky. It'd be simpler to create another PCM instances
for hwdep PCM.
For example, when hwdep is opened and mmapped, only hwdep-pcm is
allowed, i.e. access to the normal PCM would result in -EBUSY.
OTOH, when hwdep is closed, hwdep-pcm would return -EBUSY.
Also, hwdep should return -EBUSY if pcm is already running.
2. RAM mmap support
The RAM mmap would work only on certain architectures.
For example, it won't work properly on ARM.
You should add some ifdefs, or more restriction in Kconfig.
(This is true for the other hwdep mmap, too.)
Takashi
[-- Attachment #2: usx2yhwdeppcm.c --]
[-- Type: application/octet-stream, Size: 25435 bytes --]
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* USX2Y "rawusb" aka hwdep_pcm implementation
Its usb's unableness to atomically handle power of 2 period sized data chuncs
at standard samplerates,
what led to this part of the usx2y module:
It provides the alsa kernel half of the usx2y-alsa-jack driver pair.
The pair uses a hardware dependant alsa-device for mmaped pcm transport.
Advantage achieved:
The usb_hcd places reads/writes pcm data into dma-memory.
That memory is mmaped by jack's usx2y driver.
Jack's usx2y driver is the first/last to read/write pcm data.
Read/write is a combination of power of 2 period shaping and
float/int conversation.
Compared to mainline alsa/jack we leave out power of 2 period shaping inside
snd-usb-usx2y which needs memcpy() and additional buffers.
As a side effect possible unwanted pcm-data coruption resulting of
standard alsa's snd-usb-usx2y period shaping scheme falls away.
Result is sane jack operation at buffering schemes down to 128frames,
2 periods.
plain usx2y alsa mode is able to achieve 64frames, 4periods, but only at the
cost of easier triggered i.e. aeolus xruns (128 or 256frames,
2periods works but is useless cause of crackling).
This is a first "proof of concept" implementation.
Later, funcionalities should migrate to more apropriate places:
Userland:
- The jackd could mmap its float-pcm buffers directly from alsa-lib.
- alsa-lib could provide power of 2 period sized shaping combined with int/float
conversation.
Currently the usx2y jack driver provides above 2 services.
Kernel:
- rawusb dma pcm buffer transport should go to snd-usb-lib, so also snd-usb-audio
devices can use it.
Currently rawusb dma pcm buffer transport (this file) is only available to snd-usb-usx2y.
*/
#include "usbusx2yaudio.c"
#if defined(USX2Y_NRPACKS_VARIABLE) || (!defined(USX2Y_NRPACKS_VARIABLE) && USX2Y_NRPACKS == 1)
#include <sound/hwdep.h>
static int usX2Y_usbpcm_urb_capt_retire(snd_usX2Y_substream_t *subs)
{
struct urb *urb = subs->completed_urb;
snd_pcm_runtime_t *runtime = subs->pcm_substream->runtime;
int i, lens = 0, hwptr_done = subs->hwptr_done;
usX2Ydev_t *usX2Y = subs->usX2Y;
if (0 > usX2Y->hwdep_pcm_shm->capture_iso_start) { //FIXME
int head = usX2Y->hwdep_pcm_shm->captured_iso_head + 1;
if (head >= ARRAY_SIZE(usX2Y->hwdep_pcm_shm->captured_iso))
head = 0;
usX2Y->hwdep_pcm_shm->capture_iso_start = head;
snd_printdd("cap start %i\n", head);
}
for (i = 0; i < nr_of_packs(); i++) {
if (urb->iso_frame_desc[i].status) { /* active? hmm, skip this */
snd_printk("activ frame status %i. Most propably some hardware problem.\n", urb->iso_frame_desc[i].status);
return urb->iso_frame_desc[i].status;
}
lens += urb->iso_frame_desc[i].actual_length / usX2Y->stride;
}
if ((hwptr_done += lens) >= runtime->buffer_size)
hwptr_done -= runtime->buffer_size;
subs->hwptr_done = hwptr_done;
subs->transfer_done += lens;
/* update the pointer, call callback if necessary */
if (subs->transfer_done >= runtime->period_size) {
subs->transfer_done -= runtime->period_size;
snd_pcm_period_elapsed(subs->pcm_substream);
}
return 0;
}
static inline int usX2Y_iso_frames_per_buffer(snd_pcm_runtime_t *runtime, usX2Ydev_t * usX2Y)
{
return (runtime->buffer_size * 1000) / usX2Y->rate + 1; //FIXME: so far only correct period_size == 2^x ?
}
/*
* prepare urb for playback data pipe
*
* we copy the data directly from the pcm buffer.
* the current position to be copied is held in hwptr field.
* since a urb can handle only a single linear buffer, if the total
* transferred area overflows the buffer boundary, we cannot send
* it directly from the buffer. thus the data is once copied to
* a temporary buffer and urb points to that.
*/
static int usX2Y_hwdep_urb_play_prepare(snd_usX2Y_substream_t *subs,
struct urb *urb)
{
int count, counts, pack;
usX2Ydev_t *usX2Y = subs->usX2Y;
struct snd_usX2Y_hwdep_pcm_shm *shm = usX2Y->hwdep_pcm_shm;
snd_pcm_runtime_t *runtime = subs->pcm_substream->runtime;
if (0 > shm->playback_iso_start) {
shm->playback_iso_start = shm->captured_iso_head -
usX2Y_iso_frames_per_buffer(runtime, usX2Y);
if (0 > shm->playback_iso_start)
shm->playback_iso_start += ARRAY_SIZE(shm->captured_iso);
shm->playback_iso_head = shm->playback_iso_start;
}
count = 0;
for (pack = 0; pack < nr_of_packs(); pack++) {
/* calculate the size of a packet */
counts = shm->captured_iso[shm->playback_iso_head].length / usX2Y->stride;
if (counts < 43 || counts > 50) {
snd_printk("should not be here with counts=%i\n", counts);
return -EPIPE;
}
/* set up descriptor */
urb->iso_frame_desc[pack].offset = shm->captured_iso[shm->playback_iso_head].offset;
urb->iso_frame_desc[pack].length = shm->captured_iso[shm->playback_iso_head].length;
if (atomic_read(&subs->state) != state_RUNNING)
memset((char *)urb->transfer_buffer + urb->iso_frame_desc[pack].offset, 0,
urb->iso_frame_desc[pack].length);
if (++shm->playback_iso_head >= ARRAY_SIZE(shm->captured_iso))
shm->playback_iso_head = 0;
count += counts;
}
urb->transfer_buffer_length = count * usX2Y->stride;
return 0;
}
static inline void usX2Y_usbpcm_urb_capt_iso_advance(snd_usX2Y_substream_t *subs, struct urb *urb)
{
int pack;
for (pack = 0; pack < nr_of_packs(); ++pack) {
struct usb_iso_packet_descriptor *desc = urb->iso_frame_desc + pack;
if (NULL != subs) {
snd_usX2Y_hwdep_pcm_shm_t *shm = subs->usX2Y->hwdep_pcm_shm;
int head = shm->captured_iso_head + 1;
if (head >= ARRAY_SIZE(shm->captured_iso))
head = 0;
shm->captured_iso[head].frame = urb->start_frame + pack;
shm->captured_iso[head].offset = desc->offset;
shm->captured_iso[head].length = desc->actual_length;
shm->captured_iso_head = head;
shm->captured_iso_frames++;
}
if ((desc->offset += desc->length * NRURBS*nr_of_packs()) +
desc->length >= SSS)
desc->offset -= (SSS - desc->length);
}
}
static inline int usX2Y_usbpcm_usbframe_complete(snd_usX2Y_substream_t *capsubs,
snd_usX2Y_substream_t *capsubs2,
snd_usX2Y_substream_t *playbacksubs, int frame)
{
int err, state;
struct urb *urb = playbacksubs->completed_urb;
state = atomic_read(&playbacksubs->state);
if (NULL != urb) {
if (state == state_RUNNING)
usX2Y_urb_play_retire(playbacksubs, urb);
else
if (state >= state_PRERUNNING) {
atomic_inc(&playbacksubs->state);
}
} else {
switch (state) {
case state_STARTING1:
urb = playbacksubs->urb[0];
atomic_inc(&playbacksubs->state);
break;
case state_STARTING2:
urb = playbacksubs->urb[1];
atomic_inc(&playbacksubs->state);
break;
}
}
if (urb) {
if ((err = usX2Y_hwdep_urb_play_prepare(playbacksubs, urb)) ||
(err = usX2Y_urb_submit(playbacksubs, urb, frame))) {
return err;
}
}
playbacksubs->completed_urb = NULL;
state = atomic_read(&capsubs->state);
if (state >= state_PREPARED) {
if (state == state_RUNNING) {
if ((err = usX2Y_usbpcm_urb_capt_retire(capsubs)))
return err;
} else {
if (state >= state_PRERUNNING)
atomic_inc(&capsubs->state);
}
usX2Y_usbpcm_urb_capt_iso_advance(capsubs, capsubs->completed_urb);
if (NULL != capsubs2)
usX2Y_usbpcm_urb_capt_iso_advance(NULL, capsubs2->completed_urb);
if ((err = usX2Y_urb_submit(capsubs, capsubs->completed_urb, frame)))
return err;
if (NULL != capsubs2)
if ((err = usX2Y_urb_submit(capsubs2, capsubs2->completed_urb, frame)))
return err;
}
capsubs->completed_urb = NULL;
if (NULL != capsubs2)
capsubs2->completed_urb = NULL;
return 0;
}
static void i_usX2Y_usbpcm_urb_complete(struct urb *urb, struct pt_regs *regs)
{
snd_usX2Y_substream_t *subs = (snd_usX2Y_substream_t*)urb->context;
usX2Ydev_t *usX2Y = subs->usX2Y;
snd_usX2Y_substream_t *capsubs, *capsubs2, *playbacksubs;
if (unlikely(atomic_read(&subs->state) < state_PREPARED)) {
snd_printdd("hcd_frame=%i ep=%i%s status=%i start_frame=%i\n", usb_get_current_frame_number(usX2Y->chip.dev), subs->endpoint, usb_pipein(urb->pipe) ? "in" : "out", urb->status, urb->start_frame);
return;
}
if (unlikely(urb->status)) {
usX2Y_error_urb_status(usX2Y, subs, urb);
return;
}
if (likely((0xFFFF & urb->start_frame) == usX2Y->wait_iso_frame))
subs->completed_urb = urb;
else {
usX2Y_error_sequence(usX2Y, subs, urb);
return;
}
capsubs = usX2Y->subs[SNDRV_PCM_STREAM_CAPTURE];
capsubs2 = usX2Y->subs[SNDRV_PCM_STREAM_CAPTURE + 2];
playbacksubs = usX2Y->subs[SNDRV_PCM_STREAM_PLAYBACK];
if (capsubs->completed_urb && atomic_read(&capsubs->state) >= state_PREPARED &&
(NULL == capsubs2 || capsubs2->completed_urb) &&
(playbacksubs->completed_urb || atomic_read(&playbacksubs->state) < state_PREPARED)) {
if (!usX2Y_usbpcm_usbframe_complete(capsubs, capsubs2, playbacksubs, urb->start_frame)) {
if (nr_of_packs() <= urb->start_frame &&
urb->start_frame <= (2 * nr_of_packs() - 1)) // uhci and ohci
usX2Y->wait_iso_frame = urb->start_frame - nr_of_packs();
else
usX2Y->wait_iso_frame += nr_of_packs();
} else {
snd_printdd("\n");
usX2Y_clients_stop(usX2Y);
}
}
}
static void usX2Y_hwdep_urb_release(struct urb** urb)
{
usb_kill_urb(*urb);
usb_free_urb(*urb);
*urb = NULL;
}
/*
* release a substream
*/
static void usX2Y_usbpcm_urbs_release(snd_usX2Y_substream_t *subs)
{
int i;
snd_printdd("snd_usX2Y_urbs_release() %i\n", subs->endpoint);
for (i = 0; i < NRURBS; i++)
usX2Y_hwdep_urb_release(subs->urb + i);
}
static void usX2Y_usbpcm_subs_startup_finish(usX2Ydev_t * usX2Y)
{
usX2Y_urbs_set_complete(usX2Y, i_usX2Y_usbpcm_urb_complete);
usX2Y->prepare_subs = NULL;
}
static void i_usX2Y_usbpcm_subs_startup(struct urb *urb, struct pt_regs *regs)
{
snd_usX2Y_substream_t *subs = (snd_usX2Y_substream_t*)urb->context;
usX2Ydev_t *usX2Y = subs->usX2Y;
snd_usX2Y_substream_t *prepare_subs = usX2Y->prepare_subs;
if (NULL != prepare_subs &&
urb->start_frame == prepare_subs->urb[0]->start_frame) {
atomic_inc(&prepare_subs->state);
if (prepare_subs == usX2Y->subs[SNDRV_PCM_STREAM_CAPTURE]) {
snd_usX2Y_substream_t *cap_subs2 = usX2Y->subs[SNDRV_PCM_STREAM_CAPTURE + 2];
if (cap_subs2 != NULL)
atomic_inc(&cap_subs2->state);
}
usX2Y_usbpcm_subs_startup_finish(usX2Y);
wake_up(&usX2Y->prepare_wait_queue);
}
i_usX2Y_usbpcm_urb_complete(urb, regs);
}
/*
* initialize a substream's urbs
*/
static int usX2Y_usbpcm_urbs_allocate(snd_usX2Y_substream_t *subs)
{
int i;
unsigned int pipe;
int is_playback = subs == subs->usX2Y->subs[SNDRV_PCM_STREAM_PLAYBACK];
struct usb_device *dev = subs->usX2Y->chip.dev;
pipe = is_playback ? usb_sndisocpipe(dev, subs->endpoint) :
usb_rcvisocpipe(dev, subs->endpoint);
subs->maxpacksize = usb_maxpacket(dev, pipe, is_playback);
if (!subs->maxpacksize)
return -EINVAL;
/* allocate and initialize data urbs */
for (i = 0; i < NRURBS; i++) {
struct urb** purb = subs->urb + i;
if (*purb) {
usb_kill_urb(*purb);
continue;
}
*purb = usb_alloc_urb(nr_of_packs(), GFP_KERNEL);
if (NULL == *purb) {
usX2Y_usbpcm_urbs_release(subs);
return -ENOMEM;
}
(*purb)->transfer_buffer = is_playback ?
subs->usX2Y->hwdep_pcm_shm->playback : (
subs->endpoint == 0x8 ?
subs->usX2Y->hwdep_pcm_shm->capture0x8 :
subs->usX2Y->hwdep_pcm_shm->capture0xA);
(*purb)->dev = dev;
(*purb)->pipe = pipe;
(*purb)->number_of_packets = nr_of_packs();
(*purb)->context = subs;
(*purb)->interval = 1;
(*purb)->complete = i_usX2Y_usbpcm_subs_startup;
}
return 0;
}
/*
* free the buffer
*/
static int snd_usX2Y_usbpcm_hw_free(snd_pcm_substream_t *substream)
{
snd_pcm_runtime_t *runtime = substream->runtime;
snd_usX2Y_substream_t *subs = (snd_usX2Y_substream_t *)runtime->private_data,
*cap_subs2 = subs->usX2Y->subs[SNDRV_PCM_STREAM_CAPTURE + 2];
down(&subs->usX2Y->prepare_mutex);
snd_printd("snd_usX2Y_usbpcm_hw_free(%p)\n", substream);
if (SNDRV_PCM_STREAM_PLAYBACK == substream->stream) {
snd_usX2Y_substream_t *cap_subs = subs->usX2Y->subs[SNDRV_PCM_STREAM_CAPTURE];
atomic_set(&subs->state, state_STOPPED);
usX2Y_usbpcm_urbs_release(subs);
if (!cap_subs->pcm_substream ||
!cap_subs->pcm_substream->runtime ||
!cap_subs->pcm_substream->runtime->status ||
cap_subs->pcm_substream->runtime->status->state < SNDRV_PCM_STATE_PREPARED) {
atomic_set(&cap_subs->state, state_STOPPED);
if (NULL != cap_subs2)
atomic_set(&cap_subs2->state, state_STOPPED);
usX2Y_usbpcm_urbs_release(cap_subs);
if (NULL != cap_subs2)
usX2Y_usbpcm_urbs_release(cap_subs2);
}
} else {
snd_usX2Y_substream_t *playback_subs = subs->usX2Y->subs[SNDRV_PCM_STREAM_PLAYBACK];
if (atomic_read(&playback_subs->state) < state_PREPARED) {
atomic_set(&subs->state, state_STOPPED);
if (NULL != cap_subs2)
atomic_set(&cap_subs2->state, state_STOPPED);
usX2Y_usbpcm_urbs_release(subs);
if (NULL != cap_subs2)
usX2Y_usbpcm_urbs_release(cap_subs2);
}
}
up(&subs->usX2Y->prepare_mutex);
return snd_pcm_lib_free_pages(substream);
}
static void usX2Y_usbpcm_subs_startup(snd_usX2Y_substream_t *subs)
{
usX2Ydev_t * usX2Y = subs->usX2Y;
usX2Y->prepare_subs = subs;
subs->urb[0]->start_frame = -1;
smp_wmb(); // Make shure above modifications are seen by i_usX2Y_subs_startup()
usX2Y_urbs_set_complete(usX2Y, i_usX2Y_usbpcm_subs_startup);
}
static int usX2Y_usbpcm_urbs_start(snd_usX2Y_substream_t *subs)
{
int p, u, err,
stream = subs->pcm_substream->stream;
usX2Ydev_t *usX2Y = subs->usX2Y;
if (SNDRV_PCM_STREAM_CAPTURE == stream) {
usX2Y->hwdep_pcm_shm->captured_iso_head = -1;
usX2Y->hwdep_pcm_shm->captured_iso_frames = 0;
}
for (p = 0; 3 >= (stream + p); p += 2) {
snd_usX2Y_substream_t *subs = usX2Y->subs[stream + p];
if (subs != NULL) {
if ((err = usX2Y_usbpcm_urbs_allocate(subs)) < 0)
return err;
subs->completed_urb = NULL;
}
}
for (p = 0; p < 4; p++) {
snd_usX2Y_substream_t *subs = usX2Y->subs[p];
if (subs != NULL && atomic_read(&subs->state) >= state_PREPARED)
goto start;
}
usX2Y->wait_iso_frame = -1;
start:
usX2Y_usbpcm_subs_startup(subs);
for (u = 0; u < NRURBS; u++) {
for (p = 0; 3 >= (stream + p); p += 2) {
snd_usX2Y_substream_t *subs = usX2Y->subs[stream + p];
if (subs != NULL) {
struct urb *urb = subs->urb[u];
if (usb_pipein(urb->pipe)) {
unsigned long pack;
if (0 == u)
atomic_set(&subs->state, state_STARTING3);
urb->dev = usX2Y->chip.dev;
urb->transfer_flags = URB_ISO_ASAP;
for (pack = 0; pack < nr_of_packs(); pack++) {
urb->iso_frame_desc[pack].offset = subs->maxpacksize * (pack + u * nr_of_packs());
urb->iso_frame_desc[pack].length = subs->maxpacksize;
}
urb->transfer_buffer_length = subs->maxpacksize * nr_of_packs();
if ((err = usb_submit_urb(urb, GFP_KERNEL)) < 0) {
snd_printk (KERN_ERR "cannot usb_submit_urb() for urb %d, err = %d\n", u, err);
err = -EPIPE;
goto cleanup;
} else {
snd_printdd("%i\n", urb->start_frame);
if (0 > usX2Y->wait_iso_frame)
usX2Y->wait_iso_frame = urb->start_frame;
}
urb->transfer_flags = 0;
} else {
atomic_set(&subs->state, state_STARTING1);
break;
}
}
}
}
err = 0;
wait_event(usX2Y->prepare_wait_queue, NULL == usX2Y->prepare_subs);
if (atomic_read(&subs->state) != state_PREPARED)
err = -EPIPE;
cleanup:
if (err) {
usX2Y_subs_startup_finish(usX2Y); // Call it now
usX2Y_clients_stop(usX2Y); // something is completely wroong > stop evrything
}
return err;
}
/*
* prepare callback
*
* set format and initialize urbs
*/
static int snd_usX2Y_usbpcm_prepare(snd_pcm_substream_t *substream)
{
snd_pcm_runtime_t *runtime = substream->runtime;
snd_usX2Y_substream_t *subs = (snd_usX2Y_substream_t *)runtime->private_data;
usX2Ydev_t *usX2Y = subs->usX2Y;
snd_usX2Y_substream_t *capsubs = subs->usX2Y->subs[SNDRV_PCM_STREAM_CAPTURE];
int err = 0;
snd_printdd("snd_usX2Y_pcm_prepare(%p)\n", substream);
if (NULL == usX2Y->hwdep_pcm_shm) {
if (NULL == (usX2Y->hwdep_pcm_shm = snd_malloc_pages(sizeof(snd_usX2Y_hwdep_pcm_shm_t), GFP_KERNEL)))
return -ENOMEM;
memset(usX2Y->hwdep_pcm_shm, 0, sizeof(snd_usX2Y_hwdep_pcm_shm_t));
}
down(&usX2Y->prepare_mutex);
usX2Y_subs_prepare(subs);
// Start hardware streams
// SyncStream first....
if (atomic_read(&capsubs->state) < state_PREPARED) {
if (usX2Y->format != runtime->format)
if ((err = usX2Y_format_set(usX2Y, runtime->format)) < 0)
goto up_prepare_mutex;
if (usX2Y->rate != runtime->rate)
if ((err = usX2Y_rate_set(usX2Y, runtime->rate)) < 0)
goto up_prepare_mutex;
snd_printdd("starting capture pipe for %s\n", subs == capsubs ? "self" : "playpipe");
if (0 > (err = usX2Y_usbpcm_urbs_start(capsubs)))
goto up_prepare_mutex;
}
if (subs != capsubs) {
usX2Y->hwdep_pcm_shm->playback_iso_start = -1;
if (atomic_read(&subs->state) < state_PREPARED) {
while (usX2Y_iso_frames_per_buffer(runtime, usX2Y) > usX2Y->hwdep_pcm_shm->captured_iso_frames) {
signed long timeout;
snd_printd("Wait: iso_frames_per_buffer=%i,captured_iso_frames=%i\n", usX2Y_iso_frames_per_buffer(runtime, usX2Y), usX2Y->hwdep_pcm_shm->captured_iso_frames);
set_current_state(TASK_INTERRUPTIBLE);
timeout = schedule_timeout(HZ/100 + 1);
if (signal_pending(current)) {
err = -ERESTARTSYS;
goto up_prepare_mutex;
}
}
if (0 > (err = usX2Y_usbpcm_urbs_start(subs)))
goto up_prepare_mutex;
}
snd_printd("Ready: iso_frames_per_buffer=%i,captured_iso_frames=%i\n", usX2Y_iso_frames_per_buffer(runtime, usX2Y), usX2Y->hwdep_pcm_shm->captured_iso_frames);
} else
usX2Y->hwdep_pcm_shm->capture_iso_start = -1;
up_prepare_mutex:
up(&usX2Y->prepare_mutex);
return err;
}
static snd_pcm_hardware_t snd_usX2Y_4c =
{
.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_S24_3LE,
.rates = SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000,
.rate_min = 44100,
.rate_max = 48000,
.channels_min = 2,
.channels_max = 4,
.buffer_bytes_max = (2*128*1024),
.period_bytes_min = 64,
.period_bytes_max = (128*1024),
.periods_min = 2,
.periods_max = 1024,
.fifo_size = 0
};
static int snd_usX2Y_usbpcm_open(snd_pcm_substream_t *substream)
{
snd_usX2Y_substream_t *subs = ((snd_usX2Y_substream_t **)
snd_pcm_substream_chip(substream))[substream->stream];
snd_pcm_runtime_t *runtime = substream->runtime;
runtime->hw = SNDRV_PCM_STREAM_PLAYBACK == substream->stream ? snd_usX2Y_2c :
(subs->usX2Y->subs[3] ? snd_usX2Y_4c : snd_usX2Y_2c);
runtime->private_data = subs;
subs->pcm_substream = substream;
snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_PERIOD_TIME, 1000, 200000);
return 0;
}
extern snd_pcm_ops_t snd_usX2Y_pcm_ops;
static void usX2Y_reset(snd_card_t *card, snd_pcm_substream_t *substream)
{
struct list_head *list;
snd_device_t *dev;
snd_pcm_t *pcm;
snd_printd("\n");
list_for_each(list, &card->devices) {
snd_device_t *dev;
snd_pcm_t *pcm;
int s;
dev = snd_device(list);
if (dev->type != SNDRV_DEV_PCM)
continue;
pcm = dev->device_data;
for (s = 0; s <= 1; ++s) {
snd_pcm_substream_t *test_substream;
test_substream = pcm->streams[s].substream;
if (NULL != test_substream &&
test_substream != substream &&
test_substream->runtime)
return;
}
}
list_for_each(list, &card->devices) {
dev = snd_device(list);
if (dev->type != SNDRV_DEV_PCM)
continue;
pcm = dev->device_data;
snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_usX2Y_pcm_ops);
snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_usX2Y_pcm_ops);
}
}
static int snd_usX2Y_usbpcm_close(snd_pcm_substream_t *substream)
{
snd_pcm_runtime_t *runtime = substream->runtime;
snd_usX2Y_substream_t *subs = (snd_usX2Y_substream_t *)runtime->private_data;
int err = 0;
snd_printd("\n");
subs->pcm_substream = NULL;
usX2Y_reset(substream->pstr->pcm->card, substream);
return err;
}
static snd_pcm_ops_t snd_usX2Y_usbpcm_ops =
{
.open = snd_usX2Y_usbpcm_open,
.close = snd_usX2Y_usbpcm_close,
.ioctl = snd_pcm_lib_ioctl,
.hw_params = snd_usX2Y_pcm_hw_params,
.hw_free = snd_usX2Y_usbpcm_hw_free,
.prepare = snd_usX2Y_usbpcm_prepare,
.trigger = snd_usX2Y_pcm_trigger,
.pointer = snd_usX2Y_pcm_pointer,
};
static int snd_usX2Y_hwdep_pcm_open(snd_hwdep_t *hw, struct file *file)
{
// we need to be the first
snd_card_t *card = hw->card;
struct list_head *list;
snd_device_t *dev;
snd_pcm_t *pcm;
int err = 0;
list_for_each(list, &card->devices) {
dev = snd_device(list);
if (dev->type != SNDRV_DEV_PCM)
continue;
pcm = dev->device_data;
down(&pcm->open_mutex);
}
list_for_each(list, &card->devices) {
int s;
dev = snd_device(list);
if (dev->type != SNDRV_DEV_PCM)
continue;
pcm = dev->device_data;
for (s = 0; s < 2; ++s) {
snd_pcm_substream_t *substream;
substream = pcm->streams[s].substream;
if (substream && substream->open_flag)
err = -EBUSY;
}
}
if (0 == err) {
usX2Y(card)->chip_status |= USX2Y_STAT_CHIP_MMAP_PCM_URBS;
list_for_each(list, &card->devices) {
dev = snd_device(list);
if (dev->type != SNDRV_DEV_PCM)
continue;
pcm = dev->device_data;
snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_usX2Y_usbpcm_ops);
snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_usX2Y_usbpcm_ops);
}
}
list_for_each(list, &card->devices) {
dev = snd_device(list);
if (dev->type != SNDRV_DEV_PCM)
continue;
pcm = dev->device_data;
up(&pcm->open_mutex);
}
return err;
}
static int snd_usX2Y_hwdep_pcm_release(snd_hwdep_t *hw, struct file *file)
{
snd_printd("\n");
usX2Y(hw->card)->chip_status &= ~USX2Y_STAT_CHIP_MMAP_PCM_URBS;
usX2Y_reset(hw->card, NULL);
return 0;
}
static void snd_usX2Y_hwdep_pcm_vm_open(struct vm_area_struct *area)
{
}
static void snd_usX2Y_hwdep_pcm_vm_close(struct vm_area_struct *area)
{
}
static struct page * snd_usX2Y_hwdep_pcm_vm_nopage(struct vm_area_struct *area, unsigned long address, int *type)
{
unsigned long offset;
struct page *page;
void *vaddr;
offset = area->vm_pgoff << PAGE_SHIFT;
offset += address - area->vm_start;
snd_assert((offset % PAGE_SIZE) == 0, return NOPAGE_OOM);
vaddr = (char*)((usX2Ydev_t*)area->vm_private_data)->hwdep_pcm_shm + offset;
page = virt_to_page(vaddr);
if (type)
*type = VM_FAULT_MINOR;
return page;
}
static struct vm_operations_struct snd_usX2Y_hwdep_pcm_vm_ops = {
.open = snd_usX2Y_hwdep_pcm_vm_open,
.close = snd_usX2Y_hwdep_pcm_vm_close,
.nopage = snd_usX2Y_hwdep_pcm_vm_nopage,
};
static int snd_usX2Y_hwdep_pcm_mmap(snd_hwdep_t * hw, struct file *filp, struct vm_area_struct *area)
{
unsigned long size = (unsigned long)(area->vm_end - area->vm_start);
usX2Ydev_t *usX2Y = (usX2Ydev_t*)hw->private_data;
if (!(((usX2Ydev_t*)hw->private_data)->chip_status & USX2Y_STAT_CHIP_INIT))
return -EBUSY;
/* if userspace tries to mmap beyond end of our buffer, fail */
if (size > PAGE_ALIGN(sizeof(snd_usX2Y_hwdep_pcm_shm_t))) {
snd_printd("%lu > %lu\n", size, (unsigned long)sizeof(snd_usX2Y_hwdep_pcm_shm_t));
return -EINVAL;
}
if (!usX2Y->hwdep_pcm_shm) {
return -ENODEV;
}
area->vm_ops = &snd_usX2Y_hwdep_pcm_vm_ops;
area->vm_flags |= VM_RESERVED;
snd_printd("vm_flags=0x%lX\n", area->vm_flags);
area->vm_private_data = hw->private_data;
return 0;
}
static void snd_usX2Y_hwdep_pcm_private_free(snd_hwdep_t *hwdep)
{
usX2Ydev_t *usX2Y = (usX2Ydev_t *)hwdep->private_data;
if (NULL != usX2Y->hwdep_pcm_shm)
snd_free_pages(usX2Y->hwdep_pcm_shm, sizeof(snd_usX2Y_hwdep_pcm_shm_t));
}
int usX2Y_hwdep_pcm_new(snd_card_t* card)
{
int err;
snd_hwdep_t *hw;
struct usb_device *dev = usX2Y(card)->chip.dev;
if (1 != nr_of_packs())
return 0;
if ((err = snd_hwdep_new(card, SND_USX2Y_USBPCM_ID, 1, &hw)) < 0) {
snd_printd("\n");
return err;
}
hw->iface = SNDRV_HWDEP_IFACE_USX2Y_PCM;
hw->private_data = usX2Y(card);
hw->private_free = snd_usX2Y_hwdep_pcm_private_free;
hw->ops.open = snd_usX2Y_hwdep_pcm_open;
hw->ops.release = snd_usX2Y_hwdep_pcm_release;
hw->ops.mmap = snd_usX2Y_hwdep_pcm_mmap;
hw->exclusive = 1;
sprintf(hw->name, "/proc/bus/usb/%03d/%03d/hwdeppcm", dev->bus->busnum, dev->devnum);
return 0;
}
#else
int usX2Y_hwdep_pcm_new(snd_card_t* card)
{
return 0;
}
#endif
[-- Attachment #3: usx2yhwdeppcm.patch --]
[-- Type: application/octet-stream, Size: 1064 bytes --]
--- ../../alsa-kernel/usb/usx2y/usx2yhwdeppcm.c 2004-12-07 12:23:37.452839956 +0100
+++ usx2yhwdeppcm.c 2004-12-07 12:26:24.732747471 +0100
@@ -1,3 +1,14 @@
+#include <linux/config.h>
+#include <linux/version.h>
+
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,5)
+#define SND_NEED_USB_SET_INTERFACE
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
+#define SND_NEED_USB_WRAPPER
+#endif
+#define __NO_VERSION__
+#endif
+
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -226,7 +237,11 @@
}
+#ifndef OLD_USB
static void i_usX2Y_usbpcm_urb_complete(struct urb *urb, struct pt_regs *regs)
+#else
+static void i_usX2Y_usbpcm_urb_complete(struct urb *urb)
+#endif
{
snd_usX2Y_substream_t *subs = (snd_usX2Y_substream_t*)urb->context;
usX2Ydev_t *usX2Y = subs->usX2Y;
@@ -308,7 +323,11 @@
wake_up(&usX2Y->prepare_wait_queue);
}
+#ifndef OLD_USB
i_usX2Y_usbpcm_urb_complete(urb, regs);
+#else
+ i_usX2Y_usbpcm_urb_complete(urb);
+#endif
}
/*
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH]snd-usb-usx2y 0.8.7: Use macro usb_maxpacket() for portability
2004-12-07 11:48 ` Takashi Iwai
@ 2004-12-07 22:01 ` Karsten Wiese
2004-12-08 19:32 ` Takashi Iwai
0 siblings, 1 reply; 16+ messages in thread
From: Karsten Wiese @ 2004-12-07 22:01 UTC (permalink / raw)
To: Takashi Iwai; +Cc: alsa-devel
[-- Attachment #1: Type: text/plain, Size: 2548 bytes --]
Am Dienstag 07 Dezember 2004 12:48 schrieb Takashi Iwai:
> A part of patches seems missing. I got:
>
> usx2yhwdeppcm.c: In function `usX2Y_usbpcm_urb_capt_retire':
> usx2yhwdeppcm.c:77: error: structure has no member named `hwdep_pcm_shm'
> ...
oops, this patch should be complete now.
>
>
> The code looks almost fine. I found some strange coding style
> occasinally (e.g. unnecessary block in a function or a goto-jump into
> the if-branch). The fixed usx2yhwdeppcm.c is attached below. Also,
> the patch file which would be needed for alsa-driver tree is below,
> too.
This patch is based on your usx2yhwdeppcm.c.
>
>
> In addition, two things I'd like to request you to change.
>
> 1. handling of pcm streams in usX2Y_reset() and
> snd_usX2Y_hwdep_pcm_open()
>
> It's quite hacky. It'd be simpler to create another PCM instances
> for hwdep PCM.
>
> For example, when hwdep is opened and mmapped, only hwdep-pcm is
> allowed, i.e. access to the normal PCM would result in -EBUSY.
> OTOH, when hwdep is closed, hwdep-pcm would return -EBUSY.
> Also, hwdep should return -EBUSY if pcm is already running.
Ok, done.
To use it now, jackd is started like this:
$ jackd -R -dusx2y -dhw:1,2 -r44100 -p128 -n2
The important difference is the ",2".
>
> 2. RAM mmap support
>
> The RAM mmap would work only on certain architectures.
> For example, it won't work properly on ARM.
> You should add some ifdefs, or more restriction in Kconfig.
> (This is true for the other hwdep mmap, too.)
snd-usb-usx2y now depends on X86 || PPC || ALPHA.
slightly corrected patch header:
>>>>
Summary: hwdep interface for pcm data.
Implements "rawusb" pcm data transfer through hwdep interface:
The usb_hc moves pcm data from/into memory via DMA.
That memory is mmaped by jack's usx2y driver.
Jack's usx2y driver is the first/last executable code to read/write pcm data.
Read/write is a combination of power of 2 period shaping and float/int conversation.
Compared to standard alsa/jack we leave out power of 2 period shaping
inside snd-usb-usx2y which needs memcpy() and additional buffers.
As a side effect possible unwanted pcm-data coruption resulting of
standard alsa's snd-usb-usx2y period shaping scheme falls away.
Result is sane jack operation at buffering schemes down to 128frames, 2 periods.
Also changed Kconfig file, so snd-usb-usx2y is only available for X86, PPC or ALPHA platforms,
as on others DMA-memory isn't mmapable.
Signed-off-by: Karsten Wiese <annabellesgarden@yahoo.de>
<<<<
Karsten
[-- Attachment #2: snd-usb-usx2y+hwdep_pcm.patch.0.8.7a.bz2 --]
[-- Type: application/x-bzip2, Size: 8088 bytes --]
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH]snd-usb-usx2y 0.8.7: Use macro usb_maxpacket() for portability
2004-12-07 22:01 ` Karsten Wiese
@ 2004-12-08 19:32 ` Takashi Iwai
2004-12-09 8:18 ` Jaroslav Kysela
2004-12-09 12:06 ` Karsten Wiese
0 siblings, 2 replies; 16+ messages in thread
From: Takashi Iwai @ 2004-12-08 19:32 UTC (permalink / raw)
To: Karsten Wiese; +Cc: alsa-devel
At Tue, 7 Dec 2004 23:01:51 +0100,
Karsten Wiese wrote:
>
> >>>>
> Summary: hwdep interface for pcm data.
>
> Implements "rawusb" pcm data transfer through hwdep interface:
> The usb_hc moves pcm data from/into memory via DMA.
> That memory is mmaped by jack's usx2y driver.
> Jack's usx2y driver is the first/last executable code to read/write pcm data.
> Read/write is a combination of power of 2 period shaping and float/int conversation.
> Compared to standard alsa/jack we leave out power of 2 period shaping
> inside snd-usb-usx2y which needs memcpy() and additional buffers.
> As a side effect possible unwanted pcm-data coruption resulting of
> standard alsa's snd-usb-usx2y period shaping scheme falls away.
> Result is sane jack operation at buffering schemes down to 128frames, 2 periods.
> Also changed Kconfig file, so snd-usb-usx2y is only available for X86, PPC or ALPHA platforms,
> as on others DMA-memory isn't mmapable.
>
> Signed-off-by: Karsten Wiese <annabellesgarden@yahoo.de>
> <<<<
Thanks, applied to the CVS tree now.
Please check later whether it works for you...
Takashi
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://productguide.itmanagersjournal.com/
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH]snd-usb-usx2y 0.8.7: Use macro usb_maxpacket() for portability
2004-12-08 19:32 ` Takashi Iwai
@ 2004-12-09 8:18 ` Jaroslav Kysela
2004-12-09 10:14 ` Takashi Iwai
2004-12-09 12:06 ` Karsten Wiese
1 sibling, 1 reply; 16+ messages in thread
From: Jaroslav Kysela @ 2004-12-09 8:18 UTC (permalink / raw)
To: Takashi Iwai; +Cc: Karsten Wiese, alsa-devel
On Wed, 8 Dec 2004, Takashi Iwai wrote:
> At Tue, 7 Dec 2004 23:01:51 +0100,
> Karsten Wiese wrote:
> >
> > >>>>
> > Summary: hwdep interface for pcm data.
> >
> > Implements "rawusb" pcm data transfer through hwdep interface:
> > The usb_hc moves pcm data from/into memory via DMA.
> > That memory is mmaped by jack's usx2y driver.
> > Jack's usx2y driver is the first/last executable code to read/write pcm data.
> > Read/write is a combination of power of 2 period shaping and float/int conversation.
> > Compared to standard alsa/jack we leave out power of 2 period shaping
> > inside snd-usb-usx2y which needs memcpy() and additional buffers.
> > As a side effect possible unwanted pcm-data coruption resulting of
> > standard alsa's snd-usb-usx2y period shaping scheme falls away.
> > Result is sane jack operation at buffering schemes down to 128frames, 2 periods.
> > Also changed Kconfig file, so snd-usb-usx2y is only available for X86, PPC or ALPHA platforms,
> > as on others DMA-memory isn't mmapable.
> >
> > Signed-off-by: Karsten Wiese <annabellesgarden@yahoo.de>
> > <<<<
>
> Thanks, applied to the CVS tree now.
> Please check later whether it works for you...
My feeling is that it's against all we're trying to do with the PCM
interface. Cannot we extend/optimize the current PCM API? Using hwdep for
PCM data transfers seems very ugly. We can add a new special access method
for example for URBs etc. I think that we will have exactly similar
problem with Bluetooth and Firewire.
Jaroslav
-----
Jaroslav Kysela <perex@suse.cz>
Linux Kernel Sound Maintainer
ALSA Project, SUSE Labs
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://productguide.itmanagersjournal.com/
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH]snd-usb-usx2y 0.8.7: Use macro usb_maxpacket() for portability
2004-12-09 8:18 ` Jaroslav Kysela
@ 2004-12-09 10:14 ` Takashi Iwai
0 siblings, 0 replies; 16+ messages in thread
From: Takashi Iwai @ 2004-12-09 10:14 UTC (permalink / raw)
To: Jaroslav Kysela; +Cc: Karsten Wiese, alsa-devel
At Thu, 9 Dec 2004 09:18:04 +0100 (CET),
Jaroslav wrote:
>
> On Wed, 8 Dec 2004, Takashi Iwai wrote:
>
> > At Tue, 7 Dec 2004 23:01:51 +0100,
> > Karsten Wiese wrote:
> > >
> > > >>>>
> > > Summary: hwdep interface for pcm data.
> > >
> > > Implements "rawusb" pcm data transfer through hwdep interface:
> > > The usb_hc moves pcm data from/into memory via DMA.
> > > That memory is mmaped by jack's usx2y driver.
> > > Jack's usx2y driver is the first/last executable code to read/write pcm data.
> > > Read/write is a combination of power of 2 period shaping and float/int conversation.
> > > Compared to standard alsa/jack we leave out power of 2 period shaping
> > > inside snd-usb-usx2y which needs memcpy() and additional buffers.
> > > As a side effect possible unwanted pcm-data coruption resulting of
> > > standard alsa's snd-usb-usx2y period shaping scheme falls away.
> > > Result is sane jack operation at buffering schemes down to 128frames, 2 periods.
> > > Also changed Kconfig file, so snd-usb-usx2y is only available for X86, PPC or ALPHA platforms,
> > > as on others DMA-memory isn't mmapable.
> > >
> > > Signed-off-by: Karsten Wiese <annabellesgarden@yahoo.de>
> > > <<<<
> >
> > Thanks, applied to the CVS tree now.
> > Please check later whether it works for you...
>
> My feeling is that it's against all we're trying to do with the PCM
> interface. Cannot we extend/optimize the current PCM API?
Don't worry, in the new patch, the hwdep does actually only mmap. The
others are done with the usual PCM API.
The implementation is still a bit tricky, IMO, though.
We can generalize this if there would be more wide needs for such
stuff.
Takashi
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://productguide.itmanagersjournal.com/
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH]snd-usb-usx2y 0.8.7: Use macro usb_maxpacket() for portability
2004-12-08 19:32 ` Takashi Iwai
2004-12-09 8:18 ` Jaroslav Kysela
@ 2004-12-09 12:06 ` Karsten Wiese
2004-12-10 15:57 ` Rui Nuno Capela
1 sibling, 1 reply; 16+ messages in thread
From: Karsten Wiese @ 2004-12-09 12:06 UTC (permalink / raw)
To: Rui Nuno Capela; +Cc: alsa-devel, Takashi Iwai
Am Mittwoch 08 Dezember 2004 20:32 schrieb Takashi Iwai:
> At Tue, 7 Dec 2004 23:01:51 +0100,
> Karsten Wiese wrote:
> >
> > >>>>
> > Summary: hwdep interface for pcm data.
> >
> > Implements "rawusb" pcm data transfer through hwdep interface:
> > The usb_hc moves pcm data from/into memory via DMA.
> > That memory is mmaped by jack's usx2y driver.
> > Jack's usx2y driver is the first/last executable code to read/write pcm data.
> > Read/write is a combination of power of 2 period shaping and float/int conversation.
> > Compared to standard alsa/jack we leave out power of 2 period shaping
> > inside snd-usb-usx2y which needs memcpy() and additional buffers.
> > As a side effect possible unwanted pcm-data coruption resulting of
> > standard alsa's snd-usb-usx2y period shaping scheme falls away.
> > Result is sane jack operation at buffering schemes down to 128frames, 2 periods.
> > Also changed Kconfig file, so snd-usb-usx2y is only available for X86, PPC or ALPHA platforms,
> > as on others DMA-memory isn't mmapable.
> >
> > Signed-off-by: Karsten Wiese <annabellesgarden@yahoo.de>
> > <<<<
>
> Thanks, applied to the CVS tree now.
> Please check later whether it works for you...
May I ask you to check CVS's version?
Keep in mind that jackd is now called like:
$ jackd -dusx2y -dhw:1,2
You might also change qjackctl to always append ",2" to the hw device in the usx2y case.
thanks,
Karsten
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://productguide.itmanagersjournal.com/
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH]snd-usb-usx2y 0.8.7: Use macro usb_maxpacket() for portability
2004-12-09 12:06 ` Karsten Wiese
@ 2004-12-10 15:57 ` Rui Nuno Capela
2004-12-10 16:13 ` Takashi Iwai
0 siblings, 1 reply; 16+ messages in thread
From: Rui Nuno Capela @ 2004-12-10 15:57 UTC (permalink / raw)
To: Karsten Wiese; +Cc: alsa-devel, Takashi Iwai
>
> May I ask you to check CVS's version?
> Keep in mind that jackd is now called like:
> $ jackd -dusx2y -dhw:1,2
> You might also change qjackctl to always append ",2" to the hw device in
the usx2y case.
>
Oh oh. Tried with alsa-kernel+driver CVS as of yesterday...
First thing:
- Missing SNDRV_HWDEP_IFACE_USX2Y_PCM definition (used to be defined under
asound.h on the pre-CVS 0.8.6 prototypes)
--
rncbc aka Rui Nuno Capela
rncbc@rncbc.org
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://productguide.itmanagersjournal.com/
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH]snd-usb-usx2y 0.8.7: Use macro usb_maxpacket() for portability
2004-12-10 15:57 ` Rui Nuno Capela
@ 2004-12-10 16:13 ` Takashi Iwai
2004-12-10 17:42 ` Rui Nuno Capela
0 siblings, 1 reply; 16+ messages in thread
From: Takashi Iwai @ 2004-12-10 16:13 UTC (permalink / raw)
To: Rui Nuno Capela; +Cc: Karsten Wiese, alsa-devel
At Fri, 10 Dec 2004 15:57:22 -0000 (WET),
Rui Nuno Capela wrote:
>
> >
> > May I ask you to check CVS's version?
> > Keep in mind that jackd is now called like:
> > $ jackd -dusx2y -dhw:1,2
> > You might also change qjackctl to always append ",2" to the hw device in
> the usx2y case.
> >
>
> Oh oh. Tried with alsa-kernel+driver CVS as of yesterday...
>
> First thing:
>
> - Missing SNDRV_HWDEP_IFACE_USX2Y_PCM definition (used to be defined under
> asound.h on the pre-CVS 0.8.6 prototypes)
Already fixed.
Takashi
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://productguide.itmanagersjournal.com/
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH]snd-usb-usx2y 0.8.7: Use macro usb_maxpacket() for portability
2004-12-10 16:13 ` Takashi Iwai
@ 2004-12-10 17:42 ` Rui Nuno Capela
2004-12-10 17:53 ` Takashi Iwai
0 siblings, 1 reply; 16+ messages in thread
From: Rui Nuno Capela @ 2004-12-10 17:42 UTC (permalink / raw)
To: Takashi Iwai; +Cc: Karsten Wiese, alsa-devel
Takashi Iwai wrote:
> Rui Nuno Capela wrote:
>>
>> >
>> > May I ask you to check CVS's version?
>> > Keep in mind that jackd is now called like:
>> > $ jackd -dusx2y -dhw:1,2
>> > You might also change qjackctl to always append ",2" to the hw device
>> > in the usx2y case.
>> >
>>
>> Oh oh. Tried with alsa-kernel+driver CVS as of yesterday...
>>
>> First thing:
>>
>> - Missing SNDRV_HWDEP_IFACE_USX2Y_PCM definition (used to be defined
>> under asound.h on the pre-CVS 0.8.6 prototypes)
>
> Already fixed.
>
Thanks. I've fixed myself and went on... and it doesn't seem to be working
at all: I get complaints about non existing /dev/snd/pcmC1D2c and
/dev/snd/pcmC1D2p devices. That is, it fails whether I enter:
aplay -D hw:1,2 somefile.wav
or:
jackd -R -dusx2y -dhw:1,2 -r44100 -p128 -n2
OTOH if I issue the good old jackd command line:
jackd -R -dusx2y -dhw:1 -r44100 -p128 -n2
the complaint is:
jackd: hwdep.c:263: snd_hwdep_poll_descriptors: Assertion 'hwdep' failed.
However, it works barely on this regular one:
jackd -R -dalsa -dhw:1 -r44100 -p1024 -n2
All this to the bottom-line: this 0.8.7 seems broken, I'll revert to my
own functional 0.8.6, for the time being ;)
Just for the record here goes some status info:
# cat /proc/asound/version
Advanced Linux Sound Architecture Driver Version 1.0.7.
Compiled on Dec 10 2004 for kernel 2.6.10-rc2-mm3-RT-V0.7.32-17.0.
# cat /proc/asound/cards
0 [A5451 ]: ALI5451 - ALI 5451
ALI 5451 at 0x1000, irq 5
1 [USX2Y ]: USB US-X2Y - TASCAM US-X2Y
TASCAM US-X2Y (1604:8005 if 0 at 001/003)
# cat /proc/asound/devices
0: [0- 0]: ctl
16: [0- 0]: digital audio playback
24: [0- 0]: digital audio capture
1: : sequencer
33: : timer
32: [1- 0]: ctl
36: [1- 0]: hardware dependent
48: [1- 0]: digital audio playback
56: [1- 0]: digital audio capture
40: [1- 0]: raw midi
# cat /proc/asound/hwdep
01-00: /proc/bus/usb/001/003
# cat /proc/asound/pcm
00-00: ALI 5451 : ALI 5451 : playback 32 : capture 1
01-00: US-X2Y Audio : US-X2Y Audio #0 : playback 1 : capture 1
Bye now. bbl
--
rncbc aka Rui Nuno Capela
rncbc@rncbc.org
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://productguide.itmanagersjournal.com/
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH]snd-usb-usx2y 0.8.7: Use macro usb_maxpacket() for portability
2004-12-10 17:42 ` Rui Nuno Capela
@ 2004-12-10 17:53 ` Takashi Iwai
2004-12-10 18:18 ` Rui Nuno Capela
0 siblings, 1 reply; 16+ messages in thread
From: Takashi Iwai @ 2004-12-10 17:53 UTC (permalink / raw)
To: Rui Nuno Capela; +Cc: Karsten Wiese, alsa-devel
At Fri, 10 Dec 2004 17:42:22 -0000 (WET),
Rui Nuno Capela wrote:
>
> Takashi Iwai wrote:
> > Rui Nuno Capela wrote:
> >>
> >> >
> >> > May I ask you to check CVS's version?
> >> > Keep in mind that jackd is now called like:
> >> > $ jackd -dusx2y -dhw:1,2
> >> > You might also change qjackctl to always append ",2" to the hw device
> >> > in the usx2y case.
> >> >
> >>
> >> Oh oh. Tried with alsa-kernel+driver CVS as of yesterday...
> >>
> >> First thing:
> >>
> >> - Missing SNDRV_HWDEP_IFACE_USX2Y_PCM definition (used to be defined
> >> under asound.h on the pre-CVS 0.8.6 prototypes)
> >
> > Already fixed.
> >
>
> Thanks. I've fixed myself and went on... and it doesn't seem to be working
> at all: I get complaints about non existing /dev/snd/pcmC1D2c and
> /dev/snd/pcmC1D2p devices. That is, it fails whether I enter:
Did you pass nrpacks=1 module option?
Otherwise the pcm won't be created.
Takashi
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://productguide.itmanagersjournal.com/
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH]snd-usb-usx2y 0.8.7: Use macro usb_maxpacket() for portability
2004-12-10 17:53 ` Takashi Iwai
@ 2004-12-10 18:18 ` Rui Nuno Capela
2004-12-10 18:24 ` Takashi Iwai
0 siblings, 1 reply; 16+ messages in thread
From: Rui Nuno Capela @ 2004-12-10 18:18 UTC (permalink / raw)
To: Takashi Iwai; +Cc: Karsten Wiese, alsa-devel
Takashi Iwai wrote:
> Rui Nuno Capela wrote:
>> >>
>> >> >
>> >> > May I ask you to check CVS's version?
>> >> > Keep in mind that jackd is now called like:
>> >> > $ jackd -dusx2y -dhw:1,2
>> >> > You might also change qjackctl to always append ",2" to the hw
>> >> > device in the usx2y case.
>> >> >
>> >>
>> >> Oh oh. Tried with alsa-kernel+driver CVS as of yesterday...
>> >>
>> >> First thing:
>> >>
>> >> - Missing SNDRV_HWDEP_IFACE_USX2Y_PCM definition (used to be defined
>> >> under asound.h on the pre-CVS 0.8.6 prototypes)
>> >
>> > Already fixed.
>> >
>>
>> Thanks. I've fixed myself and went on... and it doesn't seem to be
>> working
>> at all: I get complaints about non existing /dev/snd/pcmC1D2c and
>> /dev/snd/pcmC1D2p devices. That is, it fails whether I enter:
>
> Did you pass nrpacks=1 module option?
> Otherwise the pcm won't be created.
>
Duh? Yet another magic spell?
OK. Wired the nrpacks=1 on the options snd-usb-usx2y line in
/etc/modprobe.conf and things are working now.
Thanks for the help, Takashi-san.
All these magic numbers builds for the urge of some documentation or is it
about to change in the near future? In another words, is that really
necessary?
Take care.
--
rncbc aka Rui Nuno Capela
rncbc@rncbc.org
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://productguide.itmanagersjournal.com/
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH]snd-usb-usx2y 0.8.7: Use macro usb_maxpacket() for portability
2004-12-10 18:18 ` Rui Nuno Capela
@ 2004-12-10 18:24 ` Takashi Iwai
2004-12-10 21:08 ` Rui Nuno Capela
0 siblings, 1 reply; 16+ messages in thread
From: Takashi Iwai @ 2004-12-10 18:24 UTC (permalink / raw)
To: Rui Nuno Capela; +Cc: Karsten Wiese, alsa-devel
At Fri, 10 Dec 2004 18:18:56 -0000 (WET),
Rui Nuno Capela wrote:
>
> Takashi Iwai wrote:
> > Rui Nuno Capela wrote:
> >> >>
> >> >> >
> >> >> > May I ask you to check CVS's version?
> >> >> > Keep in mind that jackd is now called like:
> >> >> > $ jackd -dusx2y -dhw:1,2
> >> >> > You might also change qjackctl to always append ",2" to the hw
> >> >> > device in the usx2y case.
> >> >> >
> >> >>
> >> >> Oh oh. Tried with alsa-kernel+driver CVS as of yesterday...
> >> >>
> >> >> First thing:
> >> >>
> >> >> - Missing SNDRV_HWDEP_IFACE_USX2Y_PCM definition (used to be defined
> >> >> under asound.h on the pre-CVS 0.8.6 prototypes)
> >> >
> >> > Already fixed.
> >> >
> >>
> >> Thanks. I've fixed myself and went on... and it doesn't seem to be
> >> working
> >> at all: I get complaints about non existing /dev/snd/pcmC1D2c and
> >> /dev/snd/pcmC1D2p devices. That is, it fails whether I enter:
> >
> > Did you pass nrpacks=1 module option?
> > Otherwise the pcm won't be created.
> >
>
> Duh? Yet another magic spell?
>
> OK. Wired the nrpacks=1 on the options snd-usb-usx2y line in
> /etc/modprobe.conf and things are working now.
>
> Thanks for the help, Takashi-san.
>
> All these magic numbers builds for the urge of some documentation or is it
> about to change in the near future? In another words, is that really
> necessary?
The current code requires that condition. Though, it'd be possible to
solve this restriction including the more better merge with the normal
audio mode.
Better to ask Karsten ;)
Takashi
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://productguide.itmanagersjournal.com/
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH]snd-usb-usx2y 0.8.7: Use macro usb_maxpacket() for portability
2004-12-10 18:24 ` Takashi Iwai
@ 2004-12-10 21:08 ` Rui Nuno Capela
0 siblings, 0 replies; 16+ messages in thread
From: Rui Nuno Capela @ 2004-12-10 21:08 UTC (permalink / raw)
To: Takashi Iwai; +Cc: Karsten Wiese, alsa-devel
Takashi Iwai wrote
>Rui Nuno Capela wrote:
>> >
>> > Did you pass nrpacks=1 module option?
>> > Otherwise the pcm won't be created.
>> >
>>
>> Duh? Yet another magic spell?
>>
>> OK. Wired the nrpacks=1 on the options snd-usb-usx2y line in
>> /etc/modprobe.conf and things are working now.
>>
>> Thanks for the help, Takashi-san.
>>
>> All these magic numbers builds for the urge of some documentation or is
>> it about to change in the near future? In another words, is that really
>> necessary?
>
> The current code requires that condition. Though, it'd be possible to
> solve this restriction including the more better merge with the normal
> audio mode.
>
> Better to ask Karsten ;)
>
Although this new hwdep pcm interface may seem tricky, when engaged with
the corresponding jackd backend on a Ingo's RT patched kernel it works as
never before.
This is my personal low-latency record using a USB audio device and jackd:
jackd -R -dusx2y -dhw:1,2 -r44100 -p64 -n2
with a couple (yes, only 2) xruns in 60 minutes, mainly due to extra app
desktop loading (KDE), running 2.6.10-rc2-mm3-RT-V0.7.32-18 on my
P4@2.5Ghz laptop.
Things' are getting brighter all the time.
Thanks Karsten, Takashi. Now let's get this less esotheric, would we?
Things to care about next, IMO:
- merge of this new hwdep interface into the mainstream ALSA usb audio
module code, or whatever.
- lobbying for official integration in the JACK alsa backend; it would be
just great if it could be merged in the current alsa backend driver,
instead on a cloned one.
You can take a look by my personal homeserver:
http://www.rncbc.org/usx2y/
where you can find custom jack tarballs and RPMs (for SUSE 9.2 and Mdk
10.1, x86 only)
Bye now.
--
rncbc aka Rui Nuno Capela
rncbc@rncbc.org
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://productguide.itmanagersjournal.com/
^ permalink raw reply [flat|nested] 16+ messages in thread
end of thread, other threads:[~2004-12-10 21:08 UTC | newest]
Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-12-02 12:19 [PATCH]snd-usb-usx2y 0.8.7: Use macro usb_maxpacket() for portability Karsten Wiese
2004-12-02 14:42 ` Takashi Iwai
2004-12-06 22:15 ` Karsten Wiese
2004-12-07 11:48 ` Takashi Iwai
2004-12-07 22:01 ` Karsten Wiese
2004-12-08 19:32 ` Takashi Iwai
2004-12-09 8:18 ` Jaroslav Kysela
2004-12-09 10:14 ` Takashi Iwai
2004-12-09 12:06 ` Karsten Wiese
2004-12-10 15:57 ` Rui Nuno Capela
2004-12-10 16:13 ` Takashi Iwai
2004-12-10 17:42 ` Rui Nuno Capela
2004-12-10 17:53 ` Takashi Iwai
2004-12-10 18:18 ` Rui Nuno Capela
2004-12-10 18:24 ` Takashi Iwai
2004-12-10 21:08 ` Rui Nuno Capela
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.