//========================================================================== // FeigenSound v. 1.0 // // Logistische Gleichung als Sound-Generator. // // written by Peter Schmitteckert // email: peter@schmitteckert.com // // This source may be distributed, changed or deleted without any restriction. // Comments are welcome // //========================================================================== // // Should run on every decent X11, testet on "Linux baxter 2.2.17-RAID" // Compile: g++ FeigenSound.C -I /usr/X11/include/X11 -o FeigenSound -L/usr/X11/lib -lX11 // // It runs under X, so you can even run it on a server, using your local PC-Speaker. :) // //========================================================================== #include #include #include #include using namespace std; void Beep( Display* pDisplay, const int Frequency, const int Duration) { XKeyboardState OldState; XKeyboardControl KbdCtl; XGetKeyboardControl(pDisplay, &OldState); // switch to new state KbdCtl.bell_percent = 100; KbdCtl.bell_pitch = Frequency; KbdCtl.bell_duration = Duration; XChangeKeyboardControl( pDisplay, KBBellPercent | KBBellPitch | KBBellDuration, &KbdCtl); // ring bell XBell( pDisplay,100); // restore old state KbdCtl.bell_percent = OldState.bell_percent; KbdCtl.bell_pitch = OldState.bell_pitch; KbdCtl.bell_duration = OldState.bell_duration; XChangeKeyboardControl( pDisplay, KBBellPercent | KBBellPitch | KBBellDuration, &KbdCtl); } int main( int argc, char* argv[]) { double FrequencyFactor = 1000; int Duration = 100; // in ms. double a=3.7; double x = 0.5; bool bOk = true; // Initialisiere Display auf aktuelle Display Display* pDisplay; pDisplay = XOpenDisplay( NULL); if( argc > 4) { bOk = false; } if( argc > 1) a = atof( argv[1] ); if( (a<1.0) || (a>4.0) ) { cout << " a muß zwischen 1.0 und 4.0 liegen." << endl; bOk = false; } if( argc > 2) FrequencyFactor = atof( argv[2] ); if( (FrequencyFactor<1.0) || (FrequencyFactor>10000.0) ) { cout << " Der Frequenz-Factor muß zwischen 1.0 und 10000 liegen." << endl; bOk = false; } if( argc > 3) Duration = atoi( argv[3] ); if( (Duration<1.0) || (Duration>10000) ) { cout << " Die Tondauer FrequencyFactor muß zwischen 1.0ms und 10000ms liegen."<< endl; bOk = false; } if( !bOk) cout << "Usage: " << argv[0] << " [a] [FrquenzFactor] [ Dauer ] " << endl; // FeigenBaum - Schleife while(bOk) { x = a * x * (1.0 - x); if( ( x<=0) || ( x>=1.0) ) break; Beep( pDisplay, int(FrequencyFactor*x), Duration); // Warten auf das ende des Beep + etwas Pause (usleep(x) wartet x µ-sekunden) usleep( 1100 * Duration); cout << x << endl; }; cout << "Closing Display" << endl; // Schliesse Display XCloseDisplay( pDisplay); }