Mercurial > hg > Game > Cerium
changeset 2023:8c3c826ba4d5 draft
add make command "make test"
author | Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 21 Jul 2014 18:49:17 +0900 |
parents | fac44ad2867d |
children | 472528b62bbf |
files | example/synthesizer/AudioData.h example/synthesizer/Makefile example/synthesizer/main.cc example/synthesizer/ppe/OSC.cc |
diffstat | 4 files changed, 28 insertions(+), 21 deletions(-) [+] |
line wrap: on
line diff
--- a/example/synthesizer/AudioData.h Wed Jul 16 02:50:32 2014 +0900 +++ b/example/synthesizer/AudioData.h Mon Jul 21 18:49:17 2014 +0900 @@ -2,10 +2,10 @@ typedef struct audioData { struct audioData *self; int volume; - double Frequency; + double frequency; char *waveform_name; - int freq; + int sampling_rate; Uint16 format; Uint8 channels; Uint8 silence;
--- a/example/synthesizer/Makefile Wed Jul 16 02:50:32 2014 +0900 +++ b/example/synthesizer/Makefile Mon Jul 21 18:49:17 2014 +0900 @@ -21,7 +21,7 @@ @$(MAKE) -f Makefile.cuda test: - ./word_count -file c.txt + ./synthesizer parallel-test: macosx @$(MAKE) -f Makefile.macosx test
--- a/example/synthesizer/main.cc Wed Jul 16 02:50:32 2014 +0900 +++ b/example/synthesizer/main.cc Mon Jul 21 18:49:17 2014 +0900 @@ -23,28 +23,26 @@ extern void task_init(); CPU_TYPE spe_cpu = SPE_ANY; int volume = 3000; -double Frequency = 440; -char *waveform_name; +double frequency = 440; +char *waveform_name = "tri"; -const char *usr_help_str = "Usage: ./word_count [-a -c -s] [-cpu spe_num] [-g] [-file filename] [-br]\n"; +const char *usr_help_str = "Usage: ./synthesizer [-freq freqency] [-wave \"sqr\" or \"tri\"] [-vol volume]\n"; static void run_start(TaskManager *manager) { - AudioDataPtr au = (AudioDataPtr)manager->allocate(sizeof(AudioData)); au->self = au; au->volume = volume; - au->Frequency = Frequency; + au->frequency = frequency; au->waveform_name = waveform_name; - printf("Freq:%f\n",Frequency); - au->freq= 44100; /* Sampling rate: 44100Hz */ + printf("Freq:%f\n",frequency); + au->sampling_rate= 44100; /* Sampling rate: 44100Hz */ au->format= AUDIO_S16LSB; /* 16-bit signed audio */ au->channels= 1; /* Mono */ au->samples= 8192; /* Buffer size: 8K = 0.37 sec. */ - // au->callback= callback; au->userdata= NULL; HTaskPtr osc = manager->create_task(OSC_TASK); @@ -57,7 +55,7 @@ { for (int i = 1; argv[i]; ++i) { if (strcmp(argv[i], "-freq") == 0) { - Frequency = atof(argv[i+1]); + frequency = atof(argv[i+1]); } else if (strcmp(argv[i], "-wave") == 0) { waveform_name = argv[i+1]; } else if (strcmp(argv[i], "-vol") == 0) { @@ -70,6 +68,15 @@ int TMmain(TaskManager *manager, int argc, char *argv[]) { + init(argc, argv); + if(argc == 1) { + printf("%s",usr_help_str); + printf("Default settings\n"); + printf("frequency :%fHz(A)\n",frequency); + printf("wave :%s\n",waveform_name); + printf("Volume :%d\n",volume); + } + task_init(); run_start(manager); return 0;
--- a/example/synthesizer/ppe/OSC.cc Wed Jul 16 02:50:32 2014 +0900 +++ b/example/synthesizer/ppe/OSC.cc Mon Jul 21 18:49:17 2014 +0900 @@ -10,8 +10,6 @@ /* これは必須 */ SchedDefineTask1(Audioosc,osc); -int gvolume = 3000; -double gFrequency = 440; SDL_AudioSpec Desired; SDL_AudioSpec Obtained; @@ -34,7 +32,11 @@ void callback(void *userdata,Uint8 *stream,int len){ - char *waveform_name = (char*)userdata; + 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; @@ -42,13 +44,13 @@ if(strcmp(waveform_name, "tri")){ for (int i = 0; i < framesize ; i++, step++){ - frames[i] = tri(step * gFrequency / Obtained.freq) * gvolume ; + 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 * gFrequency / Obtained.freq) * gvolume ; + frames[i] = square(step * frequency / Obtained.freq) * volume ; } } @@ -59,18 +61,16 @@ { AudioData *i_data = (AudioDataPtr)s->get_input(0); - gvolume = i_data->volume; const char* waveform_name = "tri"; - gFrequency = i_data->Frequency; i_data->userdata = (void*)waveform_name; - Desired.freq = i_data->freq; /* Sampling rate: 44100Hz */ + Desired.freq = i_data->sampling_rate; /* Sampling rate: 44100Hz */ Desired.format = i_data->format; /* 16-bit signed audio */ Desired.channels = i_data->channels; /* Mono */ Desired.samples = i_data->samples; /* Buffer size: 8K = 0.37 sec. */ Desired.callback = callback; - Desired.userdata = i_data->userdata; + Desired.userdata = (void*)i_data; SDL_OpenAudio(&Desired, &Obtained); SDL_PauseAudio(0);