Intel® Integrated Performance Primitives
Deliberate problems developing high-performance vision, signal, security, and storage applications.

ippsResamplePolyphase sample usage quesiton

Kamil_K_
Beginner
832 Views

Hello,

I need to resample my signal from 44100 hZ to 8000 hZ with similar method that Matlab does. As Matlab's help description says that resample method uses polyphase implementation:

 resample  Change the sampling rate of a signal.
    Y = resample(X,P,Q) resamples the sequence in vector X at P/Q times
    the original sample rate using a polyphase implementation.  Y is P/Q
    times the length of X (or the ceiling of this if P/Q is not an integer).  
    P and Q must be positive integers.

I wanted to try IPP's resampling. But I don't quite get it. I found in documentation such example of usage:

void resampleIPP(
    int      inRate,    // input frequency
    int      outRate,   // output frequency
    FILE    *infd,      // input pcm file
    FILE    *outfd)     // output pcm file
 {  short *inBuf,*outBuf;
    int bufsize=4096;
    int history=128;
    double time=history;
    int lastread=history;
    int inCount=0,outCount=0,inLen,outLen;
    int size,len,height;
    IppsResamplingPolyphaseFixed_16s *state;
    ippsResamplePolyphaseFixedGetSize_16s(inRate,outRate,2*(history-1),&size,&len,      &height,ippAlgHintAccurate);
    state=(IppsResamlingPolyphaseFixed_16s*)ippsMalloc_8u(size);
    ippsResamplePolyphaseFixedInit_16s(inRate,outRate,2*(history-1),0.95f,9.0f,state,           ippAlgHintAccurate);
    inBuf=ippsMalloc_16s(bufsize+history+2);
    outBuf=ippsMalloc_16s((int)((bufsize-history)*outRate/(float)inRate+2));
    ippsZero_16s(inBuf,history);
    while ((inLen=fread(inBuf+lastread,sizeof(short),bufsize-lastread,infd))>0) {
       inCount+=inLen;
       lastread+=inLen;
       ippsResamplePolyphaseFixed_16s(inBuf,lastread-history-(int)time,
                             outBuf,0.98f,&time,&outLen,state);
       fwrite(outBuf,outLen,sizeof(short),outfd);
       outCount+=outLen;
       ippsMove_16s(inBuf+(int)time-history,inBuf,lastread+history-(int)time);
       lastread-=(int)time-history;     
       time-=(int)time-history;
    }    
                                ippsZero_16s(inBuf+lastread,history);
    ippsResamplePolyphaseFixed_16s(inBuf,lastread-(int)time,
                          outBuf,0.98f,&time,&outLen,state);
    fwrite(outBuf,outLen,sizeof(short),outfd);
    outCount+=outLen;
    printf("%d inputs resampled to %d outputs\n",inCount,outCount);
    ippsFree(outBuf);
    ippsFree(inBuf);
    ippsFree (state);
 }

So I have my *.wav file which data of header looks like this:

Chunk name: RIFF

File size: 31636640

File format: WAVE

Sub chunk id: fmt

Sub chunk size: 16

Compression format: 1

Channels: 1

Sample rate: 44100

Byte rate: 88200

Block align: 2

Bits per sample: 16

Sub chunk id: data

Sub chunk size: 31636604

And I insert it to this examplary function as FILE should be inserted to input from what I understand. I get something on output but I can't play it. I do it like that:

FILE *fInput =fopen(wavFile0.filePath,"rb");
FILE *fOutput  =  fopen ("myTestFile.wav", "wb");

 resampleIPP(44100, 8000, fInput, fOutput);

fclose(fInput);
fclose((fOutput);

By investigating file structure I can say for sure that something has happened with header of the file. Would that mean that I have to insert only vector of data located under sub chunk with id "data" and then after resampleIPP function resamples my data then append it to new header?

I am using IPP 7.1
 

0 Kudos
1 Reply
Chao_Y_Intel
Moderator
832 Views

Hello,  

The sample code take the raw PCM files.   For a wave file, it also include wave header.   When you save to  a wave file, you also need to handle the wave headers. 

Thanks,
Chao

0 Kudos
Reply