www.pudn.com > VirtualVCR-src-v2.6.9.zip > AudioResampleProp.cpp


/* 
	Virtual VCR 
    Copyright (C) 2002  Shaun Faulds 
 
    This program is free software; you can redistribute it and/or modify 
    it under the terms of the GNU General Public License as published by 
    the Free Software Foundation; either version 2 of the License, or 
    (at your option) any later version. 
 
    This program is distributed in the hope that it will be useful, 
    but WITHOUT ANY WARRANTY; without even the implied warranty of 
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
    GNU General Public License for more details. 
 
    You should have received a copy of the GNU General Public License 
    along with this program; if not, write to the Free Software 
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 
 
	Acknowledgments: 
	This application and associated filters are based on the examples 
	from the Microsoft DirectX DirectShow SDK. 
*/ 
 
 
#include  
#include  
#include  
#include  
#include  
#include  
#include  
#include  
#include  
 
#include "resource.h" 
#include "AudioResampleUIDs.h" 
#include "iAudioResample.h" 
#include "AudioResample.h" 
#include "AudioResampleProp.h" 
 
// 
// CreateInstance 
// 
// Used by the DirectShow base classes to create instances 
// 
CUnknown *CAudioResampleProperties::CreateInstance(LPUNKNOWN lpunk, HRESULT *phr) 
{ 
    CUnknown *punk = new CAudioResampleProperties(lpunk, phr); 
    if (punk == NULL) 
	{ 
		*phr = E_OUTOFMEMORY; 
    } 
    return punk; 
 
} // CreateInstance 
 
// 
// Constructor 
// 
CAudioResampleProperties::CAudioResampleProperties(LPUNKNOWN pUnk, HRESULT *phr) : 
    CBasePropertyPage(NAME("Audio Resample Property Page"), 
                      pUnk,IDD_AudioResamplePropDlg,IDS_TITLE), 
					  m_pAudioResample(NULL) 
{ 
 
 
} // (Constructor) 
 
 
// 
// OnReceiveMessage 
// 
// Handles the messages for our property window 
// 
BOOL CAudioResampleProperties::OnReceiveMessage(HWND hwnd, 
	UINT uMsg, 
	WPARAM wParam, 
	LPARAM lParam) 
{ 
		 
	switch (uMsg) 
	{ 
		case WM_INITDIALOG: 
		{ 
			ASSERT(m_pAudioResample); 
			 
			double data = 0; 
			m_pAudioResample->get_Percent(&data); 
 
			__int64 samplesAdded = 0; 
			m_pAudioResample->get_SamplesAdded(&samplesAdded); 
 
			__int64 rawSamples = 0; 
			m_pAudioResample->get_RawTotal(&rawSamples); 
 
			double actualPercent = 0; 
			m_pAudioResample->get_ActualPercent(&actualPercent); 
 
			TCHAR  Cwidth[32]; 
				 
			_stprintf(Cwidth, TEXT("%f"), data); 
			SetDlgItemText(hwnd, IDC_PERCENT, Cwidth); 
 
			_stprintf(Cwidth, TEXT("%d"), samplesAdded); 
			SetDlgItemText(hwnd, IDC_SAMPLES_ADDED, Cwidth); 
 
			_stprintf(Cwidth, TEXT("%d"), rawSamples); 
			SetDlgItemText(hwnd, IDC_TOTAL_SAMPLES, Cwidth); 
 
			_stprintf(Cwidth, TEXT("%f"), actualPercent); 
			SetDlgItemText(hwnd, IDC_ACTUAL_PERCENT, Cwidth); 
 
			return (LRESULT) 1; 
		} 
			 
		case WM_COMMAND: 
		{ 
			switch(LOWORD(wParam)) 
			{ 
			case IDC_SET: 
				{ 
					char *per = new char[128]; 
					GetDlgItemText(hwnd, IDC_PERCENT, per, 256); 
					 
					double newPercent = 0; 
					char *pEnd; 
					newPercent = strtod(per, &pEnd); 
					 
					m_pAudioResample->set_Percent(newPercent); 
					 
					delete []per; 
 
					return (LRESULT) 1; 
				} 
			} 
		} 
/* 
        case WM_DESTROY: 
        { 
			KillTimer(hwnd, 1); 
 
			return (LRESULT) 1; 
		} 
*/ 
		case WM_CREATE: 
		{ 
			SetTimer(hwnd, 1, 250, NULL); 
 
			return (LRESULT) 1; 
		} 
 
		case WM_TIMER: 
		{ 
			ASSERT(m_pAudioResample); 
 
			__int64 samplesAdded = 0; 
			m_pAudioResample->get_SamplesAdded(&samplesAdded); 
 
			__int64 rawSamples = 0; 
			m_pAudioResample->get_RawTotal(&rawSamples); 
 
			double actualPercent = 0; 
			m_pAudioResample->get_ActualPercent(&actualPercent); 
 
			TCHAR  Cwidth[32]; 
				 
			_stprintf(Cwidth, TEXT("%d"), samplesAdded); 
			SetDlgItemText(hwnd, IDC_SAMPLES_ADDED, Cwidth); 
 
			_stprintf(Cwidth, TEXT("%d"), rawSamples); 
			SetDlgItemText(hwnd, IDC_TOTAL_SAMPLES, Cwidth); 
 
			_stprintf(Cwidth, TEXT("%f"), actualPercent); 
			SetDlgItemText(hwnd, IDC_ACTUAL_PERCENT, Cwidth); 
 
			return (LRESULT) 1; 
		} 
 
	} 
	return CBasePropertyPage::OnReceiveMessage(hwnd,uMsg,wParam,lParam); 
			 
} // OnReceiveMessage 
 
 
// 
// OnConnect 
// 
// Called when we connect to a transform filter 
// 
HRESULT CAudioResampleProperties::OnConnect(IUnknown *pUnknown) 
{ 
    ASSERT(m_pAudioResample == NULL); 
 
    HRESULT hr = pUnknown->QueryInterface(IID_IAudioResample, (void **) &m_pAudioResample); 
    if (FAILED(hr)) 
	{ 
        return E_NOINTERFACE; 
    } 
 
    ASSERT(m_pAudioResample); 
 
    return NOERROR; 
 
} // OnConnect 
 
 
// 
// OnDisconnect 
// 
// Likewise called when we disconnect from a filter 
// 
HRESULT CAudioResampleProperties::OnDisconnect() 
{ 
    // Release of Interface after setting the appropriate old effect value 
 
    if (m_pAudioResample == NULL) { 
        return E_UNEXPECTED; 
    } 
 
    m_pAudioResample->Release(); 
    m_pAudioResample = NULL; 
    return NOERROR; 
 
} // OnDisconnect 
 
 
// 
// OnActivate 
// 
// We are being activated 
// 
HRESULT CAudioResampleProperties::OnActivate() 
{ 
    return NOERROR; 
 
} // OnActivate 
 
 
// 
// OnDeactivate 
// 
// We are being deactivated 
// 
HRESULT CAudioResampleProperties::OnDeactivate(void) 
{ 
    return NOERROR; 
 
} // OnDeactivate 
 
 
// 
// OnApplyChanges 
// 
// Apply any changes so far made 
// 
HRESULT CAudioResampleProperties::OnApplyChanges() 
{ 
    return NOERROR; 
} // OnApplyChanges 
 
 
void CAudioResampleProperties::GetControlValues() 
{ 
    ASSERT(m_pAudioResample); 
}