This project has moved. For the latest updates, please go here.

How custom decode with dynamic rate song in Universal app

Apr 2, 2015 at 8:08 AM
I need to process dynamic rate song format, like VBR.

In my previous app (Wp 8.0 SL), I decode the song in my class based on MediaStreamSource, and set a static rate before opening, then change the rate to the same rate with I set before opening in my custom decode code, it works.

Now I want to upgrade to Universal, I found there is no AudioPlayerAgent, AudioStreamingAgent and MediaStreamSource, I need to reach following goals:
  • decode my song format by myself, and play it background
  • support dynamic rate
  • further consideration add effect like equalizer (that's the main reason why I need decode it by myself)
Thanks for any help.
Coordinator
Apr 13, 2015 at 12:17 AM
I could have sworn I wrote an answer to this before...?

The way that background audio works has changed significantly on WP8.1. Take a look at the MSDN "Background Audio for Windows Phone 8.1 Sample" and the "MediaStreamSource Streaming Sample". For effects, you may want to look at the "Media extensions sample".

phonesm has a sample for using the WP8.1 Background Audio from C# (this implementation is still missing persistence). The actual WinRT MediaStreamSource is managed by WinRtMediaStreamConfigurator and WinRtStreamState.

The phonesm implementation has been tested with various oddball MP3 and AAC streams and to my knowledge has not had any problems with VBR. I recall saying something along the lines of how it may not work so well if the number of channels or the sampling rate changes during playback (deja vu or perhaps my reply post went to the Codeplex outage page instead of to the discussion thread).
Apr 13, 2015 at 1:49 AM
Thanks for your feedback, I think I can go ahead with your help. And I am so sorry that troubling you to answer again. Thanks again.
Coordinator
Apr 13, 2015 at 4:53 AM
You're welcome.

But no need to apologize; you didn't gobble my previous reply.

Which reminds me: if you do want to run an equalizer and such, you should probably look at doing at least that part in C++, using the ARM NEON extensions for the heavy-duty math. That should cut battery consumption significantly. SIMD support for .NET is coming, but it is not here yet.
(I've also heard some rumors that background audio on WP8.1 is less susceptible to memory leaks when used from unmanaged code. I should test that hypothesis myself.)

There is also some code in the tree that is not currently used--or even referenced by a project--that might be of interest if you are handling raw PCM samples. Most of it is in the SM.Media's Audio/Generator directory, but the platform specific stuff lives in SM.Media.Platform.WinRT's Audio/Generator directory.

Good luck.