Теперь это работает. Я пытаюсь изменить высоту звука и темп с помощью Superpowered SDK. Я пытался извлечь mp3-файл с устройства хранения телефона. Я использую superpowered-ndk-example для выполнения моя работа. Ниже приведен пример кода.
В методе onCreate
this.binding.setPlaying(playing);
// Get the device's sample rate and buffer size to enable low-latency Android audio output, if available.
Pair<Integer, Integer> deviceAudioInfo = getDeviceAudioInfo();
Integer sampleRate = deviceAudioInfo.first;
Integer bufferSize = deviceAudioInfo.second;
Pair<Integer, Integer> trackLocationInfo = getTrackLocationInfo();
Integer fileOffset = trackLocationInfo.first;
Integer fileLength = trackLocationInfo.second;
String pat = "/storage/emulated/0/rec.wav";
// Arguments: path to the APK file, offset and length of the two resource files, sample rate, audio buffer size.
// this code works with assets
SuperpoweredExample(sampleRate, bufferSize, getPackageResourcePath(), fileOffset, fileLength);
//this code works for storage devices
SuperpoweredExample(sampleRate, bufferSize, pat, fileOffset, fileLength);
setupViews();
необходимые методы
private void setupViews() {
binding.btnPlayPause.setOnClickListener((view) -> {
setPlaying(!playing);
});
binding.sbPitch.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
onPitchChanged(progress - 12);
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
binding.sbTrackProgress.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
seekTo(progress);
if (progress == seekBar.getMax()) {
setPlaying(!playing);
}
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
seekTo(seekBar.getProgress() / 100.0f);
}
});
binding.radioGroup.check(binding.rbNormalTime.getId());
binding.radioGroup.setOnCheckedChangeListener((group, checkedId) -> {
switch (checkedId) {
case R.id.rb_slow_down:
onTempoSelected(TEMPO_HALF);
break;
case R.id.rb_normal_time:
onTempoSelected(TEMPO_NORMAL);
break;
case R.id.rb_speed_up:
onTempoSelected(TEMPO_DOUBLE);
break;
default:
onTempoSelected(TEMPO_NORMAL);
break;
}
});
}
private void setPlaying(boolean playing) {
this.playing = playing;
this.binding.setPlaying(this.playing);
onPlayPause(this.playing);
}
private Pair<Integer, Integer> getDeviceAudioInfo() {
String samplerateString;
String buffersizeString;
AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
samplerateString = audioManager.getProperty(AudioManager.PROPERTY_OUTPUT_SAMPLE_RATE);
buffersizeString = audioManager.getProperty(AudioManager.PROPERTY_OUTPUT_FRAMES_PER_BUFFER);
if (samplerateString == null) samplerateString = "44100";
if (buffersizeString == null) buffersizeString = "512";
return new Pair<>(Integer.parseInt(samplerateString), Integer.parseInt(buffersizeString));
}
private Pair<Integer, Integer> getTrackLocationInfo() {
AssetFileDescriptor fd;
Pair<Integer, Integer> trackLocationInfo = null;
try {
fd = getTrackAsset();
int fileOffset = (int) fd.getStartOffset();
int fileLength = (int) fd.getLength();
trackLocationInfo = new Pair<>(fileOffset, fileLength);
} catch (IOException e) {
e.printStackTrace();
}
return trackLocationInfo;
}
private AssetFileDescriptor getTrackAsset() throws IOException {
return getAssets().openFd("kal.mp3");
}
private native void SuperpoweredExample(int samplerate, int buffersize, String apkPath,
int fileOffset, int fileLength);
private native void onPlayPause(boolean play);
private native void seekTo(double positionPercent);
private native void onPitchChanged(int pitchValue);
private native void onTempoSelected(int tempoValue);
public native String stringFromJNI();
Этот нативный метод используется в файле SuperpoweredExample.cpp. В этом изменяется только одна вещь, чем this
изменить player->open(path, fileOffset, fileLength);
на player->open(path);
Работает для изменения высоты и тампа.