ModPlug Central

OpenMPT => Development Corner => Topic started by: djliquidice on April 16, 2015, 21:51:57

Title: Apple iOS development - audio sounds fast forwarded
Post by: djliquidice on April 16, 2015, 21:51:57
Does anyone here have experience with iOS audio development that could lend a quick hand?

   
    int16_t *tempBuffer[bufferSize];

    for (int i = 0; i < NUM_BUFFERS; i++) {
       
        AudioQueueBufferRef mBuffer;

        AudioQueueAllocateBuffer(mAudioQueue, bufferSize, &mBuffer);

        mBuffers[i] = mBuffer;
       
        openmpt_module_read_interleaved_stereo(mod, PLAYBACK_FREQ, bufferSize, mBuffer->mAudioData);

        AudioQueueEnqueueBuffer(mAudioQueue, mBuffer, 0, NULL);
    }


The following implementation of ModPlug works fine:

    int bufferSize = 1024;

    for (int i = 0; i < NUM_BUFFERS; i++) {
       
        AudioQueueBufferRef mBuffer;

        AudioQueueAllocateBuffer(mAudioQueue, bufferSize, &mBuffer);

mBuffers[i] = mBuffer;
        mBuffer->mAudioDataByteSize = bufferSize;
        ModPlug_Read(mpFile, (char*)mBuffer->mAudioData, bufferSize);

        AudioQueueEnqueueBuffer(mAudioQueue, mBuffer, 0, NULL);
    }
   


Demo of the problem: https://www.youtube.com/watch?v=naSXx_xh0AY

Any suggestions would greatly be appreciated.
Title: Re: Apple iOS development - audio sounds fast forwarded
Post by: manx on April 16, 2015, 22:04:37
Quote from: djliquidice on April 16, 2015, 21:51:57
   
                openmpt_module_read_interleaved_stereo(mod, PLAYBACK_FREQ, bufferSize, mBuffer->mAudioData);


In contrast to libmodplug, which takes the buffer size in bytes, libopenmpt takes the buffer size in number of sample frames.
This means, you have to devide the bufferSize by the number of channels (2 in the case of stereo in this case) multiplied by the size of an individual sample (sizeof(int16_t), or just 2 in this case).

i.e. replace the line quoted above with
   
                openmpt_module_read_interleaved_stereo(mod, PLAYBACK_FREQ, bufferSize / (2*sizeof(int16_t)), mBuffer->mAudioData);


Title: Re: Apple iOS development - audio sounds fast forwarded
Post by: djliquidice on April 16, 2015, 22:47:21
OMG.  ;D ;D ;D ;D ;D

I completely missed that :(

Your suggestion worked like a champ!!!

(http://www.imgion.com/images/01/you-are-awesome....jpg)
Title: Re: Apple iOS development - audio sounds fast forwarded
Post by: manx on April 17, 2015, 09:50:37
On a related note, as we do not regularly test on Apple platforms and have never been testing on iOS at all:
Did you have to make any modifications to libopenmpt itself in order to make it work on iOS? If yes, we would like to make the necessary modifications to the upstream source in order to aid other iOS developers.

Title: Re: Apple iOS development - audio sounds fast forwarded
Post by: djliquidice on April 21, 2015, 17:34:20
Hi Manx,

There were some structural changes that had to be made.  This is Such a huge codebase. to get things working, I had to remove quite a bit.

Is it possible to make changes that leverage header search paths over relative paths?

I can tell you that by adding the raw source files to an xcode project causes major pain ;).

I'd *love* to see what I can do to assist with helping migrate libopempt to being iOS friendly.  Should I just ask questions here? I'm not very familiar w/ the internals, but I believe w/ enough help from you & other contribs, we can make this happen =).
Title: Re: Apple iOS development - audio sounds fast forwarded
Post by: manx on April 21, 2015, 17:54:55
I'm not sure what your talking about when saying "structural changes" and "removing quite a bit". Both really should not be required and will possibly make keeping your version up-to-date way harder than it needs to be.
The search path required by libopenmpt code is in particular the root directory of the source tree (i.e. adding "-I." if building relative to the source tree root) and to common directory (i.e. "-Icommon")
Could you provide a copy of the libopenmpt source tree you ended up using after your modifications, so we can take a look at it?
Also, feel free to ask further more specific/detailed questions here.
Title: Re: Apple iOS development - audio sounds fast forwarded
Post by: djliquidice on May 24, 2016, 18:56:54
Hi @Manx,

Thank you for responding. I apologize for not getting back to you.   I had to shift my focus elsewhere.

I was reminded by the latest release of openmpt (congrats to you guys & the community) that my work here wasn't done.

I tried to create an iOS library again and here's the steps I had to take:

(Add files means add files to xcode project)

Quote- Create common/ group
    - Add files
- Create include/modplug, include/stb_vorbis group
    - Add files

- Create libopenmpt/ group
    - Add files

- Create soundlib/ soundlib/plugins, soundlib/plugins/dmo groups
    - Add files

- Remove libopenmpt/
    - xmp-openmpt.cpp
    - in_openmpt.cpp
    - libopenmpt_plugin_gui.*
    - foo_openmpt.*

- Configure header search paths as $(SRCROOT)/  -- recursive

- Add "Other C flags":
-DMPT_WITH_ZLIB
-DMPT_CHARSET_CUSTOMUTF8
-DLIBOPENMPT_BUILD



Github repo is here: https://github.com/ModusCreateOrg/libOpenMPT-ios
Title: Re: Apple iOS development - audio sounds fast forwarded
Post by: Saga Musix on May 24, 2016, 19:28:35
So it's just a matter of setting up a proper Xcode project. We already use Premake to generate Visual Studio solutions, so it could generate Xcode project files automatically as well, I guess.
Title: Re: Apple iOS development - audio sounds fast forwarded
Post by: djliquidice on May 25, 2016, 14:13:32
@Saga Musix,

Yes. I believe it's entirely possible to automate that.

I'm no expert, but I've been a customer of such an automated process.

There is a tool here that may be of help: http://www.rubydoc.info/gems/xcodeproj/frames

I can start testing this process out and work on an example project. Integrating it with the greater libOpenMPT source & automation process is something i have zero experience in.
Title: Re: Apple iOS development - audio sounds fast forwarded
Post by: Saga Musix on May 25, 2016, 14:21:12
Well, there's no need to drag in yet another scripting language and meta build tool if ours can already do it. I think we could look into adding an Xcode project to the output of our Premake config. If you want to try it yourself, get Premake 5.0 (http://premake.github.io/), and call it with the parameters "build/premake/mpt-libopenmpt.lua xcode" (you will of course have to take care of of specifying that relative path correctly). Similarly, you can create a project for ext-stb_vorbis.lua, but I wonder if libvorbis could be used on OSX/iOS instead? If it's available, it's a better choice than stb_vorbis.
Title: Re: Apple iOS development - audio sounds fast forwarded
Post by: manx on May 25, 2016, 14:44:57
It is probably better to support system installed libraries instead of bundled libraries for OSX. However, I have no idea how to properly integrate XCode with libraries installed via e.g. homebrew. Depending on system-installed libraries might also be better covered by the autotools build system anyway, so it may actually kind of make sense to build all external libraries with XCode like we are doing with MSVC. I have no opinion here as I am not a Mac developer.

Long story short: I (or better we) have absolutely no idea what would bee workable or common workflows and system setups for developers on OSX/iOS.