<p>I'm looking into writing a audio syntesizer in Java, and was wondering if anybody has any advice or good resources for writing such a program. I'm looking for info on generating raw sound waves, how to output them into a usable form (playing over speakers), as well as general theory on the topic. Thanks guys.</p>

[{'answer_id': 36588, 'author': 'David Crow', 'author_id': 2783, 'author_profile': 'https://Stackoverflow.com/users/2783', 'pm_score': 2, 'selected': False, 'text': '<p>Check out <a href="http://frinika.sourceforge.net/" rel="nofollow noreferrer">Frinika</a>. It\'s a full-featured music workstation implemented in Java (open source). Using the API, you can run midi events through the synthesizer, read the raw sound output, and write it to a WAV file (see source code link below).</p>\n\n<p>Additional information:</p>\n\n<ul>\n<li><a href="http://frinika.wikispaces.com/DeveloperArea" rel="nofollow noreferrer">Frinika Developer Area</a></li>\n<li><a href="http://frinika.svn.sourceforge.net/viewvc/frinika/frinika/trunk/src/com/frinika/tools/MyMidiRenderer.java?view=markup" rel="nofollow noreferrer">Source code for midi renderer tool</a></li>\n</ul>\n'}, {'answer_id': 38203, 'author': 'secr', 'author_id': 4085, 'author_profile': 'https://Stackoverflow.com/users/4085', 'pm_score': 4, 'selected': True, 'text': '<ol>\n<li><p>This problem is basically about mapping functions to arrays of numbers. A language that  supports first-class functions would come in really handy here.</p></li>\n<li><p>Check out\n<a href="http://www.harmony-central.com/Computer/Programming" rel="nofollow noreferrer">http://www.harmony-central.com/Computer/Programming</a> and\n<a href="http://www.developer.com/java/other/article.php/3071021" rel="nofollow noreferrer">http://www.developer.com/java/other/article.php/3071021</a> for some Java-related info.</p></li>\n<li><p>If you don\'t know the basic concepts of encoding sound data, then read <a href="http://en.wikipedia.org/wiki/Sampling_rate" rel="nofollow noreferrer">http://en.wikipedia.org/wiki/Sampling_rate</a></p></li>\n<li><p>The canonical WAVE format is very simple, see <a href="http://www.lightlink.com/tjweber/StripWav/Canon.html" rel="nofollow noreferrer">http://www.lightlink.com/tjweber/StripWav/Canon.html</a>. A header (first 44 bytes) + the wave-data. You don\'t need any library to implement that.</p></li>\n</ol>\n\n<p>In C/C++, the corresponding data structure would look something like this:</p>\n\n<pre class="lang-cpp prettyprint-override"><code>typedef struct _WAVstruct\n{\n    char headertag[4];\n    unsigned int remnantlength;\n    char fileid[4];\n\n    char fmtchunktag[4];\n    unsigned int fmtlength;\n    unsigned short fmttag;\n    unsigned short channels;\n    unsigned int samplerate;\n    unsigned int bypse;\n    unsigned short ba;\n    unsigned short bipsa;\n\n    char datatag[4];\n    unsigned int datalength;\n\n    void* data; //&lt;--- that\'s where the raw sound-data goes\n}* WAVstruct;\n</code></pre>\n\n<p>I\'m not sure about Java. I guess you\'ll have to substitute "struct" with "class" and "void* data" with "char[] data" or "short[] data" or "int[] data", corresponding to the number of bits per sample, as defined in the field bipsa.</p>\n\n<p>To fill it with data, you would use something like that in C/C++:</p>\n\n<pre class="lang-cpp prettyprint-override"><code>int data2WAVstruct(unsigned short channels, unsigned short bipsa, unsigned int samplerate, unsigned int datalength, void* data, WAVstruct result)\n{\n    result-&gt;headertag[0] = \'R\';\n    result-&gt;headertag[1] = \'I\';\n    result-&gt;headertag[2] = \'F\';\n    result-&gt;headertag[3] = \'F\';\n    result-&gt;remnantlength = 44 + datalength - 8;\n    result-&gt;fileid[0] = \'W\';\n    result-&gt;fileid[1] = \'A\';\n    result-&gt;fileid[2] = \'V\';\n    result-&gt;fileid[3] = \'E\';\n\n    result-&gt;fmtchunktag[0] = \'f\';\n    result-&gt;fmtchunktag[1] = \'m\'; \n    result-&gt;fmtchunktag[2] = \'t\';\n    result-&gt;fmtchunktag[3] = \' \';\n    result-&gt;fmtlength = 0x00000010;\n    result-&gt;fmttag = 1;\n    result-&gt;channels = channels;\n    result-&gt;samplerate = samplerate;\n    result-&gt;bipsa = bipsa;\n    result-&gt;ba = channels*bipsa / 8;\n    result-&gt;bypse = samplerate*result-&gt;ba;\n\n    result-&gt;datatag[0] = \'d\';\n    result-&gt;datatag[1] = \'a\';\n    result-&gt;datatag[2] = \'t\';\n    result-&gt;datatag[3] = \'a\';\n    result-&gt;datalength = datalength;\n\n    result-&gt;data = data; // &lt;--- that\'s were the data comes in\n\n    return 0; // an error code, not implemented, yet ...; in Java: return result\n}\n</code></pre>\n\n<p>Again, I\'m not sure about Java but the conversion should be straightforward if you convert the void-pointer to an array corresponding to the bitrate. </p>\n\n<p>Then simply write the entire structure to a file to get a playable wave file.</p>\n'}, {'answer_id': 38480, 'author': 'Nick Higgs', 'author_id': 3187, 'author_profile': 'https://Stackoverflow.com/users/3187', 'pm_score': 2, 'selected': False, 'text': '<p>While studying for my degree, my dissertation project was the creation of a Java based modular synthesizer, and the University at which I studied saw fit to make my report publicly available:</p>\n\n<p><a href="http://www.dcs.shef.ac.uk/intranet/teaching/projects/archive/ug2004/pdf/u1nh.pdf" rel="nofollow noreferrer">A Software Based Modular Synthesiser in Java</a></p>\n'}, {'answer_id': 86359, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 1, 'selected': False, 'text': '<p>I dont\'t know if that helps, but if you can use MIDI for anything, you should check out <a href="http://www.jfugue.org/" rel="nofollow noreferrer">JFuge</a>.</p>\n'}]
['https://Stackoverflow.com/questions/36567', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/-1/']