📄 devctxt.cpp
字号:
//-----------------------------------------------------------------------------
// Copyright (c) Wolfson Microelectronics plc. All rights reserved.
//
// This software as well as any related documentation is furnished under
// license and may only be used or copied in accordance with the terms of the
// license. The information in this file is furnished for informational use
// only, is subject to change without notice, and should not be construed as
// a commitment by Wolfson Microelectronics plc. Wolfson Microelectronics plc
// assumes no responsibility or liability for any errors or inaccuracies that
// may appear in this document or any software that may be provided in
// association with this document.
//
// Except as permitted by such license, no part of this document may be
// reproduced, stored in a retrieval system, or transmitted in any form or by
// any means without the express written consent of Wolfson Microelectronics plc.
//
// $Id: devctxt.cpp 1796 2005-06-10 15:46:04Z ian $
//
// This file handles the device context for the WaveDev2 driver for
// Wolfson codecs.
//
// Warning:
// This driver is specifically written for Wolfson Audio Codecs. It is
// not a general audio CODEC device driver.
//-----------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
// -----------------------------------------------------------------------------
//
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// -----------------------------------------------------------------------------
#include "wavemain.h"
BOOL DeviceContext::IsSupportedFormat(LPWAVEFORMATEX lpFormat)
{
if (lpFormat->wFormatTag != WAVE_FORMAT_PCM)
return FALSE;
if ( (lpFormat->nChannels!=1) && (lpFormat->nChannels!=2) )
return FALSE;
if ( (lpFormat->wBitsPerSample!=8) && (lpFormat->wBitsPerSample!=16) )
return FALSE;
if (lpFormat->nSamplesPerSec < 100 || lpFormat->nSamplesPerSec > 192000)
return FALSE;
return TRUE;
}
// We also support MIDI on output
BOOL HiFiOutputDeviceContext::IsSupportedFormat(LPWAVEFORMATEX lpFormat)
{
if (lpFormat->wFormatTag == WAVE_FORMAT_MIDI)
{
return TRUE;
}
return DeviceContext::IsSupportedFormat(lpFormat);
}
#if WM_VOICE
// We also support MIDI on output
BOOL VoiceOutputDeviceContext::IsSupportedFormat(LPWAVEFORMATEX lpFormat)
{
if (lpFormat->wFormatTag == WAVE_FORMAT_MIDI)
{
return TRUE;
}
return DeviceContext::IsSupportedFormat(lpFormat);
}
#endif // WM_VOICE
#if WM_MONODAC
// We also support MIDI on output
BOOL MonoOutputDeviceContext::IsSupportedFormat(LPWAVEFORMATEX lpFormat)
{
if (lpFormat->wFormatTag == WAVE_FORMAT_MIDI)
{
return TRUE;
}
return DeviceContext::IsSupportedFormat(lpFormat);
}
#endif // WM_MONODAC
// Assumes lock is taken
void DeviceContext::NewStream(StreamContext *pStreamContext)
{
InsertTailList(&m_StreamList,&pStreamContext->m_Link);
}
// Assumes lock is taken
void DeviceContext::DeleteStream(StreamContext *pStreamContext)
{
RemoveEntryList(&pStreamContext->m_Link);
}
// Returns # of samples of output buffer filled
// Assumes that g_pHWContext->Lock already held.
PBYTE DeviceContext::TransferBuffer(PBYTE pBuffer, PBYTE pBufferEnd, DWORD *pNumStreams)
{
PLIST_ENTRY pListEntry;
StreamContext *pStreamContext;
PBYTE pBufferLastThis;
PBYTE pBufferLast=pBuffer;
DWORD NumStreams=0;
pListEntry = m_StreamList.Flink;
while (pListEntry != &m_StreamList)
{
// Get a pointer to the stream context
pStreamContext = CONTAINING_RECORD(pListEntry,StreamContext,m_Link);
// Note: The stream context may be closed and removed from the list inside
// of Render, and the context may be freed as soon as we call Release.
// Therefore we need to grab the next Flink first in case the
// entry disappears out from under us.
pListEntry = pListEntry->Flink;
// Render buffers
pStreamContext->AddRef();
pBufferLastThis = pStreamContext->Render(pBuffer, pBufferEnd, pBufferLast);
pStreamContext->Release();
if (pBufferLastThis>pBuffer)
{
NumStreams++;
}
if (pBufferLast < pBufferLastThis)
{
pBufferLast = pBufferLastThis;
}
}
if (pNumStreams)
{
*pNumStreams=NumStreams;
}
return pBufferLast;
}
void DeviceContext::RecalcAllGains()
{
PLIST_ENTRY pListEntry;
StreamContext *pStreamContext;
for (pListEntry = m_StreamList.Flink;
pListEntry != &m_StreamList;
pListEntry = pListEntry->Flink)
{
pStreamContext = CONTAINING_RECORD(pListEntry,StreamContext,m_Link);
pStreamContext->GainChange();
}
return;
}
void HiFiOutputDeviceContext::StreamReadyToRender(StreamContext *pStreamContext)
{
g_pHWContext->StartHiFiOutputDMA();
return;
}
void HiFiInputDeviceContext::StreamReadyToRender(StreamContext *pStreamContext)
{
g_pHWContext->StartHiFiInputDMA();
return;
}
#if WM_VOICE
void VoiceOutputDeviceContext::StreamReadyToRender(StreamContext *pStreamContext)
{
g_pHWContext->StartVoiceOutputDMA();
return;
}
void VoiceInputDeviceContext::StreamReadyToRender(StreamContext *pStreamContext)
{
g_pHWContext->StartVoiceInputDMA();
return;
}
#endif // WM_VOICE
#if WM_MONODAC
void MonoOutputDeviceContext::StreamReadyToRender(StreamContext *pStreamContext)
{
g_pHWContext->StartMonoOutputDMA();
return;
}
#endif // WM_MONODAC
DWORD HiFiOutputDeviceContext::GetDevCaps(LPVOID pCaps, DWORD dwSize)
{
static const WAVEOUTCAPS wc =
{
MM_MICROSOFT,
MM_MSFT_GENERIC_WAVEOUT,
WM_VERSION,
TEXT("Wolfson Codec Audio HiFi Output"),
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
#if !defined(MONO_GAIN)
| WAVECAPS_LRVOLUME
#endif
};
memcpy( pCaps, &wc, min(dwSize,sizeof(wc)));
return MMSYSERR_NOERROR;
}
DWORD HiFiInputDeviceContext::GetDevCaps(LPVOID pCaps, DWORD dwSize)
{
static const WAVEINCAPS wc =
{
MM_MICROSOFT,
MM_MSFT_GENERIC_WAVEIN,
WM_VERSION,
TEXT("Wolfson Codec Audio HiFi Input"),
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
};
memcpy( pCaps, &wc, min(dwSize,sizeof(wc)));
return MMSYSERR_NOERROR;
}
#if WM_VOICE
DWORD VoiceOutputDeviceContext::GetDevCaps(LPVOID pCaps, DWORD dwSize)
{
static const WAVEOUTCAPS wc =
{
MM_MICROSOFT,
MM_MSFT_GENERIC_WAVEOUT,
WM_VERSION,
TEXT("Wolfson Codec Voice Output"),
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;
}
DWORD VoiceInputDeviceContext::GetDevCaps(LPVOID pCaps, DWORD dwSize)
{
static const WAVEINCAPS wc =
{
MM_MICROSOFT,
MM_MSFT_GENERIC_WAVEIN,
WM_VERSION,
TEXT("Wolfson Codec Audio Voice Input"),
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
};
memcpy( pCaps, &wc, min(dwSize,sizeof(wc)));
return MMSYSERR_NOERROR;
}
#endif // WM_VOICE
#if WM_MONODAC
DWORD MonoOutputDeviceContext::GetDevCaps(LPVOID pCaps, DWORD dwSize)
{
static const WAVEOUTCAPS wc =
{
MM_MICROSOFT,
MM_MSFT_GENERIC_WAVEOUT,
WM_VERSION,
TEXT("Wolfson Codec Mono DAC Output"),
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -