summaryrefslogtreecommitdiff
path: root/src/liblame_wrapper.cc
diff options
context:
space:
mode:
authordeva <deva>2005-07-05 23:15:16 +0000
committerdeva <deva>2005-07-05 23:15:16 +0000
commit26f488caef0e88e1995b6141e17e3595a6cf34dc (patch)
tree4d1ae92031f5b1f04900882d9888d5c474312c15 /src/liblame_wrapper.cc
parent91e9b782cc9ea0252ab2b211b15e8da4a3043d5f (diff)
*** empty log message ***
Diffstat (limited to 'src/liblame_wrapper.cc')
-rw-r--r--src/liblame_wrapper.cc78
1 files changed, 67 insertions, 11 deletions
diff --git a/src/liblame_wrapper.cc b/src/liblame_wrapper.cc
index 751c41b..7af9b68 100644
--- a/src/liblame_wrapper.cc
+++ b/src/liblame_wrapper.cc
@@ -31,6 +31,9 @@
/*
* $Log$
+ * Revision 1.2 2005/07/05 23:15:16 deva
+ * *** empty log message ***
+ *
* Revision 1.1 2005/07/02 11:39:51 deva
* Added some audiocode.
* Moved libfame code out of mov_encoder
@@ -45,25 +48,45 @@ LibLAMEWrapper::LibLAMEWrapper(Info *i)
info = i;
// Init library.
- lamegf = lame_init();
- if(!lamegf) {
+ if( (gfp = lame_init()) == NULL) {
info->error("LAME initialization failed (due to malloc failure!)");
+ return;
}
- lame_init_params(lamegf);
+ lame_set_in_samplerate(gfp, SAMPLE_RATE);
+ lame_set_out_samplerate(gfp, SAMPLE_RATE);
+ lame_set_num_channels(gfp, CHANNELS);
+ // lame 3.91 dies on quality != 5
+ lame_set_quality(gfp, 5);
+ // lame 3.91 doesn't work in mono
+ lame_set_mode(gfp, STEREO);
+ lame_set_brate(gfp, 192);
+ lame_set_strict_ISO(gfp, 1);
+
+ if (lame_init_params(gfp) < 0) {
+ info->error("LAME parameter initialization failed.");
+ return;
+ }
- decoder = NULL;
+ lame_init_bitstream(gfp);
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;
}
LibLAMEWrapper::~LibLAMEWrapper()
{
+ lame_close(gfp);
+
delete audio_buffer[0];
delete audio_buffer[1];
-
+ delete audio_buffer[2];
+ delete audio_buffer[3];
}
Frame *LibLAMEWrapper::encode(Frame *dvframe)
@@ -90,12 +113,17 @@ Frame *LibLAMEWrapper::encode(Frame *dvframe)
*/
// int n, i;
// int16_t* s = ( int16_t * ) sound;
+
dv_decode_full_audio( decoder, dvframe->data, audio_buffer );
/*
- for ( n = 0; n < SAMPLES; ++n )
- for ( i = 0; i < CHANNELS; i++ )
- *s++ = audio_buffer[ i ][ n ];
- */
+ 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.
@@ -104,6 +132,9 @@ Frame *LibLAMEWrapper::encode(Frame *dvframe)
* 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)
@@ -127,12 +158,12 @@ Frame *LibLAMEWrapper::encode(Frame *dvframe)
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[0]; // PCM data for right 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(lamegf, buffer_l, buffer_r, nsamples, mp3buf, mp3buf_size);
+ int val = lame_encode_buffer(gfp, buffer_l, buffer_r, nsamples, mp3buf, mp3buf_size);
if(val < 0) {
switch(val) {
@@ -154,5 +185,30 @@ 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;
}