浏览代码

ALSA: hdspm - Introduce hdspm_get_latency() to harmonize latency calculation

Currently, hdspm_decode_latency is called several times, violating the
DRY principle. Given that we need to distinguish between old and new
cards when decoding the latency bits in the control register, introduce
hdspm_get_latency() to provide the required functionality.

Signed-off-by: Adrian Knoth <adi@drcomp.erfurt.thur.de>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Adrian Knoth 13 年之前
父节点
当前提交
7cb155ff3e
共有 1 个文件被更改,包括 23 次插入5 次删除
  1. 23 5
      sound/pci/rme9652/hdspm.c

+ 23 - 5
sound/pci/rme9652/hdspm.c

@@ -1241,10 +1241,30 @@ static int hdspm_external_sample_rate(struct hdspm *hdspm)
 	return rate;
 	return rate;
 }
 }
 
 
+/* return latency in samples per period */
+static int hdspm_get_latency(struct hdspm *hdspm)
+{
+	int n;
+
+	n = hdspm_decode_latency(hdspm->control_register);
+
+	/* Special case for new RME cards with 32 samples period size.
+	 * The three latency bits in the control register
+	 * (HDSP_LatencyMask) encode latency values of 64 samples as
+	 * 0, 128 samples as 1 ... 4096 samples as 6. For old cards, 7
+	 * denotes 8192 samples, but on new cards like RayDAT or AIO,
+	 * it corresponds to 32 samples.
+	 */
+	if ((7 == n) && (RayDAT == hdspm->io_type || AIO == hdspm->io_type))
+		n = -1;
+
+	return 1 << (n + 6);
+}
+
 /* Latency function */
 /* Latency function */
 static inline void hdspm_compute_period_size(struct hdspm *hdspm)
 static inline void hdspm_compute_period_size(struct hdspm *hdspm)
 {
 {
-	hdspm->period_bytes = 1 << ((hdspm_decode_latency(hdspm->control_register) + 8));
+	hdspm->period_bytes = 4 * hdspm_get_latency(hdspm);
 }
 }
 
 
 
 
@@ -4801,8 +4821,7 @@ snd_hdspm_proc_read_madi(struct snd_info_entry * entry,
 
 
 	snd_iprintf(buffer, "--- Settings ---\n");
 	snd_iprintf(buffer, "--- Settings ---\n");
 
 
-	x = 1 << (6 + hdspm_decode_latency(hdspm->control_register &
-							HDSPM_LatencyMask));
+	x = hdspm_get_latency(hdspm);
 
 
 	snd_iprintf(buffer,
 	snd_iprintf(buffer,
 		"Size (Latency): %d samples (2 periods of %lu bytes)\n",
 		"Size (Latency): %d samples (2 periods of %lu bytes)\n",
@@ -4965,8 +4984,7 @@ snd_hdspm_proc_read_aes32(struct snd_info_entry * entry,
 
 
 	snd_iprintf(buffer, "--- Settings ---\n");
 	snd_iprintf(buffer, "--- Settings ---\n");
 
 
-	x = 1 << (6 + hdspm_decode_latency(hdspm->control_register &
-				HDSPM_LatencyMask));
+	x = hdspm_get_latency(hdspm);
 
 
 	snd_iprintf(buffer,
 	snd_iprintf(buffer,
 		    "Size (Latency): %d samples (2 periods of %lu bytes)\n",
 		    "Size (Latency): %d samples (2 periods of %lu bytes)\n",