Changeset 8 for trunk/Utilities/GeneratePcmWavFile/GeneratePcmWavFile.cpp
- Timestamp:
- Aug 28, 2011, 4:11:27 AM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Utilities/GeneratePcmWavFile/GeneratePcmWavFile.cpp
r7 r8 148 148 DOUBLE m_fSignalPeriod; 149 149 DOUBLE m_fSignalAmplitude; 150 DOUBLE m_fNoiseAmplitude; 150 151 151 152 public: … … 154 155 m_nDataLength(0), 155 156 m_fSignalPeriod(0), 156 m_fSignalAmplitude(0) 157 m_fSignalAmplitude(0), 158 m_fNoiseAmplitude(0) 157 159 { 158 160 _Z4(atlTraceRefcount, 4, _T("this 0x%p\n"), this); … … 231 233 { 232 234 ZeroMemory(Properties.pbBuffer, nDataSize); 233 #pragma region Si ze Wave Data235 #pragma region Sine Wave Data 234 236 if(m_fSignalPeriod > 0) 235 237 { 236 #if _DEVELOPMENT237 const SIZE_T nAnchorCurrentSampleIndex = ThreadContext.m_nCurrentSampleIndex;238 #endif // _DEVELOPMENT239 238 for(SIZE_T nIndex = 0; nIndex < nDataSize; nIndex += pWaveFormatEx->nBlockAlign) 240 239 { 241 const SHORT nValue = (SHORT) (m_fSignalAmplitude * sin(2 * M_PI * ThreadContext.m_nCurrentSampleIndex++/ m_fSignalPeriod));240 const SHORT nValue = (SHORT) (m_fSignalAmplitude * sin(2 * M_PI * (ThreadContext.m_nCurrentSampleIndex + nIndex) / m_fSignalPeriod)); 242 241 SHORT* pnSampleData = (SHORT*) (Properties.pbBuffer + nIndex); 243 242 for(WORD nChannelIndex = 0; nChannelIndex < pWaveFormatEx->nChannels; nChannelIndex++) 244 243 pnSampleData[nChannelIndex] = nValue; 245 244 } 246 #if _DEVELOPMENT 247 _A(ThreadContext.m_nCurrentSampleIndex == nAnchorCurrentSampleIndex + nDataSize / pWaveFormatEx->nBlockAlign); 248 #endif // _DEVELOPMENT 245 } 246 #pragma endregion 247 #pragma region Noise Wave Data 248 if(m_fNoiseAmplitude > 0) 249 { 250 for(SIZE_T nIndex = 0; nIndex < nDataSize; nIndex += pWaveFormatEx->nBlockAlign) 251 { 252 SHORT* pnSampleData = (SHORT*) (Properties.pbBuffer + nIndex); 253 for(WORD nChannelIndex = 0; nChannelIndex < pWaveFormatEx->nChannels; nChannelIndex++) 254 pnSampleData[nChannelIndex] += (SHORT) (m_fSignalAmplitude * (DOUBLE) (rand() - RAND_MAX / 2) / (RAND_MAX / 2)); 255 } 249 256 } 250 257 #pragma endregion 251 258 } 252 259 ThreadContext.m_nMediaSampleTime += nDataSize * (1000 * 10000i64) / pWaveFormatEx->nAvgBytesPerSec; 253 //ThreadContext.m_nCurrentSampleIndex += nDataSize / pWaveFormatEx->nBlockAlign;260 ThreadContext.m_nCurrentSampleIndex += nDataSize / pWaveFormatEx->nBlockAlign; 254 261 Properties.lActual = (LONG) nDataSize; 255 262 Properties.Set(); … … 264 271 m_nDataLength = nLength; 265 272 } 266 VOID InitializeSignal(DOUBLE fSignalPeriod, DOUBLE fSignalAmplitude )273 VOID InitializeSignal(DOUBLE fSignalPeriod, DOUBLE fSignalAmplitude, DOUBLE fNoiseAmplitude) 267 274 { 268 275 __D(fSignalPeriod > 0 && fSignalAmplitude >= 0, E_INVALIDARG); 269 276 m_fSignalPeriod = fSignalPeriod; 270 277 m_fSignalAmplitude = fSignalAmplitude; 278 m_fNoiseAmplitude = fNoiseAmplitude; 271 279 } 272 280 }; … … 343 351 m_pOutputPin->InitializeData(pWaveFormatEx, nLength); 344 352 } 345 VOID InitializeSignal(DOUBLE fSignalAmplitude, DOUBLE fSignalPeriod )346 { 347 m_pOutputPin->InitializeSignal(fSignalAmplitude, fSignalPeriod );353 VOID InitializeSignal(DOUBLE fSignalAmplitude, DOUBLE fSignalPeriod, DOUBLE fNoiseAmplitude) 354 { 355 m_pOutputPin->InitializeSignal(fSignalAmplitude, fSignalPeriod, fNoiseAmplitude); 348 356 } 349 357 }; … … 354 362 UINT m_nSignalFrequency; 355 363 UINT m_nSignalLoudness; 364 UINT m_nNoiseLoudness; 356 365 CPath m_sPath; 357 366 … … 368 377 m_nSignalFrequency = 0; 369 378 m_nSignalLoudness = 0; 379 m_nNoiseLoudness = 0; 370 380 } 371 381 ~CModule() throw() … … 402 412 __D(nSignalLoudness >= 0, E_INVALIDARG); 403 413 m_nSignalLoudness = nSignalLoudness; 414 } 415 VOID SetNoiseLoudness(UINT nNoiseLoudness) 416 { 417 __D(nNoiseLoudness >= 0, E_INVALIDARG); 418 m_nNoiseLoudness = nNoiseLoudness; 404 419 } 405 420 VOID SetPath(LPCTSTR pszPath) … … 426 441 _tprintf(_T(" /f:N: Sine Signal Frequency N, Hz\n")); 427 442 _tprintf(_T(" /l:N: Sine Signal Loudness N, dB below full scale\n")); 443 _tprintf(_T(" /n:N: Noise Signal Loudness N, dB below full scale\n")); 428 444 __C(S_FALSE); 429 445 } … … 441 457 CObjectPtr<CSourceFilter> pSourceFilter; 442 458 pSourceFilter.Construct()->Initialize(pWaveFormatEx, m_nLength); 443 if(m_nSignalFrequency )459 if(m_nSignalFrequency && m_nSignalLoudness || m_nNoiseLoudness) 444 460 { 445 461 __D(m_WaveFormatEx.wBitsPerSample == 16, E_NOTIMPL); 446 462 const DOUBLE fSignalPeriod = (DOUBLE) pWaveFormatEx->nSamplesPerSec / m_nSignalFrequency; 447 463 const DOUBLE fSignalAmplitude = 32767.0 / pow(10.0, m_nSignalLoudness / 20.0); 448 pSourceFilter->InitializeSignal(fSignalPeriod, fSignalAmplitude); 464 const DOUBLE fNoiseAmplitude = 32767.0 / pow(10.0, m_nNoiseLoudness / 20.0); 465 pSourceFilter->InitializeSignal(fSignalPeriod, fSignalAmplitude, fNoiseAmplitude); 449 466 } 450 467 __C(GenericFilterGraph->AddFilter(pSourceFilter, CT2CW(_T("Source")))); … … 557 574 //_tprintf(_T("Option: Sine Signal Loudness, %d\n"), nIntegerArgumentValue); 558 575 Module.SetSignalLoudness(nIntegerArgumentValue); 576 } else 577 if(_tcschr(_T("Nn"), sArgument[0])) // Noise Signal Loudness, dB below FS 578 { 579 __D(bIntegerArgumentValueValid, E_INVALIDARG); 580 //_tprintf(_T("Option: Noise Signal Loudness, %d\n"), nIntegerArgumentValue); 581 Module.SetNoiseLoudness(nIntegerArgumentValue); 559 582 } 560 583 continue;
Note: See TracChangeset
for help on using the changeset viewer.