# HG changeset patch
# User Masataka Kohagura
@@ -133,6 +133,35 @@
+ コンピュータ上で作曲を行うときは、ハードウェアシンセサイザーの音を録音するのではなく、ソフトウェアシンセサイザー(以下ソフトシンセ)で収録することが主流となっている。 +
++ ソフトシンセのマルチコア化は進んでいる。しかし、現状としてはマルチコアで駆動しているわけではなく、1つのコアだけに負荷がかかるものが多い。 +
+
+ 作曲をする上ではソフトシンセを複数立ち上げることが基本となっている。
+ また、オシレーターの複数使用や Filter による波形編集を重ねると計算量が大きくなっていくため、ソフトシンセ単体の動作を軽量化する必要がある。
+
+ また、実用的なシンセサイザーは入力に対するレスポンスが必須となるので、計算量が多くなっても入力から出力までの遅延を抑える必要がある。 +
+
+ (軽量化しながら音を良くしたいが、抽象的すぎて評価する点がみつけづらい)
+ 音がいいって何??
+ 評価どうするの??
+
+
+typedef struct SDL_AudioSpec {
+ int freq; /** DSP frequency -- samples per second */
+ Uint16 format; /** Audio data format */
+ Uint8 channels; /** Number of channels: 1 mono, 2 stereo */
+ Uint8 silence; /** Audio buffer silence value (calculated) */
+ Uint16 samples; /** Audio buffer size in samples (power of 2) */
+ Uint16 padding; /** Necessary for some compile environments */
+ Uint32 size; /** Audio buffer size in bytes (calculated) */
+ void (SDLCALL *callback)(void *userdata, Uint8 *stream, int len);
+ void *userdata;
+} SDL_AudioSpec;
+
+
+
+
+
+SDL_AudioSpec Desired;
+SDL_AudioSpec Obtained;
+
+int main(int argc, char *argv[])
+{
+ printf("Freq:%f\n",Frequency);
+ Desired.freq= 44100; /* Sampling rate: 44100Hz */
+ Desired.format= AUDIO_S16LSB; /* 16-bit signed audio */
+ Desired.channels= 1; /* Mono */
+ Desired.samples= 8192; /* Buffer size: 8K = 0.37 sec. */
+ Desired.callback= callback;
+ Desired.userdata= NULL;
+
+ SDL_OpenAudio(&Desired, &Obtained);
+ SDL_PauseAudio(0);
+ SDL_Delay(200);
+ SDL_Quit();
+ return 0;
+}
+
+
+
+
+
+void callback(void *userdata,Uint8 *stream,int len){
+
+ AudioDataPtr au = (AudioData*)userdata;
+
+ char *waveform_name = au->waveform_name;
+ double frequency = au->frequency;
+ int volume = au->volume;
+ static unsigned int step = 0;
+ Uint16 *frames = (Uint16 *) stream;
+ int framesize = len / 2;
+
+ if(strcmp(waveform_name, "tri")){
+
+ for (int i = 0; i < framesize ; i++, step++){
+ frames[i] = tri(step * frequency / Obtained.freq) * volume ;
+ }
+
+ }else if(strcmp(waveform_name, "sqr")){
+
+ for (int i = 0; i < framesize ; i++, step++){
+ frames[i] = square(step * frequency / Obtained.freq) * volume ;
+ }
+
+ }
+}
+
+
+
+ 矩形波
+
+
+double
+square(double t){
+ double decimal_part = t - abs(t);
+ return decimal_part < 0.5 ? 1 : -1;
+}
+
+
+
+
+
+ 三角波
+ +
+
+double
+tri(double t){
+
+ double decimal_part = t - abs(t);
+
+ if(abs(t) % 2 != 0){
+ return decimal_part < 0.5 ? decimal_part : 1 - decimal_part;
+ }else{
+ return decimal_part < 0.5 ? -decimal_part : 1 - decimal_part;
+ }
+}
+
+
+
+
+
+
+ のこぎり波
+
+
+double
+saw(double t)
+{
+ double decimal_part = t - abs(t);
+ return decimal_part;
+}
+
+
+
+
+