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
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