zoukankan      html  css  js  c++  java
  • 乒乓Buffer

    #define LEN_PING_PANG          (48000)  //1 seconds
    typedef struct S_PINGPANG
    {
        void* p1 ;
        void* p2 ;
        int  position;
    }PINGPANG;
    PINGPANG * Ping;

    这里是结构和变量的定义

        Ping = malloc(sizeof(PINGPANG)) ;
        Ping->p1 = malloc(LEN_PING_PANG) ;
        Ping->p2 = malloc(LEN_PING_PANG) ;
        Ping->position=0;

    初始化

        if (Ping != NULL){
            free(Ping->p1) ;
            free(Ping->p2) ;
            free(Ping) ;
        }

    释放资源

    void* savePingPang(void* p, int len) {
        if (len<=0) {
            if (Ping->position < LEN_PING_PANG) {
                memset(Ping->p1+Ping->position,'',LEN_PING_PANG-Ping->position);
                Ping->position=0;
                return Ping->p1 ;
            }
            else  {
                memset(Ping->p2+Ping->position-LEN_PING_PANG,'',2*LEN_PING_PANG-Ping->position);
                Ping->position=0;
                return Ping->p2 ;
            }
        }
        if (Ping->position + len < LEN_PING_PANG){
            memcpy(Ping->p1+Ping->position,p,len);
            Ping->position+=len;
            return NULL;
        }else if(Ping->position + len < (LEN_PING_PANG*2)){
            if (Ping->position < LEN_PING_PANG) {
                int byte_p1 = LEN_PING_PANG - Ping->position ;
                memcpy(Ping->p1+Ping->position,p,byte_p1) ;
                memcpy(Ping->p2,p+byte_p1,len-byte_p1);
                Ping->position+=len;
                return Ping->p1;
            }else{
                memcpy(Ping->p2+Ping->position-LEN_PING_PANG,p,len);
                Ping->position+=len;
                return NULL;
            }
        }else{
            int byte_p2=LEN_PING_PANG*2-Ping->position;
            memcpy(Ping->p2+Ping->position-LEN_PING_PANG,p,byte_p2) ;
            memcpy(Ping->p1,p+byte_p2,len-byte_p2);
            Ping->position=Ping->position+len-LEN_PING_PANG-LEN_PING_PANG;
            return Ping->p2;
        }
    }
        void* buffer = savePingPang(ReSampleBuffer,lenOutput*sizeof(short)) ;
        if (buffer != NULL)
            WriteAudioData((void *)userContext, (void *)buffer,LEN_PING_PANG);

    实现和调用

  • 相关阅读:
    hdp (ambari) 集成hue
    Hive的metastore
    windows 常用cmd命令
    HDFS datanode心跳与运维中的实际案例
    scala drools and map
    hadoop nn 运维一例
    Eclipse 多行注释选择
    JSP SERVLET 基础知识
    记录一次代码错误,elastic search的INDEX需要使用小写字母
    HIVE大数据出现倾斜怎么办
  • 原文地址:https://www.cnblogs.com/shinedream/p/12724776.html
Copyright © 2011-2022 走看看