예제 #1
0
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;
}
예제 #2
0
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;
}
예제 #3
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;
}
예제 #4
0
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;
}
예제 #5
0
파일: mp3write~.c 프로젝트: Angeldude/pd
    /* 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;

}
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;
}
void lame_encoder_impl_internal::set_artist(const std::string & Artist)
{
    id3tag_set_artist(m_Lame.get(), Artist.c_str());
}
예제 #8
0
파일: MP3Writer.cpp 프로젝트: roxlu/roxlu
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;
}
예제 #9
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;
}