我正在研究用Java编写音频同步器,并且想知道是否有人有任何建议或良好的资源来编写这样的程序.我正在寻找有关生成原始声波的信息,如何将它们输出为可用的形式(在扬声器上播放),以及关于该主题的一般理论.多谢你们.
这个问题基本上是将函数映射到数字数组.支持一流功能的语言在这里非常方便.
有关Java相关信息,请访问 http://www.harmony-central.com/Computer/Programming和 http://www.developer.com/java/other/article.php/3071021.
如果您不了解编码声音数据的基本概念,请阅读http://en.wikipedia.org/wiki/Sampling_rate
规范的WAVE格式非常简单,请访问http://www.lightlink.com/tjweber/StripWav/Canon.html.标题(前44个字节)+波数据.您不需要任何库来实现它.
在C/C++中,相应的数据结构如下所示:
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.我想你必须将"struct"替换为"class"和"void*data"替换为"char [] data"或"short [] data"或"int [] data",对应于每位数样本,如字段bipsa中所定义.
要用数据填充它,你可以在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,但如果将void-pointer转换为与bitrate对应的数组,则转换应该是直截了当的.
然后简单地将整个结构写入文件以获得可播放的波形文件.