No iCloud Drive on iOS? No problem

For quite a while, AudioStretch has been able to open audio files that are not in an iOS device’s Music library via the “Open In…” mechanism. For example, I can open the Dropbox app, choose an mp3, then click on the “Action” icon, choose “Open In…” then choose AudioStretch from the list of compatible apps that appears. After a second or two, the file opens up in AudioStretch.

I find this really handy for keeping a small selection of test files that I don’t want to have cluttering up my Music library, e.g. brief excerpts of various types of music, sine tones, etc.

Now that iOS 10.10 (aka Yosemite) and iOS 8 are out, I thought I’d try iCloud Drive instead. So I dragged a few audio files into iCloud Drive on my Mac, which is really easy, as iCloud Drive is nicely integrated with the Finder (as is Dropbox).

I figured I’d then open up Apple’s iCloud Drive app on my iPhone, choose one of the files, and use “Open In…” just like I do with Dropbox. Problem: Apple, rather incredibly, doesn’t have a iCloud Drive app!

With iOS 8, it’s now possible for an app to access files you put in iCloud Drive, but only if the app has been set up to do so. Specifically, it needs to use the UIDocumentMenuViewController class. I’m experimenting with it right now in my AudioStretch app. Works well, but before I can ship this feature, I have to figure out where to add yet another button to the UI, test it thoroughly, submit it to the app store, etc. which means it’ll be easily several weeks before it’s deployed.

In the meantime, there’s a stop gap measure: the Cloud Grab app. Ridiculously simple app: it just shows the documents you have in iCloud, and allows you to “Grab” and “Use” them (via Open In) in other apps. For $0.99 it was a no-brainer for me to buy it.

Seems a little crazy that Apple didn’t provide something like this out of the box, but hey, the developer of Cloud Grab was smart enough to spot this gap, so good on him! That’s entrepreneurship: spotting some little niche and filling it fast.


Posted in Uncategorized | Leave a comment

Predictable PIN numbers

An interesting analysis of PIN numbers in this article in Data Genetics shows astonishing lack of randomness in how people choose PIN numbers.   For example, just 20 4-digit numbers account for a staggering 26% of 4-digit PIN numbers, with “1234” alone accounting for over 10%!

Posted in Uncategorized | Leave a comment


Besides writing audio software, I play guitar in various styles.  Mostly at home just to myself, but very occasionally I play in public.

Earlier this year, I had the pleasure and honour of playing the lead guitar part in the world premiere of “Semisopochnoi (Семисопочный)”, a concerto for solo electric guitar, electro-acoustic sounds and Niibori guitar orchestra. The piece was composed by my friends Robert Casteels (concept and acoustic music) and Peter Kellock (electro-acoustic music).

The premiere took place during the NUS Guitar Ensemble’s “Wanderlust” concert on 16 March 2014 at the Conservatory Concert Hall of the Yong Siew Toh Conservatory of Music, in front of an audience of ~400 people, with Robert Casteels conducting.

There’s a very nicely-done video of the performance (below).  It’s a long and slightly unusual piece.  If you’d like to just see my solo playing, I reckon the best bit is the ~1 minute solo from ~12:00.

Posted in Uncategorized | Leave a comment

A Public, Cross-Platform DSP API?

Porting DSP code to take advantage of platform-specific ‘native’ DSP libraries is a pain. Surely there’s a better way.

Over the years, I’ve worked on DSP projects for many different platforms. As much as possible I try to find a library of essential DSP functions that are well-optimized for the target platform. For example, when I was doing a lot of development on Windows, I used Intel IPP (Integrated Performance Primitives). In recent years, I’ve been developing a lot for iOS, so I now use Apple’s Accelerate/vDSP Framework.

The advantage of using a ‘native’ DSP library is that it can be wicked fast. The FFTs in Intel IPP and in the Apple Accelerate framework are substantially faster than any of the C versions you’ll find on the web. They’re also very nicely documented. Unfortunately they’re also totally non-portable. If you write some nice code using Intel IPP, for example, porting it to some other platform where IPP is not supported will be a lot of work. Even within just the Windows world, you can’t even count on using Intel IPP alone, as it’s not supported on ARM.

A while ago, I needed to port a bunch of DSP code I’d written for iOS to make it run on a Linux server and on Android tablets. I ended up writing my own vDSP-like library – optimistically dubbed “OpenDSP” – all in standard C++, using signatures that are nearly identical to Apple’s own functions. For example, the Accelerate framework has function vDSP_vmul(), which “multiplies vector A by vector B and leaves the result in vector C”. My own implementation looks like this:

void DSP_vmul(
	const float x1[],
	DSP_Stride stride1,
	const float x2[],
	DSP_Stride stride2,
	float y[],
	DSP_Stride strideResult,
	DSP_Length n)
	while (n--)
		*y = *x1 * *x2;
		x1 += stride1;
		x2 += stride2;
		y += strideResult;

I wrote my own implementations for the couple-of-dozen vDSP functions I needed, including several of the FFT ones. I put them all into a single file (OpenDSP.cpp), and in the accompanying OpenDSP.h header, I mapped the vDSP_abc function names to my DSP_abc, but only if the target was a non-Apple platform.

#ifdef __APPLE__

// If you're building for an Apple platform (Mac or iOS), then you really should use
// the Accelerate framework. It's really fast!

#include < Accelerate/Accelerate.h >


// If you're *not* building for an Apple platform, we use #defines to map vDSP function
// names to the corresponding OpenDSP function names. This allows you to write cross-platform
// signal processing code that's blazingly fast on Apple platforms, and uses Apple's vDSP
// functions, and run the same code on other platforms as well.

#define vDSP_vmul  DSP_vmul

// Similarly for vDSP_vclr, vadd, vsmul, create_fftsetup, fft_zrip, etc...


This approach worked very well, in that I can now compile code using vDSP functions on any platform, not just Apple’s.

I’ve considered making my OpenDSP library public, but here’s the problem: the vDSP documentation, and therefore presumably the API itself, is covered by Apple’s copyright. So if I were to release the library publicly, Apple could plausibly come after me for copyright infringement. After all, Oracle sued Google over the Java API, and ultimately won the case.

Personally, I’d rather focus my brain power on developing interesting apps, not on learning platform-specific APIs. Ideally there would be a single public-domain API for basic DSP functions, with a generic C/C++ implementation that could be compiled for any platform. Platform owners would be free to create their own super-optimised implementations, or in the mean time developers could map them to existing platform-specific libraries (Intel IPP, Apple Accelerate/vDSP, ARM Ne10, etc.).

Does anyone know whether such an API already exists? If not, would anyone be interested in helping to define one?

Posted in Audio, DSP, FFT, iOS, Programming | 5 Comments

Downloading audio and video from YouTube

Users of my AudioStretch app sometimes ask me whether you can use YouTube content in it, for example to work out how to play a solo from some jazz concert video. Short answer: you can’t. AudioStretch doesn’t have the ability to grab content directly from YouTube, and even if it were technically possible to add such a feature, it’s probably not allowed.

That said, there are services to download content from YouTube and get it into audio or video files on your PC (or Mac). Once you’ve got the file on your PC, you can copy it into Dropbox. Then in Dropbox on your iPad, you can choose the file and ‘export’ it to AudioStrech (or other app) via the iOS “Open In…” mechanism. So here are a couple of services you can check out. lets you download the audio track of a YouTube video as an mp3 file. Just take the URL from YouTube, copy/paste it into, and in a few seconds an mp3 will be ready for download.

If you want to download a video (not just the audio) from YouTube, go to the YouTube video, then change the start of the URL from to, e.g. change:


That second link redirects to, and from there you’ll be able to download the video as an mp4. Note that you can you can open the audio track mp4 videos in AudioStretch via “Open In…” from Dropbox, just as you would load up mp3 files.

Disclaimer: I’m unsure of the legality of the above services, and have no idea whether they’re entirely safe, etc. so use them at your own risk! And also, please remember that much material on YouTube is not in the public domain, and probably shouldn’t have been uploaded to YouTube in the first place. If you’re just downloading a song to work it out in AudioStretch or some other time-stretching app, and not redistributing it, that may be OK (at least morally, if not legally). But if you really like a song, support the artist by buying a copy of it from a legitimate source. If your favourite artist puts out educational videos or books for learning their stuff, buy them. You’d be surprised how little most recording artists earn (and most app developers, for that matter). Musicians and other creative people often love doing what they do, but need to buy food and pay the rent too!

Posted in Uncategorized | Leave a comment

The Expert (Short Comedy Sketch)

Classic! I’ve been in so many meetings like this…

Video | Posted on by | Leave a comment

Real-Time Audio Generation Using WASAPI on Windows 8.1

Most of my audio coding work these days is in Flash or iOS, but I always keep an eye on other possible platforms to develop audio apps for. One of the biggies is of course Windows 8, so I figured I should at least get familiar with the basics of doing interactive real-time audio generation in a Windows 8 app, using Microsoft audio APIs.

Much to my surprise I couldn’t find a good demo app (at least when I searched a few months ago). The nearest I could find was an MSDN WASAPI sample, which is fine, but doesn’t do real-time audio generation, i.e. it doesn’t generate audio that’s calculated continuously, on-the-fly, and sent to the audio output with relatively little latency.

So I created my own (full code here), using the MSDN WASAPI sample as a starting point, stripping it down to the bare essentials for interactive audio generation. It’s a simple continuous sine tone generator, with the sine frequency adjustable via a slider. It looks like this:


My code sets up a real-time audio output that calls an audio generation callback function at regular intervals. The fiddly WASAPI stuff is encapsulated in C++ AudioOutput class with a very simple interface. Basically you create the AudioOutput, initialize it with a static callback function and an object pointer.

	// Create and initialize a WASAPI renderer
	m_audioOutput = Make<AudioOutput>();
	if (m_audioOutput)
		m_audioOutput->Init(AudioOutputCallback, this);

In that static callback function, you can use the object pointer to call a non-static method of an object. In my demo, the callback function is implemented in MainPage.xaml.cpp. MainPage.xaml has a slider that sets the instantaneous frequency of the sine tone. Here’s the static callback function and the redirection to MainPage’s class method:

void MainPage::AudioOutputCallback(
	float32 *output, 
	int n, 
	int numChannels,
	int sampleRate,
	Platform::Object^ user)
	MainPage^ mainPage = safe_cast<MainPage^>(user);
	mainPage->GenerateAudio(output, n, numChannels, sampleRate);

And here’s MainPage’s GenerateAudio function:

void MainPage::GenerateAudio(
	float32 *output, 
	int n, 
	int numChannels, 
	int sampleRate)
	// Compute the phase increment for the current frequency
	assert(m_frequency != 0);
	double phaseInc = 2*M_PI*m_frequency/sampleRate;

	// Generate the samples
	for (int i = 0; i < n; i++)
		float32 x = float(0.1 * sin(m_phase));
		for (int ch = 0; ch < numChannels; ch++)
			*output++ = x;
		m_phase += phaseInc;

	// Bring phase back into range [0, 2pi]
	m_phase = fmod(m_phase, 2*M_PI);

Again, you can download a zip with the full project source code. It builds fine in Microsoft Visual Studio Express 2013 for Windows, and runs fine on Windows 8.1 running under Bootcamp on my MacBook Pro. I make no claims that it will build or run on any other configuration! If you find this code useful and adapt the code for your own projects, no attribution is necessary… but of course it’s always welcome, as are thank you notes in comments. Enjoy!

Posted in Uncategorized | 6 Comments