Appendix. Computational parts of the program lists for Each Systems

Appendix A. Simulation System

/*
** system's header files
*/
#include <windows.h>
#include <string.h>
#include <stdio.h>
#include <math.h>

/*
** user's header files
*/
#include "..\..\inc\common.h"
#include "..\..\inc\mimdef.h"
/*
** prtotype functions
*/
exterm void KmCxdr(double *,double *,double,double *,double *,double*);

double zDX[3],zDY[3],zDZ[3],zAX,zBY,zCZ,zDD;

void KmClfg(double *CENT,double *XAXS,double XROT,double *A,double *B);

/*
** <Title>    Transform the equation of spherical surface by local coordinates system into generalized doordinates.
*/
void KmClfg(double *CENT,double *XAXS,double XROT,double *A,double *B)
{
/*
** double CENT[3]    (I ) :position of spher by local coordinates system
** double XAXS[3]    (I ) :direction of X-axis
** double XROT    (I ) :rotation angle with X-axis
** double A[4]    (I ) :the equation of spherical surface
** double B[4]    ( O) :the equation of spherical surface by generalized coordinates
*/

    /* Calculate the direction of axis. */
    KmCxdr( CENT, XAXS, XROT, zDX, zDY, zDZ );

    /* Calculate the equation of spherical surface. */
    zAX = zDX[X_CO] * A[KSU_A] + zDY[X_CO] * A[KSU_B] + zDZ[X_CO] * A[KSU_C];
    zBY = zDX[Y_CO] * A[KSU_A] + zDY[Y_CO] * A[KSU_B] + zDZ[Y_CO] * A[KSU_C];
    zCZ = zDX[Z_CO] * A[KSU_A] + zDY[Z_CO] * A[KSU_B] + zDZ[Z_CO] * A[KSU_C];

    zDD = -(zAX * CENT[X_CO] + zBY * CENT[Y_CO] + zCZ * CENT[Z_CO]) + A[KSU_D];

    B[0] = zAX;
    B[1] = zBY;
    B[2] = zCZ;
    B[3] = zDD;

    return;
}


Appendix B. Diagnostic System for Sound Fields in the Room

The point where the energy which does not include the minimum reflection time of the reflection from a floor is maximum is obtained by the sum of all frequency band.

///////////////////////////////////////////////////////////////////////////
//
//    function :calculation of Dt1
//
//    argument :pData - impulse answer data
//                            nData - number of impulse answer data
//                            fRate - sampling rate
//                           minTime - minimum delay time of reflection
//                            pT0 - delay time of the direct sound(output)
//                            pT1 - delay time of the first reflection sound(output)
//
//    return value :no
//
///////////////////////////////////////////////////////////////////////////

void CalcParamDeltaT1(float *pData, int nData, double fRate, double minTime,
        double *pT0, double *pT1)
{
    float T0Level, T1Level;
    int T0Pos, T1Pos;
    float maxLevel;
    int i;
    float data;
    int startPos;
    BOOL bUpFlag;

    // Ascertain exsitence of impulse answer data.
    if (pData == NULL) {
        *pT0 = 0;
        *pT1 = 0;
        return;
   }

    // Calculate the maximum peak value of impulse answer data.
    maxLevel = 0;
    for (i = 1; i < nData / 2; i++) {
        data = (float)fabs(pData[i]);
        if (data > maxLevel)
            maxLevel = data;
    }

    // Calculate the delay time of the diredt sound.
    T0Level = 0;
    T0Pos = 0;
    for (i = 1; i < nData / 2; i++) {
        data = (float)fabs(pData[i]);
        if (data > (float)fabs(pData[i - 1]) && data > (float)fabs(pData[i + 1])) {
            if (data > T0Level) {
                T0Level = data;
                T0Pos = i;
            } else if (T0Level > maxLevel / 5)
                break;
        }
    }

    // Calculate the position where it passed for minimum delay time of reflection from direct sound.
    startPos = (int)(T0Pos + minTime / 1000 * fRate) + 1;
    if (startPos >= nData)
        startPos = nData - 1;

    // Calculate the maximum peak value after above positon.
    maxLevel = 0;
    for (i = startPos; i < nData / 2; i++) {
        data = (float)fabs(pData[i]);
        if (data > maxLevel)
            maxLevel = data;
    }

    // Calculate the delay time of the first reflection sound.
    T1Level = 0;
    T1Pos = 0;
    bUpFlag = FALSE;
    for (i = startPos; i < nData / 2; i++) {
        data = (float)fabs(pData[i]);
        if (data > (float)fabs(pData[i - 1]) && data > (float)fabs(pData[i + 1])) {
            if (bUpFlag) {
                if (data > T1Level) {
                    T1Level = data;
                    T1Pos = i;
                } else if (T1Level > maxLevel / 2)
                    break;
            } else {
                if (T1Level != 0 && data > T1Level && data > maxLevel / 10)
                    bUpFlag = TRUE;
                else {
                    T1Level = data;
                    T1Pos = i;
                }
            }
        }
    }

    // Calculate the time direct sound and first reflection sound in milli-second unit.
    *pT0 = (double)T0Pos / fRate * 1000;
    *pT1 = (double)T1Pos / fRate * 1000;
}


Appendix C. Diagnostic System for Environmental Noise

Algorithm for the identification of the sound source

///////////////////////////////////////////////////////////////////////////
//
//    function :identification with noise source
//
//    argument :pNmsFactorData - AFC factor data
//                    nNmsFactorData - number of AFC factor data
//                    pNoiseSrcData - data of noise source(output)
//
//    return value :ID-number of noise source template
//
///////////////////////////////////////////////////////////////////////////
long Identification(NmsFactorData *pNmsFactorData, int nNmsFactorData, NoiseSrcData *pNoiseSrcData)
{
    CDbNsTmp dbNsTmp;
    DbNsTmpRec dbNsTmpRec;
    NsTmpData nsTmpData;
    AcfFactorData acfFactorData;
    float fdPhi0;
    float fdTaue;
    float fdTau1;
    float fdPhi1;
    float fdTotal;
    float fdMin;
    CString str;
    NsWeightData nsWeightData;
    long nNoiseTmpID = -1;

    // Open the database about noise source template.
    if (!dbNsTmp.Open())
        return nNoiseTmpID;

    // When AFC factor data is zero, noise source can't identify.
    if (nNmsFactorData == 0)
        return nNoiseTmpID;

    // Acquisition of weight coefficient.
    ReadNsWeightData(&nsWeightData);

    // Acquire the factor whose F(0) made the target of identification is the biggest.
    acfFactorData = GetNoiseAcfFactor(pNmsFactorData, nNmsFactorData);

    // The initialization of the name of noise source.(initial name is unknown)
    str.LoadString(IDS_UNKNOWN);
    strcpy(pNoiseSrcData->name, str);

    // The initialization of distance variable.
    fdMin = 1000;

    // Look up the template that distance becomes the smallest.
    for (;;) {
    // Acquisition of noise source template.
        if (!dbNsTmp.ReadRecNext(&dbNsTmpRec, &nsTmpData))
            break;

        // Check limit value, and calculate a distance inside the range.
        if ((!nsTmpData.bPhi0LowerCheck || acfFactorData.fPhi0 >= nsTmpData.fPhi0LowerLimit)
                && (!nsTmpData.bPhi0UpperCheck || acfFactorData.fPhi0 <= nsTmpData.fPhi0UpperLimit)
                && (!nsTmpData.bTaueLowerCheck || acfFactorData.fTauE >= nsTmpData.fTaueLowerLimit)
                && (!nsTmpData.bTaueUpperCheck || acfFactorData.fTauE <= nsTmpData.fTaueUpperLimit)
                && (!nsTmpData.bTau1LowerCheck || acfFactorData.fTau1 >= nsTmpData.fTau1LowerLimit)
                && (!nsTmpData.bTau1UpperCheck || acfFactorData.fTau1 <= nsTmpData.fTau1UpperLimit)
                && (!nsTmpData.bPhi1LowerCheck || acfFactorData.fPhi1 >= nsTmpData.fPhi1LowerLimit)
                && (!nsTmpData.bPhi1UpperCheck || acfFactorData.fPhi1 <= nsTmpData.fPhi1UpperLimit)) {

            // Calculate the distance between template with factor of data that was measured.
            fdPhi0 = (float)fabs(acfFactorData.fPhi0 - nsTmpData.fPhi0Standard) / 10 * nsWeightData.fPhi0;
            fdTaue = (float)fabs(log(acfFactorData.fTauE) - log(nsTmpData.fTaueStandard)) * nsWeightData.fTaue;
            fdTau1 = (float)fabs(log(acfFactorData.fTau1) - log(nsTmpData.fTau1Standard)) * nsWeightData.fTau1;
            fdPhi1 = (float)fabs(log(acfFactorData.fPhi1) - log(nsTmpData.fPhi1Standard)) * nsWeightData.fPhi1;
            fdTotal = fdPhi0 + fdTaue + fdTau1 + fdPhi1;

            // Output the template --factor and name of noise source-- of the minimum distance.
            if (fdTotal < fdMin) {
                fdMin = fdTotal;
                pNoiseSrcData->fdPhi0 = fdPhi0;
                pNoiseSrcData->fdTauE = fdTaue;
                pNoiseSrcData->fdTau1 = fdTau1;
                pNoiseSrcData->fdPhi1 = fdPhi1;
                strcpy(pNoiseSrcData->name, dbNsTmpRec.name);
                nNoiseTmpID = dbNsTmpRec.nsTmpID;
            }
        }
    }

    return nNoiseTmpID;
}

| BACK |