Mercurial > hg > Game > Cerium
changeset 2026:652dd569acc1 draft
add audio_settings function
author | Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 10 Aug 2014 18:44:47 +0900 |
parents | f31415b52f51 |
children | cd2ef2861eb1 |
files | example/synthesizer/main.cc example/synthesizer/ppe/OSC.cc |
diffstat | 2 files changed, 21 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/example/synthesizer/main.cc Wed Aug 06 02:09:05 2014 +0900 +++ b/example/synthesizer/main.cc Sun Aug 10 18:44:47 2014 +0900 @@ -29,10 +29,9 @@ const char *usr_help_str = "Usage: ./synthesizer -wave \"sqr\" or \"tri\" [-freq freqency] [-vol volume]"; -static void -run_start(TaskManager *manager) +void +audio_settings(AudioDataPtr au) { - AudioDataPtr au = (AudioDataPtr)manager->allocate(sizeof(AudioData)); au->self = au; au->volume = volume; @@ -46,6 +45,15 @@ au->channels= 1; /* Mono */ au->samples= 8192; /* Buffer size: 8K = 0.37 sec. */ au->userdata= NULL; +} + + +static void +run_start(TaskManager *manager) +{ + AudioDataPtr au = (AudioDataPtr)manager->allocate(sizeof(AudioData)); + + audio_settings(au); HTaskPtr osc = manager->create_task(OSC_TASK); osc->set_inData(0,au,sizeof(AudioDataPtr));
--- a/example/synthesizer/ppe/OSC.cc Wed Aug 06 02:09:05 2014 +0900 +++ b/example/synthesizer/ppe/OSC.cc Sun Aug 10 18:44:47 2014 +0900 @@ -13,15 +13,17 @@ SDL_AudioSpec Desired; SDL_AudioSpec Obtained; -double square(double t){ +double +square(double t) +{ double decimal_part = t - abs(t); return decimal_part < 0.5 ? 1 : -1; } -double tri(double t){ - +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{ @@ -29,7 +31,9 @@ } } -double saw(double t){ +double +saw(double t) +{ double decimal_part = t - abs(t); return decimal_part; } @@ -60,7 +64,6 @@ for (int i = 0; i < framesize ; i++, step++){ frames[i] = saw(step * frequency / Obtained.freq) * volume ; } - } } @@ -78,7 +81,7 @@ SDL_OpenAudio(&Desired, &Obtained); SDL_PauseAudio(0); - SDL_Delay(200); + SDL_Delay(1000); SDL_Quit(); return 0;