2013-12-13 2 views
1

Lame을 사용할 때 어려운 문제가 발생하여 도움이 필요합니다. 디버깅을위한 장치가 삼성 Galaxy s2 (OS android 4.0)입니다. LAME (버전 3.9.9.5)을 사용하고 있습니다. 3ga 파일을 녹음하고 가져 와서 LAME을 사용하여 mp3 파일로 구성한 후 .wav 파일로 이름을 바꿉니다. 나는 mp3 파일을 가지고 있지만 올바른 파일 (zet zet) 및 원본 wav 파일보다 shoter를 재생할 때. 이것은 내 mp3ConvertFIle입니다 : `public static final int NUM_CHANNELS = 2; // public static final int SAMPLE_RATE = 16000; 공공 정적 final int SAMPLE_RATE = 48000; 공공 정적 final int BITRATE = 128; 공공 정적 final int MODE = 1; 공공 정적 final int QUALITY = 2; static { System.loadLibrary ("mp3lame"); }wmp에서 .mp3을 android의 Lame 라이브러리를 사용하여 변환하십시오.

private native void initEncoder(int numChannels, int sampleRate, 
     int bitRate, int mode, int quality); 

private native void destroyEncoder(); 

private native int encodeFile(String sourcePath, String targetPath); 

private native int wavToMp3(String src, String dest, String quality, 
     String bitrate); 

/** 
* Convert a WAV file to MP3 
* 
* @param src 
*   path to WAV file 
* @param dest 
*   path to MP3 file 
*/ 
public void convert(String src, String dest) { 
    initEncoder(NUM_CHANNELS, SAMPLE_RATE, BITRATE, MODE, QUALITY); 
    encodeFile(src, dest); 
}` 

이 내 wrapper.c 파일입니다

#include "stdio.h" 
#include "stdlib.h" 
#include "jni.h" 
#include "android/log.h" 
#include "libmp3lame/lame.h" 
#define BUFFER_SIZE 8192 
#define be_short(s) ((short) ((unsigned short) (s) << 8) | ((unsigned short) (s) >> 8)) 
#define LOG_TAG "LAME ENCODER" 
#define LOGD(format, args...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, format, ##args); 

lame_t lame; 

int read_samples(FILE *input_file, short *input) { 
    int nb_read; 
    nb_read = fread(input, 1, sizeof(short), input_file)/sizeof(short); 

    int i = 0; 
    while (i < nb_read) { 
     input[i] = be_short(input[i]); 
     i++; 
    } 

    return nb_read; 
} 

void Java_com_dao_smsring_utility_MP3Converter_initEncoder(JNIEnv *env, 
     jobject jobj, jint in_num_channels, jint in_samplerate, jint in_brate, 
     jint in_mode, jint in_quality) { 
    lame = lame_init(); 
    lame_set_num_channels(lame, in_num_channels); 
    lame_set_in_samplerate(lame, in_samplerate); 
    lame_set_out_samplerate(lame, 48000); 
    lame_set_brate(lame, in_brate); 
    lame_set_mode(lame, in_mode); 
    lame_set_quality(lame, in_quality); 
    int res = lame_init_params(lame); 
    LOGD("version of %s is",get_lame_version()); 
} 

void Java_com_dao_smsring_utility_MP3Converter_destroyEncoder(
     JNIEnv *env, jobject jobj) { 
    int res = lame_close(lame); 
} 


void Java_com_dao_smsring_utility_MP3Converter_encodeFile(JNIEnv *env, 
     jobject jobj, jstring in_source_path, jstring in_target_path) { 
    const char *source_path, *target_path; 
    source_path = (*env)->GetStringUTFChars(env, in_source_path, NULL); 
    target_path = (*env)->GetStringUTFChars(env, in_target_path, NULL); 

    FILE *input_file, *output_file; 
    input_file = fopen(source_path, "rb"); 
    output_file = fopen(target_path, "wb"); 

    short input[BUFFER_SIZE]; 
    char output[BUFFER_SIZE]; 
    int nb_read = 0; 
    int nb_write = 0; 
    int nb_total = 0; 

    while (nb_read = read_samples(input_file, input)) { 
     nb_write = lame_encode_buffer(lame, input, input, nb_read, output, 
       BUFFER_SIZE); 
     fwrite(output, nb_write, 1, output_file); 
     nb_total += nb_write; 
    } 
    LOGD(" total read %d is",nb_total); 
    nb_write = lame_encode_flush(lame, output, BUFFER_SIZE); 
// fwrite(output, nb_write, 1, output_file); 

    LOGD(" total write %d is",nb_write); 
    lame_mp3_tags_fid(lame,output_file); 

    lame_close(lame); 
    fclose(input_file); 
    fclose(output_file); 
} 

내가 왜 몰라? 도와주세요, 제발. 대단히 감사합니다. 내 Gmail : [email protected] 지원 받기를 바랍니다.

답변

1

wav 파일을 녹음하려면 pga 오디오 코덱으로 3ga로 캡처하십시오. amr을 사용하고 있습니다.

난 당신이 link

+0

친애을 추천 할 것입니다 안드로이드에서 절름발이를 사용하려면, 당신의 의견을 주셔서 감사합니다, 내 문제가 캡처 단계에있다 생각한다. 나는 그것을 점검 할 것이다. 대단히 감사합니다. – vidp