File: AlsaMixerTest.java

package info (click to toggle)
libtritonus-java 20070428-7
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 6,792 kB
  • ctags: 11,840
  • sloc: ansic: 53,846; java: 45,251; sh: 3,032; makefile: 1,189; xml: 820; cpp: 147
file content (151 lines) | stat: -rw-r--r-- 4,130 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/*
 *	AlsaMixerTest.java
 */

import	org.tritonus.lowlevel.alsa.AlsaMixer;
import	org.tritonus.lowlevel.alsa.AlsaMixerElement;



public class AlsaMixerTest
{
	private static boolean	sm_bShowInactiveElements;



	public static void main(String[] args)
		throws Exception
	{
		String	strMixerName = "hw:0";
		if (args.length > 0)
		{
			strMixerName = args[0];
		}
		out("Mixer: " + strMixerName);
		AlsaMixer	mixer = new AlsaMixer(strMixerName);
		int[]		anIndices = new int[200];
		String[]	astrNames = new String[200];
		int	nReturn = mixer.readControlList(anIndices, astrNames);
		out("readControlList() returns: " + nReturn);
		if (nReturn > 0)
		{
			out("Mixer controls:");
			for (int i = 0; i < nReturn; i++)
			{
				out("" + i + " " + anIndices[i] + " " + astrNames[i]);
				AlsaMixerElement	element = new AlsaMixerElement(mixer, anIndices[i], astrNames[i]);
				if (element.isActive() || sm_bShowInactiveElements)
				{
					out("--------------------------------------------------------------------------------");
					output(element);
				}
			}
			out("--------------------------------------------------------------------------------");
		}
		mixer.close();
	}



	private static void output(AlsaMixerElement element)
	{
		out("  name: " + element.getName());
		out("  index: " + element.getName());
		out("  active: " + element.isActive());

		if (hasPlaybackChannels(element))
		{
			outputPlayback(element);
		}
		else
		{
			out("* no playback channels");
		}
		if (hasCaptureChannels(element))
		{
			outputCapture(element);
		}
		else
		{
			out("* no capture channels");
		}
	}



	private static void outputPlayback(AlsaMixerElement element)
	{
		out("  playback mono: " + element.isPlaybackMono());
		for (int nChannel = AlsaMixerElement.SND_MIXER_SCHN_FRONT_LEFT;
		     nChannel <= AlsaMixerElement.SND_MIXER_SCHN_WOOFER;
		     nChannel++)
		{
			out("  playback channel (" + AlsaMixerElement.getChannelName(nChannel) + "): " + element.hasPlaybackChannel(nChannel));
		}
		out("  common volume: " + element.hasCommonVolume());
		out("  playback volume: " + element.hasPlaybackVolume());
		out("  playback volume joined: " + element.hasPlaybackVolumeJoined());
		out("  common switch: " + element.hasCommonSwitch());
		out("  playback switch: " + element.hasPlaybackSwitch());
		out("  playback switch joined: " + element.hasPlaybackSwitchJoined());
	}


	private static void outputCapture(AlsaMixerElement element)
	{
		out("  capture mono: " + element.isCaptureMono());
		for (int nChannel = AlsaMixerElement.SND_MIXER_SCHN_FRONT_LEFT;
		     nChannel <= AlsaMixerElement.SND_MIXER_SCHN_WOOFER;
		     nChannel++)
		{
			out("  capture channel (" + AlsaMixerElement.getChannelName(nChannel) + "): " + element.hasCaptureChannel(nChannel));
		}
		out("  common volume: " + element.hasCommonVolume());
		out("  capture volume: " + element.hasCaptureVolume());
		out("  capture volume joined: " + element.hasCaptureVolumeJoined());
		out("  common switch: " + element.hasCommonSwitch());
		out("  capture switch: " + element.hasCaptureSwitch());
		out("  capture switch joined: " + element.hasCaptureSwitchJoinded());
		out("  capture switch exclusive: " + element.hasCaptureSwitchExclusive());
		if (element.hasCaptureSwitchExclusive())
		{
			out("  capture group: " + element.getCaptureGroup());
		}
	}


	private static boolean hasPlaybackChannels(AlsaMixerElement element)
	{
		boolean	bHasChannels = false;
		for (int nChannel = AlsaMixerElement.SND_MIXER_SCHN_FRONT_LEFT;
		     nChannel <= AlsaMixerElement.SND_MIXER_SCHN_WOOFER;
		     nChannel++)
		{
			bHasChannels |= element.hasPlaybackChannel(nChannel);
		}
		return bHasChannels;
	}


	private static boolean hasCaptureChannels(AlsaMixerElement element)
	{
		boolean	bHasChannels = false;
		for (int nChannel = AlsaMixerElement.SND_MIXER_SCHN_FRONT_LEFT;
		     nChannel <= AlsaMixerElement.SND_MIXER_SCHN_WOOFER;
		     nChannel++)
		{
			bHasChannels |= element.hasCaptureChannel(nChannel);
		}
		return bHasChannels;
	}


	private static void out(String strMessage)
	{
		System.out.println(strMessage);
	}
}



/*** AlsaMixerTest.java ***/