【VC开源代码栏目提醒】:网学会员为广大网友收集整理了,MIXERINFO.CPP,希望对大家有所帮助!
//=============================================================================
// Copyright Langis Pitre 1998
// You may do whatever you want with this code, as long as you include this
// copyright notice in your implementation files.
//
// If you wish to add new classes to this collection, feel free to do so.
// But please send me your code so that I can update the collection.
//
// Comments and bug reports: lpitre@sympatico.ca
//
//=============================================================================
// MixerInfo.cpp
//
// Utility function to list all available options of your mixer device interface
//
//=============================================================================
#include "stdafx.h"
#include "MixerInfo.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
// Helper functions used by GetDevicesInfo
static void PrintLineType( int nIndent, MIXERLINE &line, FILE *file );
static void PrintControl( HMIXEROBJ mixer, MIXERLINE &line, MIXERCONTROL &control, FILE *file );
//mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm
// Name : GetDevicesInfo
//
// Descr. : Finds all the input and output lines, and all mixer controls
// available through the audio mixer device.
//
// Use GetDevicesInfo() to find out the capabilities of your sound card.
// Check the the file and note the type and number of destination (output)
// lines, as well as the source (input) lines associated with every
// destination line. Note also the type of the controls available.
// You will need these to create your windows controls.
//
// Return : void
// Arg : LPCSTR filename :
//-----------------------------------------------------------------------------
void GetDevicesInfo( LPCSTR filename )
{
FILE *file;
UINT nbMixers = mixerGetNumDevs();
if( nbMixers < 1 )
{
AfxMessageBox( "No mixer device present" );
return;
}
file = fopen( filename, "w" );
if( file == NULL )
{
AfxMessageBox("Could not open file.");
return;
}
HMIXER hMixer;
if( mixerOpen( &hMixer, 0, 0, 0, 0 ) != MMSYSERR_NOERROR )
{
AfxMessageBox( "Could not open mixer device" );
return;
}
MIXERCAPS caps;
if( mixerGetDevCaps( ( UINT )hMixer, &caps, sizeof( MIXERCAPS ) ) != MMSYSERR_NOERROR )
{
fclose( file );
mixerClose(hMixer);
return;
}
fprintf( file, "Name of device: %s\n", caps.szPname );
fprintf( file, "Number of destination lines: %d\n\n", caps.cDestinations );
fprintf( file, "\nPay particular attention to the \"Line type\" and \"Control type\" lines.\n"
"You will pass these to the Init() functions of the various CMixerBase-derived classes\n"
"to specify which type of control you want to use.\n");
MIXERLINE line;
MIXERLINECONTROLS mixerLineControl;
MIXERCONTROL *pMixerControl;
int nDest = caps.cDestinations;
for( int i = 0; i < nDest; i++ )
{
line.cbStruct = sizeof( MIXERLINE );
line.dwSource = 0;
line.dwDestination = i;
mixerGetLineInfo( ( HMIXEROBJ )hMixer, &line, MIXER_GETLINEINFOF_DESTINATION );
fprintf( file, "\n***************************************************************************************************\n");
fprintf( file, "** Destination line. Index = %d *******************************************************************\n", i );
fprintf( file, "***************************************************************************************************\n");
PrintLineType( 0, line, file );
pMixerControl = new MIXERCONTROL[line.cControls];
ASSERT( pMixerControl != NULL );
mixerLineControl.cbStruct = sizeof( MIXERLINECONTROLS );
mixerLineControl.dwLineID = line.dwLineID;
mixerLineControl.cControls = line.cControls;
mixerLineControl.cbmxctrl = sizeof( MIXERCONTROL );
mixerLineControl.pamxctrl = pMixerControl;
mixerGetLineControls( ( HMIXEROBJ )hMixer, &mixerLineControl, MIXER_GETLINECONTROLSF_ALL );
UINT ncontrols = line.cControls;
for( UINT k = 0; k < ncontrols; k++ )
{
PrintControl( ( HMIXEROBJ )hMixer, line, pMixerControl[k], file );
}
delete[] pMixerControl;
// for each destination line, list the source lines and their controls
UINT nconn = line.cConnections;
for( UINT j = 0; j < nconn; j++ )
{
line.cbStruct = sizeof( MIXERLINE );
line.dwSource = j;
line.dwDestination = i;
mixerGetLineInfo( ( HMIXEROBJ )hMixer, &a