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.cc127
1 files changed, 51 insertions, 76 deletions
diff --git a/src/liblame_wrapper.cc b/src/liblame_wrapper.cc
index 7af9b68..90b8824 100644
--- a/src/liblame_wrapper.cc
+++ b/src/liblame_wrapper.cc
@@ -31,6 +31,9 @@
/*
* $Log$
+ * Revision 1.3 2005/07/07 12:42:19 deva
+ * *** empty log message ***
+ *
* Revision 1.2 2005/07/05 23:15:16 deva
* *** empty log message ***
*
@@ -62,6 +65,18 @@ LibLAMEWrapper::LibLAMEWrapper(Info *i)
lame_set_mode(gfp, STEREO);
lame_set_brate(gfp, 192);
lame_set_strict_ISO(gfp, 1);
+ lame_set_num_samples(gfp, SAMPLES);
+
+ lame_set_copyright(gfp, 0); // is there a copyright on the encoded data?
+ lame_set_original(gfp, 1); // is the encoded data on the original media?
+ lame_set_error_protection(gfp, 0);// add 2 byte CRC protection to each frame?
+ lame_set_padding_type(gfp, PAD_NO); // PAD_NO, PAD_ALL, PAD_ADJUST, PAD_MAX_INDICATOR
+ // 0 = do not pad frames
+ // 1 = always pad frames
+ // 2 = adjust padding to satisfy bit rate
+ lame_set_extension(gfp, 0); // private extension bit
+
+ info->info("Lame version %d", lame_get_version(gfp));
if (lame_init_params(gfp) < 0) {
info->error("LAME parameter initialization failed.");
@@ -72,8 +87,6 @@ LibLAMEWrapper::LibLAMEWrapper(Info *i)
audio_buffer[0] = new int16_t[AUDIO_BUFFER_SIZE];
audio_buffer[1] = new int16_t[AUDIO_BUFFER_SIZE];
- audio_buffer[2] = new int16_t[AUDIO_BUFFER_SIZE];
- audio_buffer[3] = new int16_t[AUDIO_BUFFER_SIZE];
// And now for the dv decoder!
decoder = NULL;
@@ -85,8 +98,6 @@ LibLAMEWrapper::~LibLAMEWrapper()
delete audio_buffer[0];
delete audio_buffer[1];
- delete audio_buffer[2];
- delete audio_buffer[3];
}
Frame *LibLAMEWrapper::encode(Frame *dvframe)
@@ -104,66 +115,53 @@ Frame *LibLAMEWrapper::encode(Frame *dvframe)
decoder->num_dif_seqs = 12;
}
- // See
- // http://www.koders.com/cpp/fidE614E999154E2B4A813DA272C4421633063C78CA.aspx
- // line 769
-
/**
* Decode audio using libdv
*/
- // int n, i;
- // int16_t* s = ( int16_t * ) sound;
-
dv_decode_full_audio( decoder, dvframe->data, audio_buffer );
- /*
- memset(audio_buffer[0], 0, sizeof(audio_buffer[0]));
- memset(audio_buffer[1], 0, sizeof(audio_buffer[1]));
- */
- /*
- for ( n = 0; n < SAMPLES; ++n )
- for ( i = 0; i < CHANNELS; i++ )
- *s++ = audio_buffer[ i ][ n ];
- */
-
-/*
- * input pcm data, output (maybe) mp3 frames.
- * This routine handles all buffering, resampling and filtering for you.
- *
- * The required mp3buf_size can be computed from num_samples,
- * samplerate and encoding rate, but here is a worst case estimate:
- *
- * return code number of bytes output in mp3buffer. can be 0
- * if return code = -1: mp3buffer was too small
- *
- * mp3buf_size in bytes = 1.25*num_samples + 7200
- *
- * I think a tighter bound could be: (mt, March 2000)
- * MPEG1:
- * num_samples*(bitrate/8)/samplerate + 4*1152*(bitrate/8)/samplerate + 512
- * MPEG2:
- * num_samples*(bitrate/8)/samplerate + 4*576*(bitrate/8)/samplerate + 256
- *
- * but test first if you use that!
- *
- * set mp3buf_size = 0 and LAME will not check if mp3buf_size is
- * large enough.
- *
- * NOTE:
- * if gfp->num_channels=2, but gfp->mode = 3 (mono), the L & R channels
- * will be averaged into the L channel before encoding only the L channel
- * This will overwrite the data in buffer_l[] and buffer_r[].
- *
-*/
+ /**
+ * input pcm data, output (maybe) mp3 frames.
+ * This routine handles all buffering, resampling and filtering for you.
+ *
+ * The required mp3buf_size can be computed from num_samples,
+ * samplerate and encoding rate, but here is a worst case estimate:
+ *
+ * return code number of bytes output in mp3buffer. can be 0
+ * if return code = -1: mp3buffer was too small
+ *
+ * mp3buf_size in bytes = 1.25*num_samples + 7200
+ *
+ * I think a tighter bound could be: (mt, March 2000)
+ * MPEG1:
+ * num_samples*(bitrate/8)/samplerate + 4*1152*(bitrate/8)/samplerate + 512
+ * MPEG2:
+ * num_samples*(bitrate/8)/samplerate + 4*576*(bitrate/8)/samplerate + 256
+ *
+ * but test first if you use that!
+ *
+ * set mp3buf_size = 0 and LAME will not check if mp3buf_size is
+ * large enough.
+ *
+ * NOTE:
+ * if gfp->num_channels=2, but gfp->mode = 3 (mono), the L & R channels
+ * will be averaged into the L channel before encoding only the L channel
+ * This will overwrite the data in buffer_l[] and buffer_r[].
+ *
+ */
Frame* audio_frame = new Frame(NULL, (int)(1.25 * SAMPLES + 7200));
- const short int *buffer_l = audio_buffer[0]; // PCM data for left channel
- const short int *buffer_r = audio_buffer[1]; // PCM data for right channel
+ const short int *buffer_l = audio_buffer[0]; // PCM data for left channel
+ const short int *buffer_r = audio_buffer[1]; // PCM data for right channel
const int nsamples = SAMPLES; // number of samples per channel
unsigned char* mp3buf = audio_frame->data; // pointer to encoded MP3 stream
const int mp3buf_size = audio_frame->size; // number of valid octets in this
- int val = lame_encode_buffer(gfp, buffer_l, buffer_r, nsamples, mp3buf, mp3buf_size);
+ int val;
+ val = lame_encode_buffer(gfp, buffer_l, buffer_r, nsamples, mp3buf, mp3buf_size);
+ // val = lame_encode_mp3_frame(gfp, buffer_l, buffer_r, mp3buf, mp3buf_size);
+
+ info->info("Framenr: %d", lame_get_frameNum(gfp));
if(val < 0) {
switch(val) {
@@ -185,29 +183,6 @@ Frame *LibLAMEWrapper::encode(Frame *dvframe)
}
}
- /*
- val = lame_encode_flush(gfp, mp3buf, val);
-
- if(val < 0) {
- switch(val) {
- case -1: // mp3buf was too small
- info->error("Lame encoding failed (during flush), mp3buf was too small.");
- break;
- case -2: // malloc() problem
- info->error("Lame encoding failed (during flush), due to malloc() problem.");
- break;
- case -3: // lame_init_params() not called
- info->error("Lame encoding failed (during flush), lame_init_params() not called.");
- break;
- case -4: // psycho acoustic problems
- info->error("Lame encoding failed (during flush), due to psycho acoustic problems.");
- break;
- default:
- info->error("Lame encoding failed (during flush), due to unknown error.");
- break;
- }
- }
- */
audio_frame->size = val;
return audio_frame;