我使用Lame時遇到了一個難題,我需要你的幫助。 我正在使用LAME(版本3.9.9.5)我的設備進行調試是三星銀河s2(操作系統的Android 4.0)。 我錄製並獲得3ga文件,然後重命名爲.wav文件,然後使用LAME配置爲mp3文件。 我得到了mp3文件,但當我播放它不正確的文件(只是zet zet)和比原始的wav文件的射手。 這是我的mp3ConvertFIle: `public static final int NUM_CHANNELS = 2; // public static final int SAMPLE_RATE = 16000; public static final int SAMPLE_RATE = 48000; public static final int BITRATE = 128; public static final int MODE = 1; public static final int QUALITY = 2; static靜態{System.loadLibrary(「mp3lame」); }從wav轉換.mp3使用Lame庫在Android
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] 希望能得到您的支持
親愛的,謝謝你的評論,我認爲我的問題是在捕捉階段。 我要檢查它。 非常感謝你, – vidp