c_encoder_aacp.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #include "c_encoder_aacp.h"
  2. #include "../../utils.h"
  3. HINSTANCE C_ENCODER_AACP::hEncoderInstance = NULL;
  4. C_ENCODER_AACP::C_ENCODER_AACP(HWND winamp) : C_ENCODER_NSV(sizeof(T_ENCODER_AACP_INFO)) {
  5. SetName("AAC+ Encoder");
  6. winampWnd = winamp;
  7. ConfigAudio3 = NULL;
  8. if(hEncoderInstance == NULL) {
  9. wchar_t dir[MAX_PATH] = {0};
  10. snwprintf(dir, MAX_PATH, L"%s\\enc_aacplus.dll", GetPluginDirectoryW(winamp));
  11. hEncoderInstance = LoadLibraryW(dir);
  12. }
  13. if(hEncoderInstance) {
  14. void * CreateAudio3=(void *)GetProcAddress(hEncoderInstance, "CreateAudio3");
  15. void * GetAudioTypes3=(void *)GetProcAddress(hEncoderInstance, "GetAudioTypes3");
  16. void * ConfigAudio3=(void *)GetProcAddress(hEncoderInstance, "ConfigAudio3");
  17. void * SetWinampHWND=(void *)GetProcAddress(hEncoderInstance, "SetWinampHWND");
  18. SetEncoder(CreateAudio3,GetAudioTypes3,ConfigAudio3,SetWinampHWND);
  19. }
  20. T_ENCODER_AACP_INFO * EncInfo = (T_ENCODER_AACP_INFO *)ExtendedInfoPtr;
  21. EncInfo->output_bitRate = AACP_DEFAULT_OUTPUTBITRATE;
  22. EncInfo->output_channelmode = AACP_DEFAULT_OUTPUTCHANNELMODE;
  23. EncInfo->output_quality = AACP_DEFAULT_OUTPUTQUALITY;
  24. EncInfo->output_samplerate = AACP_DEFAULT_OUTPUTSAMPLERATE;
  25. EncInfo->output_v2enable = AACP_DEFAULT_OUTPUTV2ENABLE;
  26. }
  27. C_ENCODER_AACP::~C_ENCODER_AACP() {
  28. C_ENCODER_NSV::~C_ENCODER_NSV();
  29. }
  30. static int cacheVal=0;
  31. bool C_ENCODER_AACP::isPresent(HWND winamp) {
  32. if(cacheVal!=0 && hEncoderInstance!=0) return cacheVal==2;
  33. bool ret=false;
  34. wchar_t dir[MAX_PATH] = {0};
  35. snwprintf(dir, MAX_PATH, L"%s\\enc_aacplus.dll", GetPluginDirectoryW(winamp));
  36. FILE * f = _wfopen(dir, L"rb");
  37. if (f) {
  38. fseek(f,0,2);
  39. if(ftell(f) > 0) ret=true;
  40. fclose(f);
  41. }
  42. cacheVal=ret?2:1;
  43. return ret;
  44. }
  45. void C_ENCODER_AACP::FillAttribs() {
  46. T_ENCODER_AACP_INFO &EncInfo = *(T_ENCODER_AACP_INFO *)ExtendedInfoPtr;
  47. T_ENCODER_AACP_INFO *attribs = new T_ENCODER_AACP_INFO;
  48. *attribs = EncInfo;
  49. AddAttrib("",attribs);
  50. }
  51. void C_ENCODER_AACP::FillConfFile(char * conf_file, char * section) {
  52. if(!section) section="audio_aacplus";
  53. T_ENCODER_AACP_INFO &EncInfo = *(T_ENCODER_AACP_INFO *)ExtendedInfoPtr;
  54. WritePrivateProfileInt("samplerate", EncInfo.output_samplerate, section, conf_file);
  55. WritePrivateProfileInt("channelmode", EncInfo.output_channelmode, section, conf_file);
  56. WritePrivateProfileInt("bitrate", EncInfo.output_bitRate * 1000, section, conf_file);
  57. WritePrivateProfileInt("v2enable", EncInfo.output_v2enable, section, conf_file);
  58. }
  59. void C_ENCODER_AACP::ReadConfFile(char * conf_file, char * section) {
  60. if(!section) section="audio_aacplus";
  61. T_ENCODER_AACP_INFO &EncInfo = *(T_ENCODER_AACP_INFO *)ExtendedInfoPtr;
  62. T_ENCODER_AACP_INFO *attribs = new T_ENCODER_AACP_INFO;
  63. *attribs = EncInfo;
  64. attribs->output_samplerate = GetPrivateProfileInt(section,"samplerate",AACP_DEFAULT_OUTPUTSAMPLERATE,conf_file);
  65. attribs->output_channelmode = GetPrivateProfileInt(section,"channelmode",AACP_DEFAULT_OUTPUTCHANNELMODE,conf_file);
  66. attribs->output_bitRate = GetPrivateProfileInt(section,"bitrate",AACP_DEFAULT_OUTPUTBITRATE,conf_file)/1000;
  67. attribs->output_quality = GetPrivateProfileInt(section,"quality",AACP_DEFAULT_OUTPUTQUALITY,conf_file);
  68. attribs->output_v2enable = GetPrivateProfileInt(section,"v2enable",AACP_DEFAULT_OUTPUTV2ENABLE,conf_file);
  69. ChangeSettings(attribs);
  70. }