From: Takashi Sakamoto <o-takashi@sakamocchi.jp>
To: tiwai@suse.de
Cc: alsa-devel@alsa-project.org, clemens@ladisch.de
Subject: [PATCH 1/3] ALSA: firewire-motu: use macro for magic numbers relevant to IEC 61883-1
Date: Wed, 2 Jun 2021 10:34:04 +0900 [thread overview]
Message-ID: <20210602013406.26442-2-o-takashi@sakamocchi.jp> (raw)
In-Reply-To: <20210602013406.26442-1-o-takashi@sakamocchi.jp>
ALSA firewire-motu driver has some magic numbers from IEC 61883-1 to
operates source packet header (SPH). This commit replaces them with
macros.
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
---
sound/firewire/motu/amdtp-motu.c | 40 +++++++++++++++++++++-----------
1 file changed, 26 insertions(+), 14 deletions(-)
diff --git a/sound/firewire/motu/amdtp-motu.c b/sound/firewire/motu/amdtp-motu.c
index 18bf433f43b6..89638e1fbb69 100644
--- a/sound/firewire/motu/amdtp-motu.c
+++ b/sound/firewire/motu/amdtp-motu.c
@@ -16,6 +16,18 @@
#define CIP_FMT_MOTU_TX_V3 0x22
#define MOTU_FDF_AM824 0x22
+#define TICKS_PER_CYCLE 3072
+#define CYCLES_PER_SECOND 8000
+#define TICKS_PER_SECOND (TICKS_PER_CYCLE * CYCLES_PER_SECOND)
+
+#define IEEE1394_SEC_MODULUS 128
+
+#define TRANSFER_DELAY_TICKS 0x2e00 /* 479.17 microseconds */
+
+#define CIP_SPH_CYCLE_SHIFT 12
+#define CIP_SPH_CYCLE_MASK 0x01fff000
+#define CIP_SPH_OFFSET_MASK 0x00000fff
+
/*
* Nominally 3125 bytes/second, but the MIDI port's clock might be
* 1% too slow, and the bus clock 100 ppm too fast.
@@ -97,17 +109,16 @@ int amdtp_motu_set_parameters(struct amdtp_stream *s, unsigned int rate,
p->midi_db_count = 0;
p->midi_db_interval = rate / MIDI_BYTES_PER_SECOND;
- /* IEEE 1394 bus requires. */
- delay = 0x2e00;
+ delay = TRANSFER_DELAY_TICKS;
- /* For no-data or empty packets to adjust PCM sampling frequency. */
- delay += 8000 * 3072 * s->syt_interval / rate;
+ // For no-data or empty packets to adjust PCM sampling frequency.
+ delay += TICKS_PER_SECOND * s->syt_interval / rate;
p->next_seconds = 0;
- p->next_cycles = delay / 3072;
+ p->next_cycles = delay / TICKS_PER_CYCLE;
p->quotient_ticks_per_event = params[s->sfc].quotient_ticks_per_event;
p->remainder_ticks_per_event = params[s->sfc].remainder_ticks_per_event;
- p->next_ticks = delay % 3072;
+ p->next_ticks = delay % TICKS_PER_CYCLE;
p->next_accumulated = 0;
return 0;
@@ -363,18 +374,18 @@ static inline void compute_next_elapse_from_start(struct amdtp_motu *p)
}
p->next_ticks += p->quotient_ticks_per_event;
- if (p->next_ticks >= 3072) {
- p->next_ticks -= 3072;
+ if (p->next_ticks >= TICKS_PER_CYCLE) {
+ p->next_ticks -= TICKS_PER_CYCLE;
p->next_cycles++;
}
- if (p->next_cycles >= 8000) {
- p->next_cycles -= 8000;
+ if (p->next_cycles >= CYCLES_PER_SECOND) {
+ p->next_cycles -= CYCLES_PER_SECOND;
p->next_seconds++;
}
- if (p->next_seconds >= 128)
- p->next_seconds -= 128;
+ if (p->next_seconds >= IEEE1394_SEC_MODULUS)
+ p->next_seconds -= IEEE1394_SEC_MODULUS;
}
static void write_sph(struct amdtp_stream *s, __be32 *buffer, unsigned int data_blocks,
@@ -386,8 +397,9 @@ static void write_sph(struct amdtp_stream *s, __be32 *buffer, unsigned int data_
u32 sph;
for (i = 0; i < data_blocks; i++) {
- next_cycles = (rx_start_cycle + p->next_cycles) % 8000;
- sph = ((next_cycles << 12) | p->next_ticks) & 0x01ffffff;
+ next_cycles = (rx_start_cycle + p->next_cycles) % CYCLES_PER_SECOND;
+ sph = ((next_cycles << CIP_SPH_CYCLE_SHIFT) | p->next_ticks) &
+ (CIP_SPH_CYCLE_MASK | CIP_SPH_OFFSET_MASK);
*buffer = cpu_to_be32(sph);
compute_next_elapse_from_start(p);
--
2.27.0
next prev parent reply other threads:[~2021-06-02 1:36 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-02 1:34 [PATCH 0/3] ALSA: firewire-motu: media clock recovery for sph-aware devices Takashi Sakamoto
2021-06-02 1:34 ` Takashi Sakamoto [this message]
2021-06-02 1:34 ` [PATCH 2/3] ALSA: firewire-motu: cache event ticks in source packet header per data block Takashi Sakamoto
2021-06-02 1:34 ` [PATCH 3/3] ALSA: firewire-motu: sequence replay for source packet header Takashi Sakamoto
2021-06-02 7:00 ` [PATCH 0/3] ALSA: firewire-motu: media clock recovery for sph-aware devices Takashi Iwai
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210602013406.26442-2-o-takashi@sakamocchi.jp \
--to=o-takashi@sakamocchi.jp \
--cc=alsa-devel@alsa-project.org \
--cc=clemens@ladisch.de \
--cc=tiwai@suse.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).