Skip to content

Instantly share code, notes, and snippets.

@dstrekelj
Created October 31, 2016 14:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dstrekelj/93738b8d19c1f3261a3ba44734300beb to your computer and use it in GitHub Desktop.
Save dstrekelj/93738b8d19c1f3261a3ba44734300beb to your computer and use it in GitHub Desktop.
Just Kha stuff.

To put things in context, I'm finally getting around to implementing audio1 for Android (Java). As it turns out, I'm a little confused about how the backends are laid out.

Below are some questions I'd like to know the answers to. Of course, any additional information that comes to mind is welcome as well. My plan is to compile this into a Wiki entry later on, so that people who want to contribute to Kha know what to watch out for.

General questions

  1. How are the backend sources included in the compilation process?

The library sources and backend sources often overlap. I'm wondering if the packages are remapped before compilation so that the backend types overwrite the library types, or is there something else going on? It's a bit confusing because backend sources often reference types from library sources that aren't implemented for that backend. Makes it difficult to configure the display server and get completion, so far I had to write a couple of stubs or temporarily comment things to appease the parser.

  1. What is the purpose of stub classes (definitions without implementations) in Kha library sources?

Some classes in the library sources only contain method stubs (e.g. kha.graphics2.Graphics). Is your intention for these classes to be implemented by the backend?

  1. Some backends have kha/<backend name> folders. When should these be created?

I assume it's for implementations that require more code to be written in order for the end result to conform to Kha's API.

  1. Is the 'Empty' backend a template for future backends?

It looks like Empty is just a template, so I'm just looking for confirmation.

kha.audio1 questions

  1. Since there are no tests for audio, what would constitute a good test for the implementation?

  2. Android audio playback can be handled in different ways, but for kha.audio1 the SoundPool class seems like a good choice. However, it puts a limit on the maximum number of simultaneous playback streams. What should the limit be?

@caiopsouza
Copy link

What is the difference between SoundPool and MediaPlayer for playing sound?

I also would like to know how Assets are implemented. When I briefly tried to implement audio I saw that they were all null. I didn't test further but maybe they were in Assets.blobs or weren't loaded at at all.

@dstrekelj
Copy link
Author

@caiopsouza MediaPlayer is the general purpose audio/video reproduction API. SoundPool is an abstraction over MediaPlayer which simplifies audio playback.

The nice thing about SoundPool is that it's pretty much a "done deal". You configure it for the environment you want to use it in (e.g. games), and let it worry about the latency and streaming. It also comes with a couple of nifty features, such as playback rate modification which allows for pitch shifting.

Alternatively, you could handle AudioTrack instances yourself, which requires you to manually pass the buffers around. It's cool, but tedious in the long run.

You can read more about media playback here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment