bool KRecExport_MP3::initialize( const QString &filename ) { kdDebug( 60005 ) << k_funcinfo << endl; if ( !_file && !( bits()!=16 && channels()!=2 && KMessageBox::warningContinueCancel( KRecGlobal::the()->mainWidget(), i18n( "At this time MP3-Export only supports files in stereo and 16bit." ) ) == KMessageBox::Cancel ) ) { KMessageBox::information( KRecGlobal::the()->mainWidget(), i18n( "Please note that this plugin takes its qualitysettings from" \ " the corresponding section of the Audio CDs Control Center module" \ " configuration. Make use" \ " of the Control Center to configure these settings." ), i18n( "Quality Configuration" ), "qualityinfo_mp3" ); _file = new QFile( filename ); if ( _file->open( IO_Raw|IO_WriteOnly ) ) { if ( ! init_done ) { gfp = lame_init(); setLameParameters(); if ( write_id3 ) { id3tag_init( gfp ); id3tag_v1_only ( gfp ); id3tag_set_album ( gfp, "" ); id3tag_set_artist ( gfp, "" ); id3tag_set_title ( gfp, "" ); id3tag_set_comment( gfp, "krec" ); } /// Set input parameters right lame_set_in_samplerate( gfp, this->samplingRate() ); lame_set_num_channels( gfp, this->channels() ); lame_init_params( gfp ); } if ( _file->size() >= 128 ) _file->at( _file->size() - 128 ); else _file->at( _file->size() ); } else return false; return true; } else return false; }
/* initialize the lame library */ static int mp3write_tilde_lame_init(t_mp3write *x) { time_t now; int ret; x->lgfp = lame_init(); /* set default parameters for now */ #ifndef UNIX /* load lame_enc.dll library */ HINSTANCE dll; dll=LoadLibrary("lame_enc.dll"); if(dll==NULL) { error("mp3write~: error loading lame_enc.dll"); closesocket(x->x_fd); x->x_fd = -1; post("mp3write~: connection closed"); return -1; } #endif { const char *lameVersion = get_lame_version(); post( "mp3write~ : using lame version : %s", lameVersion ); } /* setting lame parameters */ lame_set_num_channels( x->lgfp, 2); lame_set_in_samplerate( x->lgfp, sys_getsr() ); lame_set_out_samplerate( x->lgfp, x->x_samplerate ); lame_set_brate( x->lgfp, x->x_bitrate ); lame_set_mode( x->lgfp, x->x_mp3mode ); lame_set_quality( x->lgfp, x->x_mp3quality ); lame_set_emphasis( x->lgfp, 1 ); lame_set_original( x->lgfp, 1 ); lame_set_copyright( x->lgfp, 1 ); /* viva free music societies !!! */ lame_set_disable_reservoir( x->lgfp, 0 ); lame_set_padding_type( x->lgfp, PAD_NO ); ret = lame_init_params( x->lgfp ); if ( ret<0 ) { post( "mp3write~ : error : lame params initialization returned : %d", ret ); return -1; } else { x->x_lame=1; /* magic formula copied from windows dll for MPEG-I */ x->x_lamechunk = 2*1152; post( "mp3write~ : lame initialization done. (%d)", x->x_lame ); } lame_init_bitstream( x->lgfp ); /* setting tag information */ id3tag_init(x->lgfp); id3tag_v1_only(x->lgfp); id3tag_space_v1(x->lgfp); id3tag_set_artist(x->lgfp, "Pd Session"); now=time(NULL); sprintf( x->x_title, "Started at %s", ctime(&now) ); id3tag_set_title(x->lgfp, x->x_title ); return 0; }
static gint mp3_open(void) { int imp3; gfp = lame_init(); if (gfp == NULL) return 0; /* setup id3 data */ id3tag_init(gfp); if (tuple) { /* XXX write UTF-8 even though libmp3lame does id3v2.3. --yaz */ lameid3.track_name = tuple_get_str (tuple, FIELD_TITLE, NULL); id3tag_set_title(gfp, lameid3.track_name); lameid3.performer = tuple_get_str (tuple, FIELD_ARTIST, NULL); id3tag_set_artist(gfp, lameid3.performer); lameid3.album_name = tuple_get_str (tuple, FIELD_ALBUM, NULL); id3tag_set_album(gfp, lameid3.album_name); lameid3.genre = tuple_get_str (tuple, FIELD_GENRE, NULL); id3tag_set_genre(gfp, lameid3.genre); lameid3.year = str_printf ("%d", tuple_get_int (tuple, FIELD_YEAR, NULL)); id3tag_set_year(gfp, lameid3.year); lameid3.track_number = str_printf ("%d", tuple_get_int (tuple, FIELD_TRACK_NUMBER, NULL)); id3tag_set_track(gfp, lameid3.track_number); if (force_v2_val) { id3tag_add_v2(gfp); } if (only_v1_val) { id3tag_v1_only(gfp); } if (only_v2_val) { id3tag_v2_only(gfp); } } /* input stream description */ lame_set_in_samplerate(gfp, input.frequency); lame_set_num_channels(gfp, input.channels); /* Maybe implement this? */ /* lame_set_scale(lame_global_flags *, float); */ lame_set_out_samplerate(gfp, out_samplerate_val); /* general control parameters */ lame_set_bWriteVbrTag(gfp, toggle_xing_val); lame_set_quality(gfp, algo_quality_val); if (audio_mode_val != 4) { AUDDBG("set mode to %d\n", audio_mode_val); lame_set_mode(gfp, audio_mode_val); } lame_set_errorf(gfp, lame_debugf); lame_set_debugf(gfp, lame_debugf); lame_set_msgf(gfp, lame_debugf); if (enc_toggle_val == 0 && vbr_on == 0) lame_set_brate(gfp, bitrate_val); else if (vbr_on == 0) lame_set_compression_ratio(gfp, compression_val); /* frame params */ lame_set_copyright(gfp, mark_copyright_val); lame_set_original(gfp, mark_original_val); lame_set_error_protection(gfp, error_protect_val); lame_set_strict_ISO(gfp, enforce_iso_val); if (vbr_on != 0) { if (vbr_type == 0) lame_set_VBR(gfp, 2); else lame_set_VBR(gfp, 3); lame_set_VBR_q(gfp, vbr_quality_val); lame_set_VBR_mean_bitrate_kbps(gfp, abr_val); lame_set_VBR_min_bitrate_kbps(gfp, vbr_min_val); lame_set_VBR_max_bitrate_kbps(gfp, vbr_max_val); lame_set_VBR_hard_min(gfp, enforce_min_val); } /* not to write id3 tag automatically. */ lame_set_write_id3tag_automatic(gfp, 0); if (lame_init_params(gfp) == -1) return 0; /* write id3v2 header */ imp3 = lame_get_id3v2_tag(gfp, encbuffer, sizeof(encbuffer)); if (imp3 > 0) { write_output(encbuffer, imp3); id3v2_size = imp3; } else { id3v2_size = 0; } write_buffer = NULL; write_buffer_size = 0; return 1; }