Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.

Q: mixer API

Skoðað 0 sinnum
Fara í fyrstu ólesnu skilaboð

EnviTech AS

ólesið,
3. maí 2000, 03:00:003.5.2000
til
In my windows mixer "Recording control" I can "Select" which control to
use for recording: MIDI, CD, Wave, Mic etc. But I can't find out how to
set this on/off with the mixer API. I only now how to adjust the rec
volume on each control

Anyone done this before?


Bev M Ewen-Smith

ólesið,
3. maí 2000, 03:00:003.5.2000
til
You could try this - it works for me but beware that the names of the inputs
vary from installation to installation.

Regards

Bev

--
Bev and Jan Ewen-Smith
COAA, sítio do Poio, Mexilhoeira Grande 8500-149, Portugal
Tel 00 351 282 471180 Fax 00 351 282 471516
><> co...@mail.telepac.pt www.ip.pt/coaa ><>

-----
// set mixer to line
SelectSource("Auxiliary"); // or line in or auxiliary or analog
SetVolume("Auxiliary",volumesetting);
UnMute("Auxiliary"); // or "_LINE"
// Auxiliary/Line-In/Analog
// Microphone
// CD/CD Record
// Wave/Wave Record
--------
void CBirdsDoc::UnMute(char componentsource[])
{
// Open the mixer device
HMIXER hmx;
mixerOpen(&hmx, 0, 0, 0, 0);

// Get the line info for the wave in destination line
MIXERLINE mxl;
mxl.cbStruct = sizeof(mxl);
mxl.dwComponentType = MIXERLINE_COMPONENTTYPE_DST_WAVEIN;
mixerGetLineInfo((HMIXEROBJ)hmx, &mxl, MIXER_GETLINEINFOF_COMPONENTTYPE);

// Now find the microphone (or whatever) source line connected to this wave in
// destination
DWORD cConnections = mxl.cConnections;
for(DWORD j=0; j<cConnections; j++)
{
mxl.dwSource = j;
mixerGetLineInfo((HMIXEROBJ)hmx, &mxl, MIXER_GETLINEINFOF_SOURCE);
if (strcmp(componentsource,mxl.szName) == 0)
break;
}
// Find a mute control, if any, of the microphone line
LPMIXERCONTROL pmxctrl = (LPMIXERCONTROL)malloc(sizeof MIXERCONTROL);
MIXERLINECONTROLS mxlctrl = {sizeof mxlctrl, mxl.dwLineID,
MIXERCONTROL_CONTROLTYPE_MUTE, 1, sizeof MIXERCONTROL, pmxctrl};
if(!mixerGetLineControls((HMIXEROBJ) hmx, &mxlctrl,MIXER_GETLINECONTROLSF_ONEBYTYPE))
{
// Found, so proceed
DWORD cChannels = mxl.cChannels;
if (MIXERCONTROL_CONTROLF_UNIFORM & pmxctrl->fdwControl)
cChannels = 1;

LPMIXERCONTROLDETAILS_BOOLEAN pbool =
(LPMIXERCONTROLDETAILS_BOOLEAN) malloc(cChannels *
sizeof(MIXERCONTROLDETAILS_BOOLEAN));
MIXERCONTROLDETAILS mxcd = {sizeof(mxcd),
pmxctrl->dwContro
lID,cChannels, (HWND)0,
sizeof MIXERCONTROLDETAILS_BOOLEAN, (LPVOID) pbool};
mixerGetControlDetails((HMIXEROBJ)hmx,
&mxcd,MIXER_SETCONTROLDETAILSF_VALUE);
// Unmute the microphone line (for both channels)
pbool[0].fValue = pbool[cChannels - 1].fValue = 0;
mixerSetControlDetails((HMIXEROBJ)hmx,
&mxcd,MIXER_SETCONTROLDETAILSF_VALUE);

free(pmxctrl);
free(pbool);
}
else
free(pmxctrl);

mixerClose(hmx);

}

void CBirdsDoc::SetVolume(char componentsource[],int level)
{
// Open the mixer device
HMIXER hmx;
mixerOpen(&hmx, 0, 0, 0, 0);

// Get the line info for the wave in destination line
MIXERLINE mxl;
mxl.cbStruct = sizeof(mxl);
mxl.dwComponentType = MIXERLINE_COMPONENTTYPE_DST_WAVEIN;
mixerGetLineInfo((HMIXEROBJ)hmx, &mxl,MIXER_GETLINEINFOF_COMPONENTTYPE);

// Now find the microphone source line connected to this wave in
// destination
DWORD cConnections = mxl.cConnections;
for(DWORD j=0; j<cConnections; j++)
{
mxl.dwSource = j;
mixerGetLineInfo((HMIXEROBJ)hmx, &mxl, MIXER_GETLINEINFOF_SOURCE);
// if (componentsource == mxl.dwComponentType)
if (strcmp(componentsource,mxl.szName) == 0) // TEST naming
break;
}
// Find a volume control, if any, of the microphone line
LPMIXERCONTROL pmxctrl = (LPMIXERCONTROL)malloc(sizeof MIXERCONTROL);
MIXERLINECONTROLS mxlctrl = {sizeof mxlctrl, mxl.dwLineID,
MIXERCONTROL_CONTROLTYPE_VOLUME, 1, sizeof MIXERCONTROL, pmxctrl};
if(!mixerGetLineControls((HMIXEROBJ) hmx, &mxlctrl,MIXER_GETLINECONTROLSF_ONEBYTYPE))
{
// Found!
DWORD cChannels = mxl.cChannels;
if (MIXERCONTROL_CONTROLF_UNIFORM & pmxctrl->fdwControl)
cChannels = 1;

LPMIXERCONTROLDETAILS_UNSIGNED pUnsigned = (LPMIXERCONTROLDETAILS_UNSIGNED)
malloc(cChannels * sizeof MIXERCONTROLDETAILS_UNSIGNED);
MIXERCONTROLDETAILS mxcd = {sizeof(mxcd),
pmxctrl->dwControlID,cChannels, (HWND)0,
sizeof MIXERCONTROLDETAILS_UNSIGNED, (LPVOID) pUnsigned};
mixerGetControlDetails((HMIXEROBJ)hmx,

&mxcd,MIXER_SETCONTROLDETAILSF_VALUE);
// Set the volume to the middle (for both channels as needed)
pUnsigned[0].dwValue = pUnsigned[cChannels - 1].dwValue =

(DWORD)((pmxctrl->Bounds.dwMinimum+pmxctrl->Bounds.dwMaximum)*level/20.0);
mixerSetControlDetails((HMIXEROBJ)hmx,
&mxcd,MIXER_SETCONTROLDETAILSF_VALUE);

free(pmxctrl);
free(pUnsigned);
}
else
free(pmxctrl);
mixerClose(hmx);
}

void CBirdsDoc::SelectSource(char *sourcename)
{
// Open the mixer device
HMIXER hmx;
mixerOpen(&hmx, 0, 0, 0, 0);

// Get the line info for the wave in destination line
MIXERLINE mxl;
mxl.cbStruct = sizeof(mxl);
mxl.dwComponentType = MIXERLINE_COMPONENTTYPE_DST_WAVEIN;
mixerGetLineInfo((HMIXEROBJ)hmx, &mxl,MIXER_GETLINEINFOF_COMPONENTTYPE);

// Find a LIST control, if any, for the wave in line
LPMIXERCONTROL pmxctrl = (LPMIXERCONTROL)malloc(mxl.cControls * sizeof(MIXERCONTROL));
MIXERLINECONTROLS mxlctrl = {sizeof mxlctrl, mxl.dwLineID, 0,mxl.cControls, sizeof MIXERCONTROL, pmxctrl};
mixerGetLineControls((HMIXEROBJ) hmx, &mxlctrl,MIXER_GETLINECONTROLSF_ALL);

// Now walk through each control to find a type of LIST control. This
// can be either Mux, Single-select, Mixer or Multiple-select.
DWORD i;
for(i=0; i < mxl.cControls; i++)
if (MIXERCONTROL_CT_CLASS_LIST == (pmxctrl[i].dwControlType &MIXERCONTROL_CT_CLASS_MASK))
break;
if (i < mxl.cControls)
{ // Found a LIST control
// Check if the LIST control is a Mux or Single-select type
BOOL bOneItemOnly = FALSE;
switch (pmxctrl[i].dwControlType) {
case MIXERCONTROL_CONTROLTYPE_MUX:
case MIXERCONTROL_CONTROLTYPE_SINGLESELECT:

bOneItemOnly = TRUE;
}

DWORD cChannels = mxl.cChannels, cMultipleItems = 0;
if (MIXERCONTROL_CONTROLF_UNIFORM & pmxctrl[i].fdwControl)
cChannels = 1;
if (MIXERCONTROL_CONTROLF_MULTIPLE & pmxctrl[i].fdwControl)
cMultipleItems = pmxctrl[i].cMultipleItems;

// Get the text description of each item

LPMIXERCONTROLDETAILS_LISTTEXT plisttext =
(LPMIXERCONTROLDETAILS_LISTTEXT)malloc(cChannels * cMultipleItems *
sizeof(MIXERCONTROLDETAILS_LISTTEXT));
MIXERCONTROLDETAILS mxcd = {sizeof(mxcd),
pmxctrl[i].dwControlID,cChannels,
(HWND)cMultipleItems, sizeof MIXERCONTROLDETAILS_LISTTEXT,(LPVOID)
plisttext};
mixerGetControlDetails((HMIXEROBJ)hmx, &mxcd,
MIXER_GETCONTROLDETAILSF_LISTTEXT);

// Now get the value for each item
LPMIXERCONTROLDETAILS_BOOLEAN plistbool
=(LPMIXERCONTROLDETAILS_BOOLEAN)malloc(cChannels * cMultipleItems *
sizeof(MIXERCONTROLDETAILS_BOOLEAN));
mxcd.cbDetails = sizeof MIXERCONTROLDETAILS_BOOLEAN;
mxcd.paDetails = plistbool;
mixerGetControlDetails((HMIXEROBJ)hmx,
&mxcd,MIXER_GETCONTROLDETAILSF_VALUE);

// Select the "Microphone" item
for (DWORD j=0; j<cMultipleItems; j = j + cChannels)
if (0 == strcmp(plisttext[j].szName, sourcename))
// Select it for both left and right channels
plistbool[j].fValue = plistbool[j+ cChannels - 1].fValue = 1;
file://else if (bOneItemOnly) ---- deselect the others
else
// Mux or Single-select allows only one item to be selected
// so clear other items as necessary
plistbool[j].fValue = plistbool[j+ cChannels - 1].fValue = 0;
// Now actually set the new values in
mixerSetControlDetails((HMIXEROBJ)hmx,
&mxcd,MIXER_GETCONTROLDETAILSF_VALUE);

free(pmxctrl);
free(plisttext);
free(plistbool);
}
else
free(pmxctrl);
mixerClose(hmx);
}

0 ný skilaboð