关于网友提出的“ c++ 如何获取麦克风收到的声音的音量 根据声音绘制进度条”问题疑问,本网通过在网上对“ c++ 如何获取麦克风收到的声音的音量 根据声音绘制进度条”有关的相关答案进行了整理,供用户进行参考,详细问题解答如下:
问题: c++ 如何获取麦克风收到的声音的音量 根据声音绘制进度条描述:
麦克风接收到一个声音信号,进度条上则产生一定的变化,声音消失后进度条变化消失.
类似于qq的录音功能。
我用wave函数实现了接受到声音,接下来怎么处理呢??
解决方案1:
友情帮顶 额不会啊楼主
解决方案2: 以下节选自MSDN98\SAMPLES\VC98\SDK\GRAPHICS\AUDIO\MIXAPP\MAMETER.C
,仅供参考:
//--------------------------------------------------------------------------;解决方案3:
//
// BOOL MixAppControlChangeMeter
//
// Description:
//
//
// Arguments:
// HWND hwnd:
//
// HMIXER hmx:
//
// DWORD dwControlID:
//
// Return (BOOL):
//
// History:
// 09/22/93
//
//--------------------------------------------------------------------------;
BOOL FNLOCAL MixAppControlChangeMeter
(
HWND hwnd,
HMIXER hmx,
DWORD dwControlID
)
{
MMRESULT mmr;
HWND htxt;
PMACONTROLINSTANCE_METER pmaci_meter;
LPMACONTROLINSTANCE pmaci;
LPMIXERLINE pmxl;
LPMIXERCONTROL pmxctrl;
PMIXERCONTROLDETAILS_SIGNED pmxcd_s;
UINT cChannels;
UINT cMultipleItems;
UINT u;
UINT uIndex;
UINT v;
MIXERCONTROLDETAILS mxcd;
HWND hsbFocus;
HWND hsb;
BOOL fSigned;
DWORD dwRange;
DWORD dwValue;
int nValue;
hsbFocus = GetFocus();
if (NULL == hsbFocus)
{
hsbFocus = GetDlgItem(hwnd, IDD_MACONTROL_MULTICHANNEL_BASE);
}
else
{
uIndex = GetDlgCtrlID(hsbFocus);
if (uIndex < IDD_MACONTROL_MULTICHANNEL_BASE)
{
hsbFocus = GetDlgItem(hwnd, IDD_MACONTROL_MULTICHANNEL_BASE);
}
}
//
//
//
pmaci_meter = (PMACONTROLINSTANCE_METER)(UINT)GetWindowLong(hwnd, DWL_USER);
pmaci = pmaci_meter->pmaci;
pmxl = pmaci->pmxl;
pmxctrl = pmaci->pmxctrl;
pmxcd_s = &pmaci_meter->pmxcd_s[0];
fSigned = pmaci_meter->fSigned;
dwRange = pmaci_meter->dwRange;
cChannels = (UINT)pmxl->cChannels;
if (MIXERCONTROL_CONTROLF_UNIFORM & pmxctrl->fdwControl)
cChannels = 1;
//
//
//
mxcd.cbStruct = sizeof(mxcd);
mxcd.dwControlID = pmxctrl->dwControlID;
mxcd.cChannels = cChannels;
mxcd.cMultipleItems = pmxctrl->cMultipleItems;
mxcd.cbDetails = sizeof(*pmxcd_s);
mxcd.paDetails = pmxcd_s;
mmr = mixerGetControlDetails((HMIXEROBJ)pmaci->hmx, &mxcd, MIXER_GETCONTROLDETAILSF_VALUE);
if (MMSYSERR_NOERROR != mmr)
{
AppMsgBox(hwnd, MB_OK | MB_ICONEXCLAMATION,
"mixerGetControlDetails(ctrlid=%.08lXh) failed on hmx=%.04Xh, mmr=%u!",
pmxctrl->dwControlID, pmaci->hmx, mmr);
return (FALSE);
}
cMultipleItems = 1;
if (MIXERCONTROL_CONTROLF_MULTIPLE & pmxctrl->fdwControl)
cMultipleItems = (UINT)pmxctrl->cMultipleItems;
for (u = 0; u < cChannels; u++)
{
for (v = 0; v < cMultipleItems; v++)
{
uIndex = (u * cMultipleItems) + v;
if (fSigned)
{
dwValue = (DWORD)(pmxcd_s[uIndex].lValue -
pmxctrl->Bounds.lMinimum);
}
else
{
dwValue = (DWORD)pmxcd_s[uIndex].lValue;
dwValue -= pmxctrl->Bounds.dwMinimum;
}
nValue = (int)MulDivRN(dwValue, 32767, dwRange);
//
// Windows is stupid and forces an update to scrollbars
// (a flickering paint) even when the position does not
// change... so don't update if it is already in the
// right position.
//
hsb = GetDlgItem(hwnd, IDD_MACONTROL_MULTICHANNEL_BASE + uIndex);
if (hsbFocus == hsb)
{
htxt = GetDlgItem(hwnd, IDD_MACONTROL_TXT_VALUE);
if (fSigned)
{
AppSetWindowText(htxt, "mapped=%d, lValue=%ld",
nValue,
pmxcd_s[uIndex].lValue);
}
else
{
AppSetWindowText(htxt, "mapped=%d, dwValue=%lu",
nValue,
pmxcd_s[uIndex].lValue);
}
}
if (32767 - nValue == GetScrollPos(hsb, SB_CTL))
continue;
//
// note that we _invert_ the position since a meter will
// increase approaching the top (opposite of scrollbar
// logic)
//
SetScrollPos(hsb, SB_CTL, 32767 - nValue, TRUE);
}
}
//
//
//
mxcd.cbStruct = sizeof(mxcd);
mxcd.dwControlID = pmxctrl->dwControlID;
mxcd.cChannels = 1;
mxcd.cMultipleItems = pmxctrl->cMultipleItems;
mxcd.cbDetails = sizeof(*pmxcd_s);
mxcd.paDetails = pmxcd_s;
mmr = mixerGetControlDetails((HMIXEROBJ)pmaci->hmx, &mxcd, MIXER_GETCONTROLDETAILSF_VALUE);
if (MMSYSERR_NOERROR != mmr)
{
AppMsgBox(hwnd, MB_OK | MB_ICONEXCLAMATION,
"mixerGetControlDetails(ctrlid=%.08lXh) failed on hmx=%.04Xh, mmr=%u!",
pmxctrl->dwControlID, pmaci->hmx, mmr);
return (FALSE);
}
for (v = 0; v < cMultipleItems; v++)
{
uIndex = v;
if (fSigned)
{
dwValue = (DWORD)(pmxcd_s[uIndex].lValue -
pmxctrl->Bounds.lMinimum);
}
else
{
dwValue = (DWORD)pmxcd_s[uIndex].lValue;
dwValue -= pmxctrl->Bounds.dwMinimum;
}
nValue = (int)MulDivRN(dwValue, 32767, dwRange);
hsb = GetDlgItem(hwnd, IDD_MACONTROL_UNIFORM_BASE + uIndex);
if (hsbFocus == hsb)
{
htxt = GetDlgItem(hwnd, IDD_MACONTROL_TXT_VALUE);
if (fSigned)
{
AppSetWindowText(htxt, "mapped=%d, lValue=%ld",
nValue,
pmxcd_s[uIndex].lValue);
}
else
{
AppSetWindowText(htxt, "mapped=%d, dwValue=%lu",
nValue,
pmxcd_s[uIndex].lValue);
}
}
if (32767 - nValue == GetScrollPos(hsb, SB_CTL))
continue;
//
// note that we _invert_ the position since a meter will
// increase approaching the top (opposite of scrollbar
// logic)
//
SetScrollPos(hsb, SB_CTL, 32767 - nValue, TRUE);
}
return (TRUE);
} // MixAppControlChangeMeter()
mixerGetControlDetails
The mixerGetControlDetails function retrieves details about a single control associated with an audio line.
MMRESULT mixerGetControlDetails(
HMIXEROBJ hmxobj,
LPMIXERCONTROLDETAILS pmxcd,
DWORD fdwDetails
);
Parameters
hmxobj
Handle of the mixer device object being queried.
pmxcd
Address of a MIXERCONTROLDETAILS structure, which is filled with state information about the control.
fdwDetails
Flags for retrieving control details. The following values are defined:
MIXER_GETCONTROLDETAILSF_LISTTEXT
The paDetails member of the MIXERCONTROLDETAILS structure points to one or more MIXERCONTROLDETAILS_LISTTEXT structures to receive text labels for multiple-item controls. An application must get all list text items for a multiple-item control at once. This flag cannot be used with MIXERCONTROL_CONTROLTYPE_CUSTOM controls.
MIXER_GETCONTROLDETAILSF_VALUE
Current values for a control are retrieved. The paDetails member of the MIXERCONTROLDETAILS structure points to one or more details structures appropriate for the control class.
MIXER_OBJECTF_AUX
The hmxobj parameter is an auxiliary device identifier in the range of zero to one less than the number of devices returned by the auxGetNumDevs function.
MIXER_OBJECTF_HMIDIIN
The hmxobj parameter is the handle of a MIDI (Musical Instrument Digital Interface) input device. This handle must have been returned by the midiInOpen function.
MIXER_OBJECTF_HMIDIOUT
The hmxobj parameter is the handle of a MIDI output device. This handle must have been returned by the midiOutOpen function.
MIXER_OBJECTF_HMIXER
The hmxobj parameter is a mixer device handle returned by the mixerOpen function. This flag is optional.
MIXER_OBJECTF_HWAVEIN
The hmxobj parameter is a waveform-audio input handle returned by the waveInOpen function.
MIXER_OBJECTF_HWAVEOUT
The hmxobj parameter is a waveform-audio output handle returned by the waveOutOpen function.
MIXER_OBJECTF_MIDIIN
The hmxobj parameter is the identifier of a MIDI input device. This identifier must be in the range of zero to one less than the number of devices returned by the midiInGetNumDevs function.
MIXER_OBJECTF_MIDIOUT
The hmxobj parameter is the identifier of a MIDI output device. This identifier must be in the range of zero to one less than the number of devices returned by the midiOutGetNumDevs function.
MIXER_OBJECTF_MIXER
The hmxobj parameter is the identifier of a mixer device in the range of zero to one less than the number of devices returned by the mixerGetNumDevs function. This flag is optional.
MIXER_OBJECTF_WAVEIN
The hmxobj parameter is the identifier of a waveform-audio input device in the range of zero to one less than the number of devices returned by the waveInGetNumDevs function.
MIXER_OBJECTF_WAVEOUT
The hmxobj parameter is the identifier of a waveform-audio output device in the range of zero to one less than the number of devices returned by the waveOutGetNumDevs function.
Return Values
Returns MMSYSERR_NOERROR if successful or an error otherwise. Possible error values include the following:
Value Description
MIXERR_INVALCONTROL The control reference is invalid.
MMSYSERR_BADDEVICEID The hmxobj parameter specifies an invalid device identifier.
MMSYSERR_INVALFLAG One or more flags are invalid.
MMSYSERR_INVALHANDLE The hmxobj parameter specifies an invalid handle.
MMSYSERR_INVALPARAM One or more parameters are invalid.
MMSYSERR_NODRIVER No mixer device is available for the object specified by hmxobj.
Remarks
All members of the MIXERCONTROLDETAILS structure must be initialized before calling this function.
QuickInfo
Windows NT: Requires version 3.1 or later.
Windows: Requires Windows 95 or later.
Windows CE: Unsupported.
Header: Declared in mmsystem.h.
Import Library: Use winmm.lib.
Unicode: Implemented as Unicode and ANSI versions on Windows NT.
See Also
Audio Mixers Overview, Audio Mixer Functions, MIXERCONTROLDETAILS, MIXERCONTROLDETAILS_LISTTEXT, auxGetNumDevs, midiInOpen, midiOutOpen, mixerOpen, waveInOpen, waveOutOpen, midiInGetNumDevs, midiOutGetNumDevs, mixerGetNumDevs, waveInGetNumDevs, waveOutGetNumDevs