关于写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));
最后一句是不是以二进制写入文件的??????
是的话添入数据以后怎么不能播放呢?
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));
最后一句是不是以二进制写入文件的??????
是的话添入数据以后怎么不能播放呢?
QQ:69786714
 
后退
顶部