zoukankan      html  css  js  c++  java
  • 程序集之·一(初步结果)

    Main

    #include <stdio.h>
    #include <stdlib.h>
    #include "wavIo.h"
    //#include "PreAccent.h"
    //#include "HammingWindow.h"
    //#include "Enframe.h"
    #define factor 0.97
    void main()
    {    
    
        char* rawfile = "MF.wav";
        //len=Getlength(rawfile);
        double sample[65000];
        int len;
        len=Read(rawfile,sample);
    
        /*frame*/
        int i=0,j=0;
        double frames[600][512];
        
        int winsize=512;
        int hopsize=128;
        int framenum=(int)((len-winsize)/hopsize)+1;
        //frames = new double [framenum][512];
        for(int i=0; i<framenum; i++)
        {
            for(int j=0; j<winsize; j++)
            {
                frames[i][j] = sample[i*hopsize+j];
            }
        }
        for(int i=0;i<100;i++) printf("the frames[][] is %f
    ",frames[i][j]);
        
        
        
        /*Pre-cent*/
        //PreAccent(sample,len,factor );//欲加重,factor 为预加重因子
        
        /*Enframe*/
    }

    wavIo.h

    #ifndef ML_WAVFILE
    #define ML_WAVFILE
    
    //#include <afx.h>
    //#include "RealVec.h"
    #include <stdio.h>
    
    
         int Read(char *filename,double *sample);
        // int Getlength(char *filename);
    
    
    #endif

    wavIo.cpp

    #include "WavIo.h"
    #include "stdio.h"
    
    
    #ifndef MAXWORD
        #define MAXWORD            0xFFFF
    #endif
    
    typedef unsigned int uint;
    typedef unsigned long  dword;
    typedef unsigned short word;
    
    int Read(char *filename,double *s)
    {
        FILE *f = fopen(filename, "rb");
            if((f=fopen(filename,"rb"))==NULL)
                printf("open file failed!
    ");
        int size, format, samp_freq, num_samp_bits, NumSamples;
        dword dw;
        word w;
    
        fread(&dw, sizeof(dword), 1, f);
        if (dw != 0x46464952) /* RIFF*/
          return false;
        //else 
            //printf("the RIFF is %c;
    ",dw);
    
        fread(&dw, sizeof(dword), 1, f);
        fread( &dw, sizeof(dword), 1, f);
        if (dw != 0x45564157) /* WAVE */
            return false;
        //else 
            //printf("the WAVE is %c;
    ",dw);
    
        fread(&dw, sizeof(dword), 1, f);
        if (dw != 0x20746d66) /* fmt */
            return false;
        fread( &dw, sizeof(dword), 1, f);
    
        /* format */
        fread(&w, sizeof(word), 1, f);
        if (w != 7 && w != 1) 
            return false;
        format=w;
    
        /* read the number of channels */
        fread( &w, sizeof(word), 1, f);
        if (w != 1) 
            return false;
        else
            printf("the channel is:%d
    ",w);
    
        fread( &dw, sizeof(dword), 1, f);
        samp_freq=dw;
        printf("the samp_freq is:%d
    ",dw);
    
        /* Skip a few bytes */
        fread( &dw, sizeof(dword), 1, f);
        fread( &w, sizeof(word), 1, f);
    
        fread( &w, sizeof(word), 1, f);
        if (w!=16)
            return false;
        num_samp_bits=w;
        printf("the samp_bits is:%d
    ",w);
    
        if ((num_samp_bits == 8 && (format != 7 && format != 6)) ||
            (num_samp_bits == 16 && format != 1))
            return false;
    
        fread( &dw, sizeof(dword), 1, f);
        if (dw != 0x61746164) /* data */
            return false;
    
        fread( &dw, sizeof(dword), 1, f);
        size=dw;
        if (size == -1)
            NumSamples = -1;
        else 
        {
              if (format == 6 || format == 7) 
                  NumSamples = size;
              else if (format == 1) 
                  NumSamples = size / 2;
              printf("the NumSamples is:%d
    ",NumSamples);
              
        }
        signed short *buf;
        int numread;
        int i=0;
    
        //s.Resize(NumSamples);
        buf = new signed short [NumSamples];
        numread = fread( buf, sizeof(signed short), NumSamples, f );
        if (numread)
        {
            for (int i=0 ; i<NumSamples ; ++i)
            {
                s[i] = ( (double) buf[i] ) / MAXWORD;
            }
        }
        delete buf;
    
        
        fclose(f);
    
        return NumSamples;
    }
  • 相关阅读:
    16-面向对象之语法(1)
    4-编辑器IDE_for_python
    3-python入门学习路线
    2-学习方法心得
    1-语法基础
    NSMutableArray基本概念
    NSArray 与字符串
    NSArray文件读写
    NSArray排序
    NSArray 遍历
  • 原文地址:https://www.cnblogs.com/taozijy/p/3685068.html
Copyright © 2011-2022 走看看