Initial community commit
This commit is contained in:
parent
537bcbc862
commit
fc06254474
16440 changed files with 4239995 additions and 2 deletions
411
Src/Plugins/DSP/dsp_sc/sc2srclib/Encoders/_ptrlist.h
Normal file
411
Src/Plugins/DSP/dsp_sc/sc2srclib/Encoders/_ptrlist.h
Normal file
|
@ -0,0 +1,411 @@
|
|||
//PORTABLE
|
||||
#ifndef _PTRLIST_H
|
||||
#define _PTRLIST_H
|
||||
|
||||
#define POS_LAST -1
|
||||
|
||||
// 1k each, leaving 16 bytes for MALLOC overhead
|
||||
#define PTRLIST_INCREMENT 252
|
||||
|
||||
template<class T>
|
||||
class PtrList
|
||||
{
|
||||
public:
|
||||
PtrList()
|
||||
{
|
||||
nitems = 0;
|
||||
nslots = 0;
|
||||
items = NULL;
|
||||
}
|
||||
|
||||
PtrList( PtrList<T> *other )
|
||||
{
|
||||
nitems = other->nitems;
|
||||
nslots = other->nslots;
|
||||
items = (T **)memdup( other->items, nslots * sizeof( T * ) );
|
||||
}
|
||||
|
||||
virtual ~PtrList()
|
||||
{
|
||||
if ( items )
|
||||
free( items );
|
||||
}
|
||||
|
||||
int getNumItems() { return nitems; };
|
||||
|
||||
T *enumItem( int n )
|
||||
{
|
||||
if ( items == NULL )
|
||||
return NULL;
|
||||
|
||||
if ( n < 0 )
|
||||
return NULL;
|
||||
|
||||
if ( n >= nitems )
|
||||
return NULL;
|
||||
|
||||
return items[ n ];
|
||||
}
|
||||
|
||||
T *operator[]( int n ) { return enumItem( n ); }
|
||||
|
||||
// this will safely return NULL if 0 items due to enumItems's boundscheck
|
||||
T *getFirst() { return enumItem( 0 ); }
|
||||
|
||||
T *getLast() { return enumItem( nitems - 1 ); }
|
||||
|
||||
virtual T *addItem( T *item, int pos = POS_LAST )
|
||||
{
|
||||
// ASSERTPR(item != NULL, "can't put NULLs into ptrlists");
|
||||
// ASSERT(nitems <= nslots);
|
||||
if ( items == NULL )
|
||||
{
|
||||
nslots = PTRLIST_INCREMENT;
|
||||
items = (T **)malloc( sizeof( T * ) * nslots );
|
||||
nitems = 0;
|
||||
}
|
||||
else if ( nslots == nitems )
|
||||
{ // time to expand
|
||||
T **newitems;
|
||||
nslots += PTRLIST_INCREMENT;
|
||||
newitems = (T **)malloc( sizeof( T * ) * nslots );
|
||||
memcpy( newitems, items, nitems * sizeof( T * ) );
|
||||
|
||||
if ( items )
|
||||
free( items );
|
||||
|
||||
items = newitems;
|
||||
}
|
||||
|
||||
_addToList( item );
|
||||
if ( pos != POS_LAST )
|
||||
moveItem( nitems - 1, pos );
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
// FG> avoid using this before i tested it more
|
||||
void moveItem( int from, int to )
|
||||
{
|
||||
if ( from == to )
|
||||
return;
|
||||
|
||||
T *ptr = items[ from ];
|
||||
|
||||
if ( nitems > from + 1 ) // if moving from the end, there is nothing to shift behind our src position
|
||||
//IMPORTANT note for future ports: This assumes MEMCPY accepts overlapping segments.
|
||||
memcpy( &items[ from ], &items[ from + 1 ], ( nitems - from ) * sizeof( T * ) );
|
||||
|
||||
if ( to > from )
|
||||
to--;
|
||||
|
||||
if ( nitems > to ) // if moving to the end, there is nothing to shift behind our target position
|
||||
memcpy( &items[ to + 1 ], &items[ to ], ( nitems - to - 1 ) * sizeof( T * ) );
|
||||
|
||||
items[ to ] = ptr;
|
||||
}
|
||||
|
||||
// deletes first instance of a pointer in list, returns how many are left
|
||||
int delItem( T *item )
|
||||
{
|
||||
int c = 0;
|
||||
|
||||
if ( item == NULL || items == NULL || nitems <= 0 )
|
||||
return 0;
|
||||
|
||||
// count occurences of item in items, remember the first one
|
||||
T **p = items;
|
||||
int first = -1;
|
||||
|
||||
for ( int i = 0; i < nitems; i++, p++ )
|
||||
{
|
||||
if ( *p == item )
|
||||
{
|
||||
if ( c++ == 0 )
|
||||
first = i;
|
||||
}
|
||||
}
|
||||
|
||||
// if we found one, remove it
|
||||
if ( c > 0 )
|
||||
{
|
||||
delByPos( first ); // delByPos is faaast
|
||||
c--; // decrease count
|
||||
}
|
||||
|
||||
return c; // returns how many occurences of this item left
|
||||
}
|
||||
|
||||
// removes all instances of this pointer
|
||||
void delEveryItem( T *item ) { while ( delItem( item ) ); }
|
||||
|
||||
// removes pointer at specified pos
|
||||
void delByPos( int pos )
|
||||
{
|
||||
if ( pos < 0 || pos >= nitems )
|
||||
return; //JC
|
||||
|
||||
--nitems;
|
||||
if ( pos == nitems )
|
||||
return; // last one? nothing to copy over
|
||||
|
||||
memcpy( items + pos, items + ( pos + 1 ), sizeof( T * ) * ( nitems - pos ) ); // CT:not (nitems-(pos+1)) as nitems has been decremented earlier
|
||||
}
|
||||
|
||||
// removes last item, leaving pointer alone
|
||||
void removeLastItem()
|
||||
{
|
||||
if ( nitems == 0 || items == NULL )
|
||||
return;
|
||||
|
||||
nitems--; // hee hee
|
||||
}
|
||||
|
||||
// removes all entries, leaving pointers alone
|
||||
void removeAll()
|
||||
{
|
||||
if ( items )
|
||||
free( items );
|
||||
|
||||
items = NULL;
|
||||
nitems = 0;
|
||||
nslots = 0;
|
||||
}
|
||||
|
||||
// removes all entries, calling FREE on the pointers
|
||||
void freeAll()
|
||||
{
|
||||
for ( int i = 0; i < nitems; i++ ) //JC
|
||||
if ( items )
|
||||
free( items[ i ] );
|
||||
|
||||
removeAll();
|
||||
}
|
||||
|
||||
// removes all entries, calling delete on the pointers
|
||||
void deleteAll()
|
||||
{
|
||||
int i;
|
||||
if ( items == NULL || nitems <= 0 )
|
||||
return; //JC
|
||||
|
||||
for ( i = 0; i < nitems; i++ )
|
||||
{ //JC
|
||||
delete items[ i ];
|
||||
}
|
||||
|
||||
removeAll();
|
||||
}
|
||||
|
||||
virtual int haveItem( T *item )
|
||||
{// gross-ass linear search to see if we have it
|
||||
for ( int i = 0; i < nitems; i++ ) //JC
|
||||
if ( items[ i ] == item )
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
virtual int searchItem( T *item )
|
||||
{ // gross-ass linear search to find index of item
|
||||
for ( int i = 0; i < getNumItems(); i++ )
|
||||
if ( items[ i ] == item )
|
||||
return i;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual void _addToList( T *item ) { items[ nitems++ ] = item; }
|
||||
|
||||
int nitems, nslots;
|
||||
T **items;
|
||||
};
|
||||
|
||||
template<class T>
|
||||
class PtrListBaseSorted : public PtrList<T>
|
||||
{
|
||||
public:
|
||||
virtual T *findItem( char *attrib )
|
||||
{
|
||||
#if 1
|
||||
if ( nitems == 0 || items == NULL )
|
||||
return NULL;
|
||||
|
||||
int bot = 0, top = nitems - 1;
|
||||
|
||||
for ( int c = 0; c < nitems + 16; c++ )
|
||||
{
|
||||
if ( bot > top )
|
||||
return NULL;
|
||||
|
||||
int mid = ( bot + top ) / 2;
|
||||
int r = compareAttrib( attrib, items[ mid ] );
|
||||
|
||||
if ( r == 0 )
|
||||
return items[ mid ];
|
||||
|
||||
if ( r < 0 )
|
||||
{
|
||||
top = mid - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
bot = mid + 1;
|
||||
}
|
||||
}
|
||||
// ASSERTPR(0, "binary search fucked up");
|
||||
#else
|
||||
for ( int i = 0; i < nitems; i++ )
|
||||
{
|
||||
if ( compareAttrib( attrib, items[ i ] ) == 0 )
|
||||
return items[ i ];
|
||||
}
|
||||
#endif
|
||||
return NULL;
|
||||
}
|
||||
|
||||
protected:
|
||||
// comparator for searching -- override
|
||||
virtual int compareAttrib( char *attrib, T *item ) = 0;
|
||||
|
||||
// comparator for sorting -- override , -1 p1 < p2, 0 eq, 1 p1 > p2
|
||||
virtual int compareItem( T *p1, T *p2 ) = 0;
|
||||
};
|
||||
|
||||
|
||||
#if 0
|
||||
// try not to use this
|
||||
template<class T>
|
||||
class PtrListSortedInsertion : public PtrListBaseSorted<T>
|
||||
{
|
||||
protected:
|
||||
virtual void _addToList( T *item )
|
||||
{
|
||||
if ( nitems == 0 )
|
||||
{
|
||||
items[ nitems++ ] = item;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
for ( int i = 0; i < nitems; i++ )
|
||||
{
|
||||
if ( compareItem( items[ i ], item ) == 1 )
|
||||
{
|
||||
T *tmp = items[ i ];
|
||||
items[ i ] = item;
|
||||
for ( int j = i + 1; j < nitems; j++ )
|
||||
{
|
||||
T *tmp2 = items[ j ];
|
||||
items[ j ] = tmp;
|
||||
tmp = tmp2;
|
||||
}
|
||||
|
||||
items[ nitems++ ] = tmp;
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
items[ nitems++ ] = item;
|
||||
|
||||
return;
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
// a base class to defer sorting until lookup
|
||||
template<class T>
|
||||
class PtrListSorted : public PtrListBaseSorted<T>
|
||||
{
|
||||
public:
|
||||
PtrListSorted()
|
||||
{
|
||||
nitems = 0;
|
||||
nslots = 0;
|
||||
items = NULL;
|
||||
need_sorting = 0;
|
||||
}
|
||||
|
||||
virtual T *addItem( T *item )
|
||||
{
|
||||
need_sorting = 1;
|
||||
|
||||
return PtrList<T>::addItem( item );
|
||||
}
|
||||
|
||||
virtual T *findItem( char *attrib )
|
||||
{
|
||||
sort();
|
||||
|
||||
return PtrListBaseSorted<T>::findItem( attrib );
|
||||
}
|
||||
|
||||
int needSort() { return need_sorting; }
|
||||
|
||||
void sort()
|
||||
{
|
||||
if ( need_sorting )
|
||||
_sort();
|
||||
|
||||
need_sorting = 0;
|
||||
}
|
||||
|
||||
private:
|
||||
int need_sorting;
|
||||
|
||||
virtual void _sort() = 0;
|
||||
};
|
||||
|
||||
template<class T>
|
||||
class PtrListQuickSorted : public PtrListSorted<T>
|
||||
{
|
||||
public:
|
||||
virtual void _sort()
|
||||
{
|
||||
if ( items == NULL || nitems <= 1 )
|
||||
return;
|
||||
|
||||
Qsort( 0, nitems - 1 );
|
||||
}
|
||||
|
||||
void swap( int a, int b )
|
||||
{
|
||||
T *tmp = items[ a ];
|
||||
items[ a ] = items[ b ];
|
||||
items[ b ] = tmp;
|
||||
}
|
||||
|
||||
void Qsort( int lo0, int hi0 )
|
||||
{
|
||||
int lo = lo0, hi = hi0;
|
||||
if ( hi0 > lo0 )
|
||||
{
|
||||
T *mid = enumItem( ( lo0 + hi0 ) / 2 );
|
||||
while ( lo <= hi )
|
||||
{
|
||||
while ( ( lo < hi0 ) && ( compareItem( items[ lo ], mid ) < 0 ) )
|
||||
lo++;
|
||||
|
||||
while ( ( hi > lo0 ) && ( compareItem( items[ hi ], mid ) > 0 ) )
|
||||
hi--;
|
||||
|
||||
if ( lo <= hi )
|
||||
{
|
||||
swap( lo, hi );
|
||||
lo++;
|
||||
hi--;
|
||||
}
|
||||
}
|
||||
|
||||
if ( lo0 < hi )
|
||||
Qsort( lo0, hi );
|
||||
|
||||
if ( lo < hi0 )
|
||||
Qsort( lo, hi0 );
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
95
Src/Plugins/DSP/dsp_sc/sc2srclib/Encoders/c_encoder.cpp
Normal file
95
Src/Plugins/DSP/dsp_sc/sc2srclib/Encoders/c_encoder.cpp
Normal file
|
@ -0,0 +1,95 @@
|
|||
#include <windows.h>
|
||||
#include "c_encoder.h"
|
||||
|
||||
C_ENCODER::C_ENCODER(int ExtInfoSize) {
|
||||
SetName("Untyped Encoder");
|
||||
ExtendedInfoPtr = (T_EncoderIOVals *)malloc(ExtInfoSize);
|
||||
ExtendedInfoSize = ExtInfoSize;
|
||||
}
|
||||
|
||||
C_ENCODER::~C_ENCODER() {
|
||||
Close();
|
||||
if(ExtendedInfoPtr && ExtendedInfoSize) free(ExtendedInfoPtr);
|
||||
ExtendedInfoSize = 0;
|
||||
}
|
||||
|
||||
void C_ENCODER::Close() {
|
||||
ClearAttribs();
|
||||
}
|
||||
|
||||
void C_ENCODER::SetName(const char *name) {
|
||||
if (name) lstrcpyn(Name, name, C_ENCODER_NameLen);
|
||||
}
|
||||
|
||||
char *C_ENCODER::GetName() {
|
||||
return Name;
|
||||
}
|
||||
|
||||
void C_ENCODER::Reset() {
|
||||
}
|
||||
|
||||
void C_ENCODER::ChangeSettings(const void *Settings) {
|
||||
if(ExtendedInfoPtr && ExtendedInfoSize && Settings && Settings != ExtendedInfoPtr) {
|
||||
memcpy(ExtendedInfoPtr,Settings,ExtendedInfoSize);
|
||||
Reset();
|
||||
}
|
||||
}
|
||||
|
||||
void C_ENCODER::Create(const T_EncoderIOVals *Settings, const char *name) {
|
||||
if(name) SetName(name);
|
||||
ChangeSettings(Settings);
|
||||
}
|
||||
|
||||
void C_ENCODER::ClearAttribs() {
|
||||
for(int i = AttribList.size()-1; i >= 0; i--) {
|
||||
T_ATTRIB *myAttrib = AttribList[i];
|
||||
if(myAttrib->OutputVals) delete[] myAttrib->OutputVals;
|
||||
}
|
||||
|
||||
//AttribList.deleteAll();
|
||||
for (auto attrib : AttribList)
|
||||
{
|
||||
delete attrib;
|
||||
}
|
||||
AttribList.clear();
|
||||
}
|
||||
|
||||
void C_ENCODER::AddAttrib(const char *Text, const void *Attributes) {
|
||||
T_ATTRIB *myAttrib = new T_ATTRIB;
|
||||
if(Text!=NULL) {
|
||||
::strncpy((char *)&myAttrib->Text,Text,sizeof(myAttrib->Text));
|
||||
} else {
|
||||
::strncpy((char *)&myAttrib->Text,"<This should never appear here...>",sizeof(myAttrib->Text));
|
||||
}
|
||||
myAttrib->OutputVals = (T_EncoderIOVals *)Attributes;
|
||||
AttribList.push_back(myAttrib);
|
||||
}
|
||||
|
||||
int C_ENCODER::Encode(const void *inputbuf, const unsigned int inputbufsize, void *outputbuf, const unsigned int outputbufsize, int *inputamtused) {
|
||||
if((inputbuf != NULL) && (outputbuf != NULL) && (inputbufsize != 0) && (outputbufsize != 0) && (inputamtused != NULL)) {
|
||||
int numitems = (inputbufsize > outputbufsize) ? outputbufsize : inputbufsize;
|
||||
memcpy(outputbuf,inputbuf,numitems);
|
||||
*inputamtused = numitems;
|
||||
return numitems;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int C_ENCODER::GetNumAttribs() {
|
||||
return AttribList.size();
|
||||
}
|
||||
|
||||
int C_ENCODER::EnumAttrib(const int val, T_ATTRIB *buf) {
|
||||
if((val < 0)||(val >= AttribList.size())||(buf==NULL)) return 0;
|
||||
T_ATTRIB *myattrib = AttribList[val];
|
||||
if(myattrib==NULL) return 0;
|
||||
::memcpy(buf,myattrib,sizeof(T_ATTRIB));
|
||||
return 1;
|
||||
}
|
||||
|
||||
char * C_ENCODER::GetContentType() {
|
||||
|
||||
//if(strcmp(this->GetName(), "MP3 Encoder") == 0)
|
||||
return "audio/mpeg";
|
||||
|
||||
}
|
53
Src/Plugins/DSP/dsp_sc/sc2srclib/Encoders/c_encoder.h
Normal file
53
Src/Plugins/DSP/dsp_sc/sc2srclib/Encoders/c_encoder.h
Normal file
|
@ -0,0 +1,53 @@
|
|||
#ifndef __C_ENCODER_H__
|
||||
#define __C_ENCODER_H__
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <vector>
|
||||
|
||||
#define C_ENCODER_NameLen 1024
|
||||
|
||||
struct T_EncoderIOVals {
|
||||
unsigned int output_bitRate;
|
||||
};
|
||||
|
||||
struct T_ATTRIB {
|
||||
char Text[256];
|
||||
void *OutputVals;
|
||||
};
|
||||
|
||||
class C_ENCODER {
|
||||
private:
|
||||
char Name[C_ENCODER_NameLen];
|
||||
std::vector<T_ATTRIB*> AttribList;
|
||||
protected:
|
||||
T_EncoderIOVals *ExtendedInfoPtr;
|
||||
int ExtendedInfoSize;
|
||||
void SetName(const char *name);
|
||||
void ClearAttribs();
|
||||
void AddAttrib(const char *Text, const void *Attributes);
|
||||
public:
|
||||
C_ENCODER(int ExtInfoSize = 0);
|
||||
virtual ~C_ENCODER();
|
||||
|
||||
virtual void ChangeSettings(const void *Settings);
|
||||
virtual void Create(const T_EncoderIOVals *Settings, const char *name = NULL);
|
||||
virtual void Close();
|
||||
virtual void Reset();
|
||||
virtual char *GetName();
|
||||
virtual void *GetExtInfo(int *ExtInfoSize = NULL) {
|
||||
if(ExtInfoSize != NULL) *ExtInfoSize = ExtendedInfoSize;
|
||||
return ExtendedInfoPtr;
|
||||
}
|
||||
|
||||
virtual char * GetContentType();
|
||||
virtual int Encode(const void *inputbuf, const unsigned int inputbufsize, void *outputbuf, const unsigned int outputbufsize, int *inputamtused); /* all values are in BYTES! */
|
||||
|
||||
virtual int GetNumAttribs();
|
||||
virtual int EnumAttrib(const int val, T_ATTRIB *buf);
|
||||
|
||||
virtual bool UseNsvConfig() { return false; }
|
||||
};
|
||||
|
||||
#endif /* !__C_ENCODER_H__ */
|
84
Src/Plugins/DSP/dsp_sc/sc2srclib/Encoders/c_encoder_aacp.cpp
Normal file
84
Src/Plugins/DSP/dsp_sc/sc2srclib/Encoders/c_encoder_aacp.cpp
Normal file
|
@ -0,0 +1,84 @@
|
|||
#include "c_encoder_aacp.h"
|
||||
#include "../../utils.h"
|
||||
|
||||
HINSTANCE C_ENCODER_AACP::hEncoderInstance = NULL;
|
||||
|
||||
C_ENCODER_AACP::C_ENCODER_AACP(HWND winamp) : C_ENCODER_NSV(sizeof(T_ENCODER_AACP_INFO)) {
|
||||
SetName("AAC+ Encoder");
|
||||
winampWnd = winamp;
|
||||
ConfigAudio3 = NULL;
|
||||
if(hEncoderInstance == NULL) {
|
||||
wchar_t dir[MAX_PATH] = {0};
|
||||
snwprintf(dir, MAX_PATH, L"%s\\enc_aacplus.dll", GetPluginDirectoryW(winamp));
|
||||
hEncoderInstance = LoadLibraryW(dir);
|
||||
}
|
||||
|
||||
if(hEncoderInstance) {
|
||||
void * CreateAudio3=(void *)GetProcAddress(hEncoderInstance, "CreateAudio3");
|
||||
void * GetAudioTypes3=(void *)GetProcAddress(hEncoderInstance, "GetAudioTypes3");
|
||||
void * ConfigAudio3=(void *)GetProcAddress(hEncoderInstance, "ConfigAudio3");
|
||||
void * SetWinampHWND=(void *)GetProcAddress(hEncoderInstance, "SetWinampHWND");
|
||||
SetEncoder(CreateAudio3,GetAudioTypes3,ConfigAudio3,SetWinampHWND);
|
||||
}
|
||||
|
||||
T_ENCODER_AACP_INFO * EncInfo = (T_ENCODER_AACP_INFO *)ExtendedInfoPtr;
|
||||
EncInfo->output_bitRate = AACP_DEFAULT_OUTPUTBITRATE;
|
||||
EncInfo->output_channelmode = AACP_DEFAULT_OUTPUTCHANNELMODE;
|
||||
EncInfo->output_quality = AACP_DEFAULT_OUTPUTQUALITY;
|
||||
EncInfo->output_samplerate = AACP_DEFAULT_OUTPUTSAMPLERATE;
|
||||
EncInfo->output_v2enable = AACP_DEFAULT_OUTPUTV2ENABLE;
|
||||
}
|
||||
|
||||
C_ENCODER_AACP::~C_ENCODER_AACP() {
|
||||
C_ENCODER_NSV::~C_ENCODER_NSV();
|
||||
}
|
||||
|
||||
static int cacheVal=0;
|
||||
bool C_ENCODER_AACP::isPresent(HWND winamp) {
|
||||
if(cacheVal!=0 && hEncoderInstance!=0) return cacheVal==2;
|
||||
bool ret=false;
|
||||
wchar_t dir[MAX_PATH] = {0};
|
||||
snwprintf(dir, MAX_PATH, L"%s\\enc_aacplus.dll", GetPluginDirectoryW(winamp));
|
||||
FILE * f = _wfopen(dir, L"rb");
|
||||
if (f) {
|
||||
fseek(f,0,2);
|
||||
if(ftell(f) > 0) ret=true;
|
||||
fclose(f);
|
||||
}
|
||||
cacheVal=ret?2:1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
void C_ENCODER_AACP::FillAttribs() {
|
||||
T_ENCODER_AACP_INFO &EncInfo = *(T_ENCODER_AACP_INFO *)ExtendedInfoPtr;
|
||||
T_ENCODER_AACP_INFO *attribs = new T_ENCODER_AACP_INFO;
|
||||
*attribs = EncInfo;
|
||||
AddAttrib("",attribs);
|
||||
}
|
||||
|
||||
void C_ENCODER_AACP::FillConfFile(char * conf_file, char * section) {
|
||||
if(!section) section="audio_aacplus";
|
||||
|
||||
T_ENCODER_AACP_INFO &EncInfo = *(T_ENCODER_AACP_INFO *)ExtendedInfoPtr;
|
||||
|
||||
WritePrivateProfileInt("samplerate", EncInfo.output_samplerate, section, conf_file);
|
||||
WritePrivateProfileInt("channelmode", EncInfo.output_channelmode, section, conf_file);
|
||||
WritePrivateProfileInt("bitrate", EncInfo.output_bitRate * 1000, section, conf_file);
|
||||
WritePrivateProfileInt("v2enable", EncInfo.output_v2enable, section, conf_file);
|
||||
}
|
||||
|
||||
void C_ENCODER_AACP::ReadConfFile(char * conf_file, char * section) {
|
||||
if(!section) section="audio_aacplus";
|
||||
|
||||
T_ENCODER_AACP_INFO &EncInfo = *(T_ENCODER_AACP_INFO *)ExtendedInfoPtr;
|
||||
T_ENCODER_AACP_INFO *attribs = new T_ENCODER_AACP_INFO;
|
||||
*attribs = EncInfo;
|
||||
|
||||
attribs->output_samplerate = GetPrivateProfileInt(section,"samplerate",AACP_DEFAULT_OUTPUTSAMPLERATE,conf_file);
|
||||
attribs->output_channelmode = GetPrivateProfileInt(section,"channelmode",AACP_DEFAULT_OUTPUTCHANNELMODE,conf_file);
|
||||
attribs->output_bitRate = GetPrivateProfileInt(section,"bitrate",AACP_DEFAULT_OUTPUTBITRATE,conf_file)/1000;
|
||||
attribs->output_quality = GetPrivateProfileInt(section,"quality",AACP_DEFAULT_OUTPUTQUALITY,conf_file);
|
||||
attribs->output_v2enable = GetPrivateProfileInt(section,"v2enable",AACP_DEFAULT_OUTPUTV2ENABLE,conf_file);
|
||||
|
||||
ChangeSettings(attribs);
|
||||
}
|
37
Src/Plugins/DSP/dsp_sc/sc2srclib/Encoders/c_encoder_aacp.h
Normal file
37
Src/Plugins/DSP/dsp_sc/sc2srclib/Encoders/c_encoder_aacp.h
Normal file
|
@ -0,0 +1,37 @@
|
|||
#ifndef __C_ENCODER_AACP_H__
|
||||
#define __C_ENCODER_AACP_H__
|
||||
|
||||
#include "c_encoder_nsv.h"
|
||||
|
||||
struct T_ENCODER_AACP_INFO : public T_ENCODER_NSV_INFO
|
||||
{
|
||||
unsigned int output_quality;
|
||||
unsigned int output_samplerate;
|
||||
unsigned int output_channelmode;
|
||||
unsigned int output_v2enable;
|
||||
};
|
||||
|
||||
#define AACP_DEFAULT_OUTPUTCHANNELMODE 4
|
||||
#define AACP_DEFAULT_OUTPUTBITRATE 48
|
||||
#define AACP_DEFAULT_OUTPUTQUALITY 2
|
||||
#define AACP_DEFAULT_OUTPUTSAMPLERATE 44100
|
||||
#define AACP_DEFAULT_OUTPUTV2ENABLE 1
|
||||
|
||||
class C_ENCODER_AACP : public C_ENCODER_NSV {
|
||||
private:
|
||||
HWND winamp;
|
||||
protected:
|
||||
virtual void FillAttribs();
|
||||
public:
|
||||
static HINSTANCE hEncoderInstance;
|
||||
C_ENCODER_AACP(HWND hwnd = 0);
|
||||
virtual ~C_ENCODER_AACP();
|
||||
static bool isPresent(HWND winamp);
|
||||
virtual void ReadConfFile(char * conf_file, char * section=NULL);
|
||||
virtual void FillConfFile(char * conf_file, char * section=NULL);
|
||||
static void Unload() { if(hEncoderInstance) FreeLibrary(hEncoderInstance); hEncoderInstance=0; }
|
||||
virtual char * GetContentType() { return "audio/aacp"; }
|
||||
virtual HINSTANCE GetEncoderInstance() { return hEncoderInstance; }
|
||||
};
|
||||
|
||||
#endif /* !__C_ENCODER_AACP_H__ */
|
|
@ -0,0 +1,80 @@
|
|||
#include "c_encoder_fhgaac.h"
|
||||
#include "../../utils.h"
|
||||
|
||||
HINSTANCE C_ENCODER_FHGAAC::hEncoderInstance = NULL;
|
||||
|
||||
C_ENCODER_FHGAAC::C_ENCODER_FHGAAC(HWND winamp) : C_ENCODER_NSV(sizeof(T_ENCODER_FHGAAC_INFO)) {
|
||||
SetName("Fraunhofer Encoder");
|
||||
winampWnd = winamp;
|
||||
ConfigAudio3 = NULL;
|
||||
if(hEncoderInstance == NULL) {
|
||||
wchar_t dir[MAX_PATH] = {0};
|
||||
snwprintf(dir, MAX_PATH, L"%s\\enc_fhgaac.dll", GetPluginDirectoryW(winamp));
|
||||
hEncoderInstance = LoadLibraryW(dir);
|
||||
}
|
||||
|
||||
if(hEncoderInstance) {
|
||||
void * CreateAudio3=(void *)GetProcAddress(hEncoderInstance, "CreateAudio3");
|
||||
void * GetAudioTypes3=(void *)GetProcAddress(hEncoderInstance, "GetAudioTypes3");
|
||||
void * ConfigAudio3=(void *)GetProcAddress(hEncoderInstance, "ConfigAudio3");
|
||||
void * SetWinampHWND=(void *)GetProcAddress(hEncoderInstance, "SetWinampHWND");
|
||||
SetEncoder(CreateAudio3,GetAudioTypes3,ConfigAudio3,SetWinampHWND,1);
|
||||
}
|
||||
|
||||
T_ENCODER_FHGAAC_INFO * EncInfo = (T_ENCODER_FHGAAC_INFO *)ExtendedInfoPtr;
|
||||
EncInfo->output_bitRate = FHGAAC_DEFAULT_OUTPUTBITRATE;
|
||||
EncInfo->output_profile = FHGAAC_DEFAULT_OUTPUTPROFILE;
|
||||
EncInfo->output_surround = FHGAAC_DEFAULT_OUTPUTSURROUND;
|
||||
}
|
||||
|
||||
C_ENCODER_FHGAAC::~C_ENCODER_FHGAAC() {
|
||||
C_ENCODER_NSV::~C_ENCODER_NSV();
|
||||
}
|
||||
|
||||
static int cacheVal=0;
|
||||
bool C_ENCODER_FHGAAC::isPresent(HWND winamp) {
|
||||
if(cacheVal!=0 && hEncoderInstance!=0) return cacheVal==2;
|
||||
bool ret=false;
|
||||
wchar_t dir[MAX_PATH] = {0};
|
||||
snwprintf(dir, MAX_PATH, L"%s\\enc_fhgaac.dll", GetPluginDirectoryW(winamp));
|
||||
FILE * f = _wfopen(dir, L"rb");
|
||||
if (f) {
|
||||
fseek(f,0,2);
|
||||
if(ftell(f) > 0) ret=true;
|
||||
fclose(f);
|
||||
}
|
||||
cacheVal=ret?2:1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
void C_ENCODER_FHGAAC::FillAttribs() {
|
||||
T_ENCODER_FHGAAC_INFO &EncInfo = *(T_ENCODER_FHGAAC_INFO *)ExtendedInfoPtr;
|
||||
T_ENCODER_FHGAAC_INFO *attribs = new T_ENCODER_FHGAAC_INFO;
|
||||
*attribs = EncInfo;
|
||||
AddAttrib("",attribs);
|
||||
}
|
||||
|
||||
void C_ENCODER_FHGAAC::FillConfFile(char * conf_file, char * section) {
|
||||
if(!section) section="audio_adtsaac";
|
||||
|
||||
T_ENCODER_FHGAAC_INFO &EncInfo = *(T_ENCODER_FHGAAC_INFO *)ExtendedInfoPtr;
|
||||
|
||||
WritePrivateProfileInt("profile", EncInfo.output_profile, section, conf_file);
|
||||
WritePrivateProfileInt("bitrate", EncInfo.output_bitRate, section, conf_file);
|
||||
WritePrivateProfileInt("surround", EncInfo.output_surround, section, conf_file);
|
||||
WritePrivateProfileInt("shoutcast", 1, section, conf_file);
|
||||
}
|
||||
|
||||
void C_ENCODER_FHGAAC::ReadConfFile(char * conf_file, char * section) {
|
||||
if(!section) section="audio_adtsaac";
|
||||
|
||||
T_ENCODER_FHGAAC_INFO &EncInfo = *(T_ENCODER_FHGAAC_INFO *)ExtendedInfoPtr;
|
||||
T_ENCODER_FHGAAC_INFO *attribs = new T_ENCODER_FHGAAC_INFO;
|
||||
*attribs = EncInfo;
|
||||
|
||||
attribs->output_profile = GetPrivateProfileInt(section,"profile",FHGAAC_DEFAULT_OUTPUTPROFILE,conf_file);
|
||||
attribs->output_bitRate = GetPrivateProfileInt(section,"bitrate",FHGAAC_DEFAULT_OUTPUTBITRATE,conf_file);
|
||||
attribs->output_surround = GetPrivateProfileInt(section,"surround",FHGAAC_DEFAULT_OUTPUTSURROUND,conf_file);
|
||||
|
||||
ChangeSettings(attribs);
|
||||
}
|
33
Src/Plugins/DSP/dsp_sc/sc2srclib/Encoders/c_encoder_fhgaac.h
Normal file
33
Src/Plugins/DSP/dsp_sc/sc2srclib/Encoders/c_encoder_fhgaac.h
Normal file
|
@ -0,0 +1,33 @@
|
|||
#ifndef __C_ENCODER_FHGAAC_H__
|
||||
#define __C_ENCODER_FHGAAC_H__
|
||||
|
||||
#include "c_encoder_nsv.h"
|
||||
|
||||
struct T_ENCODER_FHGAAC_INFO : public T_ENCODER_NSV_INFO
|
||||
{
|
||||
unsigned int output_profile;
|
||||
unsigned int output_surround;
|
||||
};
|
||||
|
||||
#define FHGAAC_DEFAULT_OUTPUTBITRATE 48
|
||||
#define FHGAAC_DEFAULT_OUTPUTPROFILE 0 // automatic
|
||||
#define FHGAAC_DEFAULT_OUTPUTSURROUND 0
|
||||
|
||||
class C_ENCODER_FHGAAC : public C_ENCODER_NSV {
|
||||
private:
|
||||
HWND winamp;
|
||||
protected:
|
||||
virtual void FillAttribs();
|
||||
public:
|
||||
static HINSTANCE hEncoderInstance;
|
||||
C_ENCODER_FHGAAC(HWND hwnd = 0);
|
||||
virtual ~C_ENCODER_FHGAAC();
|
||||
static bool isPresent(HWND winamp);
|
||||
virtual void ReadConfFile(char * conf_file, char * section=NULL);
|
||||
virtual void FillConfFile(char * conf_file, char * section=NULL);
|
||||
static void Unload() { if(hEncoderInstance) FreeLibrary(hEncoderInstance); hEncoderInstance=0; }
|
||||
virtual char * GetContentType() { return "audio/aacp"; }
|
||||
virtual HINSTANCE GetEncoderInstance() { return hEncoderInstance; }
|
||||
};
|
||||
|
||||
#endif /* !__C_ENCODER_AACP_H__ */
|
105
Src/Plugins/DSP/dsp_sc/sc2srclib/Encoders/c_encoder_mp3dll.cpp
Normal file
105
Src/Plugins/DSP/dsp_sc/sc2srclib/Encoders/c_encoder_mp3dll.cpp
Normal file
|
@ -0,0 +1,105 @@
|
|||
#include "c_encoder_mp3dll.h"
|
||||
#include "../../utils.h"
|
||||
|
||||
T_ENCODER_MP3_INFO formatlist[] = {
|
||||
{8, 22050, 1, 44100, 2, 8}, {16, 22050, 1, 44100, 2, 8}, {24, 22050, 1, 44100, 2, 8},
|
||||
{32, 22050, 1, 44100, 2, 8}, {40, 22050, 1, 44100, 2, 8}, {48, 22050, 1, 44100, 2, 8},
|
||||
{48, 44100, 1, 44100, 2, 8}, {56, 22050, 1, 44100, 2, 8}, {56, 44100, 1, 44100, 2, 8},
|
||||
{64, 44100, 1, 44100, 2, 8}, {80, 44100, 1, 44100, 2, 8}, {96, 44100, 1, 44100, 2, 8},
|
||||
{112, 44100, 1, 44100, 2, 8}, {128, 44100, 1, 44100, 2, 8}, {40, 22050, 2, 44100, 2, 8},
|
||||
{48, 22050, 2, 44100, 2, 8}, {56, 22050, 2, 44100, 2, 8}, {64, 22050, 2, 44100, 2, 8},
|
||||
{80, 22050, 2, 44100, 2, 8}, {56, 44100, 2, 44100, 2, 8}, {64, 44100, 2, 44100, 2, 8},
|
||||
{80, 44100, 2, 44100, 2, 8}, {96, 44100, 2, 44100, 2, 8}, {112, 44100, 2, 44100, 2, 8},
|
||||
{128, 44100, 2, 44100, 2, 8}, {160, 44100, 2, 44100, 2, 8}, {192, 44100, 2, 44100, 2, 8},
|
||||
{224, 44100, 2, 44100, 2, 8}, {256, 44100, 2, 44100, 2, 8}, {320, 44100, 2, 44100, 2, 8}
|
||||
};
|
||||
|
||||
static unsigned int formatlist_numEntries = sizeof(formatlist) / sizeof(T_ENCODER_MP3_INFO);
|
||||
|
||||
C_ENCODER_MP3::C_ENCODER_MP3(void *init, void *params, void *encode, void *finish) : C_ENCODER(sizeof(T_ENCODER_MP3_INFO)) { //sizeof(T_ENCODER_LAMEMP3_INFO)
|
||||
SetName("MP3 Encoder");
|
||||
T_ENCODER_MP3_INFO &EncInfo = *((T_ENCODER_MP3_INFO *)ExtendedInfoPtr);
|
||||
Handle = NULL;
|
||||
has_encoded = 0;
|
||||
EncInfo = formatlist[MP3_DEFAULT_ATTRIBNUM];
|
||||
hMutex = CreateMutex(NULL,TRUE,NULL);
|
||||
ReleaseMutex(hMutex);
|
||||
|
||||
lame_init = (lame_t (__cdecl *)(void))init;
|
||||
lame_init_params = (int (__cdecl *)(lame_global_flags *))params;
|
||||
lame_encode_buffer_interleaved = (int (__cdecl *)(lame_global_flags *, short int pcm[], int num_samples, char *mp3buffer, int mp3buffer_size))encode;
|
||||
lame_encode_flush = (int (__cdecl *)(lame_global_flags *, char *mp3buffer, int size))finish;
|
||||
}
|
||||
|
||||
C_ENCODER_MP3::~C_ENCODER_MP3() {
|
||||
WaitForSingleObject(hMutex,INFINITE);
|
||||
CloseHandle(hMutex);
|
||||
hMutex = NULL;
|
||||
C_ENCODER::~C_ENCODER();
|
||||
}
|
||||
|
||||
void C_ENCODER_MP3::Close() {
|
||||
C_ENCODER::Close();
|
||||
if(lame_init != NULL) {
|
||||
if(has_encoded && lame_encode_flush) {
|
||||
char buf[1024] = {0};
|
||||
lame_encode_flush(Handle,(char *)buf,sizeof(buf));
|
||||
}
|
||||
//delete Handle; caused crash !! needs looking at
|
||||
Handle = NULL;
|
||||
has_encoded = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void C_ENCODER_MP3::Reset() {
|
||||
T_ENCODER_MP3_INFO &EncInfo = *(T_ENCODER_MP3_INFO *)ExtendedInfoPtr;
|
||||
if(WaitForSingleObject(hMutex,INFINITE) != WAIT_OBJECT_0) return;
|
||||
Close();
|
||||
if(lame_init != NULL && EncInfo.input_sampleRate != 0 && EncInfo.input_numChannels != 0) {
|
||||
if(EncInfo.output_sampleRate != 0 && EncInfo.output_bitRate != 0 && Handle == NULL) {
|
||||
has_encoded = 0;
|
||||
Handle = lame_init();
|
||||
Handle->samplerate_in = EncInfo.input_sampleRate;
|
||||
Handle->num_channels = 2; // always process as 2 channels as it resolves issues with soundcard input in mono mode (which is padded to stereo)
|
||||
Handle->samplerate_out = EncInfo.output_sampleRate;
|
||||
Handle->mode = EncInfo.output_numChannels == 2 ? (MPEG_mode)0 : (MPEG_mode)3;
|
||||
Handle->brate = EncInfo.output_bitRate;
|
||||
Handle->VBR = vbr_off;
|
||||
Handle->write_lame_tag = 0;
|
||||
Handle->write_id3tag_automatic = 0;
|
||||
Handle->quality = EncInfo.QualityMode;
|
||||
if(Handle->quality < 0 || Handle->quality > 9) Handle->quality = 8;
|
||||
lame_init_params(Handle);
|
||||
} else {
|
||||
Handle = NULL;
|
||||
}
|
||||
for(unsigned int i = 0; i < formatlist_numEntries; i++) {
|
||||
char textbuf[256];
|
||||
formatlist[i].QualityMode = EncInfo.QualityMode;
|
||||
snprintf(textbuf,sizeof(textbuf),"%dkbps, %dHz, %s",formatlist[i].output_bitRate,formatlist[i].output_sampleRate,(formatlist[i].output_numChannels == 1 ? "Mono" : "Stereo"));
|
||||
T_ENCODER_MP3_INFO *attribs = new T_ENCODER_MP3_INFO;
|
||||
*attribs = formatlist[i];
|
||||
AddAttrib((char *)&textbuf,attribs);
|
||||
}
|
||||
}
|
||||
ReleaseMutex(hMutex);
|
||||
}
|
||||
|
||||
int C_ENCODER_MP3::Encode(const void *inputbuf, const unsigned int inputbufsize, void *outputbuf, const unsigned int outputbufsize, int *inputamtused) {
|
||||
if((inputbuf != NULL) && (outputbuf != NULL) && (inputbufsize != 0) && (outputbufsize != 0) && (inputamtused != NULL) && (Handle != NULL)) {
|
||||
if(WaitForSingleObject(hMutex,INFINITE) != WAIT_OBJECT_0) return 0;
|
||||
int outputamtused = 0;
|
||||
if(lame_encode_buffer_interleaved) {
|
||||
outputamtused = lame_encode_buffer_interleaved(Handle, (short *)inputbuf, inputbufsize / (2 * sizeof(short)), (char *)outputbuf, outputbufsize);
|
||||
if(outputamtused < 0) {
|
||||
ReleaseMutex(hMutex);
|
||||
return 0;
|
||||
}
|
||||
has_encoded = 1;
|
||||
}
|
||||
*inputamtused = inputbufsize;
|
||||
ReleaseMutex(hMutex);
|
||||
return outputamtused;
|
||||
}
|
||||
return 0;
|
||||
}
|
51
Src/Plugins/DSP/dsp_sc/sc2srclib/Encoders/c_encoder_mp3dll.h
Normal file
51
Src/Plugins/DSP/dsp_sc/sc2srclib/Encoders/c_encoder_mp3dll.h
Normal file
|
@ -0,0 +1,51 @@
|
|||
|
||||
#ifndef __C_ENCODER_MP3DLL_H__
|
||||
#define __C_ENCODER_MP3DLL_H__
|
||||
|
||||
#include "c_encoder.h"
|
||||
#include "../lame/include/lame.h"
|
||||
#include "../lame/libmp3lame/lame_global_flags.h"
|
||||
#include <windows.h>
|
||||
|
||||
// Defaults for this encoder
|
||||
#define MP3_DEFAULT_INPUTSAMPLERATE 44100
|
||||
#define MP3_DEFAULT_INPUTNUMCHANNELS 2
|
||||
#define MP3_DEFAULT_OUTPUTSAMPLERATE 44100
|
||||
#define MP3_DEFAULT_OUTPUTNUMCHANNELS 2
|
||||
#define MP3_DEFAULT_OUTPUTBITRATE 96
|
||||
|
||||
#define MP3_DEFAULT_ATTRIBNUM 22
|
||||
|
||||
struct T_ENCODER_MP3_INFO {
|
||||
int output_bitRate;
|
||||
int output_sampleRate;
|
||||
int output_numChannels;
|
||||
int input_sampleRate;
|
||||
int input_numChannels;
|
||||
int QualityMode;
|
||||
};
|
||||
|
||||
#define HBE_STREAM lame_global_flags *
|
||||
|
||||
class C_ENCODER_MP3 : public C_ENCODER {
|
||||
private:
|
||||
HANDLE hMutex;
|
||||
lame_t Handle;
|
||||
int has_encoded;
|
||||
protected:
|
||||
lame_t (*lame_init)(void);
|
||||
int (*lame_init_params)(lame_global_flags *);
|
||||
int (*lame_encode_buffer_interleaved)(lame_global_flags *, short int pcm[], int num_samples, char *mp3buffer, int mp3buffer_size);
|
||||
int (*lame_encode_flush)(lame_global_flags *, char *mp3buffer, int size);
|
||||
|
||||
public:
|
||||
C_ENCODER_MP3(void *init, void *params, void *encode, void *finish);
|
||||
virtual ~C_ENCODER_MP3();
|
||||
|
||||
virtual void Close();
|
||||
virtual void Reset();
|
||||
|
||||
virtual int Encode(const void *inputbuf, const unsigned int inputbufsize, void *outputbuf, const unsigned int outputbufsize, int *inputamtused); /* all values are in BYTES! */
|
||||
};
|
||||
|
||||
#endif /* !__C_ENCODER_MP3_H__ */
|
151
Src/Plugins/DSP/dsp_sc/sc2srclib/Encoders/c_encoder_nsv.cpp
Normal file
151
Src/Plugins/DSP/dsp_sc/sc2srclib/Encoders/c_encoder_nsv.cpp
Normal file
|
@ -0,0 +1,151 @@
|
|||
#include "c_encoder_nsv.h"
|
||||
#include "../../utils.h"
|
||||
#include <mmsystem.h>
|
||||
#include <stdio.h>
|
||||
|
||||
static char * configfile;
|
||||
static unsigned int configfourcc;
|
||||
static HWND (*ConfigAudio3)(HWND intParent, HINSTANCE hinst, unsigned int outt, char *configfile);
|
||||
static HINSTANCE encoderDllInstance;
|
||||
static HWND cfgwnd=NULL;
|
||||
C_ENCODER_NSV::C_ENCODER_NSV(int ExtInfoSize) : C_ENCODER(ExtInfoSize) {
|
||||
hMutex = CreateMutex(NULL,TRUE,NULL);
|
||||
ReleaseMutex(hMutex);
|
||||
CreateAudio3 = NULL;
|
||||
ConfigAudio3 = NULL;
|
||||
GetAudioTypes3 = NULL;
|
||||
SetWinampHWND = NULL;
|
||||
SetConfigItem = NULL;
|
||||
GetConfigItem = NULL;
|
||||
winampWnd = NULL;
|
||||
fourcc = 0;
|
||||
encoder = NULL;
|
||||
}
|
||||
|
||||
void C_ENCODER_NSV::SetEncoder(void * CreateAudio3, void * GetAudioTypes3, void * ConfigAudio3, void * SetWinampHWND, int encoderNum) {
|
||||
*(void **)&(this->CreateAudio3) = CreateAudio3;
|
||||
*(void **)&(this->GetAudioTypes3) = GetAudioTypes3;
|
||||
*(void **)&(this->ConfigAudio3) = ConfigAudio3;
|
||||
*(void **)&(this->SetWinampHWND) = SetWinampHWND;
|
||||
|
||||
if(this->SetWinampHWND) {
|
||||
this->SetWinampHWND(winampWnd);
|
||||
}
|
||||
|
||||
if(this->GetAudioTypes3) {
|
||||
char name[C_ENCODER_NameLen];
|
||||
fourcc = this->GetAudioTypes3(encoderNum,name);
|
||||
}
|
||||
}
|
||||
|
||||
C_ENCODER_NSV::~C_ENCODER_NSV() {
|
||||
WaitForSingleObject(hMutex,INFINITE);
|
||||
|
||||
CloseHandle(hMutex);
|
||||
hMutex = NULL;
|
||||
C_ENCODER::~C_ENCODER();
|
||||
}
|
||||
|
||||
void C_ENCODER_NSV::Close() {
|
||||
C_ENCODER::Close();
|
||||
|
||||
if(encoder)
|
||||
delete encoder;
|
||||
encoder = NULL;
|
||||
}
|
||||
|
||||
void C_ENCODER_NSV::Reset() {
|
||||
if(WaitForSingleObject(hMutex,INFINITE) != WAIT_OBJECT_0) return;
|
||||
|
||||
Close();
|
||||
|
||||
if(!configfile) {
|
||||
configfile = GetSCIniFile(winampWnd);
|
||||
}
|
||||
|
||||
FillConfFile(configfile);
|
||||
|
||||
int nch = ((T_ENCODER_NSV_INFO*)ExtendedInfoPtr)->input_numChannels;
|
||||
int srate = ((T_ENCODER_NSV_INFO*)ExtendedInfoPtr)->input_sampleRate;
|
||||
if (CreateAudio3) {
|
||||
const int bps = 16; /* I think this is always the case. */
|
||||
encoder = CreateAudio3(nch,srate,bps,mmioFOURCC('P','C','M',' '),&fourcc,configfile);
|
||||
}
|
||||
else encoder = NULL;
|
||||
|
||||
/* I think (in that I havn't found anything to the contrary) that in the CreateAudio3 call, the encoder
|
||||
* reads all its settings from the conf_file and never touches them again. Hence, this is safe. Ahem.
|
||||
*/
|
||||
FillAttribs();
|
||||
ReleaseMutex(hMutex);
|
||||
}
|
||||
|
||||
int C_ENCODER_NSV::Encode(const void *inputbuf, const unsigned int inputbufsize, void *outputbuf, const unsigned int outputbufsize, int *inputamtused) {
|
||||
|
||||
if(WaitForSingleObject(hMutex,INFINITE) != WAIT_OBJECT_0) return 0;
|
||||
int ret=0;
|
||||
if(encoder && (inputbuf != NULL) && (outputbuf != NULL) && (inputbufsize != 0) && (outputbufsize != 0) && (inputamtused != NULL)) {
|
||||
ret = encoder->Encode(0,(void *)inputbuf,inputbufsize,inputamtused,outputbuf,outputbufsize);
|
||||
} else
|
||||
*inputamtused = inputbufsize; /* we havn't got the dll, so just say everything is ok? */
|
||||
|
||||
ReleaseMutex(hMutex);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static BOOL CALLBACK configure_dlgproc(HWND intDlg, UINT uMsg, WPARAM wParam,LPARAM lParam) {
|
||||
|
||||
switch(uMsg) {
|
||||
case WM_INITDIALOG:
|
||||
if(configfourcc == mmioFOURCC('A','D','T','S')) {
|
||||
SetWindowTextW(intDlg, LocalisedString(IDS_FHGAAC_ENCODER, NULL, 0));
|
||||
}
|
||||
#ifdef USE_OGG
|
||||
else if(configfourcc == mmioFOURCC('O','G','G',' ')) {
|
||||
SetWindowTextW(intDlg, LocalisedString(IDS_OGG_CONFIG_TITLE, NULL, 0));
|
||||
}
|
||||
#endif
|
||||
|
||||
cfgwnd=ConfigAudio3(intDlg, encoderDllInstance, configfourcc, configfile);
|
||||
|
||||
if(cfgwnd) {
|
||||
RECT r;
|
||||
GetWindowRect(GetDlgItem(intDlg,IDC_GO_HERE),&r);
|
||||
ScreenToClient(intDlg,(LPPOINT)&r);
|
||||
SetWindowPos(cfgwnd,NULL,r.left,r.top,0,0,SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOZORDER);
|
||||
ShowWindow(cfgwnd,SW_SHOWNA);
|
||||
InvalidateRect(intDlg,NULL,FALSE);
|
||||
}
|
||||
break;
|
||||
case WM_COMMAND:
|
||||
if(LOWORD(wParam) == IDCANCEL) EndDialog(intDlg,0);
|
||||
break;
|
||||
case WM_DESTROY:
|
||||
DestroyWindow(cfgwnd);
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void C_ENCODER_NSV::Configure(HWND parent, HINSTANCE hDllInstance) {
|
||||
if(ConfigAudio3) {
|
||||
configfourcc = fourcc;
|
||||
if(!configfile) {
|
||||
configfile = GetSCIniFile(winampWnd);
|
||||
}
|
||||
|
||||
::ConfigAudio3 = this->ConfigAudio3;
|
||||
::encoderDllInstance = GetEncoderInstance();
|
||||
|
||||
if(WaitForSingleObject(hMutex,INFINITE) != WAIT_OBJECT_0) return;
|
||||
FillConfFile(configfile);
|
||||
ReleaseMutex(hMutex);
|
||||
|
||||
LocalisedDialogBox(hDllInstance,IDD_NSVCONFIG,parent,::configure_dlgproc);
|
||||
|
||||
if(WaitForSingleObject(hMutex,INFINITE) != WAIT_OBJECT_0) return;
|
||||
ReadConfFile(configfile);
|
||||
Reset();
|
||||
ReleaseMutex(hMutex);
|
||||
}
|
||||
}
|
76
Src/Plugins/DSP/dsp_sc/sc2srclib/Encoders/c_encoder_nsv.h
Normal file
76
Src/Plugins/DSP/dsp_sc/sc2srclib/Encoders/c_encoder_nsv.h
Normal file
|
@ -0,0 +1,76 @@
|
|||
/* This is an abstract class to use the NSV style of encoder.
|
||||
*/
|
||||
|
||||
#ifndef __C_ENCODER_NSV_H__
|
||||
#define __C_ENCODER_NSV_H__
|
||||
|
||||
#include "c_encoder.h"
|
||||
#include "enc_if.h"
|
||||
#include <windows.h>
|
||||
#include <Shlobj.h>
|
||||
#include "../../Resource/resource.h"
|
||||
|
||||
struct T_ENCODER_NSV_INFO {
|
||||
unsigned int output_bitRate;
|
||||
unsigned int input_numChannels;
|
||||
unsigned int input_sampleRate;
|
||||
};
|
||||
|
||||
class C_ENCODER_NSV : public C_ENCODER {
|
||||
private:
|
||||
HANDLE hMutex;
|
||||
protected:
|
||||
// These are exported by enc_*.dll
|
||||
AudioCoder* (*CreateAudio3)(int nch, int srate, int bps, unsigned int srct, unsigned int *outt, char *configfile);
|
||||
int (*GetAudioTypes3)(int idx, char *desc);
|
||||
HWND (*ConfigAudio3)(HWND hwndParent, HINSTANCE hinst, unsigned int outt, char *configfile);
|
||||
void (*SetWinampHWND)(HWND hwnd);
|
||||
int (*SetConfigItem)(unsigned int outt, char *item, char *data, char *configfile);
|
||||
int (*GetConfigItem)(unsigned int outt, char *item, char *data, int len, char *configfile);
|
||||
/* We don't need the rest of the exports
|
||||
AudioCoder *(*FinishAudio3)(char *fn, AudioCoder *c);
|
||||
void (*PrepareToFinish)(const char *filename, AudioCoder *coder);
|
||||
*/
|
||||
|
||||
// our encoder (the AudioCoder class is defined in enc_if.h)
|
||||
AudioCoder* encoder;
|
||||
|
||||
// the type of the output format
|
||||
unsigned int fourcc;
|
||||
|
||||
// fill up the attribute list (using AddAttrib)
|
||||
virtual void FillAttribs()=0;
|
||||
|
||||
// child classes MUST call this in their constructor
|
||||
// note: encoderNum defaults to 0 which resolves to the first encoder
|
||||
// in most enc_* but make sure to set this correctly for others
|
||||
virtual void SetEncoder(void * CreateAudio3, void * GetAudioTypes3, void * ConfigAudio3, void * SetWinampHWND, int encoderNum=0);
|
||||
|
||||
// this is used in Configure()
|
||||
virtual HINSTANCE GetEncoderInstance()=0;
|
||||
|
||||
// this is used for esternal encoders so they can be correctly localised
|
||||
HWND winampWnd;
|
||||
|
||||
public:
|
||||
C_ENCODER_NSV(int ExtInfoSize = sizeof(T_ENCODER_NSV_INFO));
|
||||
virtual ~C_ENCODER_NSV();
|
||||
|
||||
virtual void Close();
|
||||
virtual void Reset();
|
||||
|
||||
virtual int Encode(const void *inputbuf, const unsigned int inputbufsize, void *outputbuf, const unsigned int outputbufsize, int *inputamtused); /* all values are in BYTES! */
|
||||
|
||||
// show configuration dialog
|
||||
virtual void Configure(HWND parent,HINSTANCE hDllInstance);
|
||||
|
||||
virtual bool UseNsvConfig() { return true; };
|
||||
|
||||
// populate the configuration file with current settings
|
||||
virtual void FillConfFile(char * conf_file, char * section=NULL)=0;
|
||||
|
||||
// read the configuration file and change current settings
|
||||
virtual void ReadConfFile(char * conf_file, char * section=NULL)=0;
|
||||
};
|
||||
|
||||
#endif /* !__C_ENCODER_NSV_H__ */
|
117
Src/Plugins/DSP/dsp_sc/sc2srclib/Encoders/c_encoder_ogg.cpp
Normal file
117
Src/Plugins/DSP/dsp_sc/sc2srclib/Encoders/c_encoder_ogg.cpp
Normal file
|
@ -0,0 +1,117 @@
|
|||
#include "c_encoder_ogg.h"
|
||||
#include "../../utils.h"
|
||||
|
||||
HINSTANCE C_ENCODER_OGG::hEncoderInstance = NULL;
|
||||
|
||||
C_ENCODER_OGG::C_ENCODER_OGG(HWND winamp) : C_ENCODER_NSV(sizeof(T_ENCODER_OGG_INFO)) {
|
||||
SetName("OGG Vorbis Encoder");
|
||||
winampWnd = winamp;
|
||||
ConfigAudio3 = NULL;
|
||||
if(hEncoderInstance == NULL) {
|
||||
wchar_t dir[MAX_PATH] = {0};
|
||||
snwprintf(dir, MAX_PATH, L"%s\\enc_vorbis.dll", GetPluginDirectoryW(winamp));
|
||||
hEncoderInstance = LoadLibraryW(dir);
|
||||
}
|
||||
|
||||
if(hEncoderInstance) {
|
||||
void * CreateAudio3=(void *)GetProcAddress(hEncoderInstance, "CreateAudio3");
|
||||
void * GetAudioTypes3=(void *)GetProcAddress(hEncoderInstance, "GetAudioTypes3");
|
||||
void * ConfigAudio3=(void *)GetProcAddress(hEncoderInstance, "ConfigAudio3");
|
||||
void * SetWinampHWND=(void *)GetProcAddress(hEncoderInstance, "SetWinampHWND");
|
||||
SetEncoder(CreateAudio3,GetAudioTypes3,ConfigAudio3,SetWinampHWND);
|
||||
}
|
||||
|
||||
T_ENCODER_OGG_INFO * EncInfo = (T_ENCODER_OGG_INFO *)ExtendedInfoPtr;
|
||||
EncInfo->output_bitRate = OGG_DEFAULT_OUTPUTBITRATE;
|
||||
EncInfo->output_channelmode = OGG_DEFAULT_OUTPUTMODE;
|
||||
EncInfo->output_samplerate = OGG_DEFAULT_OUTPUTSAMPLERATE;
|
||||
}
|
||||
|
||||
C_ENCODER_OGG::~C_ENCODER_OGG() {
|
||||
C_ENCODER_NSV::~C_ENCODER_NSV();
|
||||
}
|
||||
|
||||
static int cacheVal=0;
|
||||
bool C_ENCODER_OGG::isPresent(HWND winamp) {
|
||||
if(cacheVal!=0 && hEncoderInstance!=0) return cacheVal==2;
|
||||
bool ret=false;
|
||||
wchar_t dir[MAX_PATH] = {0};
|
||||
snwprintf(dir, MAX_PATH, L"%s\\enc_vorbis.dll", GetPluginDirectoryW(winamp));
|
||||
FILE * f = _wfopen(dir, L"rb");
|
||||
if (f) {
|
||||
fseek(f,0,2);
|
||||
if(ftell(f) > 0) ret=true;
|
||||
fclose(f);
|
||||
}
|
||||
cacheVal=ret?2:1;
|
||||
return ret;
|
||||
}
|
||||
|
||||
void C_ENCODER_OGG::FillAttribs() {
|
||||
T_ENCODER_OGG_INFO &EncInfo = *(T_ENCODER_OGG_INFO *)ExtendedInfoPtr;
|
||||
T_ENCODER_OGG_INFO *attribs = new T_ENCODER_OGG_INFO;
|
||||
*attribs = EncInfo;
|
||||
AddAttrib("",attribs);
|
||||
}
|
||||
|
||||
void C_ENCODER_OGG::FillConfFile(char * conf_file, char * section) {
|
||||
if(!section) section="audio_ogg";
|
||||
|
||||
T_ENCODER_OGG_INFO &EncInfo = *(T_ENCODER_OGG_INFO *)ExtendedInfoPtr;
|
||||
configtype * cfg = new configtype;
|
||||
cfg->cfg_abr_use_max=0;
|
||||
cfg->cfg_abr_use_min=0;
|
||||
cfg->cfg_mode=0; //VBR
|
||||
cfg->cfg_vbrquality=EncInfo.output_quality;
|
||||
cfg->cfg_abr_nominal=EncInfo.output_bitRate;
|
||||
cfg->cfg_abr_max=EncInfo.output_bitRate;
|
||||
cfg->cfg_abr_min=EncInfo.output_bitRate;
|
||||
|
||||
if (conf_file) WritePrivateProfileStruct(section,"conf",cfg,sizeof(configtype),conf_file);
|
||||
}
|
||||
int setBitrate(float ql)
|
||||
{
|
||||
int br = 64;
|
||||
//ql = ql*10;
|
||||
// jkey: this is a pain in the ass,but the only
|
||||
// way i can figure out how to get the bitrate
|
||||
// outside of enc_vorbis.
|
||||
// Also quality enforcement is needed to prevent the
|
||||
// yp filling up with non standard bitrate streams.
|
||||
// although this is vbr and will be variable bitrate anyway.
|
||||
if(ql == 10 || (ql < 10 && ql > 9.5)){br=500;ql = 10.0f; return br;}
|
||||
if(ql == 9.0f || (ql < 10.0f && ql > 9.0f)){br=320;ql = 9.0f;return br;}
|
||||
if(ql == 8.0f || (ql < 9.0f && ql > 8.0f)){br=256;ql = 8.0f;return br;}
|
||||
if(ql == 7.0f || (ql < 8.0f && ql > 7.0f)){br=224;ql = 7.0f;return br;}
|
||||
if(ql == 6.0f || (ql < 7.0f && ql > 6.0f)){br=192;ql = 6.0f;return br;}
|
||||
if(ql == 5.0f || (ql < 6.0f && ql > 5.0f)){br=160;ql = 5.0f;return br;}
|
||||
if(ql == 4.0f || (ql < 5.0f && ql > 4.0f)){br=128;ql = 4.0f;return br;}
|
||||
if(ql == 3.0f || (ql < 4.0f && ql > 3.0f)){br=112;ql = 3.0f;return br;}
|
||||
if(ql == 2.0f || (ql < 3.0f && ql > 2.0f)){br=96;ql = 2.0f;return br;}
|
||||
if(ql == 1.0f || (ql < 2.0f && ql > 1.0f)){br=80;ql = 1.0f;return br;}
|
||||
if(ql == 0.0f || (ql < 1.0f && ql > 0.0f)){ br=64;ql = 0.0f;return br;}
|
||||
if(ql == -0.5f || (ql < 0.0f && ql > -0.5f)){br=56;ql = -0.5f;return br;}
|
||||
if(ql == -1.0f || ql < -0.5f){br=48;ql = -1.0f;return br;}
|
||||
return br;
|
||||
}
|
||||
void C_ENCODER_OGG::ReadConfFile(char * conf_file, char * section) {
|
||||
if(!section) section="audio_ogg";
|
||||
T_ENCODER_OGG_INFO &EncInfo = *(T_ENCODER_OGG_INFO *)ExtendedInfoPtr;
|
||||
T_ENCODER_OGG_INFO *attribs = new T_ENCODER_OGG_INFO;
|
||||
*attribs = EncInfo;
|
||||
configtype * cfg = new configtype;
|
||||
cfg->cfg_abr_use_max=0;
|
||||
cfg->cfg_abr_use_min=0;
|
||||
cfg->cfg_mode=0; //VBR
|
||||
cfg->cfg_vbrquality=0.0f;
|
||||
cfg->cfg_abr_nominal=64;
|
||||
cfg->cfg_abr_max=352;
|
||||
cfg->cfg_abr_min=32;
|
||||
|
||||
if (conf_file) GetPrivateProfileStruct(section,"conf",cfg,sizeof(configtype),conf_file);
|
||||
attribs->output_samplerate = OGG_DEFAULT_OUTPUTSAMPLERATE;
|
||||
attribs->output_channelmode = cfg->cfg_mode;
|
||||
attribs->output_quality = cfg->cfg_vbrquality;
|
||||
attribs->output_bitRate = setBitrate(attribs->output_quality*10);
|
||||
ChangeSettings(attribs);
|
||||
}
|
47
Src/Plugins/DSP/dsp_sc/sc2srclib/Encoders/c_encoder_ogg.h
Normal file
47
Src/Plugins/DSP/dsp_sc/sc2srclib/Encoders/c_encoder_ogg.h
Normal file
|
@ -0,0 +1,47 @@
|
|||
#ifndef __C_ENCODER_OGG_H__
|
||||
#define __C_ENCODER_OGG_H__
|
||||
|
||||
#include "c_encoder_nsv.h"
|
||||
//#define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))
|
||||
|
||||
typedef struct
|
||||
{
|
||||
bool cfg_abr_use_max,cfg_abr_use_min;
|
||||
UINT cfg_mode;
|
||||
|
||||
float cfg_vbrquality;
|
||||
UINT cfg_abr_nominal;
|
||||
UINT cfg_abr_max;
|
||||
UINT cfg_abr_min;
|
||||
} configtype;
|
||||
|
||||
struct T_ENCODER_OGG_INFO : public T_ENCODER_NSV_INFO
|
||||
{
|
||||
float output_quality;
|
||||
unsigned int output_samplerate;
|
||||
unsigned int output_channelmode;
|
||||
};
|
||||
|
||||
#define OGG_DEFAULT_OUTPUTMODE 0
|
||||
#define OGG_DEFAULT_OUTPUTBITRATE 192
|
||||
#define OGG_DEFAULT_OUTPUTSAMPLERATE 44100
|
||||
#define OGG_DEFAULT_OUTPUTQUALITY 2.0f
|
||||
|
||||
class C_ENCODER_OGG : public C_ENCODER_NSV {
|
||||
private:
|
||||
HWND winamp;
|
||||
protected:
|
||||
virtual void FillAttribs();
|
||||
public:
|
||||
static HINSTANCE hEncoderInstance;
|
||||
C_ENCODER_OGG(HWND hwnd = 0);
|
||||
virtual ~C_ENCODER_OGG();
|
||||
static bool isPresent(HWND winamp);
|
||||
virtual void ReadConfFile(char * conf_file, char * section=NULL);
|
||||
virtual void FillConfFile(char * conf_file, char * section=NULL);
|
||||
static void Unload() { if(hEncoderInstance) FreeLibrary(hEncoderInstance); hEncoderInstance=0; }
|
||||
virtual char * GetContentType() { return "audio/ogg"; }
|
||||
virtual HINSTANCE GetEncoderInstance() { return hEncoderInstance; }
|
||||
};
|
||||
|
||||
#endif /* !__C_ENCODER_OGG_H__ */
|
44
Src/Plugins/DSP/dsp_sc/sc2srclib/Encoders/enc_if.h
Normal file
44
Src/Plugins/DSP/dsp_sc/sc2srclib/Encoders/enc_if.h
Normal file
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
** enc_if.h - common encoder interface
|
||||
**
|
||||
** Copyright (C) 2001-2003 Nullsoft, Inc.
|
||||
**
|
||||
** This software is provided 'as-is', without any express or implied warranty.
|
||||
** In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
**
|
||||
** Permission is granted to anyone to use this software for any purpose, including commercial
|
||||
** applications, and to alter it and redistribute it freely, subject to the following restrictions:
|
||||
** 1. The origin of this software must not be misrepresented; you must not claim that you wrote the
|
||||
** original software. If you use this software in a product, an acknowledgment in the product
|
||||
** documentation would be appreciated but is not required.
|
||||
** 2. Altered source versions must be plainly marked as such, and must not be misrepresented as
|
||||
** being the original software.
|
||||
** 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef _NSV_ENC_IF_H_
|
||||
#define _NSV_ENC_IF_H_
|
||||
class VideoCoder
|
||||
{
|
||||
public:
|
||||
VideoCoder() { }
|
||||
virtual int Encode(void *in, void *out, int *iskf)=0; // returns bytes in out
|
||||
virtual ~VideoCoder() { };
|
||||
};
|
||||
|
||||
class AudioCoder
|
||||
{
|
||||
public:
|
||||
AudioCoder() { }
|
||||
virtual int Encode(int framepos, void *in, int in_avail, int *in_used, void *out, int out_avail)=0; //returns bytes in out
|
||||
virtual ~AudioCoder() { };
|
||||
};
|
||||
|
||||
// unsigned int GetAudioTypes3(int idx, char *desc);
|
||||
// unsigned int GetVideoTypes3(int idx, char *desc);
|
||||
// AudioCoder *CreateAudio3(int nch, int srate, int bps, unsigned int srct, unsigned int *outt, char *configfile);
|
||||
// VideoCoder *CreateVideo3(int w, int h, double frt, unsigned int pixt, unsigned int *outt, char *configfile);
|
||||
// HWND ConfigAudio3(HWND hwndParent, HINSTANCE hinst, unsigned int outt, char *configfile);
|
||||
// HWND ConfigVideo3(HWND hwndParent, HINSTANCE hinst, unsigned int outt, char *configfile);
|
||||
|
||||
#endif //_NSV_ENC_IF_H_
|
Loading…
Add table
Add a link
Reference in a new issue