程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> 關於C# >> Delphi轉換Dialogic Vox文件為Wave文件

Delphi轉換Dialogic Vox文件為Wave文件

編輯:關於C#
 

千辛萬苦才查閱資料寫出來的,自己高興一下。轉換類支持8/16位,6000/8000采樣率,ADPCM,muLaw,aLaw多種格式的Vox轉換。

很奇怪的是,華為的ICD平台錄下來的音格式上有微小不同,一個平台的語音用我們這個程序可以正常轉換,但另一個平台的錄音轉換完之後卻丟失0軸以上的波形,但聽起來聲音基本一樣。估計2個平台選用的錄音卡有所不同。可是,用CoolEdit卻可以正常顯示2個語音的波形,不知裡面的算法有什麼微小的差異。用CoolEdit將我們不能正常顯示波形的聲音重新另存為Dialogic Vox格式後進行比較,發現前後兩個聲音確有不同。我們再對CoolEdit另存的聲音進行轉換,結果顯示波形正常。

最後的結果,終於波形調整好了,原因是需要判斷當累計出現了48個二進制的1000或0000的Sample後,要對ADPCM初始化一次,轉換後的噪音比源文件略為大了一些,但可以接受。

關於初始化的原文如下,總覺得自己翻譯的還不准確

“Initial Conditions
When the ADPCM algorithm is reset, the step size ss(n) is set to the minimum value (16) and the
estimated waveform value X is set to zero (half scale). Playback of 48 samples (24 bytes) of plus
and minus zero (10002 and 00002) will reset the algorithm. Twenty-four bytes of 08 Hex or 80
Hex will satisfy this requirement. It is necessary to alternate positive and negative zero values
because the encoding formula always adds 1/8 of the quantization size. If all values were positive
or negative, a DC component would be added that would create a false reference level.”

 

調用示例


procedure TForm1.btnBrowseClick(Sender: TObject);
var
vox:TVox;
begin
if (OpenDialog1.Execute) then
begin

//默認為6K采樣率,8位,ADPCM格式
vox := TVox.Create(OpenDialog1.FileName);
if(vox.Convert=0) then
ShowMessage('Convert Success! The outfile be saved as '+vox.OutFileName);
vox.Free;
end;
end;
 

 

Class of Convert Vox to Wave


unit uVoxToWave;

interface
uses
SysUtils;
type
TVoxFormat = (VF_ADPCM = 1, VF_MULAW = 2, VF_ALAW = 3);
TVoxRate = (VR_6K = 6000, VR_8K = 8000);
TVoxBitsPerSample = (VB_8 = 1, VB_16 = 2);
TWaveHead = packed record
cHead: array[0..3] of char; {'RIFF'}
nLength: longint;
cWaveTag: array[0..7] of char; {'WAVEfmt '}
nHeaderLength: LongInt; {16}
wFormatTag: Word; { format type 01 00}
nChannels: Word; { number of channels (i.e. mono, stereo, etc.) 01}
nSamplesPerSec: longint; { sample rate 8000}
nAvgBytesPerSec: longint; { for buffer estimation 8000}
nBlockAlign: Word; {1}
wBitsPerSample: word; {8}
end;
TDataHead = packed record
cDataTag: array[0..3] of char; {'data'}
nDatalen: longint;
end;
PWaveHead = ^TWaveHead;
TVox = class
private
FInFileName, FOutFileName: string;
FVoxFormat: TVoxFormat;
FVoxRate: TVoxRate;
FVoxBitsPerSample: TVoxBitsPerSample;
rate, bit_rate: integer;
sample: byte; // sample read from input file
buffer: array[0..9999] of byte; // a block of input data

SS: Word; // current step size for ADPCM
SSindex: Word; // current index into step size table
Sn: Smallint; // current 12-bit linear sample value
out_val: byte; // .WAV output value
out_int: Smallint; // linear output value
function decode(sample: byte; Sn: SmallInt; var SS: WORD; var SSindex: WORD): smallint;
procedure ConvertADPCM(infile, outfile: integer);
procedure ConvertMULAW(infile, outfile: integer);
procedure ConvertALAW(infile, outfile: integer);
published
property InFileName: string read FInFileName;
property OutFileName: string read FOutFileName;
public
constructor Create(InFileName: string; OutFileName: string = ''; VoxFormat: TVoxFormat = VF_ADPCM; VoxRate: TVoxRate = VR_6K; VoxBitsPerSample: TVoxBitsPerSample = VB_8);
function Convert: integer;
end;
const
SEEK_SET = 0;
SEEK_END = 2;
ResetValue = 48;
formats: array[0..2] of string = ('ADPCM', 'Mu-Law', 'A-Law');
mulaw: array[0..255] of smallint = (
-32124, -31100, -30076, -29052, -28028, -27004, -25980, -24956,
-23932, -22908, -21884, -20860, -19836, -18812, -17788, -16764,
-15996, -15484, -14972, -14460, -13948, -13436, -12924, -12412,
-11900, -11388, -10876, -10364, -9852, -9340, -8828, -8316,
-7932, -7676, -7420, -7164, -6908, -6652, -6396, -6140,
-5884, -5628, -5372, -5116, -4860, -4604, -4348, -4092,
-3900, -3772, -3644, -3516, -3388, -3260, -3132, -3004,
-2876, -2748, -2620, -2492, -2364, -2236, -2108, -1980,
-1884, -1820, -1756, -1692, -1628, -1564, -1500, -1436,
-1372, -1308, -1244, -1180, -1116, -1052, -988, -924,
-876, -844, -812, -780, -748, -716, -684, -652,
-620, -588, -556, -524, -492, -460, -428, -396,
-372, -356, -340, -324, -308, -292, -276, -260,
-244, -228, -212, -196, -180, -164, -148, -132,
-120, -112, -104, -96, -88, -80, -72, -64,  

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved