关于写WAVE文件头的问题?写完以后不能播放?急!!!!!!!!!!!!!在线等待 ( 积分: 50 )

  • 主题发起人 主题发起人 ansili
  • 开始时间 开始时间
A

ansili

Unregistered / Unconfirmed
GUEST, unregistred user!
写WAVE文件头:
TFileStream *DatFile;
TFileStream *WaveFile;
int datSize;
int datHandle;
int waveHandle;
short CHANNELS = 1;
//1(单声)或者2(立体声) }
short BITSPERSAMPLE = 16;
// 8或者16,代表8位或16位声音
int SAMPLESPERSEC = 8000;
// 声音频率,如11025,22050, 44100}

AnsiString WaveFileName;
WaveFileName = AWaveFileName;
if(!FileExists(AscrFileName))
{
ShowMessage("没找到文件: "
+ AscrFileName);
return;
}
if(FileExists(WaveFileName))
DeleteFile(WaveFileName);
DatFile = new TFileStream(AscrFileName, fmOpenRead);
datSize = DatFile->Size;
datHandle = DatFile->Handle;
WaveFile = new TFileStream(WaveFileName,fmCreate);
waveHandle = WaveFile->Handle;
WaveFile->Position = 0;
WaveInfo *WaveData;
//初始化wave
WaveData = new WaveInfo();
StrCopy(WaveData->RIFF_Flag,"RIFF");
WaveData->FileSize = sizeof(*WaveData) + datSize;
StrCopy(WaveData->Wave_Flag,"WAVE");
StrCopy(WaveData->FMT_Flag,"fmt ");
WaveData->Temp_Byte = 16;//sizeof(PCMWAVEFORMAT);
//
WaveData->Format_Type = 0x01;
WaveData->Channels = CHANNELS;
WaveData->nSamplesPerSec = SAMPLESPERSEC;
//0x2256;
WaveData->nAvgBytesPerSec = CHANNELS * SAMPLESPERSEC*(BITSPERSAMPLE / 8);
//0x2256;
WaveData->nBlockAlign = CHANNELS * (BITSPERSAMPLE / 8);
//0x2425;
WaveData->nBitsPerSample = BITSPERSAMPLE;//0//
StrCopy(WaveData->Data_Flag,"data");
WaveData->Data_Size = datSize;
//写wave文件
WaveFile->Write(WaveData,sizeof(*WaveData));
最后一句是不是可以将WaveData结构的数据以二进制的方式写进文件里??
如果可以的话,为什么我的WAVE文件不能放呢?从其他文件复制的文件头就可以,为什么?
附WaveData结构定义:
//Wave文件结构
typedef struct WaveInfo_tag{
char RIFF_Flag[4];
int FileSize;
char Wave_Flag[4];
char FMT_Flag[4];
int Temp_Byte;
//过渡字节
short Format_Type;
//格式类别 2
short Channels;
//通道数
int nSamplesPerSec;//记录每秒取样数。采样率(每秒样本数),表示每个通道的播放速度
int nAvgBytesPerSec;//记录每秒的数据量。
short nBlockAlign;//记录区块的对齐单位。
short nBitsPerSample;//记录每个取样所需的位元数。
char Data_Flag[4];
int Data_Size;
}WaveInfo;
刚转CB的人.
QQ:69786714
 
写WAVE文件头:
TFileStream *DatFile;
TFileStream *WaveFile;
int datSize;
int datHandle;
int waveHandle;
short CHANNELS = 1;
//1(单声)或者2(立体声) }
short BITSPERSAMPLE = 16;
// 8或者16,代表8位或16位声音
int SAMPLESPERSEC = 8000;
// 声音频率,如11025,22050, 44100}

AnsiString WaveFileName;
WaveFileName = AWaveFileName;
if(!FileExists(AscrFileName))
{
ShowMessage("没找到文件: "
+ AscrFileName);
return;
}
if(FileExists(WaveFileName))
DeleteFile(WaveFileName);
DatFile = new TFileStream(AscrFileName, fmOpenRead);
datSize = DatFile->Size;
datHandle = DatFile->Handle;
WaveFile = new TFileStream(WaveFileName,fmCreate);
waveHandle = WaveFile->Handle;
WaveFile->Position = 0;
WaveInfo *WaveData;
//初始化wave
WaveData = new WaveInfo();
StrCopy(WaveData->RIFF_Flag,"RIFF");
WaveData->FileSize = sizeof(*WaveData) + datSize;
StrCopy(WaveData->Wave_Flag,"WAVE");
StrCopy(WaveData->FMT_Flag,"fmt ");
WaveData->Temp_Byte = 16;//sizeof(PCMWAVEFORMAT);
//
WaveData->Format_Type = 0x01;
WaveData->Channels = CHANNELS;
WaveData->nSamplesPerSec = SAMPLESPERSEC;
//0x2256;
WaveData->nAvgBytesPerSec = CHANNELS * SAMPLESPERSEC*(BITSPERSAMPLE / 8);
//0x2256;
WaveData->nBlockAlign = CHANNELS * (BITSPERSAMPLE / 8);
//0x2425;
WaveData->nBitsPerSample = BITSPERSAMPLE;//0//
StrCopy(WaveData->Data_Flag,"data");
WaveData->Data_Size = datSize;
//写wave文件
WaveFile->Write(WaveData,sizeof(*WaveData));
最后一句是不是可以将WaveData结构的数据以二进制的方式写进文件里??
如果可以的话,为什么我的WAVE文件不能放呢?从其他文件复制的文件头就可以,为什么?
附WaveData结构定义:
//Wave文件结构
typedef struct WaveInfo_tag{
char RIFF_Flag[4];
int FileSize;
char Wave_Flag[4];
char FMT_Flag[4];
int Temp_Byte;
//过渡字节
short Format_Type;
//格式类别 2
short Channels;
//通道数
int nSamplesPerSec;//记录每秒取样数。采样率(每秒样本数),表示每个通道的播放速度
int nAvgBytesPerSec;//记录每秒的数据量。
short nBlockAlign;//记录区块的对齐单位。
short nBitsPerSample;//记录每个取样所需的位元数。
char Data_Flag[4];
int Data_Size;
}WaveInfo;
刚转CB的人.
QQ:69786714
 
不需要再定义结构体了,直接用WAVEFORMATEX就可以指定WAVE文件头的格式
 
你可以将你合成的文件用16位编辑器打开,对照一个小的wav文件,看看头文件什么地方写的不对!只要有耐心,一定能找到问题原因
或者可以发给kingled@126.com 我帮你改!
 
To : lijun_snut,
能留个QQ吗?
这是我的:69786714
 
我的:280059493
 
后退
顶部