3 Copyright (C) 2005 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.
25 This file provides a simple class for writing MP3 files (using lameencdec.h)
35 #include "lameencdec.h"
40 // appending doesnt check sample types
49 mp3Writer(char *filename
, int nch
, int srate
, int bitrate
, int allow_append
=1)
55 Open(filename
,nch
,srate
,bitrate
,allow_append
);
59 int Open(char *filename
, int nch
, int srate
, int bitrate
, int allow_append
=1)
64 m_fp
=fopen(filename
,"r+b");
67 fseek(m_fp
,0,SEEK_END
);
72 m_fp
=fopen(filename
,"wb");
76 m_enc
= new LameEncoder(srate
,nch
,bitrate
);
91 m_enc
->Encode(NULL
,0);
92 if (m_enc
->outqueue
.Available())
94 fwrite(m_enc
->outqueue
.Get(),1,m_enc
->outqueue
.GetSize(),m_fp
);
96 m_enc
->outqueue
.Advance(m_enc
->outqueue
.GetSize());
97 m_enc
->outqueue
.Compact();
111 int Status() { return m_enc
&& m_fp
; }
113 void WriteFloats(float *samples
, int nsamples
)
115 if (!m_fp
|| !m_enc
) return;
117 m_enc
->Encode(samples
,nsamples
/m_nch
);
118 if (m_enc
->outqueue
.Available())
120 fwrite(m_enc
->outqueue
.Get(),1,m_enc
->outqueue
.GetSize(),m_fp
);
122 m_enc
->outqueue
.Advance(m_enc
->outqueue
.GetSize());
123 m_enc
->outqueue
.Compact();
128 int get_nch() { return m_nch
; }
129 int get_srate() { return m_srate
; }