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

📄 dspfile.cpp

📁 实现了精简的FFT语音压缩 采取了一种新的算法有一定的参考价值
💻 CPP
字号:
// DSPFile.cpp: implementation of the DSPFile class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "PPQTEST.h"
#include "DSPFile.h"

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

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

DSPFile::DSPFile()
{
	this->m_pifs	=NULL;
	this->m_pofs	=NULL;
}

DSPFile::~DSPFile()
{
	if(this->m_pifs!=NULL)
		delete this->m_pifs;
	if(this->m_pofs!=NULL)
		delete this->m_pofs;
}

bool DSPFile::Serialize(BYTE byClassLevels,BYTE byAttrNo,DSP::_DSPPACKET &dsp)
{
	switch(byAttrNo)
	{
		case 1:
			dsp.Write(this->m_nFileSize);
			return false;
		case 2:
			dsp.Write(this->m_strFileName);
			return false;
		case 3:						//序列化最后一个属性
			if(this->m_pifs==NULL)
			{
				//打开文件准备读
				this->m_pifs	=new ifstream();
				if(DSP::OpenIfstreamForRead(*this->m_pifs,this->m_strPathName.c_str())==FALSE)
				{
					//如果打开文件失败
					dsp.Write(NULL,0,true);
					return true;
				}
			}
			else
			{
				//关闭文件
				delete this->m_pifs;
				this->m_pifs	=NULL;
			}
			dsp.Write(this->m_buff,0xFFF,false);
	}

	return true;
}

bool DSPFile::UnSerialize(BYTE byClassLevels,BYTE byAttrNo,DSP::_DSPPACKET &dsp,DWORD dwLen)
{
	//反序列化对象
	switch(byAttrNo)
	{
		case 1:
			dsp.Read(this->m_nFileSize);
			return false;
		case 2:
			dsp.Read(this->m_strFileName,dwLen);
			return false;
		case 3:						//序列化最后一个属性
			if(this->m_pofs==NULL)
			{
				//传送文件名和尺寸,并且打开文件输出流,准备写
				::SendMessage(this->m_hwnd,MSG_SETFILENAMESIZE,(WPARAM)&this->m_strFileName,(LPARAM)this->m_nFileSize);

				//打开对话框,选择被保存的文件名
				CFileDialog fileDialog(FALSE,NULL,this->m_strFileName.c_str(),OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT);
				if(fileDialog.DoModal()==IDOK)
				{
					//得到被选择的文件名
					CString strPath		=fileDialog.GetPathName();
					this->m_strPathName	=strPath;

					//传送文件名和尺寸
					::SendMessage(this->m_hwnd,MSG_SETFILENAMESIZE,(WPARAM)&this->m_strPathName,(LPARAM)this->m_nFileSize);

					this->m_pofs	=new ofstream();
					if(DSP::OpenOfstreamForWrite(*this->m_pofs,strPath)==FALSE)
					{
						//如果找开文件失败
						dsp.Read(NULL,0);
						return true;
					}
				}
			}
			else
			{
				//属性值已反序列化完毕,删除文件输出流对象
				delete this->m_pofs;
				this->m_pofs	=NULL;
			}
			dsp.Read(this->m_buff,dwLen);
	}

	return true;
}

bool DSPFile::AttrSectRecv(BYTE byClassLevels,BYTE byAttrNo,const char* const lpBuff,DWORD dwLen,bool bLast)
{
	switch(byAttrNo)
	{
		case 3:
			this->m_pofs->write(lpBuff,dwLen);
			if(*this->m_lpbRun==false)
			{
				//如果放弃传送
				return false;
			}
			::PostMessage(this->m_hwnd,MSG_RECVSECT,dwLen,0);
			if(bLast)
			{
				//如果是最后一个段,则文件输出流关闭
				this->m_pofs->flush();
				this->m_pofs->close();
			}
	}

	return true;
}

bool DSPFile::AttrSectSend(BYTE byClassLevels,BYTE byAttrNo,char** const lpBuff,DWORD& dwLen,bool& bContinue)
{
	switch(byAttrNo)
	{
		case 3:
			this->m_pifs->read(*lpBuff,dwLen);
			bContinue	=*this->m_lpbRun;
			if(this->m_pifs->eof())
			{
				//如果文件已经结束
				//得到文件的大小
				int size	=this->m_pifs->tellg();

				//得到最后读取的文件尺寸,设定最后接收的字节数
				dwLen		=size%dwLen;

				//设定不需要再继续接收
				bContinue	=false;

				//关闭文件
				this->m_pifs->close();
			}
			::PostMessage(this->m_hwnd,MSG_SENDSECT,dwLen,0);
	}

	return true;
}

⌨️ 快捷键说明

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