All of lore.kernel.org
 help / color / mirror / Atom feed
From: Takashi Iwai <tiwai@suse.de>
To: Mark Knecht <markknecht@gmail.com>
Cc: Giuliano Pochini <pochini@shiny.it>,
	Patrick Shirkey <pshirkey@boosthardware.com>,
	alsa-devel@lists.sourceforge.net
Subject: Re: Maintaining sound card at a specific frequency
Date: Tue, 18 Jan 2005 18:48:32 +0100	[thread overview]
Message-ID: <s5hy8eqvdan.wl@alsa2.suse.de> (raw)
In-Reply-To: <s5h651uwtp9.wl@alsa2.suse.de>

[-- Attachment #1: Type: text/plain, Size: 298 bytes --]

At Tue, 18 Jan 2005 18:08:50 +0100,
I wrote:
> 
> If this works like you want, only the locking is missing...

The attached is an experimental patch to add this feature.
You can lock system clock via

	amixer cset iface=PCM,name="System Clock Source Locking" on

It's untested, as usual.


Takashi

[-- Attachment #2: Type: text/plain, Size: 4643 bytes --]

Index: alsa-kernel/pci/rme9652/hdsp.c
===================================================================
RCS file: /suse/tiwai/cvs/alsa/alsa-kernel/pci/rme9652/hdsp.c,v
retrieving revision 1.81
diff -u -r1.81 hdsp.c
--- alsa-kernel/pci/rme9652/hdsp.c	14 Jan 2005 19:50:48 -0000	1.81
+++ alsa-kernel/pci/rme9652/hdsp.c	18 Jan 2005 17:44:54 -0000
@@ -450,6 +450,7 @@
 	u32                   control2_register;     /* cached value */
 	u32                   creg_spdif;
 	u32                   creg_spdif_stream;
+	int                   clock_source_locked;
 	char                 *card_name;	     /* digiface/multiface */
 	HDSP_IO_Type          io_type;               /* ditto, but for code use */
         unsigned short        firmware_rev;
@@ -2159,7 +2160,7 @@
 	    if (val > 6) val = 6;
 	}
 	spin_lock_irq(&hdsp->lock);
-	if (val != hdsp_clock_source(hdsp)) {
+	if (val != hdsp_clock_source(hdsp) && ! hdsp->clock_source_locked) {
 		change = (hdsp_set_clock_source(hdsp, val) == 0) ? 1 : 0;
 	} else {
 		change = 0;
@@ -2168,6 +2169,34 @@
 	return change;
 }
 
+static int snd_hdsp_info_clock_source_lock(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
+{
+	uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
+	uinfo->count = 1;
+	uinfo->value.integer.min = 0;
+	uinfo->value.integer.max = 1;
+	return 0;
+}
+
+static int snd_hdsp_get_clock_source_lock(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+{
+	hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
+	
+	ucontrol->value.integer.value[0] = hdsp->clock_source_locked;
+	return 0;
+}
+
+static int snd_hdsp_put_clock_source_lock(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+{
+	hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
+	int change;
+
+	change = (int)ucontrol->value.integer.value[0] != hdsp->clock_source_locked;
+	if (change)
+		hdsp->clock_source_locked = ucontrol->value.integer.value[0];
+	return change;
+}
+
 #define HDSP_DA_GAIN(xname, xindex) \
 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
   .name = xname, \
@@ -3129,6 +3158,13 @@
 HDSP_SPDIF_NON_AUDIO("IEC958 Non-audio Bit", 0),
 /* 'Sample Clock Source' complies with the alsa control naming scheme */ 
 HDSP_CLOCK_SOURCE("Sample Clock Source", 0),
+{
+	.iface = SNDRV_CTL_ELEM_IFACE_PCM,
+	.name = "Sample Clock Source Locking",
+	.info = snd_hdsp_info_clock_source_lock,
+	.get = snd_hdsp_get_clock_source_lock,
+	.put = snd_hdsp_put_clock_source_lock,
+},
 HDSP_SYSTEM_CLOCK_MODE("System Clock Mode", 0),
 HDSP_PREF_SYNC_REF("Preferred Sync Reference", 0),
 HDSP_AUTOSYNC_REF("AutoSync Reference", 0),
@@ -3360,6 +3396,7 @@
 	snd_iprintf (buffer, "System Clock Mode: %s\n", system_clock_mode);
 
 	snd_iprintf (buffer, "System Clock Frequency: %d\n", hdsp->system_sample_rate);
+	snd_iprintf (buffer, "System Clock Locked: %s\n", hdsp->clock_source_locked ? "Yes" : "No");
 		
 	snd_iprintf(buffer, "\n");
 
@@ -3882,21 +3919,19 @@
 		spin_unlock_irq(&hdsp->lock);
  		return 0;
 
-	} else {
-		spin_unlock_irq(&hdsp->lock);
 	}
 
 	/* how to make sure that the rate matches an externally-set one ?
 	 */
 
-	spin_lock_irq(&hdsp->lock);
-	if ((err = hdsp_set_rate(hdsp, params_rate(params), 0)) < 0) {
-		spin_unlock_irq(&hdsp->lock);
-		_snd_pcm_hw_param_setempty(params, SNDRV_PCM_HW_PARAM_RATE);
-		return err;
-	} else {
-		spin_unlock_irq(&hdsp->lock);
+	if (! hdsp->clock_source_locked) {
+		if ((err = hdsp_set_rate(hdsp, params_rate(params), 0)) < 0) {
+			spin_unlock_irq(&hdsp->lock);
+			_snd_pcm_hw_param_setempty(params, SNDRV_PCM_HW_PARAM_RATE);
+			return err;
+		}
 	}
+	spin_unlock_irq(&hdsp->lock);
 
 	if ((err = hdsp_set_interrupt_interval(hdsp, params_period_size(params))) < 0) {
 		_snd_pcm_hw_param_setempty(params, SNDRV_PCM_HW_PARAM_PERIOD_SIZE);
@@ -4318,13 +4353,17 @@
 
 	snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
 	snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, &hdsp_hw_constraints_period_sizes);
-	if (hdsp->io_type == H9632) {
-		runtime->hw.channels_min = hdsp->qs_out_channels;
-		runtime->hw.channels_max = hdsp->ss_out_channels;
+	if (hdsp->clock_source_locked) {
+		runtime->hw.rate_min = runtime->hw.rate_max = hdsp->system_sample_rate;
+	} else if (hdsp->io_type == H9632) {
 		runtime->hw.rate_max = 192000;
 		runtime->hw.rates = SNDRV_PCM_RATE_KNOT;
 		snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hdsp_hw_constraints_9632_sample_rates);
 	}
+	if (hdsp->io_type == H9632) {
+		runtime->hw.channels_min = hdsp->qs_out_channels;
+		runtime->hw.channels_max = hdsp->ss_out_channels;
+	}	
 	
 	snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
 			     snd_hdsp_hw_rule_out_channels, hdsp,

  parent reply	other threads:[~2005-01-18 17:48 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-01-16 21:05 Maintaining sound card at a specific frequency Mark Knecht
2005-01-17  5:14 ` Patrick Shirkey
2005-01-18 15:50   ` Giuliano Pochini
2005-01-18 16:48     ` Takashi Iwai
2005-01-18 17:01       ` Mark Knecht
2005-01-18 17:08         ` Takashi Iwai
2005-01-18 17:12           ` Mark Knecht
2005-01-18 17:15             ` Takashi Iwai
2005-01-18 17:43               ` Mark Knecht
2005-01-18 17:48           ` Takashi Iwai [this message]
2005-01-18 18:04             ` Mark Knecht
2005-01-18 17:31       ` Giuliano Pochini
2005-01-18 17:40         ` Takashi Iwai
2005-01-19 10:07           ` Giuliano Pochini
2005-01-18 17:45         ` Mark Knecht
2005-01-18 19:51           ` Takashi Iwai
2005-01-18 21:22             ` Mark Knecht
2005-01-18 21:30           ` Lee Revell
2005-01-18 23:16             ` Mark Knecht
2005-01-19 19:59   ` Mark Knecht
2005-01-19  9:07 ` Clemens Ladisch
2005-01-19 10:14   ` Takashi Iwai
2005-01-19 19:49   ` Mark Knecht
2005-01-19 21:09     ` Russ Pridemore
2005-01-19 23:08       ` Mark Knecht

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=s5hy8eqvdan.wl@alsa2.suse.de \
    --to=tiwai@suse.de \
    --cc=alsa-devel@lists.sourceforge.net \
    --cc=markknecht@gmail.com \
    --cc=pochini@shiny.it \
    --cc=pshirkey@boosthardware.com \
    /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 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.