📄 devctxt.cpp
字号:
WAVE_FORMAT_1M08 | WAVE_FORMAT_2M08 | WAVE_FORMAT_4M08 |
WAVE_FORMAT_1S08 | WAVE_FORMAT_2S08 | WAVE_FORMAT_4S08 |
WAVE_FORMAT_1M16 | WAVE_FORMAT_2M16 | WAVE_FORMAT_4M16 |
WAVE_FORMAT_1S16 | WAVE_FORMAT_2S16 | WAVE_FORMAT_4S16,
NumChannels(),
0, // Reserved
WAVECAPS_VOLUME | WAVECAPS_PLAYBACKRATE
};
memcpy( pCaps, &wc, min(dwSize,sizeof(wc)));
return MMSYSERR_NOERROR;
}
#endif // WM_MONODDAC
DWORD HiFiOutputDeviceContext::GetExtDevCaps(LPVOID pCaps, DWORD dwSize)
{
static const WAVEOUTEXTCAPS wec =
{
0x0000FFFF, // max number of hw-mixed streams
0x0000FFFF, // available HW streams
SampleRate(), // preferred sample rate for software mixer (0 indicates no preference)
0, // preferred buffer size for software mixer (0 indicates no preference)
0, // preferred number of buffers for software mixer (0 indicates no preference)
8000, // minimum sample rate for a hw-mixed stream
48000 // maximum sample rate for a hw-mixed stream
};
memcpy( pCaps, &wec, min(dwSize,sizeof(wec)));
return MMSYSERR_NOERROR;
}
DWORD HiFiInputDeviceContext::GetExtDevCaps(LPVOID pCaps, DWORD dwSize)
{
return MMSYSERR_NOTSUPPORTED;
}
#if WM_VOICE
DWORD VoiceOutputDeviceContext::GetExtDevCaps(LPVOID pCaps, DWORD dwSize)
{
static const WAVEOUTEXTCAPS wec =
{
0x0000FFFF, // max number of hw-mixed streams
0x0000FFFF, // available HW streams
SampleRate(), // preferred sample rate for software mixer (0 indicates no preference)
0, // preferred buffer size for software mixer (0 indicates no preference)
0, // preferred number of buffers for software mixer (0 indicates no preference)
8000, // minimum sample rate for a hw-mixed stream
48000 // maximum sample rate for a hw-mixed stream
};
memcpy( pCaps, &wec, min(dwSize,sizeof(wec)));
return MMSYSERR_NOERROR;
}
DWORD VoiceInputDeviceContext::GetExtDevCaps(LPVOID pCaps, DWORD dwSize)
{
return MMSYSERR_NOTSUPPORTED;
}
#endif // WM_VOICE
#if WM_MONODAC
DWORD MonoOutputDeviceContext::GetExtDevCaps(LPVOID pCaps, DWORD dwSize)
{
static const WAVEOUTEXTCAPS wec =
{
0x0000FFFF, // max number of hw-mixed streams
0x0000FFFF, // available HW streams
SampleRate(), // preferred sample rate for software mixer (0 indicates no preference)
0, // preferred buffer size for software mixer (0 indicates no preference)
0, // preferred number of buffers for software mixer (0 indicates no preference)
8000, // minimum sample rate for a hw-mixed stream
48000 // maximum sample rate for a hw-mixed stream
};
memcpy( pCaps, &wec, min(dwSize,sizeof(wec)));
return MMSYSERR_NOERROR;
}
#endif // WM_MONODAC
StreamContext *HiFiInputDeviceContext::CreateStream(LPWAVEOPENDESC lpWOD)
{
if ( 2 == NumChannels() )
{
return new StereoInputStreamContext;
}
else
{
return new MonoInputStreamContext;
}
}
StreamContext *HiFiOutputDeviceContext::CreateStream(LPWAVEOPENDESC lpWOD)
{
LPWAVEFORMATEX lpFormat=lpWOD->lpFormat;
if (lpWOD->lpFormat->wFormatTag == WAVE_FORMAT_MIDI)
{
return new CMidiStream;
}
if ( 2 == NumChannels() ) // Stereo
{
if (lpFormat->nChannels==1)
{
if (lpFormat->wBitsPerSample==8)
{
return new OutputStreamContextM8S;
}
else
{
return new OutputStreamContextM16S;
}
}
else
{
if (lpFormat->wBitsPerSample==8)
{
return new OutputStreamContextS8S;
}
else
{
return new OutputStreamContextS16S;
}
}
}
else // Mono
{
if (lpFormat->nChannels==1)
{
if (lpFormat->wBitsPerSample==8)
{
return new OutputStreamContextM8M;
}
else
{
return new OutputStreamContextM16M;
}
}
else
{
if (lpFormat->wBitsPerSample==8)
{
return new OutputStreamContextS8M;
}
else
{
return new OutputStreamContextS16M;
}
}
}
}
#if WM_VOICE
StreamContext *VoiceOutputDeviceContext::CreateStream(LPWAVEOPENDESC lpWOD)
{
LPWAVEFORMATEX lpFormat=lpWOD->lpFormat;
if (lpWOD->lpFormat->wFormatTag == WAVE_FORMAT_MIDI)
{
return new CMidiStream;
}
if ( 1 != NumChannels() ) // ! Mono
{
ASSERT(FALSE); // Defined as 1 (devctxt.h) => this should NEVER happen
RETAILMSG ( ZONE_ERROR,
( TEXT("VoiceOutputDeviceContext::CreateStream failed\r\n") )
);
return (StreamContext *)NULL;
}
if (lpFormat->nChannels==1) // Mono
{
if (lpFormat->wBitsPerSample==8)
{
return new OutputStreamContextM8M;
}
else
{
return new OutputStreamContextM16M;
}
}
else
{
if (lpFormat->wBitsPerSample==8)
{
return new OutputStreamContextS8M;
}
else
{
return new OutputStreamContextS16M;
}
}
}
StreamContext *VoiceInputDeviceContext::CreateStream(LPWAVEOPENDESC lpWOD)
{
if ( 2 == NumChannels() )
{
return new StereoInputStreamContext;
}
else
{
return new MonoInputStreamContext;
}
}
#endif // WM_VOICE
#if WM_MONODAC
StreamContext *MonoOutputDeviceContext::CreateStream(LPWAVEOPENDESC lpWOD)
{
LPWAVEFORMATEX lpFormat=lpWOD->lpFormat;
if (lpWOD->lpFormat->wFormatTag == WAVE_FORMAT_MIDI)
{
return new CMidiStream;
}
if ( 1 != NumChannels() ) // ! Mono
{
ASSERT(FALSE); // Defined as 1 (devctxt.h) => this should NEVER happen
RETAILMSG ( ZONE_ERROR,
( TEXT("MonoOutputDeviceContext::CreateStream failed\r\n") )
);
return (StreamContext *)NULL;
}
if (lpFormat->nChannels==1) // Mono
{
if (lpFormat->wBitsPerSample==8)
{
return new OutputStreamContextM8MW;
}
else
{
return new OutputStreamContextM16MW;
}
}
else
{
if (lpFormat->wBitsPerSample==8)
{
return new OutputStreamContextS8MW;
}
else
{
return new OutputStreamContextS16MW;
}
}
}
#endif // WM_MONODAC
DWORD DeviceContext::OpenStream(LPWAVEOPENDESC lpWOD, DWORD dwFlags, StreamContext **ppStreamContext)
{
HRESULT Result;
StreamContext *pStreamContext;
if (lpWOD->lpFormat==NULL)
{
return WAVERR_BADFORMAT;
}
if (!IsSupportedFormat(lpWOD->lpFormat))
{
return WAVERR_BADFORMAT;
}
// Query format support only - don't actually open device?
if (dwFlags & WAVE_FORMAT_QUERY)
{
return MMSYSERR_NOERROR;
}
//
// Set up our inverse sample rate, in 0.32 fixed format.
// Note we have to do this here because if we do it in the constructor,
// it picks up the default sample rate instead.
//
m_invSampleRate = ((UINT32)(((1i64<<32)/SampleRate())+1));
pStreamContext = CreateStream(lpWOD);
if (!pStreamContext)
{
return MMSYSERR_NOMEM;
}
Result = pStreamContext->Open(this,lpWOD,dwFlags);
if (FAILED(Result))
{
delete pStreamContext;
return MMSYSERR_ERROR;
}
*ppStreamContext=pStreamContext;
return MMSYSERR_NOERROR;
}
//------------------------------- END OF FILE ----------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -