Changeset 7 for trunk/Utilities/GeneratePcmWavFile/GeneratePcmWavFile.cpp
- Timestamp:
- Aug 26, 2011, 1:20:52 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Utilities/GeneratePcmWavFile/GeneratePcmWavFile.cpp
r5 r7 113 113 CEvent m_MediaSampleTimeEvent; 114 114 REFERENCE_TIME m_nMediaSampleTime; 115 SIZE_T m_nCurrentSampleIndex; 115 116 116 117 public: … … 118 119 CThreadContext(CEvent& TerminationEvent) throw() : 119 120 CPushSourceFilter::CThreadContext(TerminationEvent), 120 m_nMediaSampleTime(0) 121 m_nMediaSampleTime(0), 122 m_nCurrentSampleIndex(0) 121 123 { 122 124 } … … 144 146 CMediaType m_pDataMediaType; 145 147 REFERENCE_TIME m_nDataLength; 148 DOUBLE m_fSignalPeriod; 149 DOUBLE m_fSignalAmplitude; 146 150 147 151 public: 148 152 // COutputPin 149 153 COutputPin() throw() : 150 m_nDataLength(0) 154 m_nDataLength(0), 155 m_fSignalPeriod(0), 156 m_fSignalAmplitude(0) 151 157 { 152 158 _Z4(atlTraceRefcount, 4, _T("this 0x%p\n"), this); … … 195 201 return TRUE; 196 202 } 203 VOID InitializeThread(CThreadContext& ThreadContext) throw() 204 { 205 CRoCriticalSectionLock DataLock(GetDataCriticalSection()); 206 __super::InitializeThread(ThreadContext); 207 if(m_fSignalPeriod > 0) 208 { 209 __D(m_pDataMediaType.GetWaveFormatEx()->wBitsPerSample == 16, E_NOTIMPL); 210 ThreadContext.m_nCurrentSampleIndex = 0; 211 } 212 } 197 213 BOOL ComposeMediaSample(CThreadContext& ThreadContext, IMediaSample* pMediaSample) 198 214 { … … 210 226 nDataSize = (nDataSize / pWaveFormatEx->nBlockAlign) * pWaveFormatEx->nBlockAlign; 211 227 if(pWaveFormatEx->wBitsPerSample == 8) 228 { 212 229 FillMemory(Properties.pbBuffer, nDataSize, 0x80); 213 else 230 } else 231 { 214 232 ZeroMemory(Properties.pbBuffer, nDataSize); 233 #pragma region Size Wave Data 234 if(m_fSignalPeriod > 0) 235 { 236 #if _DEVELOPMENT 237 const SIZE_T nAnchorCurrentSampleIndex = ThreadContext.m_nCurrentSampleIndex; 238 #endif // _DEVELOPMENT 239 for(SIZE_T nIndex = 0; nIndex < nDataSize; nIndex += pWaveFormatEx->nBlockAlign) 240 { 241 const SHORT nValue = (SHORT) (m_fSignalAmplitude * sin(2 * M_PI * ThreadContext.m_nCurrentSampleIndex++ / m_fSignalPeriod)); 242 SHORT* pnSampleData = (SHORT*) (Properties.pbBuffer + nIndex); 243 for(WORD nChannelIndex = 0; nChannelIndex < pWaveFormatEx->nChannels; nChannelIndex++) 244 pnSampleData[nChannelIndex] = nValue; 245 } 246 #if _DEVELOPMENT 247 _A(ThreadContext.m_nCurrentSampleIndex == nAnchorCurrentSampleIndex + nDataSize / pWaveFormatEx->nBlockAlign); 248 #endif // _DEVELOPMENT 249 } 250 #pragma endregion 251 } 215 252 ThreadContext.m_nMediaSampleTime += nDataSize * (1000 * 10000i64) / pWaveFormatEx->nAvgBytesPerSec; 253 //ThreadContext.m_nCurrentSampleIndex += nDataSize / pWaveFormatEx->nBlockAlign; 216 254 Properties.lActual = (LONG) nDataSize; 217 255 Properties.Set(); … … 226 264 m_nDataLength = nLength; 227 265 } 266 VOID InitializeSignal(DOUBLE fSignalPeriod, DOUBLE fSignalAmplitude) 267 { 268 __D(fSignalPeriod > 0 && fSignalAmplitude >= 0, E_INVALIDARG); 269 m_fSignalPeriod = fSignalPeriod; 270 m_fSignalAmplitude = fSignalAmplitude; 271 } 228 272 }; 229 273 … … 299 343 m_pOutputPin->InitializeData(pWaveFormatEx, nLength); 300 344 } 345 VOID InitializeSignal(DOUBLE fSignalAmplitude, DOUBLE fSignalPeriod) 346 { 347 m_pOutputPin->InitializeSignal(fSignalAmplitude, fSignalPeriod); 348 } 301 349 }; 302 350 … … 304 352 CWaveFormatEx m_WaveFormatEx; 305 353 REFERENCE_TIME m_nLength; 354 UINT m_nSignalFrequency; 355 UINT m_nSignalLoudness; 306 356 CPath m_sPath; 307 357 … … 316 366 ZeroMemory(&m_WaveFormatEx, sizeof m_WaveFormatEx); 317 367 m_nLength = 0; 368 m_nSignalFrequency = 0; 369 m_nSignalLoudness = 0; 318 370 } 319 371 ~CModule() throw() … … 340 392 __D(nLength > 0, E_INVALIDARG); 341 393 m_nLength = nLength; 394 } 395 VOID SetSignalFrequency(UINT nSignalFrequency) 396 { 397 __D(nSignalFrequency > 0, E_INVALIDARG); 398 m_nSignalFrequency = nSignalFrequency; 399 } 400 VOID SetSignalLoudness(UINT nSignalLoudness) 401 { 402 __D(nSignalLoudness >= 0, E_INVALIDARG); 403 m_nSignalLoudness = nSignalLoudness; 342 404 } 343 405 VOID SetPath(LPCTSTR pszPath) … … 362 424 _tprintf(_T(" /b:N: Sample Bit Count N, 8 or 16\n")); 363 425 _tprintf(_T(" /t:N: Length N, seconds\n")); 426 _tprintf(_T(" /f:N: Sine Signal Frequency N, Hz\n")); 427 _tprintf(_T(" /l:N: Sine Signal Loudness N, dB below full scale\n")); 364 428 __C(S_FALSE); 365 429 } … … 377 441 CObjectPtr<CSourceFilter> pSourceFilter; 378 442 pSourceFilter.Construct()->Initialize(pWaveFormatEx, m_nLength); 443 if(m_nSignalFrequency) 444 { 445 __D(m_WaveFormatEx.wBitsPerSample == 16, E_NOTIMPL); 446 const DOUBLE fSignalPeriod = (DOUBLE) pWaveFormatEx->nSamplesPerSec / m_nSignalFrequency; 447 const DOUBLE fSignalAmplitude = 32767.0 / pow(10.0, m_nSignalLoudness / 20.0); 448 pSourceFilter->InitializeSignal(fSignalPeriod, fSignalAmplitude); 449 } 379 450 __C(GenericFilterGraph->AddFilter(pSourceFilter, CT2CW(_T("Source")))); 380 451 CComPtr<IPin> pCurrentOutputPin = pSourceFilter->GetOutputPin(); … … 474 545 //_tprintf(_T("Option: Length, %d\n"), nIntegerArgumentValue); 475 546 Module.SetLength(nIntegerArgumentValue * 1000 * 10000i64); 547 } else 548 if(_tcschr(_T("Ff"), sArgument[0])) // Sine Signal Frequency, Hz 549 { 550 __D(bIntegerArgumentValueValid, E_INVALIDARG); 551 //_tprintf(_T("Option: Sine Signal Frequency, %d\n"), nIntegerArgumentValue); 552 Module.SetSignalFrequency(nIntegerArgumentValue); 553 } else 554 if(_tcschr(_T("Ll"), sArgument[0])) // Sine Signal Loudness, dB below FS 555 { 556 __D(bIntegerArgumentValueValid, E_INVALIDARG); 557 //_tprintf(_T("Option: Sine Signal Loudness, %d\n"), nIntegerArgumentValue); 558 Module.SetSignalLoudness(nIntegerArgumentValue); 476 559 } 477 560 continue;
Note: See TracChangeset
for help on using the changeset viewer.