Mercurial > hg > Game > Cerium
changeset 2025:f31415b52f51 draft
implement saw
author | Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 06 Aug 2014 02:09:05 +0900 |
parents | 472528b62bbf |
children | 652dd569acc1 |
files | example/synthesizer/main.cc example/synthesizer/ppe/OSC.cc |
diffstat | 2 files changed, 14 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/example/synthesizer/main.cc Sun Jul 27 23:40:37 2014 +0900 +++ b/example/synthesizer/main.cc Wed Aug 06 02:09:05 2014 +0900 @@ -15,6 +15,7 @@ #include <sdl.h> #include <SDL_audio.h> #include <math.h> +#include <OpenAL/al.h> /* * PS3でCPU数が2以上の時に、あまりが計算されてない @@ -39,6 +40,7 @@ au->waveform_name = waveform_name; printf("Freq:%f\n",frequency); + printf("wav:%s\n",waveform_name); au->sampling_rate= 44100; /* Sampling rate: 44100Hz */ au->format= AUDIO_S16LSB; /* 16-bit signed audio */ au->channels= 1; /* Mono */
--- a/example/synthesizer/ppe/OSC.cc Sun Jul 27 23:40:37 2014 +0900 +++ b/example/synthesizer/ppe/OSC.cc Wed Aug 06 02:09:05 2014 +0900 @@ -29,6 +29,11 @@ } } +double saw(double t){ + double decimal_part = t - abs(t); + return decimal_part; +} + void callback(void *userdata,Uint8 *stream,int len){ @@ -41,18 +46,21 @@ Uint16 *frames = (Uint16 *) stream; int framesize = len / 2; - if(strcmp(waveform_name, "tri")){ - + if(strcmp(waveform_name, "tri") == 0){ for (int i = 0; i < framesize ; i++, step++){ frames[i] = tri(step * frequency / Obtained.freq) * volume ; } - }else if(strcmp(waveform_name, "sqr")){ - + }else if(strcmp(waveform_name, "sqr") == 0){ for (int i = 0; i < framesize ; i++, step++){ frames[i] = square(step * frequency / Obtained.freq) * volume ; } + }else if(strcmp(waveform_name, "saw") == 0){ + for (int i = 0; i < framesize ; i++, step++){ + frames[i] = saw(step * frequency / Obtained.freq) * volume ; + } + } } @@ -61,10 +69,6 @@ { AudioData *i_data = (AudioDataPtr)s->get_input(0); - const char* waveform_name = "tri"; - - i_data->userdata = (void*)waveform_name; - Desired.freq = i_data->sampling_rate; /* Sampling rate: 44100Hz */ Desired.format = i_data->format; /* 16-bit signed audio */ Desired.channels = i_data->channels; /* Mono */