Beispiel #1
0
static void *Audio_Record_thread(void *mPtr)
{
    struct headset *hds  = (struct headset *)mPtr;
    ALOGD(TAG "%s: Start", __FUNCTION__);
    usleep(100000);
    bool dumpFlag = read_preferred_recorddump();
    //    bool dumpFlag = true;//for test
    int magLower = 0, magUpper = 0;
    read_preferred_magnitude(&magUpper, &magLower);
    int lowFreq = 1000 * (1 - 0.1); //1k
    int highFreq = 1000 * (1 + 0.1);
    short pbuffer[8192] = {0};
    short pbufferL[4096] = {0};
    short pbufferR[4096] = {0};
    unsigned int freqDataL[3] = {0}, magDataL[3] = {0};
    unsigned int freqDataR[3] = {0}, magDataR[3] = {0};
    int checkCnt = 0;
    uint32_t samplerate = 0;

    // headsetLR: Phone level test; headset: Non-Phone level test.
    return_data.headsetL.freqL = return_data.headsetR.freqL = return_data.headset.freqL = freqDataL[0];
    return_data.headsetL.freqR = return_data.headsetR.freqR = return_data.headset.freqR = freqDataR[0];
    return_data.headsetL.amplL = return_data.headsetR.amplL = return_data.headset.amplL = magDataL[0];
    return_data.headsetL.amplR = return_data.headsetR.amplR = return_data.headset.amplR = magDataR[0];

    recordInit(hds->recordDevice, &samplerate);
    while (1)
    {
        memset(pbuffer, 0, sizeof(pbuffer));
        memset(pbufferL, 0, sizeof(pbufferL));
        memset(pbufferR, 0, sizeof(pbufferR));

        int readSize  = readRecordData(pbuffer, 8192 * 2);
        for (int i = 0 ; i < 4096 ; i++)
        {
            pbufferL[i] = pbuffer[2 * i];
            pbufferR[i] = pbuffer[2 * i + 1];
        }

        if (dumpFlag)
        {
            char filenameL[] = "/data/record_headset_dataL.pcm";
            char filenameR[] = "/data/record_headset_dataR.pcm";
            FILE *fpL = fopen(filenameL, "wb+");
            FILE *fpR = fopen(filenameR, "wb+");

            if (fpL != NULL)
            {
                fwrite(pbufferL, readSize / 2, 1, fpL);
                fclose(fpL);
            }

            if (fpR != NULL)
            {
                fwrite(pbufferR, readSize / 2, 1, fpR);
                fclose(fpR);
            }
        }

        memset(freqDataL, 0, sizeof(freqDataL));
        memset(freqDataR, 0, sizeof(freqDataR));
        memset(magDataL, 0, sizeof(magDataL));
        memset(magDataR, 0, sizeof(magDataR));
        ApplyFFT256(samplerate, pbufferL, 0, freqDataL, magDataL);
        ApplyFFT256(samplerate, pbufferR, 0, freqDataR, magDataR);        
        for (int i = 0; i < 3 ; i ++)
        {
            SXLOGV("%d.freqDataL[%d]:%d,magDataL[%d]:%d", i, i, freqDataL[i], i, magDataL[i]);
            SXLOGV("%d.freqDataR[%d]:%d,magDataR[%d]:%d", i, i, freqDataR[i], i, magDataR[i]);
        }

        if (hds->isPhoneTest)
        {
            if (headset_phonetest_state == 0) // CH1
            {
                //CH1 Log
                return_data.headsetL.freqL = freqDataL[0];
                return_data.headsetL.amplL = magDataL[0];
                return_data.headsetL.freqR = freqDataR[0];
                return_data.headsetL.amplR = magDataR[0];

                if ((freqDataL[0] <= highFreq && freqDataL[0] >= lowFreq) && (magDataL[0] <= magUpper && magDataL[0] >= magLower))
                {
                    checkCnt ++;
                    if (checkCnt >= 5)
                    {
                        ALOGD("[Headset-L] freqDataL:%d,magDataL:%d,freqDataR:%d,magDataR:%d", freqDataL[0], magDataL[0], freqDataR[0], magDataR[0]);
                        checkCnt = 0;
                    }
                }
                else
                {
                    checkCnt = 0;
                }
            }
            else if (headset_phonetest_state == 1) // CH2
            {
                if ((freqDataR[0] <= highFreq && freqDataR[0] >= lowFreq) && (magDataR[0] <= magUpper && magDataR[0] >= magLower))
                {
                    checkCnt ++;
                    if (checkCnt >= 5)
                    {
                        ALOGD("[Headset-R] freqDataL:%d,magDataL:%d,freqDataR:%d,magDataR:%d", freqDataL[0], magDataL[0], freqDataR[0], magDataR[0]);
                        snprintf(hds->info, sizeof(hds->info), "Check freq pass.\n");
                        ALOGD(" @ info : %s", hds->info);
                        break;
                    }
                }
                else
                {
                    checkCnt = 0;
                }
            }
            else
            {
                break;
            }
        }
        else // Non Phone level test
        {
            if (((freqDataL[0] <= highFreq && freqDataL[0] >= lowFreq) && (magDataL[0] <= magUpper && magDataL[0] >= magLower)) && ((freqDataR[0] <= highFreq && freqDataR[0] >= lowFreq) && (magDataR[0] <= magUpper && magDataR[0] >= magLower)))
            {
                checkCnt ++;
                if (checkCnt >= 5)
                {
                    snprintf(hds->info, sizeof(hds->info), "Check freq pass.\n");
                    ALOGD(" @ info : %s", hds->info);
                    break;
                }
            }
            else
            {
                checkCnt = 0;
            }

            if (hds->exit_thd)
            {
                break;
            }
        }
    }

    // Log and ATA Return
    if (hds->isPhoneTest)
    {
        //CH2 Log
        return_data.headsetR.freqL = freqDataL[0];
        return_data.headsetR.freqR = freqDataR[0];
        return_data.headsetR.amplL = magDataL[0];
        return_data.headsetR.amplR = magDataR[0];
        ALOGD(TAG "ATA Return Data[Headset-L]: [Mic1]Freq = %d, Amp = %d, [Mic2]Freq = %d, Amp = %d", return_data.headsetL.freqL, return_data.headsetL.amplL, return_data.headsetL.freqR, return_data.headsetL.amplR);
        ALOGD(TAG "ATA Return Data[Headset-R]: [Mic1]Freq = %d, Amp = %d, [Mic2]Freq = %d, Amp = %d", return_data.headsetR.freqL, return_data.headsetR.amplL, return_data.headsetR.freqR, return_data.headsetR.amplR);
    }
    else
    {
        return_data.headset.freqL = freqDataL[0];
        return_data.headset.freqR = freqDataR[0];
        return_data.headset.amplL = magDataL[0];
        return_data.headset.amplR = magDataR[0];
        ALOGD(TAG "ATA Return Data: FreqL = %d, FreqR = %d, AmpL = %d, AmpR = %d", return_data.headset.freqL, return_data.headset.freqR, return_data.headset.amplL, return_data.headset.amplR);
    }

    ALOGD(TAG "%s: Stop", __FUNCTION__);
    pthread_exit(NULL); // thread exit
    return NULL;
}
Beispiel #2
0
static void *Headset_THD_Record_thread(void *mPtr)
{
    struct headset *hds  = (struct headset *)mPtr;
    ALOGD(TAG "%s: Start", __FUNCTION__);
    usleep(100000);
    int magLower = 0, magUpper = 0;
    read_preferred_magnitude(&magUpper, &magLower);
    int freqOfRingtone = 1000;
    //int lowFreq = freqOfRingtone * (1-0.05);
    //int highFreq = freqOfRingtone * (1+0.05);
    short pbuffer[8192] = {0};
    short pbufferL[4096] = {0};
    short pbufferR[4096] = {0};
    //unsigned int freqDataL[3]={0},magDataL[3]={0};
    //unsigned int freqDataR[3]={0},magDataR[3]={0};
    float thdPercentage = 0;
    int lenL = 0, lenR = 0;
    float thdData[2][FFT_DAT_MAXNUM];
    audio_data_statistic headsetL_thd_sta, headsetR_thd_sta;

    uint32_t sampleRate;
    recordInit(hds->recordDevice, &sampleRate);
    while (1)
    {
        memset(pbuffer, 0, sizeof(pbuffer));
        memset(pbufferL, 0, sizeof(pbufferL));
        memset(pbufferR, 0, sizeof(pbufferR));

        int readSize  = readRecordData(pbuffer, 8192 * 2);
        for (int i = 0 ; i < 4096 ; i++)
        {
            pbufferL[i] = pbuffer[2 * i];
            pbufferR[i] = pbuffer[2 * i + 1];
        }

        if (headset_phonetest_state == 0) // L ch
        {
            thdPercentage = CalculateTHD(48000, pbufferL, freqOfRingtone, 0.0);
            ALOGD("HeadsetL THD: %f", thdPercentage);
            thdData[0][lenL] = thdPercentage;
            lenL++;
        }
        else if (headset_phonetest_state == 1)
        {
            thdPercentage = CalculateTHD(48000, pbufferR, freqOfRingtone, 0.0);
            ALOGD("HeadsetR THD: %f", thdPercentage);
            thdData[1][lenR] = thdPercentage;
            lenR++;
        }

        if (hds->exit_thd)
        {
            break;
        }
    }

    CalculateStatistics(&thdData[0][0], lenL, 5, 1, &headsetL_thd_sta);
    CalculateStatistics(&thdData[1][0], lenR, 5, 1, &headsetR_thd_sta);

    if (headsetL_thd_sta.deviation < 0.5 && headsetR_thd_sta.deviation < 0.5)
    {
        snprintf(hds->info + strlen(hds->info), sizeof(hds->info) - strlen(hds->info), "Check THD pass.\n");
        ALOGD(" @ info : %s", hds->info);
    }

    {
        return_data.headsetL_thd.thd.mean      = headsetL_thd_sta.mean;
        return_data.headsetL_thd.thd.deviation = headsetL_thd_sta.deviation;
        return_data.headsetL_thd.thd.max       = headsetL_thd_sta.max;
        return_data.headsetL_thd.thd.min       = headsetL_thd_sta.min;

        return_data.headsetR_thd.thd.mean      = headsetR_thd_sta.mean;
        return_data.headsetR_thd.thd.deviation = headsetR_thd_sta.deviation;
        return_data.headsetR_thd.thd.max       = headsetR_thd_sta.max;
        return_data.headsetR_thd.thd.min       = headsetR_thd_sta.min;

        ALOGD(TAG "ATA Return THD(Headset-L): Mean = %f, Deviation = %f, Max = %f, Min = %f", return_data.headsetL_thd.thd.mean, return_data.headsetL_thd.thd.deviation, return_data.headsetL_thd.thd.max, return_data.headsetL_thd.thd.min);
        ALOGD(TAG "ATA Return THD(Headset-R): Mean = %f, Deviation = %f, Max = %f, Min = %f", return_data.headsetR_thd.thd.mean, return_data.headsetR_thd.thd.deviation, return_data.headsetR_thd.thd.max, return_data.headsetR_thd.thd.min);
    }

    ALOGD(TAG "%s: Stop", __FUNCTION__);
    pthread_exit(NULL); // thread exit
    return NULL;
}