[IPLUG/EXAMPLES] IPlugResampler: qualification of min no longer needed
[wdl/wdl-ol.git] / WDL / lameencdec.h
blobf7778f36c26697f97b6dc864b3c83072fe5c40ab
1 /*
2 WDL - lameencdec.h
3 Copyright (C) 2005 and later Cockos Incorporated
5 This software is provided 'as-is', without any express or implied
6 warranty. In no event will the authors be held liable for any damages
7 arising from the use of this software.
9 Permission is granted to anyone to use this software for any purpose,
10 including commercial applications, and to alter it and redistribute it
11 freely, subject to the following restrictions:
13 1. The origin of this software must not be misrepresented; you must not
14 claim that you wrote the original software. If you use this software
15 in a product, an acknowledgment in the product documentation would be
16 appreciated but is not required.
17 2. Altered source versions must be plainly marked as such, and must not be
18 misrepresented as being the original software.
19 3. This notice may not be removed or altered from any source distribution.
22 This file provides a simple interface for using lame_enc.dll on Windows for MP3 encoding and decoding.
27 #ifndef _LAMEENCDEC_H_
28 #define _LAMEENCDEC_H_
30 #include "queue.h"
31 #include "wdlstring.h"
33 #ifdef _WIN32
34 #ifndef _WIN64
35 #define USE_LAME_BLADE_API
36 #endif
37 #endif
39 #ifndef USE_LAME_BLADE_API
40 #define DYNAMIC_LAME
42 #ifdef DYNAMIC_LAME
43 typedef void *lame_t;
44 #else
45 #include <lame/lame.h>
46 #endif
47 #endif
51 class LameEncoder
53 public:
55 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);
56 ~LameEncoder();
58 int Status() { return errorstat; } // 1=no dll, 2=error
60 void Encode(float *in, int in_spls, int spacing=1);
62 WDL_Queue outqueue;
64 void reinit()
66 spltmp[0].Advance(spltmp[0].Available());
67 spltmp[0].Compact();
68 spltmp[1].Advance(spltmp[1].Available());
69 spltmp[1].Compact();
72 static bool CheckDLL(); // returns true if dll is present
73 static void InitDLL(const char *extrapath=NULL); // call with extrapath != NULL if you want to try loading from another path
75 void SetVBRFilename(const char *fn)
77 m_vbrfile.Set(fn);
80 int GetNumChannels() { return m_encoder_nch; }
82 private:
83 int m_nch,m_encoder_nch;
84 WDL_Queue spltmp[2];
85 WDL_HeapBuf outtmp;
86 WDL_String m_vbrfile;
87 int errorstat;
88 int in_size_samples;
89 #ifdef USE_LAME_BLADE_API
90 UINT_PTR hbeStream;
91 #else
92 lame_t m_lamestate;
93 #endif
96 class LameDecoder
98 public:
99 LameDecoder();
100 ~LameDecoder();
102 int GetSampleRate() { return m_srate?m_srate:48000; }
103 int GetNumChannels() { return m_nch?m_nch:1; }
105 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
106 int m_samples_used;
108 void *DecodeGetSrcBuffer(int srclen)
110 if (srctmp.GetSize() < srclen) srctmp.Resize(srclen);
111 return srctmp.Get();
113 void DecodeWrote(int srclen);
115 int GetError() { return errorstat; }
117 void Reset();
119 int m_samplesdec;
121 private:
122 WDL_HeapBuf srctmp;
123 int errorstat;
124 int m_srate,m_nch;
125 int m_samples_remove;
127 #ifdef USE_LAME_BLADE_API
128 void *decinst;
129 #else
130 lame_t *decinst;
131 #endif
136 #endif