2009-02-28 11:43:04 +08:00
|
|
|
/*
|
2015-01-20 16:20:50 +08:00
|
|
|
* Line 6 Linux USB driver
|
2009-02-28 11:43:04 +08:00
|
|
|
*
|
2010-08-12 07:35:30 +08:00
|
|
|
* Copyright (C) 2004-2010 Markus Grabner (grabner@icg.tugraz.at)
|
2009-02-28 11:43:04 +08:00
|
|
|
*
|
|
|
|
* 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, version 2.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
PCM interface to POD series devices.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef PCM_H
|
|
|
|
#define PCM_H
|
|
|
|
|
|
|
|
#include <sound/pcm.h>
|
|
|
|
|
|
|
|
#include "driver.h"
|
|
|
|
#include "usbdefs.h"
|
|
|
|
|
2009-02-28 13:09:55 +08:00
|
|
|
/* number of URBs */
|
2010-08-12 07:35:30 +08:00
|
|
|
#define LINE6_ISO_BUFFERS 2
|
2009-02-28 13:09:55 +08:00
|
|
|
|
2010-08-12 07:35:30 +08:00
|
|
|
/*
|
|
|
|
number of USB frames per URB
|
2015-01-20 16:20:49 +08:00
|
|
|
The Line 6 Windows driver always transmits two frames per packet, but
|
2010-08-12 07:35:30 +08:00
|
|
|
the Linux driver performs significantly better (i.e., lower latency)
|
|
|
|
with only one frame per packet.
|
|
|
|
*/
|
|
|
|
#define LINE6_ISO_PACKETS 1
|
2009-02-28 13:09:55 +08:00
|
|
|
|
|
|
|
/* in a "full speed" device (such as the PODxt Pro) this means 1ms */
|
|
|
|
#define LINE6_ISO_INTERVAL 1
|
|
|
|
|
2010-08-12 07:35:30 +08:00
|
|
|
#define LINE6_IMPULSE_DEFAULT_PERIOD 100
|
|
|
|
|
2009-02-28 11:43:04 +08:00
|
|
|
/*
|
2015-01-20 16:20:49 +08:00
|
|
|
Get substream from Line 6 PCM data structure
|
2009-02-28 11:43:04 +08:00
|
|
|
*/
|
2010-09-22 07:58:00 +08:00
|
|
|
#define get_substream(line6pcm, stream) \
|
|
|
|
(line6pcm->pcm->streams[stream].substream)
|
2009-02-28 11:43:04 +08:00
|
|
|
|
2010-08-12 07:35:30 +08:00
|
|
|
/*
|
2012-01-20 07:09:09 +08:00
|
|
|
PCM mode bits.
|
|
|
|
|
2015-01-20 16:20:49 +08:00
|
|
|
There are several features of the Line 6 USB driver which require PCM
|
2012-01-20 07:09:09 +08:00
|
|
|
data to be exchanged with the device:
|
|
|
|
*) PCM playback and capture via ALSA
|
|
|
|
*) software monitoring (for devices without hardware monitoring)
|
|
|
|
*) optional impulse response measurement
|
|
|
|
However, from the device's point of view, there is just a single
|
|
|
|
capture and playback stream, which must be shared between these
|
|
|
|
subsystems. It is therefore necessary to maintain the state of the
|
|
|
|
subsystems with respect to PCM usage. We define several constants of
|
|
|
|
the form LINE6_BIT_PCM_<subsystem>_<direction>_<resource> with the
|
|
|
|
following meanings:
|
|
|
|
*) <subsystem> is one of
|
|
|
|
-) ALSA: PCM playback and capture via ALSA
|
|
|
|
-) MONITOR: software monitoring
|
|
|
|
-) IMPULSE: optional impulse response measurement
|
|
|
|
*) <direction> is one of
|
|
|
|
-) PLAYBACK: audio output (from host to device)
|
|
|
|
-) CAPTURE: audio input (from device to host)
|
|
|
|
*) <resource> is one of
|
|
|
|
-) BUFFER: buffer required by PCM data stream
|
|
|
|
-) STREAM: actual PCM data stream
|
|
|
|
|
|
|
|
The subsystems call line6_pcm_acquire() to acquire the (shared)
|
|
|
|
resources needed for a particular operation (e.g., allocate the buffer
|
|
|
|
for ALSA playback or start the capture stream for software monitoring).
|
|
|
|
When a resource is no longer needed, it is released by calling
|
|
|
|
line6_pcm_release(). Buffer allocation and stream startup are handled
|
|
|
|
separately to allow the ALSA kernel driver to perform them at
|
|
|
|
appropriate places (since the callback which starts a PCM stream is not
|
|
|
|
allowed to sleep).
|
2010-08-12 07:35:30 +08:00
|
|
|
*/
|
2009-02-28 11:43:04 +08:00
|
|
|
enum {
|
2012-01-20 07:09:09 +08:00
|
|
|
/* individual bit indices: */
|
|
|
|
LINE6_INDEX_PCM_ALSA_PLAYBACK_BUFFER,
|
|
|
|
LINE6_INDEX_PCM_ALSA_PLAYBACK_STREAM,
|
|
|
|
LINE6_INDEX_PCM_ALSA_CAPTURE_BUFFER,
|
|
|
|
LINE6_INDEX_PCM_ALSA_CAPTURE_STREAM,
|
|
|
|
LINE6_INDEX_PCM_MONITOR_PLAYBACK_BUFFER,
|
|
|
|
LINE6_INDEX_PCM_MONITOR_PLAYBACK_STREAM,
|
|
|
|
LINE6_INDEX_PCM_MONITOR_CAPTURE_BUFFER,
|
|
|
|
LINE6_INDEX_PCM_MONITOR_CAPTURE_STREAM,
|
|
|
|
LINE6_INDEX_PCM_IMPULSE_PLAYBACK_BUFFER,
|
|
|
|
LINE6_INDEX_PCM_IMPULSE_PLAYBACK_STREAM,
|
|
|
|
LINE6_INDEX_PCM_IMPULSE_CAPTURE_BUFFER,
|
|
|
|
LINE6_INDEX_PCM_IMPULSE_CAPTURE_STREAM,
|
|
|
|
LINE6_INDEX_PAUSE_PLAYBACK,
|
|
|
|
LINE6_INDEX_PREPARED,
|
|
|
|
|
2015-01-13 04:42:36 +08:00
|
|
|
#define LINE6_BIT(x) LINE6_BIT_ ## x = 1 << LINE6_INDEX_ ## x
|
|
|
|
|
2012-01-20 07:09:09 +08:00
|
|
|
/* individual bit masks: */
|
|
|
|
LINE6_BIT(PCM_ALSA_PLAYBACK_BUFFER),
|
|
|
|
LINE6_BIT(PCM_ALSA_PLAYBACK_STREAM),
|
|
|
|
LINE6_BIT(PCM_ALSA_CAPTURE_BUFFER),
|
|
|
|
LINE6_BIT(PCM_ALSA_CAPTURE_STREAM),
|
|
|
|
LINE6_BIT(PCM_MONITOR_PLAYBACK_BUFFER),
|
|
|
|
LINE6_BIT(PCM_MONITOR_PLAYBACK_STREAM),
|
|
|
|
LINE6_BIT(PCM_MONITOR_CAPTURE_BUFFER),
|
|
|
|
LINE6_BIT(PCM_MONITOR_CAPTURE_STREAM),
|
|
|
|
LINE6_BIT(PCM_IMPULSE_PLAYBACK_BUFFER),
|
|
|
|
LINE6_BIT(PCM_IMPULSE_PLAYBACK_STREAM),
|
|
|
|
LINE6_BIT(PCM_IMPULSE_CAPTURE_BUFFER),
|
|
|
|
LINE6_BIT(PCM_IMPULSE_CAPTURE_STREAM),
|
|
|
|
LINE6_BIT(PAUSE_PLAYBACK),
|
|
|
|
LINE6_BIT(PREPARED),
|
2010-08-12 07:35:30 +08:00
|
|
|
|
2012-01-20 07:09:09 +08:00
|
|
|
/* combined bit masks (by operation): */
|
|
|
|
LINE6_BITS_PCM_ALSA_BUFFER =
|
|
|
|
LINE6_BIT_PCM_ALSA_PLAYBACK_BUFFER |
|
|
|
|
LINE6_BIT_PCM_ALSA_CAPTURE_BUFFER,
|
|
|
|
|
|
|
|
LINE6_BITS_PCM_ALSA_STREAM =
|
|
|
|
LINE6_BIT_PCM_ALSA_PLAYBACK_STREAM |
|
|
|
|
LINE6_BIT_PCM_ALSA_CAPTURE_STREAM,
|
|
|
|
|
|
|
|
LINE6_BITS_PCM_MONITOR =
|
|
|
|
LINE6_BIT_PCM_MONITOR_PLAYBACK_BUFFER |
|
|
|
|
LINE6_BIT_PCM_MONITOR_PLAYBACK_STREAM |
|
|
|
|
LINE6_BIT_PCM_MONITOR_CAPTURE_BUFFER |
|
|
|
|
LINE6_BIT_PCM_MONITOR_CAPTURE_STREAM,
|
|
|
|
|
|
|
|
LINE6_BITS_PCM_IMPULSE =
|
|
|
|
LINE6_BIT_PCM_IMPULSE_PLAYBACK_BUFFER |
|
|
|
|
LINE6_BIT_PCM_IMPULSE_PLAYBACK_STREAM |
|
|
|
|
LINE6_BIT_PCM_IMPULSE_CAPTURE_BUFFER |
|
|
|
|
LINE6_BIT_PCM_IMPULSE_CAPTURE_STREAM,
|
|
|
|
|
|
|
|
/* combined bit masks (by direction): */
|
|
|
|
LINE6_BITS_PLAYBACK_BUFFER =
|
|
|
|
LINE6_BIT_PCM_IMPULSE_PLAYBACK_BUFFER |
|
|
|
|
LINE6_BIT_PCM_ALSA_PLAYBACK_BUFFER |
|
2015-01-13 04:42:35 +08:00
|
|
|
LINE6_BIT_PCM_MONITOR_PLAYBACK_BUFFER,
|
2012-01-20 07:09:09 +08:00
|
|
|
|
|
|
|
LINE6_BITS_PLAYBACK_STREAM =
|
|
|
|
LINE6_BIT_PCM_IMPULSE_PLAYBACK_STREAM |
|
|
|
|
LINE6_BIT_PCM_ALSA_PLAYBACK_STREAM |
|
2015-01-13 04:42:35 +08:00
|
|
|
LINE6_BIT_PCM_MONITOR_PLAYBACK_STREAM,
|
2012-01-20 07:09:09 +08:00
|
|
|
|
|
|
|
LINE6_BITS_CAPTURE_BUFFER =
|
|
|
|
LINE6_BIT_PCM_IMPULSE_CAPTURE_BUFFER |
|
|
|
|
LINE6_BIT_PCM_ALSA_CAPTURE_BUFFER |
|
2015-01-13 04:42:35 +08:00
|
|
|
LINE6_BIT_PCM_MONITOR_CAPTURE_BUFFER,
|
2010-08-12 07:35:30 +08:00
|
|
|
|
2012-01-20 07:09:09 +08:00
|
|
|
LINE6_BITS_CAPTURE_STREAM =
|
|
|
|
LINE6_BIT_PCM_IMPULSE_CAPTURE_STREAM |
|
|
|
|
LINE6_BIT_PCM_ALSA_CAPTURE_STREAM |
|
|
|
|
LINE6_BIT_PCM_MONITOR_CAPTURE_STREAM,
|
2012-11-11 20:24:42 +08:00
|
|
|
|
2012-01-20 07:09:09 +08:00
|
|
|
LINE6_BITS_STREAM =
|
|
|
|
LINE6_BITS_PLAYBACK_STREAM |
|
|
|
|
LINE6_BITS_CAPTURE_STREAM
|
2009-02-28 11:43:04 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct line6_pcm_properties {
|
|
|
|
struct snd_pcm_hardware snd_line6_playback_hw, snd_line6_capture_hw;
|
|
|
|
struct snd_pcm_hw_constraint_ratdens snd_line6_rates;
|
|
|
|
int bytes_per_frame;
|
|
|
|
};
|
|
|
|
|
2015-01-23 23:10:57 +08:00
|
|
|
struct line6_pcm_stream {
|
|
|
|
/* allocated URBs */
|
|
|
|
struct urb *urbs[LINE6_ISO_BUFFERS];
|
2009-02-28 11:43:04 +08:00
|
|
|
|
2015-01-23 23:10:57 +08:00
|
|
|
/* Temporary buffer;
|
|
|
|
* Since the packet size is not known in advance, this buffer is
|
|
|
|
* large enough to store maximum size packets.
|
|
|
|
*/
|
|
|
|
unsigned char *buffer;
|
2009-02-28 11:43:04 +08:00
|
|
|
|
2015-01-23 23:10:57 +08:00
|
|
|
/* Free frame position in the buffer. */
|
|
|
|
snd_pcm_uframes_t pos;
|
2009-02-28 11:43:04 +08:00
|
|
|
|
2015-01-23 23:10:57 +08:00
|
|
|
/* Count processed bytes;
|
|
|
|
* This is modulo period size (to determine when a period is finished).
|
|
|
|
*/
|
|
|
|
unsigned bytes;
|
2009-02-28 11:43:04 +08:00
|
|
|
|
2015-01-23 23:10:57 +08:00
|
|
|
/* Counter to create desired sample rate */
|
|
|
|
unsigned count;
|
2009-02-28 11:43:04 +08:00
|
|
|
|
2015-01-23 23:10:57 +08:00
|
|
|
/* period size in bytes */
|
|
|
|
unsigned period;
|
2009-02-28 11:43:04 +08:00
|
|
|
|
2015-01-23 23:10:57 +08:00
|
|
|
/* Processed frame position in the buffer;
|
|
|
|
* The contents of the ring buffer have been consumed by the USB
|
|
|
|
* subsystem (i.e., sent to the USB device) up to this position.
|
|
|
|
*/
|
|
|
|
snd_pcm_uframes_t pos_done;
|
2009-02-28 11:43:04 +08:00
|
|
|
|
2015-01-23 23:10:57 +08:00
|
|
|
/* Bit mask of active URBs */
|
|
|
|
unsigned long active_urbs;
|
2010-08-12 07:35:30 +08:00
|
|
|
|
2015-01-23 23:10:57 +08:00
|
|
|
/* Bit mask of URBs currently being unlinked */
|
|
|
|
unsigned long unlink_urbs;
|
2009-02-28 11:43:04 +08:00
|
|
|
|
2015-01-23 23:10:57 +08:00
|
|
|
/* Spin lock to protect updates of the buffer positions (not contents)
|
|
|
|
*/
|
|
|
|
spinlock_t lock;
|
2009-02-28 11:43:04 +08:00
|
|
|
|
2015-01-23 23:10:57 +08:00
|
|
|
int last_frame;
|
|
|
|
};
|
2009-02-28 11:43:04 +08:00
|
|
|
|
2015-01-23 23:10:57 +08:00
|
|
|
struct snd_line6_pcm {
|
2009-02-28 11:43:04 +08:00
|
|
|
/**
|
2015-01-23 23:10:57 +08:00
|
|
|
Pointer back to the Line 6 driver data structure.
|
2009-02-28 11:43:04 +08:00
|
|
|
*/
|
2015-01-23 23:10:57 +08:00
|
|
|
struct usb_line6 *line6;
|
2009-02-28 11:43:04 +08:00
|
|
|
|
|
|
|
/**
|
2015-01-23 23:10:57 +08:00
|
|
|
Properties.
|
2009-02-28 11:43:04 +08:00
|
|
|
*/
|
2015-01-23 23:10:57 +08:00
|
|
|
struct line6_pcm_properties *properties;
|
2009-02-28 11:43:04 +08:00
|
|
|
|
|
|
|
/**
|
2015-01-23 23:10:57 +08:00
|
|
|
ALSA pcm stream
|
2009-02-28 11:43:04 +08:00
|
|
|
*/
|
2015-01-23 23:10:57 +08:00
|
|
|
struct snd_pcm *pcm;
|
2009-02-28 11:43:04 +08:00
|
|
|
|
2015-01-23 23:10:57 +08:00
|
|
|
/* Capture and playback streams */
|
|
|
|
struct line6_pcm_stream in;
|
|
|
|
struct line6_pcm_stream out;
|
2009-02-28 11:43:04 +08:00
|
|
|
|
|
|
|
/**
|
2015-01-23 23:10:57 +08:00
|
|
|
Previously captured frame (for software monitoring).
|
2009-02-28 11:43:04 +08:00
|
|
|
*/
|
2015-01-23 23:10:57 +08:00
|
|
|
unsigned char *prev_fbuf;
|
2009-02-28 11:43:04 +08:00
|
|
|
|
|
|
|
/**
|
2015-01-23 23:10:57 +08:00
|
|
|
Size of previously captured frame (for software monitoring).
|
2009-02-28 11:43:04 +08:00
|
|
|
*/
|
2015-01-23 23:10:57 +08:00
|
|
|
int prev_fsize;
|
2009-02-28 11:43:04 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
Maximum size of USB packet.
|
|
|
|
*/
|
|
|
|
int max_packet_size;
|
|
|
|
|
|
|
|
/**
|
|
|
|
PCM playback volume (left and right).
|
|
|
|
*/
|
2010-08-12 07:35:30 +08:00
|
|
|
int volume_playback[2];
|
|
|
|
|
|
|
|
/**
|
|
|
|
PCM monitor volume.
|
|
|
|
*/
|
|
|
|
int volume_monitor;
|
|
|
|
|
|
|
|
/**
|
|
|
|
Volume of impulse response test signal (if zero, test is disabled).
|
|
|
|
*/
|
|
|
|
int impulse_volume;
|
|
|
|
|
|
|
|
/**
|
|
|
|
Period of impulse response test signal.
|
|
|
|
*/
|
|
|
|
int impulse_period;
|
|
|
|
|
|
|
|
/**
|
|
|
|
Counter for impulse response test signal.
|
|
|
|
*/
|
|
|
|
int impulse_count;
|
2009-02-28 11:43:04 +08:00
|
|
|
|
|
|
|
/**
|
2012-01-20 07:09:09 +08:00
|
|
|
Several status bits (see LINE6_BIT_*).
|
2009-02-28 11:43:04 +08:00
|
|
|
*/
|
|
|
|
unsigned long flags;
|
|
|
|
};
|
|
|
|
|
2009-02-28 13:09:55 +08:00
|
|
|
extern int line6_init_pcm(struct usb_line6 *line6,
|
|
|
|
struct line6_pcm_properties *properties);
|
2009-02-28 11:43:04 +08:00
|
|
|
extern int snd_line6_trigger(struct snd_pcm_substream *substream, int cmd);
|
|
|
|
extern int snd_line6_prepare(struct snd_pcm_substream *substream);
|
2010-08-12 07:35:30 +08:00
|
|
|
extern void line6_pcm_disconnect(struct snd_line6_pcm *line6pcm);
|
2012-01-20 07:09:09 +08:00
|
|
|
extern int line6_pcm_acquire(struct snd_line6_pcm *line6pcm, int channels);
|
|
|
|
extern int line6_pcm_release(struct snd_line6_pcm *line6pcm, int channels);
|
2010-08-12 07:35:30 +08:00
|
|
|
|
2009-02-28 11:43:04 +08:00
|
|
|
#endif
|