/* Huang-Jung Chang 13207260 Final Project on Virtual Location Please see paper for details */ #include #include #define R 0.5 #define FREQDIF 700.0 float ampgain(float x, float y, float xs, float ys); float speakerdis(float r); // calculating the amplitude gains for each speaker // a = 1 - sqr(d) float ampgain ( float x, float y, float xs, float ys) { float xi, yi, a; xi = x - xs; yi = y - ys; a = 1 - (yi * yi + xi * xi); return a; } // speaker distance for the origin float speakerdis(float r) { return (r/sqrt(2.0)); } void main() { float x, y; float a1, a2, a3, a4, alla; float dis, ndis; float freq; float rx, ry; double q; printf("please enter x coordinate value of sound source: "); scanf("%f", &x); printf("please enter y coordinate value of sound source: "); scanf("%f", &y); printf("please enter frequency value of sound source: "); scanf("%f", &freq); dis = speakerdis(R); ndis = 0 - dis; // negative value according to coordinate a1 = ampgain(x, y, ndis, dis); // amplitudes for each speakers a2 = ampgain(x, y, dis, dis); a3 = ampgain(x, y, dis, ndis); a4 = ampgain(x, y, ndis, ndis); printf("the gain of speaker 1 is %f\n", a1); printf("the gain of speaker 2 is %f\n", a2); printf("the gain of speaker 3 is %f\n", a3); printf("the gain of speaker 4 is %f\n", a4); if ( freq > FREQDIF) { a1 = a1 * a1; a2 = a2 * a2; a3 = a3 * a3; a4 = a4 * a4; } alla = a1+a2+a3+a4; rx = (a1*ndis + a2*dis + a3*dis + a4*ndis) / alla; ry = (a1*dis + a2*dis + a3*ndis + a4*ndis) / alla; q = atan(ry/rx); if (freq <= FREQDIF) { printf("the velocity vector of the virtual sound source is (%f, %f) \n", rx, ry); printf("the velocity theta angle is %f in radian\n", q); } else { printf("the energy vector of the virtual sound source is (%f, %f) \n", rx, ry); printf("the energy theta angle is %f in radian\n", q); } }