Skip to content

Commit

Permalink
resample loops correctly according to current sample
Browse files Browse the repository at this point in the history
rate of the engine
  • Loading branch information
Shaji Khan committed Feb 28, 2024
1 parent b366b92 commit d9f015a
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/src/main/assets/lv2/liblooper.so/looper.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"-1": {"Plugin": true, "AmplifierPlugin": true, "optionalFeature": "http://lv2plug.in/ns/lv2core#hardRTCapable", "port": "_:n62c4bb580b1c42edb579f4b1e2d6cc04b8", "project": "http://lv2plug.in/ns/lv2", "http://usefulinc.com/ns/doap#license": "http://opensource.org/licenses/isc", "http://usefulinc.com/ns/doap#name": "Looper Plugin", "pluginName": "Looper"}, "0": {"InputPort": true, "ControlPort": true, "default": "0.0", "index": 0, "maximum": 1, "minimum": 0, "name": "Toggle Record", "symbol": "toggle_rec"}, "1": {"InputPort": true, "ControlPort": true, "default": "0.0", "index": 1, "maximum": 1, "minimum": 0, "name": "Toggle Playback", "symbol": "toggle_play"}, "3": {"InputPort": true, "ControlPort": true, "default": "1.0", "index": 3, "maximum": 6, "minimum": 0, "name": "Gain", "symbol": "gain"}, "4": {"InputPort": true, "ControlPort": true, "default": 1024, "index": 4, "maximum": 2048, "minimum": 128, "name": "Buffer Size", "symbol": "buffer_size_control"}, "5": {"InputPort": true, "ControlPort": true, "default": 0, "index": 5, "maximum": 25, "minimum": 0, "step": 0.5, "name": "Start", "symbol": "start"}, "6": {"InputPort": true, "ControlPort": true, "step": 0.5, "default": 100, "index": 6, "maximum": 100, "minimum": 75, "name": "End", "symbol": "end"}, "7": {"AudioPort": true, "InputPort": true, "index": 7, "name": "In", "symbol": "input"}, "8": {"AudioPort": true, "OutputPort": true, "index": 8, "name": "Out", "symbol": "output"}}
{"-1": {"Plugin": true, "AmplifierPlugin": true, "optionalFeature": "http://lv2plug.in/ns/lv2core#hardRTCapable", "port": "_:n62c4bb580b1c42edb579f4b1e2d6cc04b8", "project": "http://lv2plug.in/ns/lv2", "http://usefulinc.com/ns/doap#license": "http://opensource.org/licenses/isc", "http://usefulinc.com/ns/doap#name": "Looper Plugin", "pluginName": "Looper"}, "0": {"InputPort": true, "ControlPort": true, "default": "0.0", "index": 0, "maximum": 1, "minimum": 0, "name": "Toggle Record", "symbol": "toggle_rec"}, "1": {"InputPort": true, "ControlPort": true, "default": "0.0", "index": 1, "maximum": 1, "minimum": 0, "name": "Toggle Playback", "symbol": "toggle_play"}, "3": {"InputPort": true, "ControlPort": true, "default": "1.0", "index": 3, "maximum": 6, "minimum": 0, "name": "Gain", "symbol": "gain"}, "4": {"InputPort": true, "ControlPort": true, "default": 1024, "index": 4, "maximum": 2048, "minimum": 128, "name": "Buffer Size", "symbol": "buffer_size_control"}, "5": {"InputPort": true, "ControlPort": true, "default": 0, "index": 5, "maximum": 25, "minimum": 0, "step": 0.5, "name": "✂ Start", "symbol": "start"}, "6": {"InputPort": true, "ControlPort": true, "step": 0.5, "default": 100, "index": 6, "maximum": 100, "minimum": 75, "name": "✂ End", "symbol": "end"}, "7": {"AudioPort": true, "InputPort": true, "index": 7, "name": "In", "symbol": "input"}, "8": {"AudioPort": true, "OutputPort": true, "index": 8, "name": "Out", "symbol": "output"}}
12 changes: 8 additions & 4 deletions app/src/main/java/com/shajikhan/ladspa/amprack/AudioDecoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ float[] decode (FileDescriptor fileDescriptor, String mimeType, int _sampleRate)
int channels = format.getInteger(MediaFormat.KEY_CHANNEL_COUNT);
String mime = format.getString(MediaFormat.KEY_MIME);
Log.d(TAG, String.format ("mimetype: %s", mimeType));
codec = MediaCodec.createDecoderByType(mime);
/*
if (_sampleRate != -1) {
codec = MediaCodec.createEncoderByType(mimeType);
Log.d(TAG, String.format ("converting to: %s [%d]", mimeType, sampleRate));
Expand All @@ -104,9 +106,11 @@ float[] decode (FileDescriptor fileDescriptor, String mimeType, int _sampleRate)
Log.d(TAG, String.format ("converting to: %s [%d]", mime, sampleRate));
}
*/

Log.i(TAG, "decode: detected format " + mime);
if (_sampleRate != -1)
format.setInteger(MediaFormat.KEY_SAMPLE_RATE, sampleRate);
// if (_sampleRate != -1)
// format.setInteger(MediaFormat.KEY_SAMPLE_RATE, sampleRate);

codec.configure(format, null /* surface */, null /* crypto */, 0 /* flags */);
codec.start();
Expand Down Expand Up @@ -217,7 +221,7 @@ float[] decode (FileDescriptor fileDescriptor, String mimeType, int _sampleRate)
decoded = mono;
}

if (sampleRate == 48000)
if (sampleRate == _sampleRate)
return decoded;

ByteBuffer bb = ByteBuffer.allocateDirect(decoded.length * 4);
Expand All @@ -227,7 +231,7 @@ float[] decode (FileDescriptor fileDescriptor, String mimeType, int _sampleRate)
floatBuffer.position(0);

Resampler resampler = new Resampler(true,0.1,30);
boolean result = resampler.process((double)48000.0/sampleRate,floatBuffer,true,resampled);
boolean result = resampler.process((double)_sampleRate/sampleRate,floatBuffer,true,resampled);
float [] res = new float[resampled.limit()];
// resampled.position(0);
for (int i = 0 ; i < resampled.limit(); i ++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1579,7 +1579,7 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
}

try {
float [] samples = audioDecoder.decode(data.getData(), null, -1);
float [] samples = audioDecoder.decode(data.getData(), null, AudioEngine.getSampleRate());
AudioEngine.setPluginBuffer(samples, plugin);
} catch (IOException e) {
toast(e.getMessage());
Expand Down
Binary file added app/src/main/res/drawable/dev.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit d9f015a

Please sign in to comment.