-
Notifications
You must be signed in to change notification settings - Fork 0
/
lameencdec.h
136 lines (100 loc) · 3.18 KB
/
lameencdec.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/*
WDL - lameencdec.h
Copyright (C) 2005 and later Cockos Incorporated
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.
This file provides a simple interface for using lame_enc.dll on Windows for MP3 encoding and decoding.
*/
#ifndef _LAMEENCDEC_H_
#define _LAMEENCDEC_H_
#include "queue.h"
#include "wdlstring.h"
#ifdef _WIN32
#ifndef _WIN64
#define USE_LAME_BLADE_API
#endif
#endif
#ifndef USE_LAME_BLADE_API
#define DYNAMIC_LAME
#ifdef DYNAMIC_LAME
typedef void *lame_t;
#else
#include <lame/lame.h>
#endif
#endif
class LameEncoder
{
public:
LameEncoder(int srate, int nch, int bitrate, int stereomode = 1, int quality = 0, int vbrmethod = -1, int vbrquality = 2, int vbrmax = 320, int abr = 128);
~LameEncoder();
int Status() { return errorstat; } // 1=no dll, 2=error
void Encode(float *in, int in_spls, int spacing=1);
WDL_Queue outqueue;
void reinit()
{
spltmp[0].Advance(spltmp[0].Available());
spltmp[0].Compact();
spltmp[1].Advance(spltmp[1].Available());
spltmp[1].Compact();
}
static bool CheckDLL(); // returns true if dll is present
static void InitDLL(const char *extrapath=NULL); // call with extrapath != NULL if you want to try loading from another path
void SetVBRFilename(const char *fn)
{
m_vbrfile.Set(fn);
}
int GetNumChannels() { return m_encoder_nch; }
private:
int m_nch,m_encoder_nch;
WDL_Queue spltmp[2];
WDL_HeapBuf outtmp;
WDL_String m_vbrfile;
int errorstat;
int in_size_samples;
#ifdef USE_LAME_BLADE_API
UINT_PTR hbeStream;
#else
lame_t m_lamestate;
#endif
};
class LameDecoder
{
public:
LameDecoder();
~LameDecoder();
int GetSampleRate() { return m_srate?m_srate:48000; }
int GetNumChannels() { return m_nch?m_nch:1; }
WDL_HeapBuf m_samples; // we let the size get as big as it needs to, so we don't worry about tons of mallocs/etc
int m_samples_used;
void *DecodeGetSrcBuffer(int srclen)
{
if (srctmp.GetSize() < srclen) srctmp.Resize(srclen);
return srctmp.Get();
}
void DecodeWrote(int srclen);
int GetError() { return errorstat; }
void Reset();
int m_samplesdec;
private:
WDL_HeapBuf srctmp;
int errorstat;
int m_srate,m_nch;
int m_samples_remove;
#ifdef USE_LAME_BLADE_API
void *decinst;
#else
lame_t *decinst;
#endif
};
#endif