changeset 2022:fac44ad2867d draft

make a sound
author Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
date Wed, 16 Jul 2014 02:50:32 +0900
parents 8130b38b5391
children 8c3c826ba4d5
files example/synthesizer/main.cc example/synthesizer/ppe/OSC.cc
diffstat 2 files changed, 15 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/example/synthesizer/main.cc	Wed Jul 16 01:28:20 2014 +0900
+++ b/example/synthesizer/main.cc	Wed Jul 16 02:50:32 2014 +0900
@@ -48,7 +48,7 @@
     au->userdata= NULL;
 
     HTaskPtr osc = manager->create_task(OSC_TASK);
-    osc->set_inData(0,(memaddr)&au->self,sizeof(memaddr));
+    osc->set_inData(0,au,sizeof(AudioDataPtr));
     osc->spawn();
 }
 
--- a/example/synthesizer/ppe/OSC.cc	Wed Jul 16 01:28:20 2014 +0900
+++ b/example/synthesizer/ppe/OSC.cc	Wed Jul 16 02:50:32 2014 +0900
@@ -12,7 +12,6 @@
 
 int gvolume = 3000;
 double  gFrequency = 440;
-char    *gwaveform_name;
 SDL_AudioSpec Desired;
 SDL_AudioSpec Obtained;
 
@@ -33,18 +32,20 @@
 }
 
 
-void callback(void *unused,Uint8 *stream,int len){
+void callback(void *userdata,Uint8 *stream,int len){
+
+    char *waveform_name = (char*)userdata;
     static unsigned int step = 0;
     Uint16 *frames = (Uint16 *) stream;
     int framesize = len / 2;
 
-    if(strcmp(gwaveform_name, "tri")){
+    if(strcmp(waveform_name, "tri")){
 
         for (int i = 0; i < framesize ; i++, step++){
             frames[i] = tri(step * gFrequency / Obtained.freq) * gvolume ;
         }
 
-    }else if(strcmp(gwaveform_name, "sqr")){
+    }else if(strcmp(waveform_name, "sqr")){
 
         for (int i = 0; i < framesize ; i++, step++){
             frames[i] = square(step * gFrequency / Obtained.freq) * gvolume ;
@@ -59,15 +60,17 @@
     AudioData *i_data = (AudioDataPtr)s->get_input(0);
 
     gvolume = i_data->volume;
-    gwaveform_name = i_data->waveform_name;
+    const char* waveform_name = "tri";
     gFrequency = i_data->Frequency;
 
-    Desired.freq= i_data->freq; /* 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;
+    i_data->userdata = (void*)waveform_name;
+
+    Desired.freq = i_data->freq; /* 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;
 
     SDL_OpenAudio(&Desired, &Obtained);
     SDL_PauseAudio(0);