1/*
2 * Copyright (c) 1999-2000, Eric Moon.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 *    notice, this list of conditions, and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 *    notice, this list of conditions, and the following disclaimer in the
14 *    documentation and/or other materials provided with the distribution.
15 *
16 * 3. The name of the author may not be used to endorse or promote products
17 *    derived from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
23 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
26 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
27 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31
32// AudioAdapterParams.cpp
33
34#include "AudioAdapterParams.h"
35
36#include <Catalog.h>
37#include <Debug.h>
38#include <ParameterWeb.h>
39
40#undef B_TRANSLATION_CONTEXT
41#define B_TRANSLATION_CONTEXT "CortexAudioAdapter"
42
43status_t
44_AudioAdapterParams::store(int32 parameterID, const void* data, size_t size)
45{
46	if (size < sizeof(int32))
47		return B_NO_MEMORY;
48
49	const uint32 d = *(uint32*)data;
50
51	switch (parameterID) {
52		// input format restrictions (0='wildcard')
53		case P_INPUT_FORMAT:
54			inputFormat.format = d;
55			break;
56
57		case P_INPUT_CHANNEL_COUNT:
58			inputFormat.channel_count = d;
59			break;
60
61		// output format restrictions (0='wildcard')
62		case P_OUTPUT_FORMAT:
63			outputFormat.format = d;
64			break;
65
66		case P_OUTPUT_CHANNEL_COUNT:
67			outputFormat.channel_count = d;
68			break;
69
70		default:
71			return B_BAD_INDEX;
72	}
73
74	return B_OK;
75}
76
77status_t _AudioAdapterParams::retrieve(
78	int32										parameterID,
79	void*										data,
80	size_t*									ioSize) {
81
82	if(*ioSize < sizeof(int32)) {
83		*ioSize = sizeof(int32);
84		return B_NO_MEMORY;
85	}
86
87	switch(parameterID) {
88		// input format restrictions (0='wildcard')
89		case P_INPUT_FORMAT:
90			*(uint32*)data = inputFormat.format;
91			break;
92
93		case P_INPUT_CHANNEL_COUNT:
94			*(uint32*)data = inputFormat.channel_count;
95			break;
96
97		// output format restrictions (0='wildcard')
98		case P_OUTPUT_FORMAT:
99			*(uint32*)data = outputFormat.format;
100			PRINT(("P_OUTPUT_FORMAT retrieved\n")); //+++++
101			break;
102
103		case P_OUTPUT_CHANNEL_COUNT:
104			*(uint32*)data = outputFormat.channel_count;
105			break;
106
107		default:
108			return B_BAD_INDEX;
109	}
110
111	return B_OK;
112}
113
114void _AudioAdapterParams::populateGroup(
115	BParameterGroup* 				group) {
116
117	BParameterGroup* inputGroup = group->MakeGroup(B_TRANSLATE("Input format"));
118
119	BNullParameter* groupName;
120	BDiscreteParameter* param;
121
122	groupName = inputGroup->MakeNullParameter(
123		0, B_MEDIA_NO_TYPE, B_TRANSLATE("Input format"), B_GENERIC);
124
125	param = inputGroup->MakeDiscreteParameter(
126		P_INPUT_FORMAT,
127		B_MEDIA_NO_TYPE,
128		B_TRANSLATE("Sample format:"),
129		B_GENERIC);
130	param->AddItem(
131		0,
132		"*");
133	param->AddItem(
134		media_multi_audio_format::B_AUDIO_FLOAT,
135		"float");
136	param->AddItem(
137		media_multi_audio_format::B_AUDIO_SHORT,
138		"short");
139	param->AddItem(
140		media_multi_audio_format::B_AUDIO_INT,
141		"int32");
142	param->AddItem(
143		media_multi_audio_format::B_AUDIO_UCHAR,
144		"uint8");
145
146	param = inputGroup->MakeDiscreteParameter(
147		P_INPUT_CHANNEL_COUNT,
148		B_MEDIA_NO_TYPE,
149		B_TRANSLATE("Channels:"),
150		B_GENERIC);
151	param->AddItem(
152		0,
153		"*");
154	param->AddItem(
155		1,
156		B_TRANSLATE("mono"));
157	param->AddItem(
158		2,
159		B_TRANSLATE("stereo"));
160	param->AddItem(
161		4,
162		"4");
163	param->AddItem(
164		8,
165		"8");
166
167	BParameterGroup* outputGroup = group->MakeGroup(B_TRANSLATE("Output format"));
168
169	groupName = outputGroup->MakeNullParameter(
170		0, B_MEDIA_NO_TYPE, B_TRANSLATE("Output format"), B_GENERIC);
171
172	param = outputGroup->MakeDiscreteParameter(
173		P_OUTPUT_FORMAT,
174		B_MEDIA_NO_TYPE,
175		B_TRANSLATE("Sample format:"),
176		B_GENERIC);
177	param->AddItem(
178		0,
179		"*");
180	param->AddItem(
181		media_multi_audio_format::B_AUDIO_FLOAT,
182		"float");
183	param->AddItem(
184		media_multi_audio_format::B_AUDIO_SHORT,
185		"short");
186	param->AddItem(
187		media_multi_audio_format::B_AUDIO_INT,
188		"int32");
189	param->AddItem(
190		media_multi_audio_format::B_AUDIO_UCHAR,
191		"uint8");
192
193	param = outputGroup->MakeDiscreteParameter(
194		P_OUTPUT_CHANNEL_COUNT,
195		B_MEDIA_NO_TYPE,
196		B_TRANSLATE("Channels:"),
197		B_GENERIC);
198	param->AddItem(
199		0,
200		"*");
201	param->AddItem(
202		1,
203		B_TRANSLATE("mono"));
204	param->AddItem(
205		2,
206		B_TRANSLATE("stereo"));
207	param->AddItem(
208		4,
209		"4");
210	param->AddItem(
211		8,
212		"8");
213}
214
215// END -- AudioAdapterParams.cpp
216
217