Skip to content

Commit

Permalink
stereo to mono conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaji Khan committed Feb 26, 2024
1 parent 46b7d07 commit 51cbffb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
1 change: 0 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions app/src/main/java/com/shajikhan/ladspa/amprack/AudioDecoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ float[] decode (FileDescriptor fileDescriptor, String mimeType, int _sampleRate)
extractor.setDataSource(fileDescriptor);
float scaleFactor = 48000 / sampleRate ;
MediaFormat format = extractor.getTrackFormat(0);
int channels = format.getInteger(MediaFormat.KEY_CHANNEL_COUNT);
String mime = format.getString(MediaFormat.KEY_MIME);
Log.d(TAG, String.format ("mimetype: %s", mimeType));
if (_sampleRate != -1) {
Expand Down Expand Up @@ -203,6 +204,16 @@ float[] decode (FileDescriptor fileDescriptor, String mimeType, int _sampleRate)
Log.i(TAG, "decode: returning " +
String.format("%d audio samples", decoded.length));

if (channels > 1) {
Log.d(TAG, String.format ("channels: %d, converting to mono", channels));
float[] mono = new float [(decoded.length/channels) + 1];
for (int i = 0, k = 0 ; i < decoded.length ; i += channels, k ++) {
mono [k] = decoded [i];
}

decoded = mono;
}

if (sampleRate == 48000)
return decoded;

Expand Down

0 comments on commit 51cbffb

Please sign in to comment.