Closed mgood7123 closed 5 years ago
Hmm ... that's a good question. It's something that has been in the back of mind for a while now, but I haven't got around to trying it.
For a start, the intel SIMD intrinsics in FIRFilter.h will not work on ARM, so they need to be disabled. However, as long as __x86_64__ is not defined (which it won't be) I think it will just use the non-SIMD code. It just means that the FIR filter will be slow since it doesn't have any vectorization (at least until some equivalent ARM code using intrinsics is written)
With regards to the multithreading, I believe the android NDK has basic pthreads support built-in but I'm not sure how it will work.
You also need to think about installing the 3rd party libraries - libsndfile and fftw64
I think it's probably achievable, but it will be a bit of a rough ride getting there.
Unfortunately, I'm flat-out with other projects at the moment, but when I get some time I might attempt it myself.
Cheers Judd
ok
ReSampler.zip
libfftw3.so
libReSampler.so
( libsndfile
could not be built as shared so it got statically linked in instead due to it requiring PythonInterp
, and I do not know how to obtain PythonInterp
)
libsndfile/CMakeLists.txt
if (BUILD_SHARED_LIBS)
set_package_properties (PythonInterp PROPERTIES
TYPE REQUIRED
URL "www.python.org/"
DESCRIPTION "Python is a widely used high-level programming language."
PURPOSE "Required to build shared libraries"
)
endif()
libsndfile/cmake/SndFileChecks.cmake
if (BUILD_SHARED_LIBS)
find_package (PythonInterp REQUIRED)
endif()
first successful build: https://github.com/mgood7123/ReSampler/tree/721d729fa23ee4441a7e5e8b7d7dc173a098abf5
and the full Android Studio
project that builds it: https://github.com/mgood7123/libmedia/tree/24d607bc0b749959b4fd4f04091e46ca4adf45d9
test run with
extern int main(int argc, char * argv[]);
const char *argv[2];
argv[0] = "ReSampler";
argv[1] = "--help";
main(2, const_cast<char **>(argv));
V/ReSampler: usage: ReSampler -i <inputfile> [-o <outputfile>] -r <samplerate> [-b <bitformat>] [-n [<normalization factor>]]
Additional options:
--help
--version
--compiler
--sndfile-version
--listsubformats <ext>
--showDitherProfiles
--gain [<amount>]
--doubleprecision
--dither [<amount>] [--autoblank] [--ns [<ID>]] [--flat-tpdf] [--seed [<num>]] [--quantize-bits <number of bits>]
--noDelayTrim
--minphase
--flacCompression <compressionlevel>
--vorbisQuality <quality>
--noClippingProtection
--relaxedLPF
--steepLPF
--lpf-cutoff <percentage> [--lpf-transition <percentage>]
--mt
--rf64
--noPeakChunk
--noMetadata
--singleStage
--multiStage
--maxStages
--showStages
--showTempFile
--noTempFile
Application terminated.
const char *argv[9];
argv[0] = "ReSampler";
argv[1] = "-i";
argv[2] = "/sdcard/ReSampler/00001313.raw";
argv[3] = "-o";
argv[4] = "/sdcard/ReSampler/00001313_48000.raw";
argv[5] = "-r";
argv[6] = "48000";
argv[7] = "-b";
argv[8] = "16";
main(9, const_cast<char **>(argv));
V/ReSampler: 2.0.7
64-bit version
Input file: /sdcard/ReSampler/00001313.raw
Output file: /sdcard/ReSampler/00001313_48000.raw
Changing output bit format to 16
E/ReSampler: Error: Couldn't Open Input File (Format not recognised.)
and for comparison, this is the same on windows
C:\Users\konek\StudioProjects\libmedia\app\src\main\assets>C:\Users\konek\StudioProjects\libmedia\app\src\main\java\libmedia\resampler\ReSampler\x64\Release\ReSampler.exe -i 00001313.raw
-o 00001313_48000.raw -r 48000 -b 16
2.0.7 64-bit version
Input file: 00001313.raw
Output file: 00001313_48000.raw
Changing output bit format to 16
Error: Couldn't Open Input File (File contains data in an unknown format.)
C:\Users\konek\StudioProjects\libmedia\app\src\main\assets>
WINDOWS:
C:\Users\konek\StudioProjects\libmedia\app\src\main\assets>C:\Users\konek\StudioProjects\libmedia\app\src\main\java\libmedia\resampler\ReSampler\x64\Release\ReSampler.exe -i 00001313.wav
-o 00001313_48000.wav -r 48000 -b 16
2.0.7 64-bit version
Input file: 00001313.wav
Output file: 00001313_48000.wav
Changing output bit format to 16
input bit format: 16
source file channels: 2
input sample rate: 44100
output sample rate: 48000
Scanning input file for peaks ...Done
Peak input sample: 0.999969 (-0.000265 dBFS) at 0:0:1.259297
LPF transition frequency: 20045.45 Hz (90.91 %)
Conversion ratio: 1.088435 (160:147)
Writing Metadata
Converting (multi-stage) ...
99%
Clipping detected !
Adjusting gain by -0.403552 dB
Writing to output file ...
Done
Peak output sample: 1.000000 (-0.000001 dBFS)
Time=2844 ms [8.2x]
C:\Users\konek\StudioProjects\libmedia\app\src\main\assets>
ANDROID:
extern int main(int argc, char * argv[]);
const char *argv[9];
argv[0] = "ReSampler";
argv[1] = "-i";
argv[2] = "/sdcard/ReSampler/00001313.wav";
argv[3] = "-o";
argv[4] = "/sdcard/ReSampler/00001313_48000.wav";
argv[5] = "-r";
argv[6] = "48000";
argv[7] = "-b";
argv[8] = "16";
main(9, const_cast<char **>(argv));
V/ReSampler: 2.0.7
64-bit version
Input file: /sdcard/ReSampler/00001313.wav
Output file: /sdcard/ReSampler/00001313_48000.wav
Changing output bit format to 16
V/ReSampler: input bit format: 16
source file channels: 2
input sample rate: 44100
output sample rate: 48000
Scanning input file for peaks ...
V/ReSampler: Done
Peak input sample: 0.999969 (-0.000265076 dBFS) at
0:0:1.2593
V/ReSampler: LPF transition frequency: 20045.5 Hz (90.9091 %)
Conversion ratio: 1.08844 (160:147)
A/libc: C:\Users\konek\StudioProjects\libmedia\app\src\main\java\libmedia\resampler\ReSampler/FIRFilter.h:389: void FIRFilter<float>::assertAlignment() [FloatType = float]: assertion "reinterpret_cast<std::uintptr_t>(kernelphases[i]) % alignment == 0" failed
A/libc: Fatal signal 6 (SIGABRT), code -6 (SI_TKILL) in tid 10851 (edia.player.pro), pid 10851 (edia.player.pro)
Application terminated.
Looks like you made a lot of progress - well done !
With the assertAlignment() - its just trying to confirm that there is 32-byte alignment for the benefit of potential AVX instructions. Since in Android, we won't need the 32-bit alignment, you could #ifdef the alignment stuff out for android-only. (at least until we start using future neon instructions in lieu of SSE / AVX).
In regards to the raw input, that definitely won't work until I add some code to do it (on any platform). I haven't really needed it until now, but will add it. (It's not libsndfiles' fault, it's something that ReSampler needs to have added)
I will probably get to have a look at that on the weekend
ok, ill try that
also NOTE that this is considered a temporary fix, as I have had builds like this that succeed then randomly fail after a while and this appears to be related to old cmake files in particular not fully cleaning the project before building it (known as dirty building
), I have yet to confirm that this is actually what is causing it to fail sometimes
made main
reentraint,
made android output natual (no longer relies on ANDROID_OUT and ANDROID_ERR for outputting)
srconvert appears to hang between stage 1 and stage 2 in android, cause is unknown
moved to separate issues
I suspect the crashing is related to the aligned malloc not working properly on android for some reason. The alignment assertions we were getting before were probably telling us something. I'm checking it out now ...
Crashing on deallocating FIR kernel buffers when in scalar mode should be fixed now, Given that you've got it to at least compile on Android now, I'm going to close this. Good Work !
ok
Yeah, sorry about that – In this particular case, I think this was a result of using Visual Studio and hitting the ‘format selection’ function. That must have done something with the whitespace.
The thing is, I use a lot of different editors/IDEs – depending on what the OS and machine I’m using is (and I have Linux / Mac/ Windows noxes), the editor could be Windows + Visual studio, VSCode, QtCreator, CLion, or just plain old VIM etc – and they might not be set up consistently !
I guess it should be 4 spaces. I’ll see if I can clean it up
From: mgood7123 [mailto:notifications@github.com] Sent: Sunday, July 7, 2019 8:42 PM To: jniemann66/ReSampler Cc: Judd Niemann; Comment Subject: Re: [jniemann66/ReSampler] Android (#6)
ok, also what is the CORRECT indentation for ReSampler.cpp?
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/jniemann66/ReSampler/issues/6?email_source=notifications&email_token=AEEXGHTWMMS3V4VS4C23GC3P6HB7JA5CNFSM4H4ZJFCKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODZLI6KA#issuecomment-508989224 , or mute the thread https://github.com/notifications/unsubscribe-auth/AEEXGHWMOVTPPMSXJMJ4MATP6HB7JANCNFSM4H4ZJFCA . https://github.com/notifications/beacon/AEEXGHQTMXVXUZ7JUBZMECTP6HB7JA5CNFSM4H4ZJFCKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODZLI6KA.gif
Actually, I think I’d like to use tabs, Most of the existing files have tabs, but I see a few spaces have crept in !
I’ll clean it all up … maybe not tonight, though …
From: Judd Niemann [mailto:jniemann666@bigpond.com] Sent: Sunday, July 7, 2019 11:00 PM To: 'jniemann66/ReSampler' Subject: RE: [jniemann66/ReSampler] Android (#6)
Yeah, sorry about that – In this particular case, I think this was a result of using Visual Studio and hitting the ‘format selection’ function. That must have done something with the whitespace.
The thing is, I use a lot of different editors/IDEs – depending on what the OS and machine I’m using is (and I have Linux / Mac/ Windows noxes), the editor could be Windows + Visual studio, VSCode, QtCreator, CLion, or just plain old VIM etc – and they might not be set up consistently !
I guess it should be 4 spaces. I’ll see if I can clean it up
From: mgood7123 [mailto:notifications@github.com] Sent: Sunday, July 7, 2019 8:42 PM To: jniemann66/ReSampler Cc: Judd Niemann; Comment Subject: Re: [jniemann66/ReSampler] Android (#6)
ok, also what is the CORRECT indentation for ReSampler.cpp?
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/jniemann66/ReSampler/issues/6?email_source=notifications&email_token=AEEXGHTWMMS3V4VS4C23GC3P6HB7JA5CNFSM4H4ZJFCKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODZLI6KA#issuecomment-508989224 , or mute the thread https://github.com/notifications/unsubscribe-auth/AEEXGHWMOVTPPMSXJMJ4MATP6HB7JANCNFSM4H4ZJFCA . https://github.com/notifications/beacon/AEEXGHQTMXVXUZ7JUBZMECTP6HB7JA5CNFSM4H4ZJFCKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODZLI6KA.gif
ok
how would I compile this for android so I can use this as a library in my application