Mercurial > audlegacy-plugins
comparison src/paranormal/containers.c @ 166:a118245b88c7 trunk
[svn] - use a quantized variance instead of a fast fft sum for beat detection with thresholding
author | nenolod |
---|---|
date | Tue, 31 Oct 2006 22:09:04 -0800 |
parents | 0393aae79318 |
children | c9d736cdc93f |
comparison
equal
deleted
inserted
replaced
165:f57b76df3d96 | 166:a118245b88c7 |
---|---|
152 struct container_cycle_data | 152 struct container_cycle_data |
153 { | 153 { |
154 GSList *children; | 154 GSList *children; |
155 GSList *current; | 155 GSList *current; |
156 int last_change; | 156 int last_change; |
157 int last_beat; | |
158 }; | 157 }; |
159 | 158 |
160 static void | 159 static void |
161 container_cycle_init (gpointer *data) | 160 container_cycle_init (gpointer *data) |
162 { | 161 { |
174 container_cycle_exec (const struct pn_actuator_option *opts, | 173 container_cycle_exec (const struct pn_actuator_option *opts, |
175 gpointer data) | 174 gpointer data) |
176 { | 175 { |
177 struct container_cycle_data *cdata = (struct container_cycle_data*)data; | 176 struct container_cycle_data *cdata = (struct container_cycle_data*)data; |
178 int now; | 177 int now; |
179 int new_beat = ((pn_sound_data->pcm_data[0][0]+pn_sound_data->pcm_data[1][0]) >> 7) >= 80 ? 1 : 0; | 178 |
179 /* quantize the average energy of the pcm_data for beat detection. */ | |
180 int fftsum = | |
181 ((pn_sound_data->pcm_data[0][0] + pn_sound_data->pcm_data[1][0]) >> 6); | |
182 | |
183 /* | |
184 * if the energy's quantization is within this, trigger as a detected | |
185 * beat. | |
186 */ | |
187 int new_beat = (fftsum >= 350 && fftsum <= 600) ? 1 : 0; | |
180 | 188 |
181 /* | 189 /* |
182 * Change branch if all of the requirements are met for the branch to change. | 190 * Change branch if all of the requirements are met for the branch to change. |
183 */ | 191 */ |
184 if ((opts[1].val.bval == TRUE && new_beat != cdata->last_beat) || opts[1].val.bval == FALSE) | 192 if ((opts[1].val.bval == TRUE && new_beat != 0) || opts[1].val.bval == FALSE) |
185 { | 193 { |
186 now = SDL_GetTicks(); | 194 now = SDL_GetTicks(); |
187 | 195 |
188 if (now - cdata->last_change | 196 if (now - cdata->last_change |
189 > opts[0].val.ival * 1000) | 197 > opts[0].val.ival * 1000) |
193 /* FIXME: add randomization support */ | 201 /* FIXME: add randomization support */ |
194 if (cdata->current) | 202 if (cdata->current) |
195 cdata->current = cdata->current->next; | 203 cdata->current = cdata->current->next; |
196 } | 204 } |
197 } | 205 } |
198 | |
199 /* reset the tracking for on-beat branch changing. */ | |
200 cdata->last_beat = new_beat; | |
201 | 206 |
202 if (! cdata->current) | 207 if (! cdata->current) |
203 cdata->current = cdata->children; | 208 cdata->current = cdata->children; |
204 | 209 |
205 if (cdata->current) | 210 if (cdata->current) |