⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hdsp.c

📁 linux-2.6.15.6
💻 C
📖 第 1 页 / 共 5 页
字号:
		break;	case 176400:		ucontrol->value.enumerated.item[0] = 8;		break;	case 192000:		ucontrol->value.enumerated.item[0] = 9;		break;	default:		ucontrol->value.enumerated.item[0] = 6;			}	return 0;}#define HDSP_SYSTEM_SAMPLE_RATE(xname, xindex) \{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \  .name = xname, \  .index = xindex, \  .access = SNDRV_CTL_ELEM_ACCESS_READ, \  .info = snd_hdsp_info_system_sample_rate, \  .get = snd_hdsp_get_system_sample_rate \}static int snd_hdsp_info_system_sample_rate(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo){	uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;	uinfo->count = 1;	return 0;}static int snd_hdsp_get_system_sample_rate(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol){	hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);		ucontrol->value.enumerated.item[0] = hdsp->system_sample_rate;	return 0;}#define HDSP_AUTOSYNC_SAMPLE_RATE(xname, xindex) \{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \  .name = xname, \  .index = xindex, \  .access = SNDRV_CTL_ELEM_ACCESS_READ, \  .info = snd_hdsp_info_autosync_sample_rate, \  .get = snd_hdsp_get_autosync_sample_rate \}static int snd_hdsp_info_autosync_sample_rate(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo){	hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);	static char *texts[] = {"32000", "44100", "48000", "64000", "88200", "96000", "None", "128000", "176400", "192000"};		uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;	uinfo->count = 1;	uinfo->value.enumerated.items = (hdsp->io_type == H9632) ? 10 : 7 ;	if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)		uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;	strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);	return 0;}static int snd_hdsp_get_autosync_sample_rate(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol){	hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);		switch (hdsp_external_sample_rate(hdsp)) {	case 32000:		ucontrol->value.enumerated.item[0] = 0;		break;	case 44100:		ucontrol->value.enumerated.item[0] = 1;		break;	case 48000:		ucontrol->value.enumerated.item[0] = 2;		break;	case 64000:		ucontrol->value.enumerated.item[0] = 3;		break;	case 88200:		ucontrol->value.enumerated.item[0] = 4;		break;	case 96000:		ucontrol->value.enumerated.item[0] = 5;		break;	case 128000:		ucontrol->value.enumerated.item[0] = 7;		break;	case 176400:		ucontrol->value.enumerated.item[0] = 8;		break;	case 192000:		ucontrol->value.enumerated.item[0] = 9;		break;		default:		ucontrol->value.enumerated.item[0] = 6;			}	return 0;}#define HDSP_SYSTEM_CLOCK_MODE(xname, xindex) \{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \  .name = xname, \  .index = xindex, \  .access = SNDRV_CTL_ELEM_ACCESS_READ, \  .info = snd_hdsp_info_system_clock_mode, \  .get = snd_hdsp_get_system_clock_mode \}static int hdsp_system_clock_mode(hdsp_t *hdsp){	if (hdsp->control_register & HDSP_ClockModeMaster)		return 0;	else if (hdsp_external_sample_rate(hdsp) != hdsp->system_sample_rate)			return 0;	return 1;}static int snd_hdsp_info_system_clock_mode(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo){	static char *texts[] = {"Master", "Slave" };		uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;	uinfo->count = 1;	uinfo->value.enumerated.items = 2;	if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)		uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;	strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);	return 0;}static int snd_hdsp_get_system_clock_mode(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol){	hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);		ucontrol->value.enumerated.item[0] = hdsp_system_clock_mode(hdsp);	return 0;}#define HDSP_CLOCK_SOURCE(xname, xindex) \{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \  .name = xname, \  .index = xindex, \  .info = snd_hdsp_info_clock_source, \  .get = snd_hdsp_get_clock_source, \  .put = snd_hdsp_put_clock_source \}static int hdsp_clock_source(hdsp_t *hdsp){	if (hdsp->control_register & HDSP_ClockModeMaster) {		switch (hdsp->system_sample_rate) {		case 32000:			return 1;		case 44100:			return 2;		case 48000:			return 3;		case 64000:			return 4;		case 88200:			return 5;		case 96000:			return 6;		case 128000:			return 7;		case 176400:			return 8;		case 192000:			return 9;		default:			return 3;			}	} else {		return 0;	}}static int hdsp_set_clock_source(hdsp_t *hdsp, int mode){	int rate;	switch (mode) {	case HDSP_CLOCK_SOURCE_AUTOSYNC:		if (hdsp_external_sample_rate(hdsp) != 0) {		    if (!hdsp_set_rate(hdsp, hdsp_external_sample_rate(hdsp), 1)) {			hdsp->control_register &= ~HDSP_ClockModeMaster;					hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);			return 0;		    }		}		return -1;	case HDSP_CLOCK_SOURCE_INTERNAL_32KHZ:		rate = 32000;		break;	case HDSP_CLOCK_SOURCE_INTERNAL_44_1KHZ:		rate = 44100;		break;	    	case HDSP_CLOCK_SOURCE_INTERNAL_48KHZ:		rate = 48000;		break;	case HDSP_CLOCK_SOURCE_INTERNAL_64KHZ:		rate = 64000;		break;	case HDSP_CLOCK_SOURCE_INTERNAL_88_2KHZ:		rate = 88200;		break;	case HDSP_CLOCK_SOURCE_INTERNAL_96KHZ:		rate = 96000;		break;	case HDSP_CLOCK_SOURCE_INTERNAL_128KHZ:		rate = 128000;		break;	case HDSP_CLOCK_SOURCE_INTERNAL_176_4KHZ:		rate = 176400;		break;	case HDSP_CLOCK_SOURCE_INTERNAL_192KHZ:		rate = 192000;		break;	default:		rate = 48000;	}	hdsp->control_register |= HDSP_ClockModeMaster;	hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);	hdsp_set_rate(hdsp, rate, 1);	return 0;}static int snd_hdsp_info_clock_source(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo){	static char *texts[] = {"AutoSync", "Internal 32.0 kHz", "Internal 44.1 kHz", "Internal 48.0 kHz", "Internal 64.0 kHz", "Internal 88.2 kHz", "Internal 96.0 kHz", "Internal 128 kHz", "Internal 176.4 kHz", "Internal 192.0 KHz" };	hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);		uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;	uinfo->count = 1;	if (hdsp->io_type == H9632)	    uinfo->value.enumerated.items = 10;	else	    uinfo->value.enumerated.items = 7;		if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)		uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;	strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);	return 0;}static int snd_hdsp_get_clock_source(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol){	hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);		ucontrol->value.enumerated.item[0] = hdsp_clock_source(hdsp);	return 0;}static int snd_hdsp_put_clock_source(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol){	hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);	int change;	int val;		if (!snd_hdsp_use_is_exclusive(hdsp))		return -EBUSY;	val = ucontrol->value.enumerated.item[0];	if (val < 0) val = 0;	if (hdsp->io_type == H9632) {		if (val > 9)			val = 9;	} else {		if (val > 6)			val = 6;	}	spin_lock_irq(&hdsp->lock);	if (val != hdsp_clock_source(hdsp))		change = (hdsp_set_clock_source(hdsp, val) == 0) ? 1 : 0;	else		change = 0;	spin_unlock_irq(&hdsp->lock);	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_MIXER, \  .name = xname, \  .index = xindex, \  .info = snd_hdsp_info_da_gain, \  .get = snd_hdsp_get_da_gain, \  .put = snd_hdsp_put_da_gain \}static int hdsp_da_gain(hdsp_t *hdsp){	switch (hdsp->control_register & HDSP_DAGainMask) {	case HDSP_DAGainHighGain:		return 0;	case HDSP_DAGainPlus4dBu:		return 1;	case HDSP_DAGainMinus10dBV:		return 2;	default:		return 1;		}}static int hdsp_set_da_gain(hdsp_t *hdsp, int mode){	hdsp->control_register &= ~HDSP_DAGainMask;	switch (mode) {	case 0:		hdsp->control_register |= HDSP_DAGainHighGain;		break;	case 1:		hdsp->control_register |= HDSP_DAGainPlus4dBu;		break;	case 2:		hdsp->control_register |= HDSP_DAGainMinus10dBV;				break;	    	default:		return -1;	}	hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);	return 0;}static int snd_hdsp_info_da_gain(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo){	static char *texts[] = {"Hi Gain", "+4 dBu", "-10 dbV"};		uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;	uinfo->count = 1;	uinfo->value.enumerated.items = 3;	if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)		uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;	strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);	return 0;}static int snd_hdsp_get_da_gain(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol){	hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);		ucontrol->value.enumerated.item[0] = hdsp_da_gain(hdsp);	return 0;}static int snd_hdsp_put_da_gain(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol){	hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);	int change;	int val;		if (!snd_hdsp_use_is_exclusive(hdsp))		return -EBUSY;	val = ucontrol->value.enumerated.item[0];	if (val < 0) val = 0;	if (val > 2) val = 2;	spin_lock_irq(&hdsp->lock);	if (val != hdsp_da_gain(hdsp))		change = (hdsp_set_da_gain(hdsp, val) == 0) ? 1 : 0;	else		change = 0;	spin_unlock_irq(&hdsp->lock);	return change;}#define HDSP_AD_GAIN(xname, xindex) \{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \  .name = xname, \  .index = xindex, \  .info = snd_hdsp_info_ad_gain, \  .get = snd_hdsp_get_ad_gain, \  .put = snd_hdsp_put_ad_gain \}static int hdsp_ad_gain(hdsp_t *hdsp){	switch (hdsp->control_register & HDSP_ADGainMask) {	case HDSP_ADGainMinus10dBV:		return 0;	case HDSP_ADGainPlus4dBu:		return 1;	case HDSP_ADGainLowGain:		return 2;	default:		return 1;		}}static int hdsp_set_ad_gain(hdsp_t *hdsp, int mode){	hdsp->control_register &= ~HDSP_ADGainMask;	switch (mode) {	case 0:		hdsp->control_register |= HDSP_ADGainMinus10dBV;		break;	case 1:		hdsp->control_register |= HDSP_ADGainPlus4dBu;				break;	case 2:		hdsp->control_register |= HDSP_ADGainLowGain;				break;	    	default:		return -1;	}	hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);	return 0;}static int snd_hdsp_info_ad_gain(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo){	static char *texts[] = {"-10 dBV", "+4 dBu", "Lo Gain"};		uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;	uinfo->count = 1;	uinfo->value.enumerated.items = 3;	if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)		uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;	strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item])

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -