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

📄 my723.cpp

📁 g723压缩算法源码
💻 CPP
字号:
// my723.cpp : Defines the class behaviors for the application.
//

#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
//extern "C"{

#include "typedef.h"
#include "basop.h"
#include "cst_lbc.h"
#include "tab_lbc.h"
#include "lbccodec.h"
#include "coder.h"
#include "decod.h"
#include "exc_lbc.h"
#include "util_lbc.h"
#include "cod_cng.h"
#include "dec_cng.h"
#include "vad.h"
#include "tame.h"
#include "lsp.h"
#include "lpc.h"
#include "util_cng.h"
//}
#include "my723.h"

#include "MainFrm.h"
#include "my723Doc.h"
#include "my723View.h"


DECSTATDEF  DecStat  ;
CODCNGDEF CodCng;
CODSTATDEF  CodStat  ;
DECCNGDEF DecCng;
VADSTATDEF  VadStat ;

/* Global variables */
enum  Wmode    WrkMode = Both ;
enum  Crate    WrkRate = Rate63 ;

int   PackedFrameSize[2] = {
   24 ,
   20
   } ;

Flag    UseHp = True ;
Flag    UsePf = True ;
Flag    UseVx = False ;
Flag    UsePr = True ;

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CMy723App

BEGIN_MESSAGE_MAP(CMy723App, CWinApp)
	//{{AFX_MSG_MAP(CMy723App)
	ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
		// NOTE - the ClassWizard will add and remove mapping macros here.
		//    DO NOT EDIT what you see in these blocks of generated code!
	//}}AFX_MSG_MAP
	// Standard file based document commands
	ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
	ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
	// Standard print setup command
	ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMy723App construction

CMy723App::CMy723App()
{
	// TODO: add construction code here,
	// Place all significant initialization in InitInstance
}

/////////////////////////////////////////////////////////////////////////////
// The one and only CMy723App object

CMy723App theApp;

/////////////////////////////////////////////////////////////////////////////
// CMy723App initialization

BOOL CMy723App::InitInstance()
{
	AfxEnableControlContainer();

	// Standard initialization
	// If you are not using these features and wish to reduce the size
	//  of your final executable, you should remove from the following
	//  the specific initialization routines you do not need.

#ifdef _AFXDLL
	Enable3dControls();			// Call this when using MFC in a shared DLL
#else
	Enable3dControlsStatic();	// Call this when linking to MFC statically
#endif

	// Change the registry key under which our settings are stored.
	// TODO: You should modify this string to be something appropriate
	// such as the name of your company or organization.
	SetRegistryKey(_T("Local AppWizard-Generated Applications"));

	LoadStdProfileSettings();  // Load standard INI file options (including MRU)

	// Register the application's document templates.  Document templates
	//  serve as the connection between documents, frame windows and views.

	CSingleDocTemplate* pDocTemplate;
	pDocTemplate = new CSingleDocTemplate(
		IDR_MAINFRAME,
		RUNTIME_CLASS(CMy723Doc),
		RUNTIME_CLASS(CMainFrame),       // main SDI frame window
		RUNTIME_CLASS(CMy723View));
	AddDocTemplate(pDocTemplate);

	// Parse command line for standard shell commands, DDE, file open
	CCommandLineInfo cmdInfo;
	ParseCommandLine(cmdInfo);

	// Dispatch commands specified on the command line
	if (!ProcessShellCommand(cmdInfo))
		return FALSE;

	// The one and only window has been initialized, so show and update it.
	m_pMainWnd->ShowWindow(SW_SHOW);
	m_pMainWnd->UpdateWindow();

	Encode();
	return TRUE;
}


/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
		// No message handlers
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

// App command to run the dialog
void CMy723App::OnAppAbout()
{
	CAboutDlg aboutDlg;
	aboutDlg.DoModal();
}

/////////////////////////////////////////////////////////////////////////////
// CMy723App message handlers


BOOL CMy723App::Encode()
{
	FILE    *Ifp, *Ofp ;            /* I/O File pointers */
    FILE    *Fep  = NULL;           /* Frame erasures file pointer */
    FILE    *Ratp = NULL;           /* Rate file pointer */

    long    FrCnt = 0 ;
    long    FlLen ;

	FILE *tmp;
    Word16  DataBuff[Frame] ;
    Word16  Crc ;
    char Rate_Rd;

    char    Line[24] ;

	WrkRate = Rate63 ;
	WrkMode = Cod ;
	Ifp=fopen("noservice.wav","rb");
	if ( Ifp == NULL ) {
         exit(1) ;
    }
	Ofp = fopen("my723.723", "wb") ;
	if ( Ofp == NULL ) {
         exit(1) ;
    }
	fseek( Ifp, 0L, SEEK_END ) ;
    FlLen = ftell( Ifp ) ;
    rewind( Ifp ) ;
    if ( WrkMode == Dec )
        FlLen = 0x7fffffffL ;
    else
        FlLen /= sizeof(Word16)*Frame ;
//	char temp[100];
//	temp=&SignOn[0];

	
//	tmp=fopen("1.trace","wd");
//	tmp2=sizeof(tmp3);
//	fwrite(argv[0],sizeof(argv),1,tmp);
//	fclose(tmp);
//    printf("%s________%d,%s", SignOn,argc,argv[0] ) ;

    /* Process arguments and open I/O files */

	//    FlLen = Process_Files( &Ifp, &Ofp, &Fep, &Ratp, argc, argv ) ;

    /*
      Init coder and the decoder
    */
    Init_Coder( ) ;
    Init_Decod( ) ;

    /* Init Comfort Noise Functions */
    if( UseVx ) {
        Init_Vad();
        Init_Cod_Cng( );
    }
    Init_Dec_Cng( );

    /* Process all the input file */
	
    do {

        switch ( WrkMode ) {

            case Both:
                if(Ratp != NULL) {
                    fread((char *)&Rate_Rd, sizeof(char), 1, Ratp);
                    WrkRate = (enum Crate)Rate_Rd;
                }
                if ( WrkRate == Rate53) reset_max_time();
                Read_lbc( DataBuff, Frame, Ifp ) ;
                Coder( DataBuff, Line ) ;
                Decod( DataBuff, Line, (Word16) 0 ) ;
                Write_lbc( DataBuff, Frame, Ofp ) ;
            break ;

            case Cod :
                if(Ratp != NULL) {
                    fread((char *)&Rate_Rd, sizeof(char), 1, Ratp);
                    WrkRate = (enum Crate)Rate_Rd;
                }
                if ( WrkRate == Rate53) reset_max_time();
                Read_lbc( DataBuff, Frame, Ifp ) ;
                Coder( DataBuff, Line ) ;
                Line_Wr( Line, Ofp ) ;
            break ;

            case Dec :
                if(Line_Rd( Line, Ifp ) == (-1)) {
                    FlLen = FrCnt;
                    break;
                }
                if ( Fep == NULL )
                    Crc = (Word16) 0 ;
                else
                    fread( (char *)&Crc, sizeof(Word16), 1, Fep ) ;
                Decod( DataBuff, Line, Crc ) ;
                Write_lbc( DataBuff, Frame, Ofp ) ;
            break ;
        }

        FrCnt ++ ;
        if( UsePr) {
            if( WrkMode == Dec) {
                if(FrCnt < FlLen) {
//                    fprintf( stdout, "Done : %6ld\r", FrCnt) ;
                }
            }
            else {
//                fprintf( stdout, "Done : %6ld %3ld\r", FrCnt, FrCnt*100/FlLen ) ;
            }
            fflush(stdout);
        }

		
    }   while ( FrCnt < FlLen ) ;

    if(Ifp) { (void)fclose(Ifp); }
    if(Ofp) { (void)fclose(Ofp); }
    if(Fep) { (void)fclose(Fep); }
    if(Ratp) { (void)fclose(Ratp); }
    return 0 ;
}

⌨️ 快捷键说明

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