Faster custom ringtones

Several people complained that my custom ringtones application is too slow when receiving calls, so I started analysing what ringtoned does when a new call is received. The three main operations in this case are creating the object that represents a call after retrieving all the needed information (caller ID, etc.) from Telepathy, looking up the contact that matches the caller and playing the ringtone.
The Telepathy bit just needed to be slightly smarter, but was already quite fast. The contact look up was already very fast, unless you have so many contacts to make your address book unusable.
The code that needed more optimisation was the one that plays ringtones. It turned out that using GStreamer with playbin2 (the element able to detect and play all the supported file types) is not fast enough for this use case. I tried different approaches and in the end I decided to always use uncompressed wave files and stream them directly to PulseAudio.[1]
Note that GStreamer is not the best solution just in this very specific case, for all the other use cases GStreamer is still the best solution.

After these changes I was really expecting to get very good performances, but it was still quite slow. My analysis was showing that, since when ringtoned gets notified from Telepathy of the existence of a new call to when it starts streaming to PulseAudio, less than 0.1 seconds passes, so why was it still slow?
At this point I tried using bustle to generate graphs of the D-Bus activity when a call is received. The graphs showed that the delay was not ringtoned’s fault, but a bug in Maemo causing a freeze that made the dispatching of new calls about 4 seconds slower when ringtoned was running. Somebody is now working on the bug and trying to figure out why it’s happening, in the meantime I’m working around it watching for new calls in a different way.[2]

Ringtoned and the related packages are available in Maemo extras-devel under the name “Custom ringtones for your contacts”. If you don’t want to add the extras-devel repository (as it contains a lot of unstable software, you have been warned!), you can download ringtoned directly from my personal repository:

Install per-contact-ringtones
Install from my personal repository
(follow the link on the N900 browser)

The only known big problem left is that ringtoned breaks vibration, I will fix it in the next days/week.

Update: It looks like MyContacts is incompatible with ringtoned, so you cannot use these two programs together.

[1] The file is uncompressed in background, so you can still use any type of file for ringtones. Just notice that, when you update from a previous version, the first time you receive a call from a contact that already had a custom ringtone you will get the default ringtone and not the custom one as previous versions were not generating the uncompressed file.
[2] For people interested in Telepathy: the freeze happens if there is an observer running, even if at that point the dispatching to observers didn’t start yet! The (ugly, but effective) solution was to just listens to the NewChannels signal directly. When the Maemo bug will be fixed I will revert my code to use an observer.

20 thoughts on “Faster custom ringtones

  1. Hi Marco, thanks a lot for providing ringtoned. Does it also use custom ringtones for incoming SMS depending on the sender? If not, where can I file a feature request?

    Like

  2. hi marco, custom ringtones doesnt allow me to play the music from my othr folder other than the ringing tone….do you know if i can dowgrade to the first version..that new updates kill me

    Like

  3. @Petteri:
    The policy daemon freezes applications based on their cgroup when a new call is received, so applications not involved in telephony (like the browser) don’t interfere.
    For some reason also dbus-daemon is frozen if the previous version of ringtoned was running, even if it doesn’t make any sense.

    @Stefan:
    No. It’s a less needed feature as for calls you often have to decide whether to answer or not very quickly, so the different ringtone is useful to make the decision.
    It’s possible also to do the same for SMSes, but I don’t think I have enough time to be honest.

    @edgar:
    Sory, but I don’t understand what you mean. What doesn’t work exactly?

    Like

  4. Regarding the slowness of playbin2 startup, that should have been solved since (i.e. the startup time has been smashed down since 0.10.25)…. but won’t help unless you (or Nokia 🙂 ) provide updated gstreamer packages.

    Nice work.

    Like

  5. If the ringtones fail playing for you it’s because there is a bug in the service that encodes the files into wave files 😦
    I’m trying to find a work around now.

    Like

  6. marco, it doesnt play the music saved in other folder than my ringing tone. when one of my contact to which i assigned those songs calls, nothing is playind and i hear nothing.

    Like

  7. however, everything was alright with the first version…can you send it to me so i can downgrade the applications

    Like

  8. Dear I faced a problem after installing previous version. Vibrator was not working for incoming calls only… It works on silent mode and for sms and alarms etc. But not for ringtones… I reflashed my device. Restored from backup and didnt install this software only. And vibrator is working now. Can you please answer me what is the reason and is it resolved now?

    Like

  9. It was working choppily in your first revision, but now not at all. It causes my phone to cease to vibrate and ring. I am trying it with my mp3s, I think you said something about using uncompressed .wav files. It now doesn’t seem to take well to .mp3 files. Please fix this when you can. Thanks for all of your effort in bringing this to the n900! 🙂

    Like

  10. I can’t get my phone to ring at all now with this app. Once I uninstalled it I can get my phone to ring. At first it worked fine now with the updates it doesn’t work at all.

    Like

  11. Have you been using playbin2 as is? Then it is really too slow. One easy tweak is to use NATIVE_AUDIO on the flags. Also using “filesrc ! decodebin2 ! pulsesink” is faster.

    Like

  12. I released 0.2.3, can people try it and tell me if it works for them?

    @Stefan Kost:
    Also with the suggestions that Collabora Multimedia people gave me it seems to be too slow for something like playing ringtones, at least in the version in Fremantle (Edward promises that new versions are much better).
    In the end I went for wavparse directly, it seems to be fast enough and more tolerant with broken wav files than canberra.

    Like

Comments are closed.