Sunday, 30 December 2012

Detect CPU architecture at runtime for Windows 8 Store Apps

  If you are developing an application for the Windows 8 Store it is very important that you test it on an ARM device (Surface RT, Asus VivoTab RT, Dell XPS 10,etc.) before sending it into certification. You will probably have some bad surprises and not everything that was fast&fluid on your development machine will continue to be so on an ARM device (the list scroll performance reminds me of the first version of Windows Phone). So you will have to simplify the layouts, animations and in some cases even rewrite part of your code. Parallel Programming is your friend if you can use it (for Kids' Orchestra I had the big problem that generating 100ms of sound output took more then 100ms so after 2 days of trying to optimize the C# source code I realized that I only had to use the Parallel.For and everything started working). 
   Due to performance differences you might need to split the user experience/code on different architectures (like disabling some animations on ARM). If this is the case it becomes very important to know the processor architecture on which your application runs. One solution would be to create 3 different packages of your applications and use the conditional compilation to differentiate between what happens on each architecture. If you still want to use only one package (Any CPU) it is enough to have a method that returns the processor architecture.
    The bad news is that WinRT framework doesn't have any method/property that returns the processor architecture  (at least I don't know it). The good news is that you can still use GetNativeSystemInfo as it is an api supported for Windows Store apps (it is even supported for Windows Phone 8 apps):


  For Windows Store apps you can use two approaches to call this api:
1. Use P/Invoke -this is the one I opted for;
2. Create a Windows Runtime Component in C++ that you can then call from managed code - this is the approach you will have to use if you need to call this function on Windows Phone 8.

   What I did is to create a public class, which I called CPU, and has one public static property NativeInfo that returns an SystemInfo object:

 public class SystemInfo  
{
public ProcessorArchitecture ProcessorArchitecture;
public ushort ProcessorArchitectureId;
public ProcessorType ProcessorType;
public uint ProcessorTypeId;
public uint NumberOfProcessors;
public ushort ProcessorLevel;
public ushort ProcessorRevision;
public uint AllocationGranularity;
};

and a public method IsProcessorFeaturePresent (invoking also a supported Api for Windows Store applications) which returns if a certain ProcessorFeature feature is supported or not.

I have also created a small sample that will give you a list with your processor details. Here is the result I got on  my Surface:


Hope you will find the class useful. Don't hesitate to contact me if you need further details.

SOURCE CODE:

NAMASTE!

Wednesday, 26 December 2012

C# XAudio2 Sound Playback for Windows Phone

     Let's begin with a small introduction to XAudio2:
     XAudio2 is a low-level audio API. It provides a signal processing and mixing foundation for games that is similar to its predecessors, DirectSound and XAudio. XAudio2 is the replacement for both DirectSound and XAudio.
     XAudio2 abstracts audio generation by separating sound data from "voice", allowing each voice to be filtered by programmable digital signal processing and effects processing functions. Voices can be "submixed" together into a single stream. There is always only one Mastering Voice that outputs the result using WASAPI.

     XAudio2 is primarily intended for developing high performance audio engines for games. For game developers who want to add sound effects and background music to their modern games, XAudio2 offers an audio graph and mixing engine with low-latency and support for dynamic buffers, synchronous sample-accurate playback, and implicit source rate conversion. Compared to WASAPI, XAudio2 requires only a minimum amount of code even for complex audio solutions. Compared to the Media Foundation engine, XAudio2 is a low-level, low-latency C++ API that is designed for use in games.
     XAudio2 cannot be used for background music - for this task you will have to use the IMFMediaEngine. XAudio2 cannot be used for capturing audio - for this task you will have to use WASAPI. Do not use XAudio2 for media playback. For that task you can use MediaElement
    XAudio2 is part of the DirectX api that is included in the new Windows Phone 8 SDK. The Api is shared between Windows 8 and Windows Phone 8 which means that you will be able to fully reuse your source code on both platforms. 

If you want to use XAudio2 for your C#/VB/HTML code you have two options:
1. Use SharpDX . SharpDX is a wrapper of the DirectX Api under .Net platform. Theoretically you can use it to call XAudio2 api directly from your managed code. Practically what happens is that the .Net CLR/GC on ARM seem to block native threads so your audio will shutter/glitch in certain conditions. I had the same problem when I was developing our Windows 8 game Kids' Orchestra and the audio had glitches even on a core i7 processor.
2. The other option, which from my experience works better, is to develop an Windows Phone Runtime Component that will manage the XAudio2 part and expose the needed methods/events to the managed code.

      To better understand how it is done I took the Windows 8 sample XAudio2 audio file playback sample C++ from MSDN and ported to Windows Phone 8 by splitting it in two projects: The C#/Xaml part for the UI and the "audio" project which is a Windows Phone Runtime component developed in C++.
     The porting was pretty easy. I only had to re-code the player class to make it "visible" to the managed code project and added an event that will tell you when a certain Source Voice has finished playing its buffer/sound (we have 7 sounds and each sound has a Source Voice associated to it). If you need further details on how to write a Windows Phone Runtime component in C++ have a look at this  MSDN Post

    This sample only plays Wav files that are resources in the C++ project. You could also dynamically generate sounds in managed code and pass the Wave/buffer data as a byte[] to the runtime component. Inside the native code you will then generate an XAUDIO2_BUFFER and submit it to a Source Voice for playing.

     I have attached the SOURCE CODE for the Windows Phone project. If you have problems with it don't hesitate to contact me.

NAMASTE!

Wednesday, 19 December 2012

Using indexOf method on array in server side JavaScript

Sometime back I was trying to use indexOf method on an Array object in server-side JavaScript (SSJS) code. But it was giving me error that indexOf method is not defined. I also couldn't find this method in help documentation. It was then it struck me that the implementation indexOf method in client side JavaScript itself is a bit fuzzy with Internet Explorer not supporting it. It can be defined using prototype property.

I found a simple solution here which implements the method. Just add the below code snippet to your SSJS code and then you would be able to use indexOf method.


Remember that this would be required for SSJS. For client side JavaScript I would recommend using dojo.indexOf.

Tuesday, 18 December 2012

Charging pattern on HTC One X

My HTC One X has a pattern in which it charges itself.


In the above screenshot of my battery usage you can see that from 10% battery level to 60% battery level my phone charges at a constant rate. But from 60% up till around 75% this rate dramatically drops and it takes much longer to charge. Then picks up again until around 90% and afterwards it charges very quickly. I don't know why does this happen and what is its significance. I contacted HTC support but there response was not satisfactory either.

So if you notice the same pattern while charging or a different one do post it in the comments.

Monday, 17 December 2012

Some business customers invited to test new BlackBerry 10 platform

If you're lucky, you may be one of the 120 select customers from 64 Fortune 500 companies to beta test the BlackBerry 10 smartphone, which is set to make a worldwide debut on the 30th of January. The new BlackBerry Hub experience is waiting for your reactions.

The by-invitation-only program starts today and includes participants from financial, government, insurance healthcare, manufacturing and media. It is design to give early adopters a real-life experience on the new BlackBerry 10 platform from Research in Motion, who introduced the BlackBerry in 1999.

“Beginning today, RIM will be visiting some of our enterprise and government ‘early adopters’ and getting them started with the BlackBerry 10 platform,” said Robin Bienfait, Chief Information Officer, Research In Motion. “At RIM, we’ve seen the power of our new enterprise mobility management solution first-hand, and we are thrilled to share BlackBerry 10 directly with these leading organizations.”



The testers will be able to use the key features of the new platform, such as BlackBerry Balance, the BlackBerry Hub, a new messenger and explore the dedicated BlackBerry app store, which is expected to contain around 100,000 apps ready at launch.

According to RIM, getting the new devices in the hands of its best and largest enterprise customers was an important step, as the launch draws closer.

The new BlackBerry 10 devices are expected to have Near Field Communication, or NFC capability, as "BlackBerry Tag" was announced by RIM in January in a BlackBerry OS 7.1. update. This technology will allow content sharing with a simple tap between two NFC-enabled BlackBerry smartphones.

RIM is also counting heavily on the new devices having the Federal Information Processing Standard in place, which also known as FIPS 140-2, a requirement for highly sensitive information. RIM says this certification will help government agencies deploy the BlackBerry 10 smartphones from the day of launch.

According to the BlackBerry Blog, a touchscreen model is expected to be shown at launch, but physical keyboard lovers shouldn't be worried, as a QWERTY model should be coming soon after the Jan. 30 unveiling.

The new devices will be based on an operating system built around features from QNX Software Systems, an automotive industry software maker, who BlackBerry acquired from Harman International Industries in April 2010. In September 2010, the BlackBerry Playbook was announced, along with a new QNX operating system.

We'll learn more about pricing, carriers and availability at the January launch.

Video: BlackBerry Fans Visit RIM HQ to Sneak a Peek at BlackBerry 10

Tips: 10 ways to use BlackBerry Bridge with your BlackBerry Playbook

Visit us on Facebook | Follow on Twitter | Send an email | View Photo Galleries

Saturday, 8 December 2012

New features in HTC One X after Jelly Bean update

Some time back I updated my HTC One X to Jelly Bean (JB) using OTA update. The update takes your Android version to 4.1.1 and Sense to 4+.


Its been almost a 2 weeks with this update and the most noticeable improvement I can see is of battery usage. My phone lasts 1-2 hours more than it used to before. Well done HTC! There also some additions (and deletions) which I am going to describe here. Now I not an Android expert so I don't know all the new features in JB itself, so you may find a feature new in JB listed here. Also you won't find Google Now and Google Play Music here as I know they are new to JB and not HTC One X.
Continue reading »

Monday, 3 December 2012

Smart watches connecting to smartphones could be next big thing

I have been feeling a little like Dick Tracy lately, as I walked around with a Sony SmartWatch on my arm. There is a certain cool factor about this device, which was on loan from Verizon Wireless.

The SmartWatch functions as an extension of your Andriod smartphone or tablet and will allow you to read text messages and view social network updates, as well as check the time and date. The latter should be a "duh" moment; of course it'll give you the time and date.

I was up and running in no time, which allowed me to leave the Android smartphone in my pocket for most tasks.

The SmartWatch makes a Bluetooth connection to Android devices. After downloading a SmartWatch Liveware manager app from the Google play store, you're off and running with Facebook and Twitter updates, the weather, text messages and other features that have smart watch apps available. After digging around in the Android app store, I discovered SmartWatch apps for eBay, Web Cams, games, and get this – a Bubble Level.

I got most of these apps and features to work with the SmartWatch, but keeping a connection to the Android phone is kind of flaky. You can't let them get too far apart, as in the next room, or the Bluetooth connection will be lost.

I also found that swiping the face of the SmartWatch to control the menus and features was a little hit and miss. I would prefer hard button for some of these functions, as the face of the watch is too small for big fingers to be swipe and pinch. The SmartWatch has a single button to bring up the time and date.

Some users found the charging cable tricky to navigate, as it plugs into the underside of the watch, but depend on clamping friction from the watch back against the band to hold it securely. But once you do it a couple of time, it becomes a fairly easy maneuver.

The SmartWatch is compatible with most Android smartphones and tablets. A long list on Verizon's website includes the Droids, HTC, LG, Motorola and Samsung devices. As expected, the Sony Xperia Play is also compatible.

The Sony SmartWatch is listed at $149 from Verizon Wireless and is only available for Android devices at this time. But other manufacturers are also working on iOS compatibility, along with their Android software.

The Citizen Watch Company is taking a different approach with their $495 Eco-Drive Proximity wristwatch. According to this well-known giant in wristwatches, their smart-watch timepiece will connect to the iPhone 4S and iPhone 5 through Bluetooth and features automatic adjustments for time zones, a lost iPhone search feature and email alerts with discrete vibration.

To use the smart watch features on the Citizen Proximity watch, you'll need the Proximity app in the Apple App Store. But early adopters are reporting Bluetooth connectivity problems in their reviews.



This technology is still in the early stages and I'll say the best is yet to come. As we look ahead to 2013, we can expect smart watches from MetaWatch, Martian Watches and Pebble. All of these firms have watches that are about to hit the market or are on the drawing board. These devices will be able to answers phone calls and the social networks integration will get better.

I'll predict that smart watches will be the next big thing and we won't have to reach for the smartphones as often to check emails or answer a call.

More: Apple smartwatch may be in the works

Visit us on Facebook | Follow on Twitter | Send an email | View Photo Galleries

Sunday, 2 December 2012

Making internet pass-through work after updating HTC One X to Jelly Bean

Update 22 Jan 2013: "HTC Sync" seems to have been discontinued so the download links given below will not work. "HTC Sync" is different from "HTC Sync Manager". For exact difference read on.

I recently upgraded my HTC One X to Jelly Bean via OTA update. After updating I was unable to use internet pass-through which used to work flawlessly before and I already had HTC Sync installed on my PC. I uninstalled, installed, uninstalled again and installed again to make it work. But it simply refused. It gave me error of "Either you do not have the latest version of HTC Sync installed on your PC, or another phone is already using Internet pass-through on your PC." on my phone.


From this discussion on XDA Developers forum I found that there is something called as HTC Sync Manager. This is different from HTC Sync which I had installed on my machine. I don't know why HTC did this but its really confusing. Here's how these two software look.
Continue reading »