ref: b35b33a1fb8c97f9f02c1517a91313d19fec4d24
parent: 68f48bbb6d1448d7f068b4084c10dd4719496612
author: ca5e <ca5e>
date: Sat Dec 13 16:58:35 EST 2003
Improved gapless encoding
--- a/frontend/main.c
+++ b/frontend/main.c
@@ -16,7 +16,7 @@
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * $Id: main.c,v 1.50 2003/11/24 18:11:14 knik Exp $
+ * $Id: main.c,v 1.51 2003/12/13 21:58:35 ca5e Exp $
*/
#ifdef _MSC_VER
@@ -637,19 +637,17 @@
if (bytesWritten > 0)
{
#ifdef HAVE_LIBMP4V2
- u_int64_t samples = (total_samples - encoded_samples) < frameSize
- ? (total_samples - encoded_samples) : frameSize;
+ u_int64_t samples_left = total_samples - encoded_samples + delay_samples;
+ MP4Duration dur = 0;
+ if (samples_left > frameSize + delay_samples)
+ dur = frameSize;
+ else if (samples_left > delay_samples)
+ dur = samples_left - delay_samples;
- if (delay_samples > 0)
- {
- samples = 0;
- delay_samples -= frameSize;
- }
-
if (mp4)
{
/* write bitstream to mp4 file */
- MP4WriteSample(MP4hFile, MP4track, bitbuf, bytesWritten, samples, 0, 1);
+ MP4WriteSample(MP4hFile, MP4track, bitbuf, bytesWritten, dur, delay_samples, 1);
}
else
{
@@ -659,7 +657,7 @@
#ifdef HAVE_LIBMP4V2
}
- encoded_samples += samples;
+ encoded_samples += dur;
#endif
}
}
@@ -686,6 +684,9 @@
/*
$Log: main.c,v $
+Revision 1.51 2003/12/13 21:58:35 ca5e
+Improved gapless encoding
+
Revision 1.50 2003/11/24 18:11:14 knik
using new version info interface
--- a/plugins/foo_faac/foo_faac.cpp
+++ b/plugins/foo_faac/foo_faac.cpp
@@ -2,6 +2,7 @@
// Copyright (C) 2003 Janne Hyv�rinen
//
// Changes:
+// 0.4.1 (2003-12-13): Added ctts field writing for MP4 mode
// 0.4 (2003-12-11): Added support for average bitrate controlling
// 0.3.5 (2003-10-17): Changed way gapless encoding is handled (iTunes is buggy...)
// 0.3.4 (2003-10-14): Fixed AAC object type selecting
@@ -35,7 +36,7 @@
#include <faac.h>
#include <version.h>
-#define FOO_FAAC_VERSION "0.4"
+#define FOO_FAAC_VERSION "0.4.1"
#define FF_AAC 0
#define FF_MP4 1
@@ -93,7 +94,7 @@
string8 path;
file_info_i_full info;
unsigned int srate, nch, bps;
- unsigned __int64 total_samples, encoded_samples, delay_samples;
+ __int64 total_samples, encoded_samples, delay_samples;
bool encode_error;
public:
@@ -303,7 +304,7 @@
}
if ( create_mp4 ) {
- MP4WriteSample ( MP4hFile, MP4track, (const unsigned __int8 *)bitbuf.get_ptr(), bytesWritten, frameSize );
+ MP4WriteSample ( MP4hFile, MP4track, (const unsigned __int8 *)bitbuf.get_ptr(), bytesWritten, frameSize, 1024 );
} else {
m_reader->write ( bitbuf.get_ptr(), bytesWritten );
}
@@ -326,7 +327,9 @@
chan_remap ( (int *)floatbuf.get_ptr(), nch, bufferedSamples/nch, chanmap );
}
- while ( encoded_samples < total_samples ) {
+ __int64 samples_left = total_samples - encoded_samples;
+
+ while ( samples_left > 0 ) {
if ( !bufferedSamples ) {
bufferedSamples = samplesInput;
memset ( floatbuf.get_ptr(), 0, samplesInput * sizeof(float) );
@@ -340,17 +343,19 @@
break;
}
else if ( bytesWritten > 0 ) {
- MP4Duration dur = (MP4Duration) (((total_samples - encoded_samples) < frameSize) ? (total_samples - encoded_samples) : frameSize);
+ MP4Duration dur = 0;
+ if ( samples_left > frameSize + 1024 ) dur = frameSize;
+ else if ( samples_left > 1024 ) dur = samples_left - 1024;
if ( create_mp4 ) {
- MP4WriteSample ( MP4hFile, MP4track, (const unsigned __int8 *)bitbuf.get_ptr(), bytesWritten, dur );
+ MP4WriteSample ( MP4hFile, MP4track, (const unsigned __int8 *)bitbuf.get_ptr(), bytesWritten, dur, 1024 );
} else {
m_reader->write ( bitbuf.get_ptr(), bytesWritten );
}
- encoded_samples += dur;
+ samples_left -= frameSize;
}
- };
+ }
faacEncClose ( hEncoder );
hEncoder = 0;