igorski / MWEngine

Audio engine and DSP library for Android, written in C++ providing low latency performance within a musical context, while providing a Java/Kotlin API. Supports both OpenSL and AAudio.
MIT License
261 stars 45 forks source link

Crash on startup #31

Closed gerosyab closed 6 years ago

gerosyab commented 6 years ago

Hello, I'm trying to import mwengine to my project.

I copied c++ and java source as same directory structure and swig build script and build was successful.

When I try to start the activity from my app, it crashes.

The activity and asserts resources are almost same as sample. (MWEngineActivity.java, hihat.wav, clap.wav)

The logcat said

12-20 15:07:31.230 30870-30870/net.gerosyab.guitaroid A/libc: Fatal signal 11 (SIGSEGV), code 1, fault addr 0x4 in tid 30870 (osyab.guitaroid)
12-20 15:07:31.230 3313-3477/? D/audio_hw_primary: out_set_parameters: enter: kvpairs: routing=2
12-20 15:07:31.230 3313-3477/? D/AudioFlinger: setCurDevice() 0x2
                                               [ 12-20 15:07:31.233  3121: 3121 W/         ]
                                               debuggerd: handling request: pid=30870 uid=10568 gid=10568 tid=30870
12-20 15:07:31.234 30870-31001/net.gerosyab.guitaroid V/MWENGINE: STARTED engine
12-20 15:07:31.235 3313-3477/? V/audio_hw_primary: start_output_stream+, out->device : 00000002 , out->type = 1
12-20 15:07:31.235 30870-31002/net.gerosyab.guitaroid I/AudioTrack: Skip ramp
12-20 15:07:31.235 3313-3477/? D/audio_hw_primary: start_output_stream jack_skip_check false
12-20 15:07:31.236 30870-31002/net.gerosyab.guitaroid I/AudioTrack: Skip ramp
12-20 15:07:31.262 3313-3477/? D/audio_hw_primary: start_output_stream (0xeeaa89a0) out->pcm_device:6 out->config.rate:48000 out->config.format:0 out->period_size:240
12-20 15:07:31.262 3313-3477/? D/audio_hw_primary: start_output_stream (0xeeaa89a0) out->config.rate:48000 out->config.format:0 out->period_size:240
12-20 15:07:31.262 3313-3477/? V/audio_hw_primary: select_devices output_scenario:0 input_scenario:-1 out_snd_device 0x2 in_snd_device:0x0
12-20 15:07:31.263 3313-3477/? I/audio_route: > audio_route_reset :
12-20 15:07:31.263 3313-3477/? I/audio_route: > audio_route_apply_path : "media-speaker"
12-20 15:07:31.375 3313-3477/? V/audio_hw_primary: select_devices() output_route "media-speaker" 
12-20 15:07:31.375 3313-3477/? I/audio_route: > audio_route_apply_path : "gain-media-speaker"
12-20 15:07:31.375 3313-3477/? V/audio_hw_primary: select_devices() output_gain "gain-media-speaker" 
12-20 15:07:31.375 3313-3477/? I/audio_route: > audio_route_update_mixer : +
12-20 15:07:31.376 3313-3477/? I/audio_route: > audio_route_update_mixer : changed(0) -
12-20 15:07:31.376 3313-3477/? I/audio_hw_primary: select_devices - 
12-20 15:07:31.376 3313-3477/? V/audio_hw_primary: start_output_stream-
12-20 15:07:31.405 3313-3477/? D/AudioFlinger: mixer(0xed883040) Spend too much time to write: delta 170(effect 0, stage 0)
12-20 15:07:31.423 31003-31003/? A/DEBUG: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
12-20 15:07:31.424 31003-31003/? A/DEBUG: Build fingerprint: 'samsung/herolteskt/herolteskt:7.0/NRD90M/G930SKSU1DQJ1:user/release-keys'
12-20 15:07:31.424 31003-31003/? A/DEBUG: Revision: '8'
12-20 15:07:31.424 31003-31003/? A/DEBUG: ABI: 'arm64'
12-20 15:07:31.424 31003-31003/? A/DEBUG: pid: 30870, tid: 30870, name: osyab.guitaroid  >>> net.gerosyab.guitaroid <<<
12-20 15:07:31.424 31003-31003/? A/DEBUG: signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x4
12-20 15:07:31.424 31003-31003/? A/DEBUG:     x0   00000074fb896620  x1   0000000000000000  x2   00000074fb896620  x3   0000007fd1c68f08
12-20 15:07:31.424 31003-31003/? A/DEBUG:     x4   0000000000000000  x5   0000000000000001  x6   0000000100000000  x7   0000000000000000
12-20 15:07:31.424 31003-31003/? A/DEBUG:     x8   0000000000000001  x9   0000000000000000  x10  0000000000430000  x11  0000000000000000
12-20 15:07:31.424 31003-31003/? A/DEBUG:     x12  000000000000018c  x13  0000000000000048  x14  0000007520d1d470  x15  76205267d1c3e4e7
12-20 15:07:31.424 31003-31003/? A/DEBUG:     x16  00000074fbcdde88  x17  00000074fbc1f00c  x18  0000000071666f10  x19  00000074fb896620
12-20 15:07:31.424 31003-31003/? A/DEBUG:     x20  0000007510d1ab68  x21  0000000000000000  x22  0000000000000000  x23  000000751b2258cc
12-20 15:07:31.424 31003-31003/? A/DEBUG:     x24  0000000000000014  x25  d77d57c4ab9dcb4c  x26  000000751c8c7a98  x27  d77d57c4ab9dcb4c
12-20 15:07:31.424 31003-31003/? A/DEBUG:     x28  0000007fd1c68f10  x29  0000007fd1c68ed0  x30  000000751c2b0494
12-20 15:07:31.425 31003-31003/? A/DEBUG:     sp   0000007fd1c68eb0  pc   00000074fbc1f030  pstate 0000000020000000
12-20 15:07:31.442 31003-31003/? A/DEBUG: backtrace:
12-20 15:07:31.442 31003-31003/? A/DEBUG:     #00 pc 0000000000046030  /data/app/net.gerosyab.guitaroid-2/lib/arm64/libmwengine.so (_ZN11SampleEvent9setSampleEP11AudioBuffer+36)
12-20 15:07:31.442 31003-31003/? A/DEBUG:     #01 pc 00000000000db490  /system/lib64/libart.so (art_quick_generic_jni_trampoline+144)
12-20 15:07:31.442 31003-31003/? A/DEBUG:     #02 pc 00000000000d2168  /system/lib64/libart.so (art_quick_invoke_static_stub+600)
12-20 15:07:31.442 31003-31003/? A/DEBUG:     #03 pc 00000000000dec20  /system/lib64/libart.so (_ZN3art9ArtMethod6InvokeEPNS_6ThreadEPjjPNS_6JValueEPKc+256)
12-20 15:07:31.442 31003-31003/? A/DEBUG:     #04 pc 0000000000291020  /system/lib64/libart.so (_ZN3art11interpreter34ArtInterpreterToCompiledCodeBridgeEPNS_6ThreadEPNS_9ArtMethodEPKNS_7DexFile8CodeItemEPNS_11ShadowFrameEPNS_6JValueE+312)
12-20 15:07:31.443 31003-31003/? A/DEBUG:     #05 pc 0000000000289fe0  /system/lib64/libart.so (_ZN3art11interpreter6DoCallILb0ELb0EEEbPNS_9ArtMethodEPNS_6ThreadERNS_11ShadowFrameEPKNS_11InstructionEtPNS_6JValueE+592)
12-20 15:07:31.443 31003-31003/? A/DEBUG:     #06 pc 000000000055d9cc  /system/lib64/libart.so (MterpInvokeStatic+356)
12-20 15:07:31.443 31003-31003/? A/DEBUG:     #07 pc 00000000000c4a14  /system/lib64/libart.so (ExecuteMterpImpl+14612)

I added more information to logcat. And I think I found the occuring point.

12-20 16:01:45.806 9054-9054/net.gerosyab.guitaroid D/MWENGINE: initing MWEngineActivity
12-20 16:01:45.816 9054-9054/net.gerosyab.guitaroid V/MWENGINE: JNI INITED OK
12-20 16:01:45.825 9054-9538/net.gerosyab.guitaroid D/MWENGINE: STARTING NATIVE AUDIO RENDER THREAD
12-20 16:01:45.826 9054-9538/net.gerosyab.guitaroid D/MWENGINE: STARTING NATIVE THREAD @ 48000 Hz using 240 samples per buffer
12-20 16:01:45.826 9054-9538/net.gerosyab.guitaroid V/MWENGINE: STARTING engine
12-20 16:01:45.837 9054-9054/net.gerosyab.guitaroid V/MWENGINE: WaveReader::Error not a valid WAVE file
12-20 16:01:45.838 9054-9054/net.gerosyab.guitaroid V/MWENGINE: WaveReader::Error not a valid WAVE file
12-20 16:01:45.841 9054-9054/net.gerosyab.guitaroid D/mwSampleEvent: SampleEvent Construnctor Entry1
12-20 16:01:45.841 9054-9054/net.gerosyab.guitaroid D/mwSampleEvent: SampleEvent Construnctor Entry3
12-20 16:01:45.841 9054-9054/net.gerosyab.guitaroid D/mwSampleEvent: SampleEvent.setSample() 1
12-20 16:01:45.842 9054-9054/net.gerosyab.guitaroid D/mwSampleEvent: SampleEvent.setSample() this : nl.igorski.lib.audio.mwengine.SampleEvent@327abf6
12-20 16:01:45.842 9054-9054/net.gerosyab.guitaroid D/mwSampleEvent: SampleEvent.setSample() sampleBuffer : null
12-20 16:01:45.842 9054-9054/net.gerosyab.guitaroid D/mwNDK: Java_nl_igorski_lib_audio_mwengine_MWEngineCoreJNI_SampleEvent_1setSample start
12-20 16:01:45.842 9054-9054/net.gerosyab.guitaroid D/mwNDK: 111
12-20 16:01:45.842 9054-9054/net.gerosyab.guitaroid D/mwNDK: 222
12-20 16:01:45.845 9054-9538/net.gerosyab.guitaroid V/MWENGINE: STARTED engine

Wav files are same as in the sample's asserts folder but don't know why the WaveReader says not a valid WAVE file.

Anyway the location is "Java_nl_igorski_lib_audio_mwengine_MWEngineCoreJNI_SampleEvent_1setSample()" in "java_interface_wrapper.cpp"

When setSample() method in SampleEvent.cpp is called, it crashed.

Could you give me any advice?

igorski commented 6 years ago

WaveReader::Error not a valid WAVE file is fired when the header of the file does not contain the correct headers information (although it has validated partial headers, e.g. the RIFF declaration, but not the WAVE declaration).

Are you using JavaUtilities.createSampleFromFile() or JavaUtilities.createSampleFromAsset() (as in the example activity?). These return boolean values to indicate file read success. If they return false, you will know setSample() will crash as an empty buffer is passed.

The questions is, how literal is the copy of your app in relation to the example application ? e.g. are you literally using the same .wav files, are they in the ./assets folder or elsewhere in the packaged .APK ? Does the example Activity build fine for you ?

gerosyab commented 6 years ago

I am using JavaUtilities.createSampleFromAsset() and it returns false.

I copied hihat.wav and clap.wav from example activity source (git cloned) and example activity building was fine for me too.

I check CRC checksum value and also check hex code value of the wav files.

They are same files as the example activity's, and they had correct header value (RIFF).

Here's my activity's loadWAVAsset() method.

private void loadWAVAsset( String assetName, String sampleName )
    {
        final Context ctx = getApplicationContext();

        AssetManager assetMgr = getAssets();
        try {
            String[] list = assetMgr.list("/");
            int length = list.length;
            for(int i= 0; i < length; i++) {
                Log.d("guitaroid", "loadWAVAsset() file #" + i + " : " + list[i]);
            }
            InputStream is = assetMgr.open("hat.wav");
            InputStream is2 = assetMgr.open("clap.wav");
            Log.d("guitaroid", "loadWAVAsset() hihat.wav available() " + is.available());
            Log.d("guitaroid", "loadWAVAsset() clap.wav available() " + is2.available());
            is.close();
            is2.close();

        } catch (IOException e) {
            e.printStackTrace();
        }

        Log.d("guitaroid", "loadWAVAsset("+ assetName + ", " + sampleName+ ")");
        Log.d("guitaroid", "loadWAVAsset() - ctx.getAssets() : "+ ctx.getAssets() + ", ctx.getCacheDir() : " + ctx.getCacheDir() + ", ctx.getCacheDir().getAbsolutePath() : " + ctx.getCacheDir().getAbsolutePath() + ")");
        boolean result = JavaUtilities.createSampleFromAsset(
                sampleName, ctx.getAssets(), ctx.getCacheDir().getAbsolutePath(), assetName
        );
        Log.d("guitaroid", "loadWAVAsset() - JavaUtilities.createSampleFromAsset() : "+ result);
    }

And here is my logcat message.

12-22 16:59:42.769 22828-22828/net.gerosyab.guitaroid D/guitaroid: loadWAVAsset() file #0 : AndroidManifest.xml
12-22 16:59:42.769 22828-22828/net.gerosyab.guitaroid D/guitaroid: loadWAVAsset() file #1 : META-INF
12-22 16:59:42.769 22828-22828/net.gerosyab.guitaroid D/guitaroid: loadWAVAsset() file #2 : SEC-INF
12-22 16:59:42.769 22828-22828/net.gerosyab.guitaroid D/guitaroid: loadWAVAsset() file #3 : assets
12-22 16:59:42.769 22828-22828/net.gerosyab.guitaroid D/guitaroid: loadWAVAsset() file #4 : classes.dex
12-22 16:59:42.769 22828-22828/net.gerosyab.guitaroid D/guitaroid: loadWAVAsset() file #5 : classes2.dex
12-22 16:59:42.769 22828-22828/net.gerosyab.guitaroid D/guitaroid: loadWAVAsset() file #6 : classes3.dex
12-22 16:59:42.769 22828-22828/net.gerosyab.guitaroid D/guitaroid: loadWAVAsset() file #7 : classes4.dex
12-22 16:59:42.769 22828-22828/net.gerosyab.guitaroid D/guitaroid: loadWAVAsset() file #8 : classes5.dex
12-22 16:59:42.769 22828-22828/net.gerosyab.guitaroid D/guitaroid: loadWAVAsset() file #9 : classes6.dex
12-22 16:59:42.769 22828-22828/net.gerosyab.guitaroid D/guitaroid: loadWAVAsset() file #10 : lib
12-22 16:59:42.769 22828-22828/net.gerosyab.guitaroid D/guitaroid: loadWAVAsset() file #11 : res
12-22 16:59:42.769 22828-22828/net.gerosyab.guitaroid D/guitaroid: loadWAVAsset() file #12 : resources.arsc
12-22 16:59:42.769 22828-22828/net.gerosyab.guitaroid D/guitaroid: loadWAVAsset() hihat.wav available() 45100
12-22 16:59:42.769 22828-22828/net.gerosyab.guitaroid D/guitaroid: loadWAVAsset() clap.wav available() 92590
12-22 16:59:42.769 22828-22828/net.gerosyab.guitaroid D/guitaroid: loadWAVAsset(hat.wav, hat)
12-22 16:59:42.769 22828-22828/net.gerosyab.guitaroid D/guitaroid: loadWAVAsset() - ctx.getAssets() : android.content.res.AssetManager@61a9182, ctx.getCacheDir() : /data/user/0/net.gerosyab.guitaroid/cache, ctx.getCacheDir().getAbsolutePath() : /data/user/0/net.gerosyab.guitaroid/cache)
12-22 16:59:42.770 22828-23801/net.gerosyab.guitaroid I/AudioTrack: Skip ramp
12-22 16:59:42.773 22828-22828/net.gerosyab.guitaroid V/MWENGINE: WaveReader::Error not a valid WAVE file
12-22 16:59:42.773 22828-22828/net.gerosyab.guitaroid D/guitaroid: loadWAVAsset() - JavaUtilities.createSampleFromAsset() : false
12-22 16:59:42.775 22828-23801/net.gerosyab.guitaroid I/AudioTrack: Skip ramp
12-22 16:59:42.780 22828-23801/net.gerosyab.guitaroid I/AudioTrack: Skip ramp
12-22 16:59:42.785 22828-23801/net.gerosyab.guitaroid I/AudioTrack: Skip ramp
12-22 16:59:42.786 22828-22828/net.gerosyab.guitaroid D/guitaroid: loadWAVAsset() file #0 : AndroidManifest.xml
12-22 16:59:42.786 22828-22828/net.gerosyab.guitaroid D/guitaroid: loadWAVAsset() file #1 : META-INF
12-22 16:59:42.786 22828-22828/net.gerosyab.guitaroid D/guitaroid: loadWAVAsset() file #2 : SEC-INF
12-22 16:59:42.786 22828-22828/net.gerosyab.guitaroid D/guitaroid: loadWAVAsset() file #3 : assets
12-22 16:59:42.786 22828-22828/net.gerosyab.guitaroid D/guitaroid: loadWAVAsset() file #4 : classes.dex
12-22 16:59:42.786 22828-22828/net.gerosyab.guitaroid D/guitaroid: loadWAVAsset() file #5 : classes2.dex
12-22 16:59:42.786 22828-22828/net.gerosyab.guitaroid D/guitaroid: loadWAVAsset() file #6 : classes3.dex
12-22 16:59:42.786 22828-22828/net.gerosyab.guitaroid D/guitaroid: loadWAVAsset() file #7 : classes4.dex
12-22 16:59:42.786 22828-22828/net.gerosyab.guitaroid D/guitaroid: loadWAVAsset() file #8 : classes5.dex
12-22 16:59:42.786 22828-22828/net.gerosyab.guitaroid D/guitaroid: loadWAVAsset() file #9 : classes6.dex
12-22 16:59:42.786 22828-22828/net.gerosyab.guitaroid D/guitaroid: loadWAVAsset() file #10 : lib
12-22 16:59:42.786 22828-22828/net.gerosyab.guitaroid D/guitaroid: loadWAVAsset() file #11 : res
12-22 16:59:42.786 22828-22828/net.gerosyab.guitaroid D/guitaroid: loadWAVAsset() file #12 : resources.arsc
12-22 16:59:42.787 22828-22828/net.gerosyab.guitaroid D/guitaroid: loadWAVAsset() hihat.wav available() 45100
12-22 16:59:42.787 22828-22828/net.gerosyab.guitaroid D/guitaroid: loadWAVAsset() clap.wav available() 92590
12-22 16:59:42.787 22828-22828/net.gerosyab.guitaroid D/guitaroid: loadWAVAsset(clap.wav, clap)
12-22 16:59:42.787 22828-22828/net.gerosyab.guitaroid D/guitaroid: loadWAVAsset() - ctx.getAssets() : android.content.res.AssetManager@61a9182, ctx.getCacheDir() : /data/user/0/net.gerosyab.guitaroid/cache, ctx.getCacheDir().getAbsolutePath() : /data/user/0/net.gerosyab.guitaroid/cache)
12-22 16:59:42.788 22828-22828/net.gerosyab.guitaroid V/MWENGINE: WaveReader::Error not a valid WAVE file
12-22 16:59:42.788 22828-22828/net.gerosyab.guitaroid D/guitaroid: loadWAVAsset() - JavaUtilities.createSampleFromAsset() : false
12-22 16:59:42.790 22828-23801/net.gerosyab.guitaroid I/AudioTrack: Skip ramp
12-22 16:59:42.791 22828-22828/net.gerosyab.guitaroid A/libc: Fatal signal 11 (SIGSEGV), code 1, fault addr 0x4 in tid 22828 (osyab.guitaroid)

I think I can get the wav files by java method (AssetManager.open() ) but can't by native method.

Can you please tell me where I should look into more?

Thanks.

12-22 18:37:22.617 10908-10908/net.gerosyab.guitaroid D/guitaroid: JavaUtilities::createSampleFromAsset filename : clap.wav
12-22 18:37:22.617 10908-10908/net.gerosyab.guitaroid D/guitaroid: JavaUtilities::createSampleFromAsset tempFolder : /data/user/0/net.gerosyab.guitaroid/cache
12-22 18:37:22.618 10908-10908/net.gerosyab.guitaroid D/guitaroid: JavaUtilities::createSampleFromAsset length : 92590
12-22 18:37:22.618 10908-10908/net.gerosyab.guitaroid D/guitaroid: JavaUtilities::createSampleFromAsset remaining : 92590
12-22 18:37:22.618 10908-10908/net.gerosyab.guitaroid D/guitaroid: JavaUtilities::createSampleFromAsset Mb : 1024000
12-22 18:37:22.618 10908-10908/net.gerosyab.guitaroid D/guitaroid: JavaUtilities::createSampleFromAsset readUsingTempFile : true
12-22 18:37:22.618 10908-10908/net.gerosyab.guitaroid V/MWENGINE: WaveReader::Error not a valid WAVE file
12-22 18:37:22.618 10908-10908/net.gerosyab.guitaroid D/guitaroid: JavaUtilities::createSampleFromAsset sampleBuffer == NULL

I think it's about reading wav file (making temp file and read from it).

gerosyab commented 6 years ago

I debugged more and found something.

AudioBuffer* WaveReader::fileToBuffer( std::string inputFile )
{
    FILE* fp;
    AudioBuffer* out = 0;

    fp = fopen( inputFile.c_str(), "rb" );

    if ( fp )
    {
        char id[ 5 ];
        unsigned long size;
        short* sound_buffer;
        short tag, amountOfChannels, blockAlign, bps;
        unsigned int format, sampleRate, bytesPerSec, dataSize, i;

        // first we'll check the necessary headers identifying the WAV file

        fread( id, sizeof( char ), 4, fp );
        id[ 4 ] = '\0';

        __android_log_print(ANDROID_LOG_DEBUG, "guitaroid", "WaveReader::fileToBuffer id 1 : %s", id);

        if ( !strcmp( id, "RIFF" ))
        {
            fread( &size, sizeof( unsigned long ), 1, fp );
            fread( id,    sizeof( unsigned char ), 4, fp );
            id[ 4 ] = '\0';

            __android_log_print(ANDROID_LOG_DEBUG, "guitaroid", "WaveReader::fileToBuffer id 2 : %s", id);

            if ( !strcmp( id, "WAVE" ))
            {
                ...
            }
            else
                Debug::log( "WaveReader::Error not a valid WAVE file" );
        }
        else
            Debug::log( "WaveReader::Error not a valid WAVE file (no RIFF header)" );

        fclose( fp );
    }
    else {
        Debug::log( "WaveReader::Error could not open file '%s'", inputFile.c_str() );
    }
    return out;
}
12-23 17:05:07.471 17173-17173/net.gerosyab.guitaroid D/guitaroid: WaveReader::fileToBuffer inputFile : /data/user/0/net.gerosyab.guitaroid/cache/tmp
12-23 17:05:07.471 17173-17173/net.gerosyab.guitaroid D/guitaroid: WaveReader::fileToBuffer id 1 : RIFF
12-23 17:05:07.471 17173-17173/net.gerosyab.guitaroid D/guitaroid: WaveReader::fileToBuffer id 2 : fmt 
12-23 17:05:07.471 17173-17173/net.gerosyab.guitaroid V/MWENGINE: WaveReader::Error not a valid WAVE file

First header value is "RIFF" and second header value is "fmt ", not "WAVE".

Now same error occurs in the Example activity too, not like before.

I've re-installed and upgraded ADT, SDK, NDK and other tools recently, so I don't know when this error happens exactly...

igorski commented 6 years ago

That is interesting! To be honest I would not know why it doesn't occur for the current sample files that are in the repository (NDK/SDK versions shouldn't really matter here).

One question: for what architecture are you building/testing ? (e.g. ARM, x64, etc.) It might be related to a hardware specific issue (perhaps the sizes of unsigned long not being as I expect them to be here).

gerosyab commented 6 years ago

Built with multiple architecure (arm64-v8a, armeabi, armeabi-v7a, x86, x86_74) I think. I use galaxy s7 and depending on the logcat message, the architecture of testing device is ARM64.

12-23 17:05:07.627 17417-17417/? A/DEBUG:     #00 pc 00000000000451c0  /data/app/net.gerosyab.guitaroid-2/lib/arm64/libmwengine.so (_ZN11SampleEvent9setSampleEP11AudioBuffer+36)
12-23 17:05:01.114 3739-3855/? I/PackageManager.DexOptimizer: Running dexopt (dex2oat) on: /data/app/vmdl712199686.tmp/base.apk pkg=net.gerosyab.guitaroid isa=arm64 vmSafeMode=false debuggable=true target-filter=interpret-only oatDir = /data/app/vmdl712199686.tmp/oat sharedLibraries=null
12-23 17:05:02.371 3739-3855/? D/PackageManager: Abis for package[net.gerosyab.guitaroid] are primary=arm64-v8a secondary=null
gerosyab commented 6 years ago
// fread( &size, sizeof( unsigned long ), 1, fp );
fread( &size, sizeof( unsigned int ), 1, fp );

// fread( &format,           sizeof( unsigned long ), 1, fp );
fread( &format,           sizeof( unsigned int ), 1, fp );
// fread( &sampleRate,       sizeof( unsigned long ), 1, fp );
fread( &sampleRate,       sizeof( unsigned int ), 1, fp );
// fread( &bytesPerSec,      sizeof( unsigned long ), 1, fp );
fread( &bytesPerSec,      sizeof( unsigned int ), 1, fp );
// fread( &dataSize,         sizeof( unsigned long ), 1, fp );
fread( &dataSize,         sizeof( unsigned int ), 1, fp );
12-29 10:59:54.975 1436-1436/net.gerosyab.guitaroid D/guitaroid: sizeof(unsigned int) : 4
12-29 10:59:54.975 1436-1436/net.gerosyab.guitaroid D/guitaroid: sizeof(unsigned long) : 8
12-29 10:59:54.975 1436-1436/net.gerosyab.guitaroid D/guitaroid: WaveReader::fileToBuffer id 1 : RIFF
12-29 10:59:54.975 1436-1436/net.gerosyab.guitaroid D/guitaroid: WaveReader::fileToBuffer id 2 : WAVE

I changed all of "sizeof(unsigned long)" to "sizeof(unsigned int)" in the wavereader.cpp and problem solved.

I think the sizeof(unsigned long) is 8 bytes in 64bit architecture, so header parsing of wav file was not right.

igorski commented 6 years ago

Hi @gerosyab I expected something horrible like this, it's strange that for ARM64 the unsigned long data type is defined to be 32-bits, but for Linux 64-bit environments, unsigned long is 64-bits. Unclear how this affects certain devices in the Android ecosphere.

However, unsigned int should be the correct value as it should be interpreted to be 32-bit in length across all supported architectures. I have updated the code in the master branch accordingly.

Referenced pull request: https://github.com/igorski/MWEngine/pull/32