Author Topic: [APK included] Issues with MIDI & SF2 and OGG(Streaming) on Android(Native)  (Read 127 times)

loom

  • Posts: 10
Hi,

I tested 3 cases for playing audio on Android devices(Samsung Galaxy s8, Samsung Galaxy s8+, LG G5), and results are as below:

1. MIDI & SF2: wrong sound as if it's not using samples from instruments correctly.
2. Pre-rendered OGG with BASS_StreamCreateFile: STALLED sometimes(device buffer: 1024), didn't started from the starting point, looping range's altered, jumped forward randomly as if the stream was created from different midifile.
3. Pre-rendered OGG with BASS_SampleLoad: Good.

Audio files from each cases: https://www.dropbox.com/s/3isuljj4d5044ps/Results_For_3_Cases.zip?dl=0

I've tried using AUDIOTRACK, BASS_DEVICE_FREQ, changing update period, changing device buffer, manual update and the results were not different.

The link for downloading APK is: https://www.dropbox.com/s/6nj0kpm1npuxw9i/newPCTest-debug.apk?dl=0

The code I used for each case(in attached APK) was,

Code: [Select]

    // Initialization

    BASS_SetConfig(BASS_CONFIG_DEV_BUFFER,1024);
    BASS_Init(-1, 44100, 0, 0, nullptr);
    BASS_SetConfig(BASS_CONFIG_UPDATEPERIOD,5);

    // 1. MIDI & SF2
    chanMIDI = BASS_MIDI_StreamCreateFile(true, FileUtils::getInstance()->getDataFromFile("G_VALSE.mid").getBytes(), 0, FileUtils::getInstance()->getDataFromFile("G_VALSE.mid").getSize(), BASS_SAMPLE_LOOP , 44100);

    font = BASS_MIDI_FontInit(FileUtils::getInstance()->getDataFromFile("ChoriumRevA.png").getBytes(), BASS_MIDI_FONT_MEM); // ErrorGetCode returned 0 after this.
   
    BASS_MIDI_FONT sf;
    sf.font = font;
    sf.preset = -1;
    sf.bank = 0;
    BASS_MIDI_StreamSetFonts(chanMIDI, &sf, 1);

    bool streamLoadSamplesResult = BASS_MIDI_StreamLoadSamples(chanMIDI); // It returned true.
    if (!streamLoadSamplesResult) {

        CCLOG("streamLoadSamples Failed!!!");
        CCLOG("[BASS_MIDI_StreamLoadSamples] %d", BASS_ErrorGetCode() );

    }

    // 2. OGG using StreamCreateFile

    chanOGGstream = BASS_StreamCreateFile(true, FileUtils::getInstance()->getDataFromFile("G_VALSE.ogg").getBytes(), 0, FileUtils::getInstance()->getDataFromFile("G_VALSE.ogg").getSize(), BASS_SAMPLE_LOOP);

    // 3. OGG using SampleLoad & SampleGetChannel

    sampleOGG = BASS_SampleLoad(true, FileUtils::getInstance()->getDataFromFile("G_VALSE.ogg").getBytes(), 0, FileUtils::getInstance()->getDataFromFile("G_VALSE.ogg").getSize(), 1, BASS_SAMPLE_LOOP);
    chanOGGLoaded = BASS_SampleGetChannel(sampleOGG, true);


There're no non-zero errorcode after all BASS-related methods.
You can also find a midifile(G_VALSE.mid), soundfont(ChoriumRevA.png - extention's changed), and a pre-rendered OGG(G_VALSE.ogg) which aren't compressed inside the APK.
Please check into that. Thanks in advance.

Regards,

Peter


« Last Edit: 8 Feb '18 - 01:38 by loom »

Ian @ un4seen

  • Administrator
  • Posts: 20616
If the BASS_SampleLoad case works well, that looks to me like the memory returned by the "FileUtils::getInstance()->getDataFromFile(...).getBytes()" function isn't persistent. BASS_SampleLoad and BASS_MIDI_StreamCreateFile will copy the file data from the provided memory location but BASS_MIDI_FontInit and BASS_StreamCreateFile won't, so the data needs to stay there until the soundfont/stream is freed.

loom

  • Posts: 10
If the BASS_SampleLoad case works well, that looks to me like the memory returned by the "FileUtils::getInstance()->getDataFromFile(...).getBytes()" function isn't persistent. BASS_SampleLoad and BASS_MIDI_StreamCreateFile will copy the file data from the provided memory location but BASS_MIDI_FontInit and BASS_StreamCreateFile won't, so the data needs to stay there until the soundfont/stream is freed.

Yes, you were right. I had the right result with using member variables for BASS_FontInit and BASS_StreamCreateFile.
Thanks for the insight.

By the way, would it be okay using BASS_MIDI_FONT_MEM flag afterwards?

Ian @ un4seen

  • Administrator
  • Posts: 20616
The BASS_MIDI_FONT_MEM option has been deprecated in favour of the safer BASS_MIDI_FontInitUser function, but it is still available, so you can still use it when you are sure that the SF2 file is valid (BASS_MIDI_FONT_MEM with a corrupt file might cause a crash). You just need to make sure that the data stays in place until after the soundfont is freed.

loom

  • Posts: 10
(BASS_MIDI_FONT_MEM with a corrupt file might cause a crash).

Actually, I have met that crash instead of non-zero errorcode with BASS_MIDI_FONT_MEM on my iOS test project.
Thanks for the clarification.
« Last Edit: 8 Feb '18 - 01:36 by loom »