初学者数字合成器 [英] Beginner Digital Synth
问题描述
我正在研究用Java编写音频合成器,并且想知道是否有人对编写这样的程序有任何建议或良好的资源.我正在寻找有关生成原始声波,如何将其输出为可用形式(通过扬声器播放)以及有关该主题的一般理论的信息.谢谢大家.
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.
推荐答案
-
此问题基本上与将函数映射到数字数组有关.支持一流功能的语言在这里非常有用.
This problem is basically about mapping functions to arrays of numbers. A language that supports first-class functions would come in really handy here.
退房 http://www.harmony-central.com/Computer/Programming 和 http://www.developer.com/java/other/article.php/3071021 获取一些与Java有关的信息.
Check out http://www.harmony-central.com/Computer/Programming and http://www.developer.com/java/other/article.php/3071021 for some Java-related info.
如果您不了解编码声音数据的基本概念,请阅读 http://en.wikipedia.org/wiki/Sampling_rate
If you don't know the basic concepts of encoding sound data, then read http://en.wikipedia.org/wiki/Sampling_rate
规范的WAVE格式非常简单,请参见 http://www.lightlink.com/tjweber/StripWav/Canon.html .标头(前44个字节)+ wave数据.您不需要任何库即可实现.
The canonical WAVE format is very simple, see http://www.lightlink.com/tjweber/StripWav/Canon.html. A header (first 44 bytes) + the wave-data. You don't need any library to implement that.
在C/C ++中,相应的数据结构如下所示:
In C/C++, the corresponding data structure would look something like this:
typedef struct _WAVstruct
{
char headertag[4];
unsigned int remnantlength;
char fileid[4];
char fmtchunktag[4];
unsigned int fmtlength;
unsigned short fmttag;
unsigned short channels;
unsigned int samplerate;
unsigned int bypse;
unsigned short ba;
unsigned short bipsa;
char datatag[4];
unsigned int datalength;
void* data; //<--- that's where the raw sound-data goes
}* WAVstruct;
我不确定Java.我想您必须将结构"替换为类",将"void *数据"替换为"char []数据"或"short []数据"或"int []数据",这对应于每位的位数样本,如bipsa字段中所定义.
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.
要在其中填充数据,您可以在C/C ++中使用类似的东西:
To fill it with data, you would use something like that in C/C++:
int data2WAVstruct(unsigned short channels, unsigned short bipsa, unsigned int samplerate, unsigned int datalength, void* data, WAVstruct result)
{
result->headertag[0] = 'R';
result->headertag[1] = 'I';
result->headertag[2] = 'F';
result->headertag[3] = 'F';
result->remnantlength = 44 + datalength - 8;
result->fileid[0] = 'W';
result->fileid[1] = 'A';
result->fileid[2] = 'V';
result->fileid[3] = 'E';
result->fmtchunktag[0] = 'f';
result->fmtchunktag[1] = 'm';
result->fmtchunktag[2] = 't';
result->fmtchunktag[3] = ' ';
result->fmtlength = 0x00000010;
result->fmttag = 1;
result->channels = channels;
result->samplerate = samplerate;
result->bipsa = bipsa;
result->ba = channels*bipsa / 8;
result->bypse = samplerate*result->ba;
result->datatag[0] = 'd';
result->datatag[1] = 'a';
result->datatag[2] = 't';
result->datatag[3] = 'a';
result->datalength = datalength;
result->data = data; // <--- that's were the data comes in
return 0; // an error code, not implemented, yet ...; in Java: return result
}
同样,我不确定Java,但是如果将空指针转换为与比特率相对应的数组,则转换应该很简单.
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.
然后只需将整个结构写入文件即可获得可播放的wave文件.
Then simply write the entire structure to a file to get a playable wave file.
这篇关于初学者数字合成器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!