Please check out [url=http://www.phy.ntnu.edu.tw/ntnujava/index.php?topic=1073.msg4021#msg4021]EJS version of Fourier Synthesis (You can hear the sound,too!)[/url].

I create my own java class to generate sound, and added it to EJS.

Add jar under run option, and add import statement, then you should be able to used it in the code.

Please do check out the above example.