// SPDX-License-Identifier: GPL-2.0-only /* * amdtp-dot.c - a part of driver for Digidesign Digi 002/003 family * * Copyright (c) 2014-2015 Takashi Sakamoto * Copyright (C) 2012 Robin Gareus <robin@gareus.org> * Copyright (C) 2012 Damien Zammit <damien@zamaudio.com>
*/
#include <sound/pcm.h> #include"digi00x.h"
#define CIP_FMT_AM 0x10
/* 'Clock-based rate control mode' is just supported. */ #define AMDTP_FDF_AM824 0x00
/* * Nominally 3125 bytes/second, but the MIDI port's clock might be * 1% too slow, and the bus clock 100 ppm too fast.
*/ #define MIDI_BYTES_PER_SECOND 3093
/* * Several devices look only at the first eight data blocks. * In any case, this is more than enough for the MIDI data rate.
*/ #define MAX_MIDI_RX_BLOCKS 8
/* * The double-oh-three algorithm was discovered by Robin Gareus and Damien * Zammit in 2012, with reverse-engineering for Digi 003 Rack.
*/ struct dot_state {
u8 carry;
u8 idx; unsignedint off;
};
struct snd_rawmidi_substream *midi[MAX_MIDI_PORTS]; int midi_fifo_used[MAX_MIDI_PORTS]; int midi_fifo_limit;
};
/* * double-oh-three look up table * * @param idx index byte (audio-sample data) 0x00..0xff * @param off channel offset shift * @return salt to XOR with given data
*/ #define BYTE_PER_SAMPLE (4) #define MAGIC_DOT_BYTE (2) #define MAGIC_BYTE_OFF(x) (((x) * BYTE_PER_SAMPLE) + MAGIC_DOT_BYTE) static u8 dot_scrt(const u8 idx, constunsignedint off)
{ /* * the length of the added pattern only depends on the lower nibble * of the last non-zero data
*/ staticconst u8 len[16] = {0, 1, 3, 5, 7, 9, 11, 13, 14,
12, 10, 8, 6, 4, 2, 0};
/* * the lower nibble of the salt. Interleaved sequence. * this is walked backwards according to len[]
*/ staticconst u8 nib[15] = {0x8, 0x7, 0x9, 0x6, 0xa, 0x5, 0xb, 0x4,
0xc, 0x3, 0xd, 0x2, 0xe, 0x1, 0xf};
/* circular list for the salt's hi nibble. */ staticconst u8 hir[15] = {0x0, 0x6, 0xf, 0x8, 0x7, 0x5, 0x3, 0x4,
0xc, 0xd, 0xe, 0x1, 0x2, 0xb, 0xa};
/* * start offset for upper nibble mapping. * note: 9 is /special/. In the case where the high nibble == 0x9, * hir[] is not used and - coincidentally - the salt's hi nibble is * 0x09 regardless of the offset.
*/ staticconst u8 hio[16] = {0, 11, 12, 6, 7, 5, 1, 4,
3, 0x00, 14, 13, 8, 9, 10, 2};
int amdtp_dot_set_parameters(struct amdtp_stream *s, unsignedint rate, unsignedint pcm_channels)
{ struct amdtp_dot *p = s->protocol; int err;
if (amdtp_stream_running(s)) return -EBUSY;
/* * A first data channel is for MIDI messages, the rest is Multi Bit * Linear Audio data channel.
*/
err = amdtp_stream_set_parameters(s, rate, pcm_channels + 1, 1); if (err < 0) return err;
s->ctx_data.rx.fdf = AMDTP_FDF_AM824 | s->sfc;
p->pcm_channels = pcm_channels;
/* * We do not know the actual MIDI FIFO size of most devices. Just * assume two bytes, i.e., one byte can be received over the bus while * the previous one is transmitted over MIDI. * (The value here is adjusted for midi_ratelimit_per_packet().)
*/
p->midi_fifo_limit = rate - MIDI_BYTES_PER_SECOND * s->syt_interval + 1;
for (f = 0; f < data_blocks; f++) {
b = (u8 *)&buffer[0];
len = b[3] & 0x0f; if (len > 0) { /* * Upper 4 bits of LSB represent port number. * - 0000b: physical MIDI port 1. Use port 0. * - 1110b: console MIDI port. Use port 2.
*/ if (b[3] >> 4 > 0)
port = 2; else
port = 0;
if (port < MAX_MIDI_PORTS && p->midi[port])
snd_rawmidi_receive(p->midi[port], b + 1, len);
}
buffer += s->data_block_quadlets;
}
}
int amdtp_dot_add_pcm_hw_constraints(struct amdtp_stream *s, struct snd_pcm_runtime *runtime)
{ int err;
/* This protocol delivers 24 bit data in 32bit data channel. */
err = snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24); if (err < 0) return err;
// Use different mode between incoming/outgoing. if (dir == AMDTP_IN_STREAM)
process_ctx_payloads = process_ir_ctx_payloads; else
process_ctx_payloads = process_it_ctx_payloads;
return amdtp_stream_init(s, unit, dir, flags, CIP_FMT_AM,
process_ctx_payloads, sizeof(struct amdtp_dot));
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.