daily pastebin goal
62%
SHARE
TWEET

Untitled

a guest Jan 11th, 2019 60 in 14 hours
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Aufgabe 2.1 ------------------------------------------------------
  2.         {
  3.             double f = 1000;
  4.             double T = 0.005; // 5ms
  5.             double[] note = sinSound(f, FS, T);
  6.             PlotPanel plot = Plot.createPlot("Aufgabe 2.1");
  7.             String plotTitle = String.format("f=%.2f kHz, fs=%.2f kHz, T=%.2f ms", f/1000, FS/1000, T*1000);
  8.             plot.addPlot(new BarPlot(plotTitle, note));
  9.             Plot.showPlot(plot, -1.0, +1.0);        // erweiterte showPlot()-Methode!
  10.         }
  11.  
  12. //      // Aufgabe 2.2 ------------------------------------------------------
  13.         {
  14.             double f = Kammerton;
  15.             double T = 1;
  16.             AudioPlayer player = new AudioPlayer(FS);
  17.             for (int i=1; i <= 10; i++) {
  18.                 double a = i * 0.1;
  19.                 double[] note = sinSound(f, FS, T, a);
  20.                 player.play(note);
  21.             }
  22.             player.close();
  23.         }
  24.  
  25.  
  26. static double[] sinSound(double f, double fs, double T) {
  27.         int n = (int)(T * fs);
  28.         double[] tmp = new double[n];
  29.         double w = (2*Math.PI*f)/fs;
  30.         for (int i=0; i < n; i ++) {
  31.             tmp[i] = Math.sin(i*w);
  32.         }
  33.         return tmp;
  34.     }
  35.    
  36.     static double[] sinSound(double f, double fs, double T, double a) {
  37.         int n = (int)(T * fs);
  38.         double[] tmp = new double[n];
  39.         if (0 <= a && a <= 1) {
  40.             double w = (2*Math.PI*f)/fs;
  41.             for (int i=0; i < n; i ++) {
  42.                 tmp[i] = Math.sin(i*w)*a;
  43.             }
  44.         }
  45.         else {
  46.             System.out.println("Lautstärke falsch angegeben! (muss zwischen 0 und 1 sein)");
  47.         }
  48.         return tmp;
  49.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top