Precise Guitar Tuner - Review

14/09/19 Permalink

Produced as a part of a study into the science of soundwaves this was possibly one of the most fun pieces of software I have written.

I've always had a love of guitars and self taught myself to a decent level using books and the Internet, but I've always been intrigued how a guitar tuner works. How does it know what is in tune?

It turns out it's all in the science of sound waves and how they're formulated. A sound wave is produced by the vibration of air particles and travels in a wave. Now the wave has a frequency (measured in hz, how many waves/second) and amplitude (how tall the wave is) and by pulling data from the mic you can measure this. This is where it gets complicated.

A mic transforms the wave into data. It can 8 bit, 16 bit, 32 bit etc. 8 bit was tested first and it was fairly easy to measure - you've only got 256 values after all, but the accuracy was poor. Too approximated. So up to 16 bit - short values. Way more accurate and suitable - it added a lot more CPU horsepower to the job but it was necessary. The sample rate was next - how much data per second was piped through. It needed to as high as possible but to keep the stability.

The software was firstly developed on desktop Java and then ported quite easily to Android. It was much easier to develop the bulk of the software on the desktop, especially when visualising the sound waves on a graph. I was blown away how different sounds make different waves. You'd think a simple note played on a guitar would look quite similar to a sine wave. Nope, they have a weird shape dependent on something called timbre - the physical shape and type of string can change the shape significantly. All kinds of weird data going on. But I eventually got some decent measurements using various calculations, buffer sizes etc.

At this point the software was at a decent level - enough to port. Because Android is basically a container for Java (mostly earlier versions), the porting was fairly straightforward. A few classes came in different flavours, but a tweak here and there, and the engine was slotted in. Then you've got Android phones supporting various sample rates to contend with. I ended up writing code that would start at a reasonable high and test down until it didn't throw an exception. So some devices will benefit from higher frequencies, ie. more data, more accurate. This has the advantage of the software improving when newer hardware does. I think all devices support 48k which is sufficient, but I wanted to use as much data as possible.

The GUI was next. I wanted it to be clean, simple and fast - you don't want to sit there waiting - you just want to tune your guitar. I always liked the idea of presenting the raw data, but not too much that it would baffle people. So the 2 decimal place accuracy number was added. Then the graphical view to give perspective of where the played string is in relation to the target string and the rest of the strings. Custom tunings presets were then added as an alternative to EADGBE. I've never tuned to some of these tunings before and have to say, they sound awesome. Then I added manual string selection. 4 half notes down, 4 half notes up. I figured if you tune below or higher than this your strings are going to be too loose/tight. This added numerous other combos of setups (531,441 as an overall total (96)). Yes you read that right, over half a million custom tunings.

Anyway, I hope you've enjoyed this blog post, and if you want to try Precise Guitar Tuner out you can download it at Amazon, or Google Play.

Android targetSdkVersion and NetworkOnMainThreadException

04/09/19 Permalink

I've just come across a runtime exception NetworkOnMainThreadException when upgrading the targetSdkVersion of an Android app. Basically what happens is Android will stop an app by refusing to load a class if it senses networking code is in the main app thread. I guess it's a way of preventing ANRs (App Not Responding).

To avoid having to redesign large portions of your app you can call this in onCreate:

StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);

From here. This will prevent NetworkOnMainThreadException from being thrown. Only do this if you're sure your network connection is reliable.

Precise Guitar Tuner

31/08/19 Permalink

Precise Guitar Tuner is a highly accurate guitar tuner app for Android.

* One of the most accurate digital mic tuners in the world *
* Fractions of hz accuracy *
* Over HALF A MILLION custom individual string tuning *
* Popular custom tuning presets *
* Fully chromatic *

Featuring cutting edge software Precise Guitar Tuner gets your Guitar in tune with minimal effort, maximum accuracy.

Precise Guitar Tuner is available free for a limited time, then requires a small purchase to enable unlimited use.

You won't believe how much better and harmonious your guitar sounds when you accurately tune it. Release the true potential of your guitar!

DOWNLOAD HERE

OR at the Amazon app store:

Java - Get Command Line Parameters

15/07/18 Permalink

I couldn't find a simple way of parsing command line parameters passed to programs without needlessly importing libraries. String[]args is parsed using spaces only, so if you want more advanced parameters were you name the values and have multiple values like java Prog -opt0 blah blah2 -opt1 blah you'll need to parse it yourself.

Here's a simple way of doing more advanced command line parsing in Java:

 public HashMap<String,ArrayList<String>> getCommandLineOptions(String[]args){
   	HashMap<String,ArrayList<String>> opts = null;
        String opt = null;	
	for(String arg:args){
	   	if(arg.startsWith("-")){
	   	      opt=arg;	   					
	   	}else if(opt!=null){
		      ArrayList oopts = opts.get(opt);
		      if(oopts==null){
			  oopts=new ArrayList();
		      }
		      oopts.add(arg);
		      opts.put(opt,oopts);
		}
	}
	return opts;  			
  }

Android - Change Project Target API

07/01/17 Permalink

To use a different API library to build with in Android use the following method:

android.bat update project --path . --target "android-8"

And to see what API libraries are available:

android list targets

Products/Projects Old Products (J2ME) Categories Bookmarks Device Manufacturers

mobile-utopia.com | Feedback