Hello,
Im having a bit of trouble with one of my methods. im new to C++ but have experince in java and this seems ok to me. Basically, all im wanting to do is fill up each array with data calculated elsewhere. When i print out the value of s in the method below its obviously the same as what i put in, but when i print for example volClip[vi], or each of the the elements in the arrays once they are full i get random data. I think its something to do with the way im initializing the arrays but im not exactly sure what. what do i need to do?
take a look at my code:
Code:
void clipBuffer ( float s, char mode )
{
static int vi = 0, pi = 0, zi = 0;
static float volClip[CLIPSIZE], pitClip[CLIPSIZE], zcrClip[CLIPSIZE];
switch (mode) {
case 'v':
volClip[vi] = s;
vi++;
printf("Mode %c vi %d\n", mode, vi);
printf("data %f",volClip[vi]);
break;
case 'p':
pitClip[pi] = s;
pi++;
printf("Mode %c pi %d\n", mode, pi);
printf("data %f ",pitClip[pi]);
break;
case 'z':
zcrClip[zi] = s;
zi++;
printf("Mode %c zi %d\n", mode, zi);
printf("data %f",zcrClip[zi]);
break;
default:
printf("Incorrect mode selected:\nOptions:\n\t");
printf("v - Volume\n\tp - Pitch\n\tz - ZCR\n\te - Energy ratio subband\n");
break;
}
// IF THEY'RE FULL THEN JUST PRINT IT OUT (FOR DEBUGGING)
if (vi == CLIPSIZE && pi == CLIPSIZE && zi == CLIPSIZE){
vi = 0;
pi = 0;
zi = 0;
int i;
printf("VOL\n");
for (i = 0; i < CLIPSIZE; ++i) {
printf("%d\n",volClip[i]);
}
printf("PIT\n");
for (i = 0; i < CLIPSIZE; ++i) {
printf("%d\n",pitClip[i]);
}
printf("ZCR\n");
for (i = 0; i < CLIPSIZE; ++i) {
printf("%d\n",zcrClip[i]);
}
}
}
Thanks very much for looking!
Steve