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

📄 g711lib_common.h

📁 Audio compression on embedded board
💻 H
字号:
/*********************************************************************
*                                                                    *
*                       Software License Agreement                   *
*                                                                    *
*   The software supplied herewith by Microchip Technology           *
*   Incorporated (the "Company") for its dsPIC controller            *
*   is intended and supplied to you, the Company's customer,         *
*   for use solely and exclusively on Microchip dsPIC                *
*   products. The software is owned by the Company and/or its        *
*   supplier, and is protected under applicable copyright laws. All  *
*   rights are reserved. Any use in violation of the foregoing       *
*   restrictions may subject the user to criminal sanctions under    *
*   applicable laws, as well as to civil liability for the breach of *
*   the terms and conditions of this license.                        *
*                                                                    *
*   THIS SOFTWARE IS PROVIDED IN AN "AS IS" CONDITION.  NO           *
*   WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING,    *
*   BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND    *
*   FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE     *
*   COMPANY SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL,  *
*   INCIDENTAL OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.  *
*                                                                    *
*********************************************************************/

#ifndef _G711LIB_COMMON_H
#define _G711LIB_COMMON_H

//-----------------------------------------------------------------------------
//INCLUDE FILES
//-----------------------------------------------------------------------------
#include <p33Fxxxx.h>

//-----------------------------------------------------------------------------
//PREPROCESSOR CONSTANTS/MACROS
//-----------------------------------------------------------------------------
#define Fs 8000L                              //Speech sampling rate in Hz.

#define Fcy 12288000L                         //(Crystal freq'cy 6.144 MHz X 4)/2

#define FSCKD (Fs * 256)                      //frame clock rate

#define BCG1 (( Fcy / ( 2 * FSCKD ) ) - 1)    //Calculation of DCI bit clock 
                                              //generator control bits.
                                              
#define BRG (((Fcy/307199)/16)-1)             //Baud rate genarator for UART           
                                              //Baud rate 307199
#define INITIATOR   1                         //1 - Master, 0 - Slave

#define LAW 0                                 /* 1 for A-law, 0 for u-Law*/

#define RATE 5                                //5 -for 40kb/s
                                              //4 -for 32kb/s
                                              //3 -for 24kb/s
                                              //2 -for 16kb/s

#define ARRAYSIZEINBYTES 0xDC8C  //This variable stores the number of bytes 
                                 //in the encoded speech sample table 
                                 //in program memory. PCRU generated .s file gives 
                                 //the total number of bytes in
                                 // decimal.Convert the dec value to Hex and 
                                 //initialize this macro.

#define NUMOFSAMPLESPERBLOCK 256 //number of speech samples in each Block.

#define RECORDSIZE     1875L     //Size of the recorded speech in number
                                 //of Blocks.

/*************************************************************************
*                    Library API prototypes
**************************************************************************/
extern void Initiator ( void );
extern void libADCFillBuffer (void);
extern void libADC12Init (void); 
extern void libADC12StartSampling ( short* buf1,short* buf2,short* expandbuf1,short* expandbuf2,short*  buffer1,short*  buffer2);
extern void libADC12StopSampling (void);    
extern void libarrayFillDecoderInputPM (void);
extern void libBufManagerDecoder (void);
extern void libPWMInit (void);
extern char libTblByteRead (void );
extern void libPWMLoadSamples (void);
extern void libPWMStartSampling (short* expandbuf1,short* expandbuf2,short*  buffer1,short*  buffer2);
extern void libRawBufManager (void);
extern void libRwndOpRawBufPtr (void);
extern void libSi3000DCIFill (void);
extern void libSi3000Init (void);
extern void libSi3000LoadDCI (void);
extern void libSi3000SlaveFillDCI (void);
extern void libSi3000SlaveLoadDCI (void);
extern void libSi3000StartSampling (short* expandbuf1,short* expandbuf2,short*  buffer1,short*  buffer2);
extern void libSi3000StopSampling  (void);
extern void libStartPlay (void);
extern void libStartPWM (void);
extern void libStopPlay (void);
extern void libStopPWM (void);
extern void libTblPtrSet (char tableno);
extern void libuart1Init (void);
extern void libuart2Init (void);

#define CODECDATA { 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x00,0x00,0x0000,\
                    0x0000,0x0000,0x0000,0x0000,NUMOFSAMPLESPERBLOCK,0x00,0x00,0x00,\
                    0x0000,0x0000,ARRAYSIZEINBYTES,RECORDSIZE,LAW,RATE,INITIATOR}
                    
                    
#define CODECSETUP codecsetup codecdata = CODECDATA;                    

/*-----------------------------------------------------------------------------
This structure is used to handle data sample buffers.The user has to create
four buffers pass their parameters to the libSi3000StartSampling-
(int* buf1,int* buf2,char* buffer1,char* buffer2) function to initialize this
structure.
-----------------------------------------------------------------------------*/
struct _codecsetup
{ 
  short          *sampleExpandIpBuffer;   //Pointer to expended Speech sample
                                          //buffer1
  short          *sampleExpandOpBuffer;   //Pointer to expanded Speech sample
                                          //buffer2
  short          *sampleIpBuffer;         //Pointer to raw Speech sample
                                          //buffer1
  short          *sampleOpBuffer;         //Pointer to raw Speech sample
                                          //buffer2
  short		     *sampleComprsIpBuffer;   //Pointer to compressed speech sample
                                          //buffer1.
  short		     *sampleComprsOpBuffer;   //Pointer to compressed speech sample
                                          //buffer2.
  volatile char     fBlockdone;           //Flag to indicate ping-pong buffer
                                          //filled or emptied.
  volatile char     fStartPlay;           //Flag to start or stop speech play
  
  volatile int      blockCount;           //Counter to keep count of number
                                          //of blocks of data filled.
  volatile int      loadblockCount;       //Counter to keep count of number
                                          //of blocks of data played out.
  volatile int      countFill;	          //Counter to keep track of the
                                          //number of samples stored.
  volatile int      countLoad;	          //Counter to keep track of the
                                          //number of samples played.
  volatile unsigned long sampleCount;     //Counter to keep track of number
                                          //of samples
  volatile int     numOfSamplesPerBlock;  //Values in this member will
                                          //indicate the number of
                                          //compredde/expanded samples in each Block.
  volatile char     fBlockplayed;         //Flag to indicate Expand is
                                          //done.
  volatile char     fCompressdone;        //Flag to indicate Compress is done

  volatile char     fEncodedone;          //Flag to indicate Encode is done

  volatile int      setOfADCData;         //Number of sets of data for the set
                                          //ADC Buffer Length
  volatile unsigned int* AdcBuf0Ptr;      //Pointer to ADCBUF0 register.
 
  unsigned long     arraysizeinbytes;     //This variable stores the number 
                                          //of bytes in the encoded speech                                         
  long              recordSize;           //Value stored in this member will
                                          //indicate the size of the recorded
                                          //speech in number of Blocks.This
                                          //value is used to stop play of
                                          //speech.
  char law;                               //1 for A-law, 0 for u-Law

  short rate;                             //This variable is used to Set the
                                          //bit rate 
  int initiator;                          //1 - Master, 0 - Slave
  };

//-----------------------------------------------------------------------------
//TYPEDEFS/EXTERNS
//-----------------------------------------------------------------------------
typedef struct _codecsetup codecsetup;
extern codecsetup codecdata;

#endif  /* G711Lib_common.h */
/*-----------------------------------------------------------------------------
                                    END OF FILE:  G711Lib_common.h 
-----------------------------------------------------------------------------*/

⌨️ 快捷键说明

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