wince音量調節的實現
劉啟明 2010-5-8
pulong pdwgain = (pulong)dwparam1;
if (pstreamcontext)
*pdwgain = pstreamcontext->getgain();
else
// handle device gain in hardware
//*pdwgain = g_phwcontext->getoutputgain();//沒有硬體音量調節支援
// handle device gain in software
devicecontext *pdevicecontext = g_phwcontext->getoutputdevicecontext(udeviceid);//軟音量獲取
*pdwgain = pdevicecontext->getgain();
dwret = mmsyserr_noerror;
break;
case wodm_setvolume://音量設定.
long dwgain = dwparam1;
if (pstreamcontext)//如果存在音訊流,則這裡調節音訊流音量
break;
m_fxpgain = mapgain(m_dwgain);//m_fxpgain儲存音訊流的音量大小
}dword totalgain = gain & 0xffff;
dword secondarygain = m_pdevicecontext->getsecondarygainlimit(m_secondarygainclass) & 0xffff;
//retailmsg(1,(_t("mapgain volume set gain = 0x%x/n"),gain));//lqm test.
if (m_secondarygainclass < secondarydevicegainclassmax)
dword devicegain = m_pdevicecontext->getgain() & 0xffff;
retailmsg(1,(_t("gain=0x%x,devicegain=0x%x/n"),gain,devicegain));//lqm test.
totalgain *= devicegain;
totalgain += 0xffff; // round up
totalgain >>= 16; // shift to lowest 16 bits
totalgain *= secondarygain;
totalgain += 0xffff; // round up
totalgain >>= 16; // shift to lowest 16 bits
retailmsg(1,(_t("mapgain volume set totalgain = 0x%x/n"),totalgain));//lqm test.
// special case 0 as totally muted
if (totalgain==0)
return 0;
// convert to index into table
dword index = 63 - (totalgain>>10);
retailmsg(1,(_t("mapgain index = 0x%x/n"),index));//lqm test.
//index = 50;//lqm added for test.10-05-06
return gainmap[index];
傳入引數gain即上面提到的m_dwgain,該引數為32位暫存器,高16位和低16位分別存放左右聲道。由於一般情況下左右聲道的音量都是一樣的,故程式中只取了低16位。
totalgain是devicegain和m_dwgain的乘積,然後右移16位得到的。其實就是totalgain=devicegain*m_dwgain/最高音量,如果把devicegain/最高音量,用百分比來算的話,就很更容易理解了,那麼最後的公式就變成totalgain=devicegain*系統音量百分比。那麼這裡就解釋了系統音量是如何限制流音量的疑問。
最終通過乙個索引求出對應音量的權值,再通過音量表設定音量。可以看到index = 63 - (totalgain>>10);index在0到63的範圍內。返回的gainmap表如下:
const dword gainmap =
0x10000, // 0: 0.000000 db
0xec77, // 1: -1.587302 db
0xda6d, // 2: -3.174603 db
0xc9c2, // 3: -4.761905 db
0xba5d, // 4: -6.349206 db
0xac25, // 5: -7.936508 db
0x9f03, // 6: -9.523810 db
0x92e1, // 7: -11.111111 db
0x87ac, // 8: -12.698413 db
0x7d52, // 9: -14.285714 db
0x73c2, // 10: -15.873016 db
0x6aed, // 11: -17.460317 db
0x62c5, // 12: -19.047619 db
0x5b3b, // 13: -20.634921 db
0x5445, // 14: -22.222222 db
0x4dd7, // 15: -23.809524 db
0x47e7, // 16: -25.396825 db
0x426b, // 17: -26.984127 db
0x3d59, // 18: -28.571429 db
0x38ab, // 19: -30.158730 db
0x3458, // 20: -31.746032 db
0x305a, // 21: -33.333333 db
0x2ca9, // 22: -34.920635 db
0x2941, // 23: -36.507937 db
0x261b, // 24: -38.095238 db
0x2333, // 25: -39.682540 db
0x2083, // 26: -41.269841 db
0x1e08, // 27: -42.857143 db
0x1bbe, // 28: -44.444444 db
0x19a0, // 29: -46.031746 db
0x17ab, // 30: -47.619048 db
0x15dd, // 31: -49.206349 db
0x1432, // 32: -50.793651 db
0x12a7, // 33: -52.380952 db
0x113b, // 34: -53.968254 db
0x0fea, // 35: -55.555556 db
0x0eb3, // 36: -57.142857 db
0x0d94, // 37: -58.730159 db
0x0c8b, // 38: -60.317460 db
0x0b96, // 39: -61.904762 db
0x0ab4, // 40: -63.492063 db
0x09e3, // 41: -65.079365 db
0x0921, // 42: -66.666667 db
0x086f, // 43: -68.253968 db
0x07ca, // 44: -69.841270 db
0x0732, // 45: -71.428571 db
0x06a6, // 46: -73.015873 db
0x0624, // 47: -74.603175 db
0x05ac, // 48: -76.190476 db
0x053d, // 49: -77.777778 db
0x04d7, // 50: -79.365079 db
0x0478, // 51: -80.952381 db
0x0421, // 52: -82.539683 db
0x03d0, // 53: -84.126984 db
0x0386, // 54: -85.714286 db
0x0341, // 55: -87.301587 db
0x0301, // 56: -88.888889 db
0x02c6, // 57: -90.476190 db
0x0290, // 58: -92.063492 db
0x025e, // 59: -93.650794 db
0x0230, // 60: -95.238095 db
0x0205, // 61: -96.825397 db
0x01de, // 62: -98.412698 db
0x01b9, // 63: -100.000000 db
這就是軟音量設定最終呼叫的音量配置表。具體它是如何通過這個表來實現軟音量設定的,還需要認真研究,難道通過i2s送到音訊晶元的數碼訊號裡面已經帶有音量資料?不過到這裡,軟的音量調節功能已經實現了,詳細的原理有空再仔細研究
WINCE音量調節(適用於智慧型裝置)
在此對作者表示感謝。在此又儲存主要是怕自己忘卻了。vs2005上通過。void updatevolumefromregistry pproc freelibrary hlibrary void setvolume dword dwvolume 注釋 coredll.dll 為系統庫。setvolum...
C 調節PCM音量
在用 解碼器 具體的實現函式如下 void raisevolume char buf,uint32 size,uint32 urepeat,double vol buf為需要調節音量的音訊資料塊首位址指標,size為長度,urepeat為重複次數,通常設為1,vol為增益倍數,可以小於1 for i...
音量調節流程
在分析 android音訊系統時,習慣將其實現分為兩個部分 資料流和策略。資料流描述了音訊資料從資料來源流向目的地的過程。而策略則是管理及控制資料流的路徑與呈現的過程.audiotrack audiorecord 和audioflinger 可以被劃歸到資料流的範疇去討論。而 audiopolicy...