// // re-calculate frequency response // void Plot::setDamp( double damping ) { const bool doReplot = autoReplot(); setAutoReplot( false ); const int ArraySize = 200; double frequency[ArraySize]; double amplitude[ArraySize]; double phase[ArraySize]; // build frequency vector with logarithmic division logSpace( frequency, ArraySize, 0.01, 100 ); int i3 = 1; double fmax = 1; double amax = -1000.0; for ( int i = 0; i < ArraySize; i++ ) { double f = frequency[i]; const ComplexNumber g = ComplexNumber( 1.0 ) / ComplexNumber( 1.0 - f * f, 2.0 * damping * f ); amplitude[i] = 20.0 * log10( qSqrt( g.real() * g.real() + g.imag() * g.imag() ) ); phase[i] = qAtan2( g.imag(), g.real() ) * ( 180.0 / M_PI ); if ( ( i3 <= 1 ) && ( amplitude[i] < -3.0 ) ) i3 = i; if ( amplitude[i] > amax ) { amax = amplitude[i]; fmax = frequency[i]; } } double f3 = frequency[i3] - ( frequency[i3] - frequency[i3 - 1] ) / ( amplitude[i3] - amplitude[i3 -1] ) * ( amplitude[i3] + 3 ); showPeak( fmax, amax ); show3dB( f3 ); showData( frequency, amplitude, phase, ArraySize ); setAutoReplot( doReplot ); replot(); }
void testSymbol() { bool res = true; int i, j; int countDups; const OSSymbol *cache[numStrCache]; void *spaceCheck; // very first test initialises the OSMetaClass cache. cache[0] = IOSymbol::withCStringNoCopy(testC00); TEST_ASSERT('u', "0a", cache[0]); if (cache[0]) cache[0]->release(); spaceCheck = checkPointSpace(); // Setup the symbol cache, make sure it grows the symbol unique'ing // hash table. Also determine that the symbol is created ok and that // it is indeed equal to the creating cString by strcmp. for (i = 0; i < numStrCache; i++) { cache[i] = OSSymbol::withCStringNoCopy(strCache[i]); if (!cache[i]) { verPrintf(("testSymbol(u) test 1a%d failed\n", i)); res = false; } else if (!cache[i]->isEqualTo(strCache[i])) { verPrintf(("testSymbol(u) test 1b%d failed\n", i)); res = false; } } // The strCache does have some duplicates in it, mostly 'the'. Make // sure that we wind them and that different cache entries really are // different by strcmp. Fundamental to OSSymbol semantics. countDups = 0; for (i = 0; i < numStrCache; i++) for (j = i+1; j < numStrCache; j++) { if (cache[i] != cache[j] && cache[i]->isEqualTo(cache[j])) { verPrintf(("testSymbol(u) test 2a%d,%d failed\n", i, j)); res = false; } else if (cache[i] == cache[j]) { if (cache[i]->getRetainCount() == 1) { verPrintf(("testSymbol(u) test 2b%d,%d failed\n", i, j)); res = false; } countDups++; } } TEST_ASSERT('u', "2c", countDups); // Clear out the cache and check that the unique'ing hashtable has grown for (i = 0; i < numStrCache; i++) { if (cache[i]) { cache[i]->release(); cache[i] = 0; } } // As of 1998-11-17 the hash growth is 364. res = res && checkSpace("(u)3", spaceCheck, 972); logSpace(); // Check for leaks by repeating the cacheing and freeing spaceCheck = checkPointSpace(); for (i = 0; i < numStrCache; i++) cache[i] = OSSymbol::withCString(strCache[i]); for (i = 0; i < numStrCache; i++) { if (cache[i]) { cache[i]->release(); cache[i] = 0; } } res = res && checkSpace("(u)4", spaceCheck, 0); // Check that the OSString based symbol constructors work // and that they don't leak, and finally double check that while // the cache is active the symbol semantics still work. spaceCheck = checkPointSpace(); for (i = 0; i < numStrCache; i++) { OSString *tmpStr; tmpStr = (i&1) ? OSString::withCString(strCache[i]) : OSString::withCStringNoCopy(strCache[i]); if (tmpStr) { cache[i] = OSSymbol::withString(tmpStr); if (!cache[i]) { verPrintf(("testSymbol(u) test 5a%d failed\n", i)); res = false; } tmpStr->release(); } } for (i = 0; i < numStrCache; i++) { if (cache[i]) { const OSSymbol *tmpSymb; tmpSymb = OSSymbol::withCStringNoCopy(strCache[i]); if (cache[i] != tmpSymb) { verPrintf(("testSymbol(u) test 5b%d failed\n", i)); res = false; } tmpSymb->release(); cache[i]->release(); cache[i] = 0; } else { verPrintf(("testSymbol(u) test 5c%d failed\n", i)); res = false; } } res = res && checkSpace("(u)5", spaceCheck, 0); if (res) verPrintf(("testSymbol: All OSSymbol Tests passed\n")); else logPrintf(("testSymbol: Some OSSymbol Tests failed\n")); }