c_encoder_ogg.cpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. #include "c_encoder_ogg.h"
  2. #include "../../utils.h"
  3. HINSTANCE C_ENCODER_OGG::hEncoderInstance = NULL;
  4. C_ENCODER_OGG::C_ENCODER_OGG(HWND winamp) : C_ENCODER_NSV(sizeof(T_ENCODER_OGG_INFO)) {
  5. SetName("OGG Vorbis 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_vorbis.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_OGG_INFO * EncInfo = (T_ENCODER_OGG_INFO *)ExtendedInfoPtr;
  21. EncInfo->output_bitRate = OGG_DEFAULT_OUTPUTBITRATE;
  22. EncInfo->output_channelmode = OGG_DEFAULT_OUTPUTMODE;
  23. EncInfo->output_samplerate = OGG_DEFAULT_OUTPUTSAMPLERATE;
  24. }
  25. C_ENCODER_OGG::~C_ENCODER_OGG() {
  26. C_ENCODER_NSV::~C_ENCODER_NSV();
  27. }
  28. static int cacheVal=0;
  29. bool C_ENCODER_OGG::isPresent(HWND winamp) {
  30. if(cacheVal!=0 && hEncoderInstance!=0) return cacheVal==2;
  31. bool ret=false;
  32. wchar_t dir[MAX_PATH] = {0};
  33. snwprintf(dir, MAX_PATH, L"%s\\enc_vorbis.dll", GetPluginDirectoryW(winamp));
  34. FILE * f = _wfopen(dir, L"rb");
  35. if (f) {
  36. fseek(f,0,2);
  37. if(ftell(f) > 0) ret=true;
  38. fclose(f);
  39. }
  40. cacheVal=ret?2:1;
  41. return ret;
  42. }
  43. void C_ENCODER_OGG::FillAttribs() {
  44. T_ENCODER_OGG_INFO &EncInfo = *(T_ENCODER_OGG_INFO *)ExtendedInfoPtr;
  45. T_ENCODER_OGG_INFO *attribs = new T_ENCODER_OGG_INFO;
  46. *attribs = EncInfo;
  47. AddAttrib("",attribs);
  48. }
  49. void C_ENCODER_OGG::FillConfFile(char * conf_file, char * section) {
  50. if(!section) section="audio_ogg";
  51. T_ENCODER_OGG_INFO &EncInfo = *(T_ENCODER_OGG_INFO *)ExtendedInfoPtr;
  52. configtype * cfg = new configtype;
  53. cfg->cfg_abr_use_max=0;
  54. cfg->cfg_abr_use_min=0;
  55. cfg->cfg_mode=0; //VBR
  56. cfg->cfg_vbrquality=EncInfo.output_quality;
  57. cfg->cfg_abr_nominal=EncInfo.output_bitRate;
  58. cfg->cfg_abr_max=EncInfo.output_bitRate;
  59. cfg->cfg_abr_min=EncInfo.output_bitRate;
  60. if (conf_file) WritePrivateProfileStruct(section,"conf",cfg,sizeof(configtype),conf_file);
  61. }
  62. int setBitrate(float ql)
  63. {
  64. int br = 64;
  65. //ql = ql*10;
  66. // jkey: this is a pain in the ass,but the only
  67. // way i can figure out how to get the bitrate
  68. // outside of enc_vorbis.
  69. // Also quality enforcement is needed to prevent the
  70. // yp filling up with non standard bitrate streams.
  71. // although this is vbr and will be variable bitrate anyway.
  72. if(ql == 10 || (ql < 10 && ql > 9.5)){br=500;ql = 10.0f; return br;}
  73. if(ql == 9.0f || (ql < 10.0f && ql > 9.0f)){br=320;ql = 9.0f;return br;}
  74. if(ql == 8.0f || (ql < 9.0f && ql > 8.0f)){br=256;ql = 8.0f;return br;}
  75. if(ql == 7.0f || (ql < 8.0f && ql > 7.0f)){br=224;ql = 7.0f;return br;}
  76. if(ql == 6.0f || (ql < 7.0f && ql > 6.0f)){br=192;ql = 6.0f;return br;}
  77. if(ql == 5.0f || (ql < 6.0f && ql > 5.0f)){br=160;ql = 5.0f;return br;}
  78. if(ql == 4.0f || (ql < 5.0f && ql > 4.0f)){br=128;ql = 4.0f;return br;}
  79. if(ql == 3.0f || (ql < 4.0f && ql > 3.0f)){br=112;ql = 3.0f;return br;}
  80. if(ql == 2.0f || (ql < 3.0f && ql > 2.0f)){br=96;ql = 2.0f;return br;}
  81. if(ql == 1.0f || (ql < 2.0f && ql > 1.0f)){br=80;ql = 1.0f;return br;}
  82. if(ql == 0.0f || (ql < 1.0f && ql > 0.0f)){ br=64;ql = 0.0f;return br;}
  83. if(ql == -0.5f || (ql < 0.0f && ql > -0.5f)){br=56;ql = -0.5f;return br;}
  84. if(ql == -1.0f || ql < -0.5f){br=48;ql = -1.0f;return br;}
  85. return br;
  86. }
  87. void C_ENCODER_OGG::ReadConfFile(char * conf_file, char * section) {
  88. if(!section) section="audio_ogg";
  89. T_ENCODER_OGG_INFO &EncInfo = *(T_ENCODER_OGG_INFO *)ExtendedInfoPtr;
  90. T_ENCODER_OGG_INFO *attribs = new T_ENCODER_OGG_INFO;
  91. *attribs = EncInfo;
  92. configtype * cfg = new configtype;
  93. cfg->cfg_abr_use_max=0;
  94. cfg->cfg_abr_use_min=0;
  95. cfg->cfg_mode=0; //VBR
  96. cfg->cfg_vbrquality=0.0f;
  97. cfg->cfg_abr_nominal=64;
  98. cfg->cfg_abr_max=352;
  99. cfg->cfg_abr_min=32;
  100. if (conf_file) GetPrivateProfileStruct(section,"conf",cfg,sizeof(configtype),conf_file);
  101. attribs->output_samplerate = OGG_DEFAULT_OUTPUTSAMPLERATE;
  102. attribs->output_channelmode = cfg->cfg_mode;
  103. attribs->output_quality = cfg->cfg_vbrquality;
  104. attribs->output_bitRate = setBitrate(attribs->output_quality*10);
  105. ChangeSettings(attribs);
  106. }