Thursday, 16 April 2015

Ren'Py Multiple Audio Channels or Tracks

I keep meaning to do this post about audio channels in Ren'Py.

It was when I was working on my Nanoreno game, New Pisces, that I realised I would need to dig a bit deeper than just the Music, Sound and Voice channels that are standard in a new Ren'Py project. I wanted to have at least 12 loops of audio playing at the same time.

(This might seem like a lot, but the loops are quite stripped back - not full songs - and the 'gameplay' focuses on the interactive audio.)

After saving my 24+ audio files as mostly wav and ogg depending on the filesize (I tend to convert my wav files to ogg if they are over 1mb in the interest of keeping overall filesize low - I've been using http://media.io/ to convert the files) I started to look at how to get multiple music channels.

The Ren'Py documentation on Audio is here http://www.renpy.org/doc/html/audio.html where I saw:
 "New channels can be registered with renpy.music.register_channel()."

I think I first tried putting that code into the options.rpy file which didn't work and eventually I had a go with it in the script.rpy file - which works just fine! I also added "init python:" which I think I must've discovered on the lemmasoft forums ( http://lemmasoft.renai.us/forums/ ) when searching for solutions. In case it's helpful to anybody here is my code from the very top of my script.rpy file:

# You can place the script of your game in this file.

init python:
    renpy.music.register_channel("one", mixer=None, loop=None, stop_on_mute=True, tight=False, file_prefix='', file_suffix='', buffer_queue=True)
    renpy.music.register_channel("two", mixer=None, loop=None, stop_on_mute=True, tight=False, file_prefix='', file_suffix='', buffer_queue=True)
    renpy.music.register_channel("three", mixer=None, loop=None, stop_on_mute=True, tight=False, file_prefix='', file_suffix='', buffer_queue=True)
    renpy.music.register_channel("four", mixer=None, loop=None, stop_on_mute=True, tight=False, file_prefix='', file_suffix='', buffer_queue=True)
    renpy.music.register_channel("five", mixer=None, loop=None, stop_on_mute=True, tight=False, file_prefix='', file_suffix='', buffer_queue=True)
    renpy.music.register_channel("six", mixer=None, loop=None, stop_on_mute=True, tight=False, file_prefix='', file_suffix='', buffer_queue=True)
    renpy.music.register_channel("seven", mixer=None, loop=None, stop_on_mute=True, tight=False, file_prefix='', file_suffix='', buffer_queue=True)
    renpy.music.register_channel("eight", mixer=None, loop=None, stop_on_mute=True, tight=False, file_prefix='', file_suffix='', buffer_queue=True)
    renpy.music.register_channel("nine", mixer=None, loop=None, stop_on_mute=True, tight=False, file_prefix='', file_suffix='', buffer_queue=True)
    renpy.music.register_channel("ten", mixer=None, loop=None, stop_on_mute=True, tight=False, file_prefix='', file_suffix='', buffer_queue=True)
    renpy.music.register_channel("eleven", mixer=None, loop=None, stop_on_mute=True, tight=False, file_prefix='', file_suffix='', buffer_queue=True)
    renpy.music.register_channel("twelve", mixer=None, loop=None, stop_on_mute=True, tight=False, file_prefix='', file_suffix='', buffer_queue=True)
    renpy.music.register_channel("zero", mixer=None, loop=None, stop_on_mute=True, tight=False, file_prefix='', file_suffix='', buffer_queue=True)
    renpy.music.register_channel("zeroone", mixer=None, loop=None, stop_on_mute=True, tight=False, file_prefix='', file_suffix='', buffer_queue=True)

#my variables

define slowdis = Dissolve(2.0, alpha=False, time_warp=None)
define vslowdis = Dissolve(3.0, alpha=False, time_warp=None)
define pixelfast = Pixellate(0.3, 8)


Then to get my file playing on the desired channel I used:
    play one "00.ogg"

I also wanted to change the volume of certain channels at various points of the game, for that I used:
    $ renpy.music.set_volume(volume=0.2, delay=0.8, channel='one')

Here the volume is expressed as a decimal with 1.0 being full volume and 0.0 being silent, I believe this is accurate to more than one decimal place, but didn't do lots of testing to be sure that it doesn't round up or down. The delay property is the amount of time in seconds the change in volume takes, so the fade between the old and new volume.

Hopefully that has been helpful, if you'd like to ask me questions on this (or anything really!) the best way to get in touch is via twitter ( @sleepyagents )

Wednesday, 8 April 2015

NaNoRenO 2015 Entry: New Pisces - Android APK available now

Blog updates were on pause while I was finishing off my NaNoRenO game, New Pisces, which I managed to get finished by 31st March 2015.

You can download from:
http://sleepyagents.itch.io/new-pisces

New Pisces - NaNoRenO2015 - Sleepy Agents
I made an android version in addition to the standard PC ,Mac and Linux builds. The latest Ren'Py version (6.99 at time of writing) has made it much smoother to build an APK in Windows 8.1, in that it worked!

In addition to making a standalone APK file which can be sideloaded onto any android device I decided to go through some of the Google Play store setup. I made a publisher account via the Google Play Developer Console - https://play.google.com/apps/publish/signup/ - and paid my 25usd. (Just a comment on that, I think this one-time fee is a fair system which allows super-tiny developers and projects to get onto the play store, I really hope it remains a one-off fee and doesn't in the future move to an annual model. If you're planning on releasing on the play store it might be worth considering signing up for an account now just in case the system changes much in the future.)

Now due to the fact my game is closer to 100mb than it is to 50mb I had to create an expansion file - which I discovered is created in the same RAPT directory that Ren'Py saves the APK to and has the extension OBB (apparently stands for Opaque Binary Blob!). This would've been fine if I had read the documentation which the android configuration wizard clearly states you should! Doc: http://www.renpy.org/doc/html/android.html the bit at the bottom of that page tells you what to do to make a working expansion file! The bits of code build.google_play_key = "..." and build.google_play_salt = ( ... ) go into the options.rpy file (I put mine at the top of that file - after a failed attempt at adding them to script.rpy!). I wasn't 100% sure what to do for the salt so I made up some random numbers which I think is what is expected!

Google Play has a beta testing option, so I've used that to upload and test my game via the play store. I don't think I'll make the game public on the play store, this was really for my own learning. Oh and a quick nod to teamtreehouse ( http://teamtreehouse.com/home ) which is a great paid for elearning site. I watched some of the android dev videos previously which was good to get a feel for what I was to be undertaking!

The next post really will be about audio channels!