»áÔ±£º ÃÜÂ룺 ¡¡Ãâ·Ñ×¢²á | Íü¼ÇÃÜÂë | »áÔ±µÇ¼ ÍøÒ³¹¦ÄÜ£º ¼ÓÈëÊÕ²Ø ÉèΪÊ×Ò³ ÍøÕ¾ËÑË÷  
¼¼ÊõÎĵµ > VCÎĵµ > ƽ̨SDK
VCµ÷ÓÃACMÒôƵѹËõ±à³Ì½Ó¿ÚµÄ·½·¨
·¢±íÈÕÆÚ£º2004-07-04 15:32:56×÷ÕߣºÍ ³ö´¦£º  

ÒôƵºÍÊÓƵÊý¾ÝÊÇ´ó¶àÊý¶àýÌåÓ¦ÓóÌÐòÏòÓû§ÌṩÐÅÏ¢µÄÖ÷Òª·½Ê½£¬ÕâЩÊý¾ÝÒ»°ã¾ßÓнϸߵIJÉÑùËÙÂÊ£¬Èç¹û²»¾­¹ýѹËõµÄ»°£¬±£´æËüÃÇÐèÒªÏûºÄ´óÁ¿µÄ´æÖü¿Õ¼ä£¬ÔÚÍøÂçÉϽøÐд«ÊäµÄЧÂÊÒ²ºÜµÍ£¬Òò´ËÒôƵÊÓƵÊý×ÖѹËõ±àÂëÔÚ¶àýÌå¼¼ÊõÖÐÕ¼ÓкÜÖØÒªµÄµØλ¡£¾ÍÒôƵÊý¾Ý¶øÑÔ£¬Ä¿Ç°³£ÓõÄѹËõ·½·¨ÓкܶàÖÖ£¬²»Í¬µÄ·½·¨¾ßÓв»Í¬µÄѹËõ±ÈºÍ»¹Ô­ÒôÖÊ£¬±àÂëµÄ¸ñʽºÍËã·¨Ò²¸÷²»Ïàͬ£¬ÆäÖÐijЩѹËõËã·¨Ï൱¸´ÔÓ£¬ÆÕͨ³ÌÐò²»¿ÉÄÜȥʵÏÖÆä±à½âÂëËã·¨¡£ËùÐÒµÄÊÇ£¬ÓëWindows3.xÏà±È£¬Windows95/NT4.0Ϊ¶àýÌåÓ¦ÓóÌÐòÌṩÁ˸üÇ¿µÄÖ§³Ö£¬ÒýÈëÁËACM£¨Audio Compression Manager£¬ÒôƵѹËõ¹ÜÀíÆ÷£©ºÍVCM£¨Video Compressio nManager£¬ÊÓƵѹËõ¹ÜÀíÆ÷£©£¬ËüÃǸºÔð¹ÜÀíϵͳÖÐËùÓÐÒôƵºÍÊÓƵ±à½âÂëÆ÷£¨Coder-Decoder£¬¼ò³ÆCODEC£¬ÊÇʵÏÖÒôƵÊÓƵÊý¾Ý±à½âÂëµÄÇý¶¯³ÌÐò£©£¬Ó¦ÓóÌÐò¿ÉÒÔͨ¹ýACM»òVCMÌṩµÄ±à³Ì½Ó¿Úµ÷ÓÃÕâЩϵͳÖÐÏֳɵıà½âÂëÆ÷À´ÊµÏÖÒôƵ»òÊÓƵÊý¾ÝµÄѹËõºÍ½âѹËõ¡£95/NT4.0ϵͳ×Ô´øµÄÒôƵCODECsÖ§³ÖһЩÔçÆÚµÄÒôƵÊý¾ÝѹËõ±ê×¼£¬ÈçADPCMµÈ£¬InternetExplorer4.0µÈÓ¦ÓóÌÐò°üº¬µÄÒôƵCODECsÖ§³ÖһЩ±È½ÏеÄѹËõ±ê×¼£¬ÈçMPEGLayer3µÈ¡£ÔÚ¿ØÖÆÃæ°åµÄ¶àýÌå×é¼þÖÐÑ¡Ôñ¡°¸ß¼¶¡±£¬´ò¿ª¡°ÒôƵѹËõµÄ±àÂë½âÂëÆ÷¡±£¬¾Í¿ÉÁгöϵͳÖа²×°µÄËùÓÐÒôƵCODECs¡£±¾ÎÄËùÒª½éÉܵľÍÊÇACMÒôƵѹËõ½Ó¿ÚµÄ±à³Ì·½·¨£¬ËùÓñà³Ì¹¤¾ßΪVC++5.0¡£
»ñÈ¡CODECsµÄÐÅÏ¢
----ACMµÄAPIº¯Êý¶¨ÒåÔÚÍ·Îļþmsacm.hÖУ¬³ý´ËÖ®Í⣬¶ÔACM±à³Ì»¹±ØÐë°üº¬Í·Îļþmmsystem.h£¬mmreg.h£¬ÕâÁ½¸öÍ·Îļþ¶¨ÒåÁ˶àýÌå±à³ÌÖÐ×î»ù±¾µÄ³£Á¿ºÍÊý¾Ý½á¹¹¡£ÎªÁ˱ÜÃâÓÐЩ¸ß°æ±¾ACM²ÅÌṩµÄº¯ÊýºÍ¹¦ÄÜÔڽϵͰ汾µÄACMÖÐÉϲ»¿ÉÓ㬳ÌÐòÖÐÓ¦µ÷ÓÃacmGetVersionº¯Êý²éѯÓû§»úÆ÷ÖÐACMµÄ°æ±¾ÐÅÏ¢¡£
----Ç°ÃæÌáµ½£¬ÔÚ¿ØÖÆÃæ°åÖпÉÒԲ鿴ϵͳÖÐCODECsµÄÐÅÏ¢£¬¶øÔÚÓ¦ÓóÌÐòÖÐÒ²³£³£ÐèÒªÖªµÀijÖÖÒôƵCODECsÊÇ·ñ´æÔÚ£¬²¢»ñÈ¡Æä±à½âÂë²ÎÊýµÈÐÅÏ¢£¬ÕâÒ»µã¿ÉÒÔͨ¹ýµ÷ÓÃÏÂÃæÁ½¸öº¯ÊýÀ´ÊµÏÖ¡£

---- MMRESULT mmr=acmMetrics(NULL, ACM_METRIC_COUNT_CODECS, &dwCodecs);

---- mmr = acmDriverEnum(CodecsEnumProc, 0, 0);

----acmMetrics()º¯Êý¿ÉÒÔ»ñÈ¡Ðí¶àACM¶ÔÏóµÄÓÐÓÃÐÅÏ¢£¬ÀýÈçÏòÆäÖд«µÝACM_METRIC_COUNT_CODECS¿ÉÒÔ²éѯϵͳÖа²×°µÄÒôƵCODECs×ÜÊý¡£º¯ÊýacmDriverEnum()µÄ¹¦ÄÜÊÇö¾ÙËùÓеÄÒôƵCODECs£¬ÔÚacmDriverEnum()µÄ²ÎÊýÖÐÖ¸¶¨»Øµ÷º¯ÊýCodecsEnumProc()¿ÉÒÔ½øÒ»²½²éѯÿ¸öCODECµÄÐÅÏ¢¡£Windows±à³ÌÖо­³£ÒªÓõ½»Øµ÷º¯Êý£¬ÏÂÃæÊÇö¾ÙÒôƵCODECsµÄÒ»¸ö»Øµ÷º¯ÊýµÄʾÀý¡£

 

BOOL CALLBACK CodecsEnumProc(HACMDRIVERID

hadid, DWORD dwInstance, DWORD fdwSupport) {

DWORD dwSize = 0;

if (fdwSupport & ACMDRIVERDETAILS_SUPPORTF_CODEC)

 printf("¶à¸ñʽת»»\n");

ACMDRIVERDETAILS add;

acmdd.cbStruct = sizeof(acmdd);

MMRESULT mmr = acmDriverDetails(hadid, &acmdd, 0);

if (mmr)  error_msg(mmr);

else {

printf(" È«³Æ:  %s\n", acmdd.szLongName);

printf(" ÃèÊö:   %s\n", acmdd.szFeatures);

}

HACMDRIVER had = NULL;

mmr = acmDriverOpen(&had, hadid, 0); //´ò¿ªÇý¶¯³ÌÐò

if (mmr)  error_msg(mmr);

else {

mmr = acmMetrics(had, ACM_METRIC_

MAX_SIZE_FORMAT, &dwSize);

WAVEFORMATEX* pwf = (WAVEFORMATEX*) malloc(dwSize);

memset(pwf, 0, dwSize);

pwf->cbSize = LOWORD(dwSize) - sizeof(WAVEFORMATEX);

pwf->wFormatTag = WAVE_FORMAT_UNKNOWN;

ACMFORMATDETAILS fd;

memset(&fd, 0, sizeof(fd));

fd.cbStruct = sizeof(fd);  fd.pwfx = pwf;  fd.cbwfx = dwSize;

fd.dwFormatTag = WAVE_FORMAT_UNKNOWN;

mmr = acmFormatEnum(had, &fd, FormatEnumProc, 0, 0); 

if (mmr)  error_msg(mmr);

free(pwf);

acmDriverClose(had, 0);

}

return TRUE;

}


----CodecsEnumProc()¹²ÓÐÈý¸ö²ÎÊý¡£µÚÒ»¸ö²ÎÊýÊÇÇý¶¯³ÌÐòµÄIDÖµ£»µÚ¶þ¸ö²ÎÊýÊÇʵÀýÊý¾Ý£¬±¾ÎÄÀý×ÓÖÐδʹÓ㻵ÚÈý¸ö²ÎÊýÃèÊö¸ÃÇý¶¯³ÌÐòËùÖ§³ÖµÄ¹¦ÄÜ£¬ËüÓÉÒ»×é±êʶ½øÐлòÔËËã¹¹³É£¬ÀýÈ磬Èç¹ûÉèÖÃÁ˱êʶACMDRIVERDETAILS_SUPPORTF_CODEC£¬Ôò˵Ã÷¸ÃÇý¶¯³ÌÐò¿ÉÒÔ½«Ò»ÖÖ±àÂë¸ñʽµÄÒôƵÐźÅת»»³ÉÁíÒ»ÖÖ±àÂë¸ñʽ¡£Í¨¹ýacmDriverDetails()º¯Êý¿ÉÒÔ»ñµÃ¶Ô¸ÃÇý¶¯³ÌÐò½øÒ»²½µÄÐÅÏ¢£¬ÈçCODECµÄÃû³Æ¡¢¼òµ¥ÃèÊöµÈ¡£ÒÔÉÏÐÅϢʵ¼ÊÉÏÊÇÓÉACMÊÕ¼¯£¬²¢±£´æÔÚACMÄÚ²¿£¬ËùÒÔ²éѯÒÔÉÏÐÅϢʱ²¢Î´ÕæÕý½«Çý¶¯³ÌÐò¼ÓÔØÖÁÄÚ´æ¡£¶øÒª»ñµÃÿһÖÖÇý¶¯³ÌÐòÖ§³ÖµÄÒôƵ¸ñʽÐÅÏ¢£¬Ôò±ØÐ뽫Çý¶¯³ÌÐò¼ÓÔØÖÁÄڴ棬ÕâÊÇͨ¹ýacmDriverOpen()Íê³ÉµÄ£¬ÔÚÍ˳öCodecsEnumProc()Ç°£¬»¹ÒªÓÃacmDriverClose()À´¹Ø±ÕÒÑ´ò¿ªµÄÇý¶¯³ÌÐò¡£ÔÚʹÓÃÒôƵ¸ñʽö¾Ùº¯ÊýÇ°£¬ÐèÒªÏÈ·ÖÅäÒ»¿é»º³åÇø´æÖøñʽÐÅÏ¢£¬»º³åÇøµÄ´óС¿Éͨ¹ýµ÷ÓÃacmMetrics()²éѯACM_METRIC_MAX_SIZE_FORMAT»ñµÃ£¬¸ñʽÐÅÏ¢ÖеÄÒôƵ¸ñʽ±êʶÉèΪWAVE_FORMAT_UNKNOWN¡£ÔÚÒôƵ¸ñʽö¾ÙÖÐͬÑùʹÓÃÁ˻ص÷º¯Êý£¬´Ë»Øµ÷º¯ÊýÖ»ÊÇÁгöÁ˸ÃÒôƵ¸ñʽµÄÃû³ÆºÍ±êʶֵ¡£

BOOL CALLBACK FormatEnumProc

(HACMDRIVERID hadid, LPACMFORMATDETAILS

 pafd, DWORD dwInstance, DWORD fdwSupport) {

printf("%4.4lXH, %s\n", pafd- >dwFormatTag, pafd- >szFormat);

return TRUE;

}


----ÉÏÃæ½éÉÜÁËä¯ÀÀϵͳÖÐËùÓÐÒôƵCODECs¼°Ã¿ÖÖCODECËùÖ§³ÖµÄÒôƵ¸ñʽµÄ·½·¨£¬Ä³Ð©µäÐ͵ÄÓ¦ÓóÌÐò¿ÉÄÜÐèÒªÁгöϵͳÖÐËùÓпÉÒÔÑ¡ÓõÄCODECs£¬²¢ÓÉÓû§À´Ñ¡ÔñʹÓÃÄÄÒ»ÖÖCODEC½øÐÐѹËõ£¬´Ëʱ¾ÍÐèÒªÀûÓÃÉÏÃæµÄ±à³Ì·½·¨À´»ñÈ¡CODECsµÄÐÅÏ¢¡£

ÒôƵÊý¾ÝµÄѹËõ
----ÏÂÃæ˵Ã÷ʹÓÃijһCODECʵÏÖÒôƵѹËõµÄ¹ý³Ì£¬¶ÁÕßÅóÓÑÖ»ÐèÉԼӸĶ¯¾Í¿É±àд³öÏàÓ¦µÄ½âѹ³ÌÐò¡£¼ÙÉèÔ´ÐźÅΪ8K²ÉÑù¡¢16bitsPCM±àÂë¡¢µ¥ÉùµÀ¡¢³¤¶ÈΪ1ÃëµÄÒôƵÐźš£Çý¶¯³ÌÐò²ÉÓÃWindows95×Ô´øµÄTrueSpeechÒôƵCODEC£¬ËüÄÜʵÏÖ´óÔ¼10£º1µÄѹËõ¡£ÔÚ´ËÀýÖУ¬TrueSpeechCODECÖ§³Ö´ÓÔ´ÒôƵ¸ñʽµ½Ä¿±ê¸ñʽµÄת»»£¬¶øÔÚʵ¼ÊÓ¦ÓÃÖУ¬¿ÉÄÜijÖÖCODEC²»Ö§³ÖÖ±½Ó½«Ô´ÒôƵ¸ñʽת»»³ÉÄ¿±ê¸ñʽ£¬Õâʱ¿ÉÒÔ²ÉÈ¡Á½²½×ª»»·¨£¬¼´ÏȽ«Ô´¸ñʽת»»³ÉÒ»ÖÖÖмä¸ñʽ£¬ÔÙ½«´ËÖмä¸ñʽת»»³ÉÄ¿±ê¸ñʽ£¬ÒòΪÏßÐÔPCM±àÂë×îΪ¼òµ¥£¬ÇÒΪ¾ø´ó¶àÊýCODECËùÖ§³Ö£¬ËùÒÔÒ»°ãÖмä¸ñʽ¶¼Ñ¡ÎªÏßÐÔPCM¸ñʽµÄÒ»ÖÖ¡£
----ÔÚ½øÐÐѹËõ֮ǰÊ×ÏÈÐèҪȷ¶¨TrueSpeechÇý¶¯³ÌÐòµÄIDÖµ¡£Îª´ËÐèÒªÓõ½acmDriverEnum()º¯Êý£¬¶Ôö¾Ùµ½µÄÿһ¸öÇý¶¯³ÌÐò£¬ÓÉacmDriverEnum()Ö¸¶¨µÄ»Øµ÷º¯Êý½«¼ì²éÆäÖ§³ÖµÄËùÓÐÒôƵ¸ñʽ£¬ÈôÆäÖаüÀ¨wFormatTagֵΪWAVE_FORMAT_DSPGROUP_TRUESPEECHµÄÒôƵ¸ñʽ£¬Ôò´ËÇý¶¯³ÌÐò¾ÍÊÇҪѰÕÒµÄTrueSpeechCODEC£¬ËüËùÖ§³ÖµÄµÚÒ»ÖÖWAVE_FORMAT_DSPGROUP_TRUESPEECHÒôƵ¸ñʽ¼´ÎªÄ¿±êÒôƵѹËõ¸ñʽ¡£²éѯËùÐèµÄCODEC¼°ÆäÖ§³ÖµÄÒôƵ¸ñʽµÄ·½·¨¼ûǰһС½ÚµÄ½éÉÜ¡£

----¸ù¾Ý²éѯµÄ½á¹û£¬ÉèhadIDΪTrueSpeechCODECµÄIDÖµ£¬pwfDrvΪָÏòÄ¿±êWAVEFORMATEX½á¹¹µÄÖ¸Õ룬½ÓÏÂÀ´ÀûÓûñµÃµÄIDÖµ´ò¿ªÏàÓ¦µÄÇý¶¯³ÌÐò¡£

HACMDRIVER had = NULL;

mmr = acmDriverOpen(&had, hadID, 0);

if(mmr) {  printf(" ´ò¿ªÇý¶¯³ÌÐòʧ°Ü\n"); exit(1);  }


----ѹËõºÍ½âѹËõÒ»Ñù£¬¶¼Êǽ«ÒôƵÐźŴÓÒ»ÖÖÒôƵ¸ñʽת»»³ÉÁíÒ»ÖÖ¸ñʽ£¬ÒªÍê³ÉÕâÒ»¹ý³Ì£¬Ê×ÏÈÒª´ò¿ª×ª»»Á÷¡£ÔÚÓÃacmStreamOpen´ò¿ª×ª»»Á÷ʱ£¬ÎÒÃÇÖ¸¶¨ÁËACM_STREAMOPENF_NONREALTIME±êÖ¾£¬Ëü±íʾת»»ÎÞÐèʵʱ½øÐС£ÒòΪºÜ¶àѹËõËã·¨µÄ¼ÆËãÁ¿ÊÇÏ൱´óµÄ£¬ÊµÊ±Íê³É¼¸ºõÊDz»¿ÉÄܵģ¬ÀýÈçÔÚ±¾ÀýÖУ¬Èç¹û²»Ö¸¶¨´Ë±êÖ¾£¬TrueSpeechCODEC¾Í»á·µ»Ø¡°ÎÞ·¨Íê³É¡±µÄ´íÎó¡£

HACMSTREAM hstr = NULL;

DWORD dwSrcBytes = dwSrcSamples * wfSrc.wBitsPerSample / 8;

mmr = acmStreamOpen(&hstr,had, //Çý¶¯³ÌÐò¾ä±ú

pwfSrc, //Ö¸ÏòÔ´ÒôƵ¸ñʽµÄÖ¸Õë

pwfDrv, //Ö¸ÏòÄ¿±êÒôƵ¸ñʽµÄÖ¸Õë

NULL, //ÎÞ¹ýÂËÆ÷

NULL, //Î޻ص÷º¯Êý

0,ACM_STREAMOPENF_NONREALTIME);


----ÔÚÕæÕý½øÐÐת»»Ö®Ç°£¬»¹±ØÐë×¼±¸×ª»»Á÷µÄÐÅϢͷ¡£ÏÂÃæÒ»¶Î´úÂëÖУ¬ÏÈÀûÓÃÔ´Êý¾ÝµÄ´óСÒÔ¼°Ä¿±ê¸ñʽµÄƽ¾ùÊý¾ÝÂʹÀËãÄ¿±êÊý¾ÝµÄ»º´æÇø´óС£¬È»ºóµ÷ÓÃacmStreamPrepareHeaderΪת»»×¼±¸ÐÅϢͷ¡£

---- DWORD dwDstBytes=pwfDrv->nAvgBytesPerSec*dwSrcSamples/wfSrc.nSamplesPerSec;

---- dwDstBytes = dwDstBytes*3/2; // ¼Æ Ëã ѹ Ëõ ºó Òô Ƶ Êý ¾Ý ´ó С£¬ ²¢ ÒÀ ´Ë ÊÊ µ± Ôö ¼Ó Êä ³ö »º ³å Çø µÄ ´ó С¡£

BYTE* pDstData = new BYTE [dwDstBytes];

ACMSTREAMHEADER shdr;

memset(&strhdr, 0, sizeof(shdr));

shdr.cbStruct = sizeof(shdr);

shdr.pbSrc = pSrcData;  //Ô´ÒôƵÊý¾ÝÇø

shdr.cbSrcLength = dwSrcBytes;

shdr.pbDst = pDstData; //ѹËõºóÒôƵÊý¾Ý»º³åÇø

shdr.cbDstLength = dwDstBytes;

mmr = acmStreamPrepareHeader(hstr, &shdr, 0);


----ÓïÒôÊý¾ÝÕæÕýµÄѹËõ¹ý³ÌÊÇÓɺ¯ÊýacmStreamConvert()Íê³ÉµÄ¡£ÔÚµ÷ÓÃacmStreamConvert()ʱ¿ÉÒÔÖ¸¶¨»Øµ÷º¯Êý£¬ÒÔ±ãÔÚת»»¹ý³ÌÖÐÏÔʾ½ø¶ÈÐÅÏ¢µÈ¡£ÔÚ±¾ÀýÖУ¬Î´Ö¸¶¨»Øµ÷º¯Êý£¬Ö»ÊǼòµ¥µØµÈ´ýѹËõµÄ½áÊø¡£

----mmr=acmStreamConvert(hstr,&shdr,0);

----Êý¾ÝѹËõÍê±Ïºó£¬Ó¦ÓóÌÐò¾Í¿ÉÒÔ°Ñ»º³åÇøÖеÄÊý¾ÝдÈëÄ¿±êÎļþÖС£

----×îºó£¬±ØÐë¹Ø±Õת»»Á÷ºÍÇý¶¯³ÌÐò¡£

mmr=acmStreamClose(hstr,0);

mmr=acmDriverClose(had,0);


----±¾ÎĽéÉÜÁËÀûÓÃACM»ñÈ¡ÒôƵCODECµÄÐÅÏ¢ÒÔ¼°ÊµÏÖÒôƵѹËõµÄÒ»°ã·½·¨ºÍ¹ý³Ì£¬¶ÔACM±à³Ì¸ÐÐËȤµÄ¶ÁÕß¿ÉÒÔ½øÒ»²½²Î¿¼VC++5µÄÁª»ú°ïÖúÖйØÓÚACMµÄÐÅÏ¢¡£

 

¡¾·µ»Ø¶¥²¿¡¿ ¡¾´òÓ¡±¾Ò³¡¿ ¡¾¹Ø±Õ´°¿Ú¡¿

¹ØÓÚÎÒÃÇ / ¸øÎÒÁôÑÔ / °æȨ¾Ù±¨ / Òâ¼û½¨Òé / ÍøÕ¾±à³ÌQQȺ   
Copyright ©2003- 2024 Lihuasoft.net webmaster(at)lihuasoft.net ¼ÓÔØʱ¼ä 0.00406