EmErrorCode LameEncoder::OpenOutput(const std::string& path) { m_OutputFile = ::fopen(path.c_str(), "wb+"); if (m_OutputFile == nullptr) return ErrorCode::EncoderFailedToOpen; // init lame m_gfp = ::lame_init(); ::lame_set_quality(m_gfp, m_Quality.userVal); ::lame_set_brate(m_gfp, m_BitRate.enumedVal[m_BitRate.userChoice]); ::lame_set_mode(m_gfp, ::JOINT_STEREO); ::lame_set_findReplayGain(m_gfp, m_ReplayGain.userChoice ? 1 : 0); ::lame_set_asm_optimizations(m_gfp, MMX, 1); ::lame_set_asm_optimizations(m_gfp, SSE, 1); if (m_MediaTag != nullptr) { lame_set_write_id3tag_automatic(m_gfp, 1); id3tag_init(m_gfp); id3tag_v2_only(m_gfp); id3tag_set_title(m_gfp, m_MediaTag->title.c_str()); id3tag_set_artist(m_gfp, m_MediaTag->artist.c_str()); id3tag_set_album(m_gfp, m_MediaTag->album.c_str()); id3tag_set_comment(m_gfp, m_MediaTag->comment.c_str()); id3tag_set_genre(m_gfp, m_MediaTag->genre.c_str()); id3tag_set_year(m_gfp, scx::NumToStr(m_MediaTag->year).c_str()); id3tag_set_track(m_gfp, scx::NumToStr(m_MediaTag->track).c_str()); } int ret = ::lame_init_params(m_gfp); if (ret < 0) return ErrorCode::EncoderFailedToInit; return ErrorCode::Ok; }
static int set_id3tag(lame_global_flags* gfp, int type, char const* str) { switch (type) { case 'a': return id3tag_set_artist(gfp, str), 0; case 't': return id3tag_set_title(gfp, str), 0; case 'l': return id3tag_set_album(gfp, str), 0; case 'g': return id3tag_set_genre(gfp, str); case 'c': return id3tag_set_comment(gfp, str), 0; case 'n': return id3tag_set_track(gfp, str); case 'y': return id3tag_set_year(gfp, str), 0; case 'v': return id3tag_set_fieldvalue(gfp, str); } return 0; }
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; }
static switch_status_t shout_file_set_string(switch_file_handle_t *handle, switch_audio_col_t col, const char *string) { shout_context_t *context = handle->private_info; switch_status_t status = SWITCH_STATUS_FALSE; if (!context->shout) { switch (col) { case SWITCH_AUDIO_COL_STR_TITLE: id3tag_set_title(context->gfp, string); break; case SWITCH_AUDIO_COL_STR_COMMENT: id3tag_set_comment(context->gfp, string); break; case SWITCH_AUDIO_COL_STR_ARTIST: id3tag_set_artist(context->gfp, string); break; case SWITCH_AUDIO_COL_STR_DATE: id3tag_set_year(context->gfp, string); break; case SWITCH_AUDIO_COL_STR_SOFTWARE: break; id3tag_set_album(context->gfp, string); case SWITCH_AUDIO_COL_STR_COPYRIGHT: id3tag_set_genre(context->gfp, string); break; default: switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Value Ignored %d, %s\n", col, string); break; } return status; } switch (col) { case SWITCH_AUDIO_COL_STR_TITLE: if (shout_set_name(context->shout, string) == SHOUTERR_SUCCESS) { status = SWITCH_STATUS_SUCCESS; } else { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error setting name: %s\n", shout_get_error(context->shout)); } break; case SWITCH_AUDIO_COL_STR_COMMENT: if (shout_set_url(context->shout, string) == SHOUTERR_SUCCESS) { status = SWITCH_STATUS_SUCCESS; } else { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error setting name: %s\n", shout_get_error(context->shout)); } break; case SWITCH_AUDIO_COL_STR_ARTIST: if (shout_set_description(context->shout, string) == SHOUTERR_SUCCESS) { status = SWITCH_STATUS_SUCCESS; } else { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error setting name: %s\n", shout_get_error(context->shout)); } break; default: switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Value Ignored %d, %s\n", col, string); break; } return status; }
lame_global_flags* simple_lame_lib_init( JNIEnv* env, jint inSamplerate, jint outChannel, jint outSamplerate, jint outBitrate, jint quality, jstring id3tagTitle, jstring id3tagArtist, jstring id3tagAlbum, jstring id3tagYear, jstring id3tagComment) { if (local_log) { __android_log_print(ANDROID_LOG_VERBOSE, TAG, "Start lame init."); } lame_global_flags* glf = lame_init(); lame_set_in_samplerate(glf, inSamplerate); lame_set_num_channels(glf, outChannel); lame_set_out_samplerate(glf, outSamplerate); lame_set_brate(glf, outBitrate); lame_set_quality(glf, quality); const jchar* title = NULL; const jchar* artist = NULL; const jchar* album = NULL; const jchar* year = NULL; const jchar* comment = NULL; if (id3tagTitle) { title = (*env)->GetStringChars(env, id3tagTitle, NULL); } if (id3tagArtist) { artist = (*env)->GetStringChars(env, id3tagArtist, NULL); } if (id3tagAlbum) { album = (*env)->GetStringChars(env, id3tagAlbum, NULL); } if (id3tagYear) { year = (*env)->GetStringChars(env, id3tagYear, NULL); } if (id3tagComment) { comment = (*env)->GetStringChars(env, id3tagComment, NULL); } if (title || artist || album || year || comment) { id3tag_init(glf); if (title) { id3tag_set_title(glf, (const char*)title); (*env)->ReleaseStringChars(env, id3tagTitle, title); } if (artist) { id3tag_set_artist(glf, (const char*)artist); (*env)->ReleaseStringChars(env, id3tagArtist, artist); } if (album) { id3tag_set_album(glf, (const char*)album); (*env)->ReleaseStringChars(env, id3tagAlbum, album); } if (year) { id3tag_set_year(glf, (const char*)year); (*env)->ReleaseStringChars(env, id3tagYear, year); } if (comment) { id3tag_set_comment(glf, (const char*)comment); (*env)->ReleaseStringChars(env, id3tagComment, comment); } } lame_init_params(glf); if (local_log) { __android_log_print(ANDROID_LOG_VERBOSE, TAG, "End lame init."); } return glf; }
bool MP3Writer::begin() { if(!is_setup) { RX_ERROR(MP3_WRERR_NOT_SETUP); return false; } if(is_started) { return false; } int samplerate = 0; MPEG_mode mode = MONO; if(config.mode == MP3_WR_MODE_STEREO) { mode = STEREO; } else { mode = MONO; } samplerate = config.samplerateToInt(); lame_flags = lame_init(); if(!lame_flags) { RX_ERROR(MP3_WRERR_LAME_INIT); return false; } lame_set_num_channels(lame_flags, config.num_channels); lame_set_in_samplerate(lame_flags, samplerate); lame_set_brate(lame_flags, config.bitrate); lame_set_mode(lame_flags, mode); lame_set_quality(lame_flags, config.quality); if(config.hasID3()) { id3tag_init(lame_flags); } if(config.id3_title.size()) { id3tag_set_title(lame_flags, config.id3_title.c_str()); } if(config.id3_artist.size()) { id3tag_set_artist(lame_flags, config.id3_artist.c_str()); } if(config.id3_album.size()) { id3tag_set_album(lame_flags, config.id3_album.c_str()); } if(config.id3_year.size()) { id3tag_set_year(lame_flags, config.id3_year.c_str()); } if(config.id3_comment.size()) { id3tag_set_comment(lame_flags, config.id3_comment.c_str()); } if(config.id3_track.size()) { int r = id3tag_set_track(lame_flags, config.id3_track.c_str()); if(r == -1) { RX_ERROR(MP3_WRERR_ID3_TRACK_OOR); } else if(r == -2) { RX_ERROR(MP3_WRERR_ID3_TRACK_INVALID); } } if(lame_init_params(lame_flags) < 0) { RX_ERROR(MP3_WRERR_LAME_PARAMS); return false; } is_started = true; config.cb_open(config.user); return true; }