ZgeSL audio library for ZGE

Use of external libraries (DLLs) from ZGE.

Moderator: Moderators

Post Reply
User avatar
Rado1
Posts: 775
Joined: Wed May 05, 2010 12:16 pm

ZgeSL audio library for ZGE

Post by Rado1 »

Probably one of my final solution to bring you (and also to me) an audio library able to play MP3, OGG, MIDI, ... music files in ZGE projects is ZgeSL. The main intention was to create a really small library (it is about 13kb now) with the possibility to extend it with more advanced sound features (3d sounds, built-in effects, support by HW, streaming, playing from URI, etc.) if you will request them. The library is created on top of OpenSL ES sound system, and therefore, it works only on Android.

Download the library, the demo project and pre-compiled Android demo application from the download page.

Do not worry about Windows, because MP3 files can be played by Winmm.dll as Kjell has already shown. Also there is no problem for OGG, because there exist some free OGG to MP3 converters.

The ZgeSL demo demonstrates creation of a common music library which uses Winmm.dll for Windows and ZgeSL for Android. After some cleaning, it can probably come to ZGE standard libraries.

To use ZgeSL in your Android projects, just copy libZgeSL.so to the libs/armeabi folder and your music file to assets folder. When playing the file, just specify its file name without the assets directory; e.g. zslPlayFile("Sunset.mp3") or musicPlayFile("Sunset.mp3") for the common music library.

Since this is still work in progress, Kjell, Ville, others, you are welcome to contribute. Any comments are welcome.

My next steps: document ZgeSL library, improve "Common music library" (add panning, and maybe more functions from Winmm.dll and ZgeSL), maybe extend ZgeSL by more features from OpenSL ES, etc.
Last edited by Rado1 on Fri Nov 14, 2014 7:29 pm, edited 1 time in total.
Imerion
Posts: 200
Joined: Sun Feb 09, 2014 4:42 pm

Post by Imerion »

Awesome work! This will be perfect for my Android projects.

Still looking for a mp3/ogg solution for ZGE that works in Linux though. Or would this perhaps do that?
User avatar
Rado1
Posts: 775
Joined: Wed May 05, 2010 12:16 pm

Post by Rado1 »

Hmm, can ZGE compile for Linux (but probably not the latest beta version)? If so, can ZGE application use external libraries? If so, does Linux support OpenSL ES? If, so, ZgeSL is written for gcc and if you have OpenSL libraries for Linux I suppose it can be compiled quite easily. Unfortunately I do not have experience with Linux, but I can make source files public on Google Code so you can try to compile it by yourself.
User avatar
Kjell
Posts: 1911
Joined: Sat Feb 23, 2008 11:15 pm

Post by Kjell »

Hi guys,
Rado1 wrote:Hmm, can ZGE compile for Linux (but probably not the latest beta version)? If so, can ZGE application use external libraries?
Yep. Ville posted a example of this a long time ago.
Rado1 wrote:If so, does Linux support OpenSL ES?
Nope.

K
User avatar
Rado1
Posts: 775
Joined: Wed May 05, 2010 12:16 pm

Post by Rado1 »

Thanks Kjell for clarification. Then, there should be found another way to play music files on Linux. Cannot be some built-in Linux library (like Winmm.dll on Windows) used also in this case?
User avatar
Kjell
Posts: 1911
Joined: Sat Feb 23, 2008 11:15 pm

Post by Kjell »

Hi Rado1,
Rado1 wrote:Then, there should be found another way to play music files on Linux. Cannot be some built-in Linux library (like Winmm.dll on Windows) used also in this case?
ZGameEditor uses SDL for audio playback on Linux, which has MP3 / OGG playback capabilities .. so you should be able to use that. Never tried it though.

+ Still think MP3 / OGG playback should be build-in .. even though it's not according demoscene / procedural principles, neither is importing Bitmaps / Meshes / Samples ;)

K
User avatar
Rado1
Posts: 775
Joined: Wed May 05, 2010 12:16 pm

Post by Rado1 »

Kjell wrote:+ Still think MP3 / OGG playback should be build-in .. even though it's not according demoscene / procedural principles, neither is importing Bitmaps / Meshes / Samples ;)
Agreed. Even now all my Android projects import bitmaps - sometimes bitmaps generated in ZGE then exported and imported to the final project.
User avatar
Rado1
Posts: 775
Joined: Wed May 05, 2010 12:16 pm

Post by Rado1 »

Imerion wrote:Still looking for a mp3/ogg solution for ZGE that works in Linux though. Or would this perhaps do that?
Until ZGE will have built-in support for mp3/ogg it would also be possible to use another sound library compiled for Linux, e.g., ZgeHekkus. Unfortunately, I do no have Linux so it could be compiled by someone else.
User avatar
Rado1
Posts: 775
Joined: Wed May 05, 2010 12:16 pm

Post by Rado1 »

ZgeSL and the "Common music library" have been updated and documented. You can find them in the demo project player.zgeproj placed at the download page. The common music library supports now also panning, getting and setting of playback position and getting duration for both Android and Windows.

Ville, does it make sense to place the Common music library (you can maybe find a better name) with ZgeSL and MCI API DLL (Winmm.dll) to the ZGE 3.1 library?

Anyway, after putting ZgeSL and ZgeHekkus to Google Code I think I'll stop working on new sound/music ZGE extensions because there are several of them available. Maybe, in meantime, Ville will provide some built-in support for playing mp3/ogg/midi/mod files on all supported platforms so extension will make no (or less) sense.
airpas
Posts: 48
Joined: Wed Apr 18, 2012 11:50 am

Post by airpas »

i think adding built-in support for mp3/ogg/... will break the idea of (64kb game/demo Tool) , so maybe extentions is a good solution in this case .
User avatar
Rado1
Posts: 775
Joined: Wed May 05, 2010 12:16 pm

Post by Rado1 »

I just updated the ZgeSL library to set volume with the same range of values as MCI used in the Common music library: 0 - no sound, 1000 - maximal volume. Therefore, the musicSetVolume() function works uniformly on Windows and Android now. It is also possible to play music files also from URL (works on Windows and Android) and also from SD card on Android. You can download the latest library version and demo project from here.

FYI I informally compared usage of the library with built-in ZGE mechanism of playing OGG files. The result is a better performance of applications while playing the music and much faster loading of a large music files in runtime which does not block rendering. Of course, this can be explained by usage of native OS audio features and playing music in separate threads. Based on these results, I recently changed implementation of my current project Karamball to the Common music library and achieved smooth animation on both Windows and Android and fast switching of soundtrack mp3 files in runtime.

I thought that after adding support for OGG files in ZGE external audio libraries become useless, but that's not 100% true if your application has certain performance requirements.
User avatar
Rado1
Posts: 775
Joined: Wed May 05, 2010 12:16 pm

Post by Rado1 »

Sources of the ZgeSL library were put to Google Code: http://code.google.com/p/zgesl/. The project contains also Common Music Library to play MP3 files on both Windows and Android + description how to use the library.
User avatar
Rado1
Posts: 775
Joined: Wed May 05, 2010 12:16 pm

Post by Rado1 »

ZgeSL source code repository has been moved to GitHub.
Post Reply