xxxx18一60岁hd中国/日韩女同互慰一区二区/西西人体扒开双腿无遮挡/日韩欧美黄色一级片 - 色护士精品影院www

資源簡介

有時DUMP下了PCM格式的數據流,要在電腦或者其它設備上聽,驗證其聲音是否正確,該小程序就是給PCM數據流添加一個WAV的文件頭,讓播放器可以以WAV格式正常播放PCM數據. 例子中代碼固定寫了44.1K采樣,雙聲道,量化BIT為16,如果格式不一致,改宏定義即可.

資源截圖

代碼片段和文件信息

//?AddPcmFileHeader.cpp?:?定義控制臺應用程序的入口點。
//

#include?“stdafx.h“
#include?
#include?
#include?


//pcm文件的聲道數
#define?PCM_CHANNEL_NUM????????????2
//pcm文件的采樣率
#define?PCM_SAMPLE_RATE????????????44100
//?每次采樣占用的位數?8/16/32等
#define?PCM_SAMPLE_BITS????????????16

/*
?*?wav?文件格式
?------------------------------------------------
?|?????????????RIFF?WAVE?Chunk??????????????????|
?|?????????????ID??=?‘RIFF‘?????????????????????|
?|?????????????RiffType?=?‘WAVE‘????????????????|
?------------------------------------------------
?|?????????????Format?Chunk?????????????????????|
?|?????????????ID?=?‘fmt?‘??????????????????????|
?------------------------------------------------
?|?????????????Fact?Chunk(optional)?????????????|
?|?????????????ID?=?‘fact‘??????????????????????|???(此Chunk可選)
?------------------------------------------------
?|?????????????Data?Chunk???????????????????????|
?|?????????????ID?=?‘data‘??????????????????????|
?------------------------------------------------

?*/


//wav頭的結構如下所示:
typedef???struct??
{
char?????fccID[4];????
unsigned???long??????dwSize;????
char?????fccType[4];???
}HEADER;?//RIFF?WAVE?Chunk

typedef???struct??
{
char????fccID[4];?????
unsigned???long??dwSize;???????
unsigned???short????wFormatTag;????
unsigned???short????wChannels;????
unsigned???long?????dwSamplesPerSec;??
unsigned???long?????dwAvgBytesPerSec;??
unsigned???short????wBlockAlign;???
unsigned???short????uiBitsPerSample;??
}FMT;?//Format?Chunk

typedef???struct?
{
char????fccID[4];????
unsigned???long?????dwSize;?????
}DATA;?//Data?Chunk
//以上是wav頭文件

int?_tmain(int?argc?_TCHAR*?argv[])
{

//以下是為了建立.wav頭而準備的變量
HEADER??pcmHEADER;
FMT??pcmFMT;
DATA?pcmDATA;

unsigned???short???m_pcmData;?????//讀入.pcm和寫入文件.wav數據變量
FILE???*fp*fpCpy;


if(argc!=2)
{
printf(“?Usage:?%s??PCM_FILE\n“);
return?1;

}

if((fp=fopen(argv[1]???“rb?“))???==???NULL)??//讀取文件
{
printf(?“打開pcm文件出錯?\n“);??????
exit(0);
}

if((fpCpy=fopen(“output_pcm.wav“???“wb+“))???==???NULL)??//為轉換建立一個新文件
{
fclose(fp);
printf(?“創建wav文件出錯\n?“);??????
exit(0);
}???


//以下是創建wav頭的HEADER;但.dwsize未定,因為不知道Data的長度。
strncpy(pcmHEADER.fccID?“RIFF“4);???????????
//pcmHEADER.dwsize==?
strncpy(pcmHEADER.fccType?“WAVE“?4);
fseek(fpCpysizeof(HEADER)SEEK_CUR);?//跳過HEADER的長度,以便下面繼續寫入wav文件的數據;
//以上是創建wav頭的HEADER;

if(ferror(fpCpy))
{??
printf(?“error!\n?“);??????????????
}

//以下是創建wav頭的FMT;
strncpy(pcmFMT.fccID?“fmt?“4);
pcmFMT.dwSize=16;
pcmFMT.wFormatTag=1;

pcmFMT.wChannels=PCM_CHANNEL_NUM;??//幾聲道此處為2聲音左右立體聲
pcmFMT.dwSamplesPerSec=PCM_SAMPLE_RATE;?//采樣率44.1KHz

//每個采樣需要的bit數?
pcmFMT.uiBitsPerSample=PCM_SAMPLE_BITS;?

//?每秒所需字節數?(采樣率*聲道數*每個采樣所需的BIT?/8?)
pcmFMT.dwAvgBytesPerSec=pcmFMT.dwSamplesPerSec?*?pcmFMT.wChannels?*?pcmFMT.uiBitsPerSample?/?8;

//數據塊對齊單位(每個采樣需要的字節數:?采樣位*聲道數/8)
pcmFMT.wB

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----

?????文件???????4401??2014-04-23?11:23??給PCM數據流加WAV格式文件頭\AddPcmFileHeader\AddPcmFileHeader.cpp

?????文件???????4178??2014-04-23?10:04??給PCM數據流加WAV格式文件頭\AddPcmFileHeader\AddPcmFileHeader.vcproj

?????文件???????1004??2014-04-23?09:23??給PCM數據流加WAV格式文件頭\AddPcmFileHeader\ReadMe.txt

?????文件????????221??2014-04-23?09:23??給PCM數據流加WAV格式文件頭\AddPcmFileHeader\stdafx.cpp

?????文件????????378??2014-04-23?09:23??給PCM數據流加WAV格式文件頭\AddPcmFileHeader\stdafx.h

?????文件????????913??2014-04-23?09:23??給PCM數據流加WAV格式文件頭\AddPcmFileHeader.sln

????..A..H.?????10752??2014-04-23?15:45??給PCM數據流加WAV格式文件頭\AddPcmFileHeader.suo

?????目錄??????????0??2014-04-24?17:09??給PCM數據流加WAV格式文件頭\AddPcmFileHeader

?????目錄??????????0??2014-04-24?17:09??給PCM數據流加WAV格式文件頭

-----------?---------??----------?-----??----

????????????????21847????????????????????9


評論

共有 條評論