資源簡(jiǎn)介
一個(gè)通過網(wǎng)絡(luò)實(shí)現(xiàn)語音對(duì)講的小程序,核心代碼就500行左右,已在這個(gè)基礎(chǔ)上實(shí)現(xiàn)了二次開發(fā),在網(wǎng)絡(luò)環(huán)境差的情況下語音會(huì)有延遲,雜音還可以接受,歡迎一起討論

代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.Text;
namespace?g711audio
{
????///?
????///?Turns?8-bit?A-law?bytes?back?into?16-bit?PCM?values.
????///?
????public?static?class?ALawDecoder
????{
????????///?
????????///?An?array?where?the?index?is?the?a-law?input?and?the?value?is
????????///?the?16-bit?PCM?result.
????????///?
????????private?static?short[]?aLawToPcmMap;
????????static?ALawDecoder()
????????{
????????????aLawToPcmMap?=?new?short[256];
????????????for?(byte?i?=?0;?i?????????????????aLawToPcmMap[i]?=?decode(i);
????????}
????????///?
????????///?Decode?one?a-law?byte.?For?internal?use?only.
????????///?
????????///?The?encoded?a-law?byte
????????///?A?short?containing?the?16-bit?result
????????private?static?short?decode(byte?alaw)
????????{
????????????//Invert?every?other?bit?and?the?sign?bit?(0xD5?=?1101?0101)
????????????alaw?^=?0xD5;
????????????//Pull?out?the?value?of?the?sign?bit
????????????int?sign?=?alaw?&?0x80;
????????????//Pull?out?and?shift?over?the?value?of?the?exponent
????????????int?exponent?=?(alaw?&?0x70)?>>?4;
????????????//Pull?out?the?four?bits?of?data
????????????int?data?=?alaw?&?0x0f;
????????????//Shift?the?data?four?bits?to?the?left
????????????data?<<=?4;
????????????//Add?8?to?put?the?result?in?the?middle?of?the?range?(like?adding?a?half)
????????????data?+=?8;
????????????
????????????//If?the?exponent?is?not?0?then?we?know?the?four?bits?followed?a?1
????????????//and?can?thus?add?this?implicit?1?with?0x100.
????????????if?(exponent?!=?0)
????????????????data?+=?0x100;
????????????/*?Shift?the?bits?to?where?they?need?to?be:?left?(exponent?-?1)?places
?????????????*?Why?(exponent?-?1)??
?????????????*?1?2?3?4?5?6?7?8?9?A?B?C?D?E?F?G
?????????????*?.?7?6?5?4?3?2?1?.?.?.?.?.?.?.?.?<--?starting?bit?(based?on?exponent)
?????????????*?.?.?.?.?.?.?.?Z?x?x?x?x?1?0?0?0?<--?our?data?(Z?is?0?only?when?exponent?is?0)
?????????????*?We?need?to?move?the?one?under?the?value?of?the?exponent
?????????????*?which?means?it?must?move?(exponent?-?1)?times
?????????????*?It?also?means?shifting?is?unnecessary?if?exponent?is?0?or?1.
?????????????*/
????????????if?(exponent?>?1)
????????????????data?<<=?(exponent?-?1);
????????????return?(short)(sign?==?0???data?:?-data);
????????}
????????///?
????????///?Decode?one?a-law?byte
????????///?
????????///?The?encoded?a-law?byte
????????///?A?short?containing?the?16-bit?result
????????public?static?short?ALawDecode(byte?alaw)
????????{
????????????return?aLawToPcmMap[alaw];
????????}
????????///?
????????///?Decode?an?array?of?a-law?encoded?bytes
????????///?
????????///?An?array?of?a-law?encoded?bytes
????????///?An?array?of?shorts?c
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????文件???????4741??2006-07-28?08:57??VoiceChat\Backup\VoiceChat\ALawDecoder.cs
?????文件???????6387??2006-07-28?09:03??VoiceChat\Backup\VoiceChat\ALawEncoder.cs
?????文件???????5055??2006-07-28?08:57??VoiceChat\Backup\VoiceChat\MuLawDecoder.cs
?????文件???????6493??2006-07-28?09:02??VoiceChat\Backup\VoiceChat\MuLawEncoder.cs
?????文件????????480??2007-06-29?01:27??VoiceChat\Backup\VoiceChat\Program.cs
?????文件???????1266??2007-06-29?01:18??VoiceChat\Backup\VoiceChat\Properties\AssemblyInfo.cs
?????文件???????2845??2007-06-29?01:18??VoiceChat\Backup\VoiceChat\Properties\Resources.Designer.cs
?????文件???????5612??2007-06-29?01:18??VoiceChat\Backup\VoiceChat\Properties\Resources.resx
?????文件???????1092??2007-06-29?01:18??VoiceChat\Backup\VoiceChat\Properties\Settings.Designer.cs
?????文件????????249??2007-06-29?01:18??VoiceChat\Backup\VoiceChat\Properties\Settings.settings
?????文件??????21765??2007-07-03?22:55??VoiceChat\Backup\VoiceChat\VoiceChat.cs
?????文件???????3661??2007-07-03?13:09??VoiceChat\Backup\VoiceChat\VoiceChat.csproj
?????文件???????6309??2007-07-03?19:19??VoiceChat\Backup\VoiceChat\VoiceChat.Designer.cs
?????文件???????5814??2007-07-03?19:19??VoiceChat\Backup\VoiceChat\VoiceChat.resx
?????文件????????916??2007-06-29?01:18??VoiceChat\Backup\VoiceChat.sln
?????文件?????178176??2005-03-18?16:23??VoiceChat\dll\Microsoft.DirectX.DirectSound.dll
?????文件?????223232??2005-03-18?16:23??VoiceChat\dll\Microsoft.DirectX.dll
?????文件??????30048??2017-12-15?21:20??VoiceChat\UpgradeLog.htm
?????文件???????8976??2017-12-15?21:20??VoiceChat\UpgradeLog.xm
?????文件???????4741??2006-07-28?08:57??VoiceChat\VoiceChat\ALawDecoder.cs
?????文件???????6387??2006-07-28?09:03??VoiceChat\VoiceChat\ALawEncoder.cs
?????文件?????178176??2005-03-18?16:23??VoiceChat\VoiceChat\bin\Debug\Microsoft.DirectX.DirectSound.dll
?????文件?????223232??2005-03-18?16:23??VoiceChat\VoiceChat\bin\Debug\Microsoft.DirectX.dll
?????文件??????20480??2017-12-15?21:23??VoiceChat\VoiceChat\bin\Debug\VoiceChat.exe
?????文件??????50688??2017-12-15?21:23??VoiceChat\VoiceChat\bin\Debug\VoiceChat.pdb
?????文件??????21464??2017-12-15?21:20??VoiceChat\VoiceChat\bin\Debug\VoiceChat.vshost.exe
?????文件????????490??2012-06-06?02:06??VoiceChat\VoiceChat\bin\Debug\VoiceChat.vshost.exe.manifest
?????文件???????5055??2006-07-28?08:57??VoiceChat\VoiceChat\MuLawDecoder.cs
?????文件???????6493??2006-07-28?09:02??VoiceChat\VoiceChat\MuLawEncoder.cs
?????文件????????789??2017-12-15?21:21??VoiceChat\VoiceChat\obj\Debug\DesignTimeResolveAssemblyReferences.cache
............此處省略44個(gè)文件信息
- 上一篇:C# 鍵盤記錄 按鍵記錄
- 下一篇:C# 中英文界面切換
評(píng)論
共有 條評(píng)論