summaryrefslogtreecommitdiff
path: root/src/liblame_wrapper.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/liblame_wrapper.cc')
-rw-r--r--src/liblame_wrapper.cc19
1 files changed, 12 insertions, 7 deletions
diff --git a/src/liblame_wrapper.cc b/src/liblame_wrapper.cc
index c72c2dc..b29acf9 100644
--- a/src/liblame_wrapper.cc
+++ b/src/liblame_wrapper.cc
@@ -94,22 +94,27 @@ LibLAMEWrapper::~LibLAMEWrapper()
Frame *LibLAMEWrapper::close(Frame *oldframe)
{
- Frame *frame = new Frame(NULL, oldframe->size + 7200);
- frame->number = oldframe->number;
+ Frame *frame;
+ unsigned int offset = 0;
- memcpy(frame->data, oldframe->data, oldframe->size);
+ frame = new Frame(NULL, (int)(1.25 * SAMPLES + 7200) * 2); // Big enough to hold two frames
+
+ if(oldframe) {
+ offset = oldframe->size;
+ frame->number = oldframe->number;
+ memcpy(frame->data, oldframe->data, oldframe->size);
+ delete oldframe;
+ }
int flush;
- flush = lame_encode_finish(gfp, frame->data + oldframe->size, 7200);
+ flush = lame_encode_finish(gfp, frame->data + offset, 7200);
- frame->size = oldframe->size + flush;
+ frame->size = offset + flush;
calc_bitrate += flush;
frame->bitrate = (unsigned int)((double)calc_bitrate / (double)(frame_number)) * 25;
- delete oldframe;
-
return frame;
}