bool CWAVFile::ProcessWAVEFORMATEX() { if (!m_fmtdata || m_fmtsize < sizeof(WAVEFORMATEX)) { return false; } WAVEFORMATEX* wfe = (WAVEFORMATEX*)m_fmtdata; if (wfe->wFormatTag == WAVE_FORMAT_EXTENSIBLE && m_fmtsize >= sizeof(WAVEFORMATEXTENSIBLE)) { WAVEFORMATEXTENSIBLE* wfex = (WAVEFORMATEXTENSIBLE*)m_fmtdata; m_subtype = wfex->SubFormat; if (CountBits(wfex->dwChannelMask) != wfex->Format.nChannels) { // fix incorrect dwChannelMask wfex->dwChannelMask = GetDefChannelMask(wfex->Format.nChannels); } } else { m_subtype = FOURCCMap(wfe->wFormatTag); } if (wfe->wFormatTag == WAVE_FORMAT_PCM && (wfe->nChannels > 2 || wfe->wBitsPerSample != 8 && wfe->wBitsPerSample != 16) || wfe->wFormatTag == WAVE_FORMAT_IEEE_FLOAT && wfe->nChannels > 2) { // convert incorrect WAVEFORMATEX to WAVEFORMATEXTENSIBLE WAVEFORMATEXTENSIBLE* wfex = DNew WAVEFORMATEXTENSIBLE; wfex->Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE; wfex->Format.nChannels = wfe->nChannels; wfex->Format.nSamplesPerSec = wfe->nSamplesPerSec; wfex->Format.wBitsPerSample = (wfe->wBitsPerSample + 7) & ~7; wfex->Format.nBlockAlign = wfex->Format.nChannels * wfex->Format.wBitsPerSample / 8; wfex->Format.nAvgBytesPerSec = wfex->Format.nSamplesPerSec * wfex->Format.nBlockAlign; wfex->Format.cbSize = 22; wfex->Samples.wValidBitsPerSample = wfe->wBitsPerSample; wfex->dwChannelMask = GetDefChannelMask(wfe->nChannels); wfex->SubFormat = m_subtype; delete[] m_fmtdata; m_fmtdata = (BYTE*)wfex; m_fmtsize = sizeof(WAVEFORMATEXTENSIBLE); wfe = (WAVEFORMATEX*)m_fmtdata; } m_samplerate = wfe->nSamplesPerSec; m_bitdepth = wfe->wBitsPerSample; m_channels = wfe->nChannels; if (wfe->wFormatTag == WAVE_FORMAT_EXTENSIBLE && m_fmtsize >= sizeof(WAVEFORMATEXTENSIBLE)) { m_layout = ((WAVEFORMATEXTENSIBLE*)m_fmtdata)->dwChannelMask; } else { m_layout = GetDefChannelMask(wfe->nChannels); } m_nAvgBytesPerSec = wfe->nAvgBytesPerSec; m_nBlockAlign = wfe->nBlockAlign; m_blocksize = max(m_nBlockAlign, m_nAvgBytesPerSec / 16); // 62.5 ms m_blocksize -= m_blocksize % m_nBlockAlign; return true; }
static DWORD GetChannelLayout(const WAVEFORMATEX* wfe) { DWORD channel_layout = 0; if (wfe->wFormatTag == WAVE_FORMAT_EXTENSIBLE) { channel_layout = ((WAVEFORMATEXTENSIBLE*)wfe)->dwChannelMask; } if (channel_layout == 0) { channel_layout = GetDefChannelMask(wfe->nChannels); } return channel_layout; }
bool CMpcAudioRendererStatusWnd::OnActivate() { ASSERT(IPP_FONTSIZE == 13); const int h20 = IPP_SCALE(20); DWORD dwStyle = WS_VISIBLE | WS_CHILD | WS_TABSTOP; CPoint p(10, 10); m_gInput.Create(L"Input", WS_VISIBLE | WS_CHILD | BS_GROUPBOX, CRect(p + CPoint(-5, 0), CSize(IPP_SCALE(150), h20 * 4 + IPP_SCALE(5))), this, (UINT)IDC_STATIC); p = CPoint(IPP_SCALE(170), 10); m_gOutput.Create(L"Output", WS_VISIBLE | WS_CHILD | BS_GROUPBOX, CRect(p + CPoint(-5, 0), CSize(IPP_SCALE(150), h20 * 4 + IPP_SCALE(5))), this, (UINT)IDC_STATIC); { // Format p = CPoint(IPP_SCALE(10), 10); p.y += h20; m_InputFormatLabel.Create(L"Format:", WS_VISIBLE|WS_CHILD, CRect(p, CSize(IPP_SCALE(50), m_fontheight)), this, (UINT)IDC_STATIC); p.x += IPP_SCALE(70); m_InputFormatText.Create(L"", WS_VISIBLE|WS_CHILD, CRect(p, CSize(IPP_SCALE(70), m_fontheight)), this, (UINT)IDC_STATIC); p = CPoint(IPP_SCALE(170), 10); p.y += h20; m_OutputFormatLabel.Create(L"Format:", WS_VISIBLE|WS_CHILD, CRect(p, CSize(IPP_SCALE(50), m_fontheight)), this, (UINT)IDC_STATIC); p.x += IPP_SCALE(70); m_OutputFormatText.Create(L"", WS_VISIBLE|WS_CHILD, CRect(p, CSize(IPP_SCALE(70), m_fontheight)), this, (UINT)IDC_STATIC); } { // Channel p = CPoint(IPP_SCALE(10), 10); p.y += h20 * 2; m_InputChannelLabel.Create(L"Channel:", WS_VISIBLE|WS_CHILD, CRect(p, CSize(IPP_SCALE(50), m_fontheight)), this, (UINT)IDC_STATIC); p.x += IPP_SCALE(70); m_InputChannelText.Create(L"", WS_VISIBLE|WS_CHILD, CRect(p, CSize(IPP_SCALE(70), m_fontheight)), this, (UINT)IDC_STATIC); p = CPoint(IPP_SCALE(170), 10); p.y += h20 * 2; m_OutputChannelLabel.Create(L"Channel:", WS_VISIBLE|WS_CHILD, CRect(p, CSize(IPP_SCALE(50), m_fontheight)), this, (UINT)IDC_STATIC); p.x += IPP_SCALE(70); m_OutputChannelText.Create(L"", WS_VISIBLE|WS_CHILD, CRect(p, CSize(IPP_SCALE(70), m_fontheight)), this, (UINT)IDC_STATIC); } { // Sample Rate p = CPoint(IPP_SCALE(10), 10); p.y += h20 * 3; m_InputRateLabel.Create(L"Sample Rate:", WS_VISIBLE|WS_CHILD, CRect(p, CSize(IPP_SCALE(70), m_fontheight)), this, (UINT)IDC_STATIC); p.x += IPP_SCALE(70); m_InputRateText.Create(L"", WS_VISIBLE|WS_CHILD, CRect(p, CSize(IPP_SCALE(70), m_fontheight)), this, (UINT)IDC_STATIC); p = CPoint(IPP_SCALE(170), 10); p.y += h20 * 3; m_OutputRateLabel.Create(L"Sample Rate:", WS_VISIBLE|WS_CHILD, CRect(p, CSize(IPP_SCALE(70), m_fontheight)), this, (UINT)IDC_STATIC); p.x += IPP_SCALE(70); m_OutputRateText.Create(L"", WS_VISIBLE|WS_CHILD, CRect(p, CSize(IPP_SCALE(70), m_fontheight)), this, (UINT)IDC_STATIC); } p = CPoint(IPP_SCALE(10), 10); p.y += h20 * 4 + IPP_SCALE(15); m_txtModeText.Create(ResStr(IDS_ARS_WASAPI_MODE_STATUS_1), WS_VISIBLE|WS_CHILD, CRect(p, CSize(IPP_SCALE(280), m_fontheight)), this, (UINT)IDC_STATIC); if (m_pMAR) { UINT status = m_pMAR->GetMode(); switch (status) { case MODE_NONE : default: break; case MODE_WASAPI_EXCLUSIVE : m_txtModeText.SetWindowText(ResStr(IDS_ARS_WASAPI_MODE_STATUS_2)); break; case MODE_WASAPI_SHARED : m_txtModeText.SetWindowText(ResStr(IDS_ARS_WASAPI_MODE_STATUS_3)); break; case MODE_WASAPI_EXCLUSIVE_BITSTREAM : CString btMode_str; BITSTREAM_MODE btMode = m_pMAR->GetBitstreamMode(); switch (btMode) { case BITSTREAM_AC3 : btMode_str = L"AC3"; break; case BITSTREAM_DTS : btMode_str = L"DTS"; break; case BITSTREAM_EAC3 : btMode_str = L"E-AC3"; break; case BITSTREAM_TRUEHD : btMode_str = L"TrueHD"; break; case BITSTREAM_DTSHD : btMode_str = L"DTS-HD"; break; } CString msg = ResStr(IDS_ARS_WASAPI_MODE_STATUS_5); if (btMode_str.GetLength()) { msg.AppendFormat(L" [%s]", btMode_str); } m_txtModeText.SetWindowText(msg); break; } if (status == MODE_WASAPI_EXCLUSIVE_BITSTREAM) { m_InputFormatText.SetWindowText(L"Bitstream"); m_OutputFormatText.SetWindowText(L"Bitstream"); } else { WAVEFORMATEX *pWfxIn, *pWfxOut; m_pMAR->GetStatus(&pWfxIn, &pWfxOut); if (pWfxIn && pWfxOut) { { // Input bool fFloat = false; DWORD layout = 0; if (pWfxIn->wFormatTag == WAVE_FORMAT_EXTENSIBLE && pWfxIn->cbSize == (sizeof(WAVEFORMATEXTENSIBLE) - sizeof(WAVEFORMATEX))) { WAVEFORMATEXTENSIBLE* wfex = (WAVEFORMATEXTENSIBLE*)pWfxIn; layout = wfex->dwChannelMask; if (wfex->SubFormat == MEDIASUBTYPE_IEEE_FLOAT) { fFloat = true; } } else { layout = GetDefChannelMask(pWfxIn->nChannels); if (pWfxIn->wFormatTag == WAVE_FORMAT_IEEE_FLOAT) { fFloat = true; } } CString sFormat; sFormat.Format(L"%dbit %s", pWfxIn->wBitsPerSample, fFloat ? L"Float" : L"Integer"); CString sChannel; switch (pWfxIn->nChannels) { case 6: sChannel = L"5.1"; break; case 8: sChannel = L"7.1"; break; default: sChannel.Format(L"%d", pWfxIn->nChannels); break; } sChannel.AppendFormat(L" / 0x%x", layout); CString sSampleRate; sSampleRate.Format(L"%d", pWfxIn->nSamplesPerSec); m_InputFormatText.SetWindowText(sFormat); m_InputChannelText.SetWindowText(sChannel); m_InputRateText.SetWindowText(sSampleRate); } { // Output bool fFloat = false; DWORD layout = 0; if (pWfxOut->wFormatTag == WAVE_FORMAT_EXTENSIBLE && pWfxOut->cbSize == (sizeof(WAVEFORMATEXTENSIBLE) - sizeof(WAVEFORMATEX))) { WAVEFORMATEXTENSIBLE* wfex = (WAVEFORMATEXTENSIBLE*)pWfxOut; layout = wfex->dwChannelMask; if (wfex->SubFormat == MEDIASUBTYPE_IEEE_FLOAT) { fFloat = true; } } else { layout = GetDefChannelMask(pWfxOut->nChannels); if (pWfxOut->wFormatTag == WAVE_FORMAT_IEEE_FLOAT) { fFloat = true; } } CString sFormat; sFormat.Format(L"%dbit %s", pWfxOut->wBitsPerSample, fFloat ? L"Float" : L"Integer"); CString sChannel; switch (pWfxOut->nChannels) { case 6: sChannel = L"5.1"; break; case 8: sChannel = L"7.1"; break; default: sChannel.Format(L"%d", pWfxOut->nChannels); break; } sChannel.AppendFormat(L" / 0x%x", layout); CString sSampleRate; sSampleRate.Format(L"%d", pWfxOut->nSamplesPerSec); m_OutputFormatText.SetWindowText(sFormat); m_OutputChannelText.SetWindowText(sChannel); m_OutputRateText.SetWindowText(sSampleRate); } } } } for (CWnd* pWnd = GetWindow(GW_CHILD); pWnd; pWnd = pWnd->GetNextWindow()) { pWnd->SetFont(&m_font, FALSE); } return true; }