⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 phonerec.c

📁 基于AVR制作的电话语音录制系统
💻 C
📖 第 1 页 / 共 5 页
字号:
    //y=((d[ 8]*0x190L)>>8)-d[ 9]+c; d[ 9]=d[ 8]; d[ 8]=y;    //y=((d[10]*0x17FL)>>8)-d[11]+c; d[11]=d[10]; d[10]=y;    //y=((d[12]*0x12BL)>>8)-d[13]+c; d[13]=d[12]; d[12]=y;    //y=((d[14]*0x104L)>>8)-d[15]+c; d[15]=d[14]; d[14]=y;    //y=((d[16]*0xD0L )>>8)-d[17]+c; d[17]=d[16]; d[16]=y;    //y=((d[18]*0x92L )>>8)-d[19]+c; d[19]=d[18]; d[18]=y;    if (++gcount==GOERTZEL_BLOCK_SIZE) {        gcount=cc=nn=0;        volatile short *aux=d;        d=q; q=aux;    }    if (nn<MAXGOERTZELITEMS) {        unsigned char one=nn<<1;         unsigned char two=one+1;        switch (cc) {            case 0: if (!nn) {                        at_least_one=FALSE; dtmf_digit=0;                    }                    q[one]>>=8;                    break;            case 1: q[two]>>=8;                    break;            case 2: mag =q[one]*q[one];                    break;            case 3: mag+=q[two]*q[two];                    break;                    // mag-=q[one]*((q[two]*gcos[nn])>>SHIFT);            case 4: coef=pgm_read_word(gcos+nn);                    //mag-=q[one]*((q[two]*coef)>>8);                    break;            case 5: coef*=q[two];                    coef>>=8;                    break;            case 6: coef*=q[one];                    break;            case 7: mag-=coef;                    break;            case 8:if (nn>0) {                       if (mag>10) {                            at_least_one=TRUE; dtmf_frames++;                            accum_flags |= ( (nn>4) ? 2 : 1 );                            accum[nn-1] += mag;                        }                    } else {                        // Dial/Remote ring/remote busy/invalid number                    }                    break;            case 9: q[one]=q[two]=0;//#define GOERTZEL_DEBUG#ifdef GOERTZEL_DEBUG                    xmit(CMD_BLOCK_START);                    xmit(CMD_GOERTZEL_DEBUG);                    xmit(nn);                    xmit_short(mag);#endif // GOERTZEL_DEBUG                    break;        }    } else {        if (nn==MAXGOERTZELITEMS) {            switch (cc) {                case 0:                    if (!at_least_one) {                        if (accum_flags==7 && dtmf_frames>1) {                            char  ri=-1,ci=-1;                            unsigned char n;                            unsigned short rv=0,cv=0;                            for (n=0;n<4;n++) {                                if (accum[n]>rv) rv=accum[n],ri=n;                            }                            for (n=4;n<8;n++) {                                if (accum[n]>cv) cv=accum[n],ci=n;                            }                            if (ri!=-1 && ci!=-1 && cv>100 && rv>100)                                dtmf_digit=pgm_read_byte(dtmf_digits+(ri*4+ci-4));                        }                        accum_flags=0; dtmf_frames=0;                    }                    if (accum_flags==3) {                        accum_flags=7;                    } else {                        if (accum_flags!=7) {                            unsigned char n;                            for (n=0;n<8;n++) accum[n]=0;                        }                    }                    break;                case 1:                    if (dtmf_digit) {                        xmit(CMD_BLOCK_START);                        xmit(CMD_DTMF_DETECTED);                        xmit(dtmf_digit);                        if (last_reported_hook==OnHook) {                            if (dtmf_digit=='A' || dtmf_digit=='B') {                                call_status=CallIncoming; dtmf_msg_pos=0;                                dtmf_string_clear(); call_timer_reset();#ifdef HAVE_MMC                                start_recording(0);#endif // HAVE_MMC                            } else {                                if (call_status==CallIncoming) {                                    dtmf_msg_pos++;                                    if (dtmf_msg_pos>1) {                                        if (dtmf_digit!='C') {                                            dtmf_string_putc(dtmf_digit);                                            if (dtmf_msg_pos==3 ||                                                dtmf_msg_pos==7)                                                    dtmf_string_putc('-');                                        }                                    }                                }                            }                        } else {                            if (call_status==CallOutgoing) {                                if (digit_age==200) {                                    dtmf_string_clear(); dialing_digits=FALSE;                                }                                dtmf_string_putc(dtmf_digit);                                if (dialing_digits) {                                    char c=dtmf_string[0];                                    if (c=='0') {                                        if (dtmf_string_length==1 ||                                            dtmf_string_length==4 ||                                            dtmf_string_length==7 ||                                            dtmf_string_length==11)                                                dtmf_string_putc('-');                                    } else {                                        if (c!='*' && c!='#') {                                            if (dtmf_string_length==4)                                                dtmf_string_putc('-');                                        }                                    }                                }                                digit_age=0; dtmf_digit=0;                            }                        }                    }                    else if (digit_age<200)                         digit_age++;                    else if (digit_age==200) {                        digit_age++;#ifdef HAVE_MMC                                             copy_call_number();   #endif // HAVE_MMC                        }                    break;                case 2:                    if (dtmf_string[0]=='*' && dtmf_string[1]=='*') {                        if (dtmf_string[2]=='0' && dtmf_string[3]=='1' &&                            dtmf_string_length==10) {                                now_hour=get_int2(dtmf_string+4);                                now_min =get_int2(dtmf_string+6);                                now_sec =get_int2(dtmf_string+8);                                dtmf_string_clear();                        } else {                            if (dtmf_string[2]=='#' && dtmf_string[3]=='#' &&                                dtmf_string_length==4) {#ifdef HAVE_MMC                                    stop_recording();#endif // HAVE_MMC                                    wavp=wavp0=wav880; wav_rep=wav_rep0=75;                                    wav_cnt=10; wav_mask=1;                                    dtmf_string_clear();                            }                        }                    }                    break;                case 3:                    if (ring_age>0) {                        if (ring_age<255) ring_age--;                    } else {                        ring_age=255;                        call_timer_stop();                        call_status=CallIdle;#ifdef HAVE_MMC                        stop_recording();#endif // HAVE_MMC                    }                    if (ringdet_quell>0) ringdet_quell--;                    if (ringlike==9) { // was 8 to work well at work                        if (last_reported_hook==OnHook) {                            ring_count++;                            if (ring_count==1) {                                if (call_status==CallIdle) {                                    call_timer_reset();                                     call_status=CallIncoming;#ifdef HAVE_MMC                                    start_recording(0);#endif // HAVE_MMC                                }                            }                            ring_age=250;                            ringdet_quell=50;                            ringlike=0;                        }                    }                    break;            }        }#ifdef HAVE_MMC        do_block_mmc_io();#endif // HAVE_MMC    }    cc++;     if (cc==10) {        cc=0; nn++;    }#endif // HAVE_GOERTZEL    if (count>45 && count<100) {#ifdef HAVE_MMC        //dtmf_string[0]=mmc_init_state+'0';        if (mmc_init_state) {            if (mmc_init_state==6) {                if (count>88 && count<99) SPDR=0xFF;                if (count==88) {                    mmc_command(MMC_GO_IDLE_STATE,0);                    mmc_init_state--;                }            } else if (mmc_init_state==5) {                if (spi_has_reply) {                    if (spi_reply!=0x01) {                        mmc_init_state++;                    } else {                        mmc_init_state--;                    }                }            } else if (mmc_init_state==4) {                mmc_command(MMC_SEND_OP_COND,0);                mmc_init_state--;                mmc_retry=0;            } else if (mmc_init_state==3) {                if (spi_has_reply) {                    if (spi_reply) {                        mmc_retry++;                        if (mmc_retry==100) {                            mmc_init_state=6;                        } else {                            mmc_init_state++;                        }                    } else {                        mmc_init_state--;                    }                }            } else if (mmc_init_state==2) {                if (count==56) {                    mmc_command(MMC_CRC_ON_OFF,0);                    mmc_init_state--;                }            } else if (mmc_init_state==1) {                if (count==46) {                    mmc_command(MMC_SET_BLOCKLEN,512);                    mmc_init_state--;                    if (mmc_write_buf_state) {                        mmc_write_buf_state=2;                    } else if (mmc_read_buf_state) {                        mmc_read_buf_state=2;                    } else {                        mmc_read_csd_state=1;                    }                }            }        } else if (mmc_read_csd_state) {            unsigned char state=mmc_read_csd_state&15;            //dtmf_string[4]=mmc_read_csd_state+'0';            if (state==1) {                if (count==46) {                    mmc_read_csd_state++;                    unsigned char cmd;                    cmd=mmc_read_csd_state<16?MMC_SEND_CSD:MMC_SEND_CID;                    mmc_command(cmd,0);                    spi_autofinish=FALSE; mmc_retry=0;                }            } else if (state==2) {                if (spi_has_reply) {                    if (spi_reply==MMC_STARTBLOCK_READ) {                        mmc_read_csd_state++;                        mmc_csd_index=0;                        spi_get_next();                    } else {                        //dtmf_string[13]=spi_reply+'0';                        mmc_retry++;                        //dtmf_string[15]=mmc_retry+'0';                        if (mmc_retry==20) {                            mmc_read_csd_state&=0xF0;                            mmc_read_csd_state|=1;                            spi_finish();                        } else {                            spi_get_next();                        }                    }                } //else spi_get_next();            } else if (state==3) {                if (spi_has_reply) {                    buffer_a[mmc_csd_index++]=spi_reply;                    if (mmc_csd_index==16) {                        spi_finish();                        mmc_read_csd_state++;                    } else {                        spi_get_next();                    }                } else {                    spi_get_next();                }            } else if (state==4) {                if (mmc_read_csd_state<16) {                    mmc_read_csd_state=17;                    unsigned char c_size_mult=buffer_a[10]>>7;                    c_size_mult |= (buffer_a[9]&0x3)<<1;                    if (c_size_mult<7) {                        mmc_last_cluster=(buffer_a[6]&0x3)<<10;                        mmc_last_cluster|=buffer_a[7]<<2;                        mmc_last_cluster|=buffer_a[8]>>6;                        mmc_last_cluster++;                        if (c_size_mult<2) {                            mmc_last_cluster>>=2-c_size_mult;                        } else if (c_size_mult>2) {                            mmc_last_cluster<<=c_size_mult-2;                        }                    } else {                        mmc_last_cluster=0;                    }                } else {                    mmc_read_csd_state=0;                    mmc_psn[0]=buffer_a[9];                    mmc_psn[1]=buffer_a[10];                    mmc_psn[2]=buffer_a[11];                    mmc_psn[3]=buffer_a[12];                    mmc_read_index_state=1;                    mmc_retry=0;                    //dtmf_string[1]='0';                }            }        } else if (mmc_read_index_state && !has_index) {            if (mmc_read_index_state==1) {                //if (count==46) {                    mmc_read_index_state++;                    mmc_command(MMC_READ_SINGLE_BLOCK,0);                    spi_autofinish=FALSE;                    mmc_ptr=(unsigned char *)&mmc_index;                    mmc_read_state=1;//                    dtmf_string[1]='0';                    mmc_retry=0;                //}             }         } else if (mmc_write_index_state) {            if (mmc_write_index_state==1) {                if (count==46) {                    mmc_write_index_state++;                    mmc_command(MMC_WRITE_BLOCK,0);                    spi_autofinish=FALSE;                    mmc_ptr=(unsigned char *)&mmc_index;                    mmc_write_state=1;                    mmc_retry=0;                }            }        }#endif // HAVE_MMC        // Keyboard scan        if (count==99) {            DDRA  |=  _BV(PA7);            PORTA &= ~_BV(PA7); // Capacitor is pulled to ground            kbd_read_state=1;            kbd_has_key=FALSE;        } else if (kbd_read_state==1) {            DDRA  &= ~_BV(PA7); // Port is now input            kbd_read_state++;        } else if (kbd_read_state==16) {            kbd_read_state=0;            if (!kbd_has_key) {                kbd_last_key=kbd_key;                kbd_key=0;                //dtmf_string[1]=kbd_last_key;            }        } else {            if (PINA & _BV(PA7)) {                if (!kbd_has_key) {                    kbd_key=pgm_read_byte(kbd_tbl+kbd_read_state-2);                    //dtmf_string[0]=kbd_key;                    kbd_has_key=TRUE;                }            }            kbd_read_state++;        }        if (kbd_last_key=='E') {#ifdef HAVE_MMC

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -