How to play a set of frequencies (Chords) at the same time with javax.sound.sampled package

前端 未结 3 526
深忆病人
深忆病人 2021-02-11 08:50

I am trying to implement a system where I give a set of frequencies to be played at once, currently can play each frequency individually. Below I have a code, that plays the giv

相关标签:
3条回答
  • 2021-02-11 08:53

    In this example, Tone opens a single SourceDataLine for each Note, but you can open as many lines as there are notes in your chord. Then simply write() each Note of the chord to a separate line. You can create an arpeggio effect by using Note.REST.

    0 讨论(0)
  • 2021-02-11 08:58

    you could use different threads for each frequence :)

    here you can find a small example of threads in java

    I hope this helps you :)

    0 讨论(0)
  • 2021-02-11 09:09

    Simply sum the sample values at each time point, and divide by an appropriate scaling factor to keep your values in range. For example, to play A 440 and C 523.25 at the same time:

    double[] a = tone(440,1.0);
    double[] b = tone(523.25,1.0);
    for( int i=0; i<a.length; ++ i )
       a[i] = ( a[i] + b[i] ) / 2;
    StdAudio.play(a);
    
    0 讨论(0)
提交回复
热议问题