Mathematical, musical curiosity

I’ve been recently writing an app that uses the autocorrelation approach to detect the pitch of musical notes. This approach basically tries to see if a given musical note is in a digital audio signal by comparing each sample with the next sample in the signal that ought to be the same (since a given note should repeat periodically as per its frequency). In exploring how to best do this in my app, I’ve come across something I found curious.

Before I get to that, I need to explain a couple of things. Firstly, I am doing this pitch detection for a particular instrument: the flute. The flute is ordinarily considered to be able to play notes from B3 (the B immediately below middle C, but only if a flute has a “B foot”, otherwise from middle C) to C7 (the C three octaves above middle C). However, very skilled players might be able to get a few notes higher, to F7. Also, the piccolo flute can go up to C8, but we’ll ignore that more now. Given that the frequency of B3 is 246.9Hz and that of F7 is 2,793.8Hz, the 43 notes are spread across about 2,550Hz of frequencies.

The other thing to explain is that CDs (and many electronic devices) use a sample frequency of 44,100Hz. This is considered to be sufficiently high to record and reproduce audio signals up to 20,000Hz, which is the general limit of human hearing. However, a higher sample frequency, of 48,000Hz, is being increasingly used, such as in DAT tapes or DVDs.

These two things come together in autocorrelation because it requires knowing the period of each note, measured in numbers of samples. For example, the audio signal for a pure B3 tone should repeat every 178.6 samples if sampled at 44.1kHz or every 194.4 samples if sampled at 48kHz. Similarly, F7 should repeat every 15.8 samples at 44.1kHz or every 17.2 samples at 48kHz. Except there’s no such thing as a fraction of a sample, so for my autocorrelation calculations, I would round to the nearest sample.

Rounding introduces error, so using a period of 16 samples (at 44.1kHz) or 17 samples (at 48kHz) for F7 is not ideal. In fact, these periods correspond to different frequencies – 2,756.3Hz and 2,823.5Hz respectively. The intervals between musical notes are measured in cents, and there are 100 evenly-spaced cents to a semitone. The frequency corresponding to a period of 16 samples at 44.1kHz is 23 cents below the real F7, and the frequency of 17 samples at 48kHz version is 18 cents above F7. Higher notes are more error-prone, and the corresponding errors for a low note like B3 are 4 cents below (for 44.1kHz) and 3 cents above (for 48kHz).

For my autocorrelation algorithm, some error in detecting pitch is okay, since as long as the flute is playing in tune, if the algorithm was less than 50 cents out, it would always get the right note. So, I wrote some code to look at what the maximum error in cents was in following this approach, considering a range of sample frequencies from 2,000Hz to 60,000, and got a curious graph:

Pitch Errors for Sample Frequencies

You might be able to see small red dots at the points for 44.1kHz and 48kHz (or you can click through to see a bigger version of the photo). This graph shows the maximum error in cents across all notes in the range between A3 and F7, and it is less than 40 cents for both 44.1kHz and 48kHz. In fact, the maximum error for 44.1kHz (29.3 cents, relating to the note G#6) is less than 48kHz (37.0 cents, relating to the note D7), and 44.1kHz is close to the minimum for all sample frequencies up until about 57.8kHz.

There is a general trend that the higher rates result in lower errors, although I wasn’t expecting that the sample rate of 44.1kHz would have lower maximum error than 48kHz. I wondered if this was due to the specific range I was examining, so I wrote some more code to examine the impact of maximum errors on these two frequencies if I used ranges of notes starting at A3 and finishing at between C7 and C8. Here’s the resulting graph:

Pitch Errors for Note Ranges

As with before, for a note range going up to F7, 44.1kHz has a lower maximum error in cents than 48kHz. However, if the note range had stopped at C7, 48kHz would have a lower maximum error. Also, if we’d gone above A7, 48kHz would also be more accurate than using 44.1kHz but at that point the error would be above 50 cents, i.e. not accurate enough to be useful.

So, curiously 44.1kHz happens to be well-suited to autocorrelation of notes in the flute range. I’m sure this wasn’t a consideration when that was selected as a common sample frequency for audio recordings, but it happens to benefit me now.

Children’s Music is Catchy

I don’t get to listen to music as much these days. When I was at school, I would have favourite CDs on repeat, studying or reading. However, perhaps I am beginning to re-live my youth, as I am starting to put CDs on repeat again, although it’s not exactly my idea.

The CDs are full of nursery rhymes or are by kids’ TV presenters. While these children’s CDs have simple melodies and the lyrics are easy to understand, they have an unfortunate tendency to get stuck in my brain for hours at a time. But I was pleasantly surprised by one CD we bought; it is a cut above the others.

Songs to make you smile

Surprisingly complex and enjoyable songs that will appeal to children

You may well scoff, but I am actually writing a review of a children’s album. Out of all of the various CDs we have to entertain our kids, this one is my favourite. So, what if it is songs by Justine Clarke, an ex-Home and Away actor and, more recently, Playschool presenter? The musical team behind her, primarily Peter Dasent and Arthur Baysting, have pulled off a wonder – a children’s album that does’t drive me out of my mind. In fact, I find myself humming or singing along.

The different songs on the album are from a variety of styles, with interesting instrumental lines and rhymes. The stand-out songs for me are the soft and sad Why Does The Baby Cry? and vaguely educational but fun Dinosaur Roar.

While bands like The Wiggles have mindlessly simple songs that are good for basic dancing, they don’t play well on repeat. It’s a relief (and lucky) to find music for children that I can also listen to.

Rating by andrew: 4.0 stars
****

Other suggestions for good children’s music will be gratefully accepted!

Getting back into flute

I think the last time I sung in a concert (where people paid actual money to hear it) was back in 2005, when we lived on the opposite side of the planet. I had begun to really miss having a musical outlet, and somehow I had managed not to end up in a choir, so what to do …

Start playing the flute again?

I learned the flute when I was at school, from year 6 through to year 12. During those 7 years, apparently I got to a half-decent level, since I received a music bursary to cover the payment of my music tuition (although, in hindsight, it might’ve been a scam to try to get more students into the choir and orchestra). But, in any case, putting in hours of practice every week for that many years must lodge some of it in the brain. Maybe even if it is about twenty years later.

So, in June, a friend mentioned that her orchestra might be interested in having another flautist around while one of theirs was on an overseas tour, and would I be interested in trying out for that. Would I? Yes!

It was to my astonishment and continual surprise that I was allowed to rehearse with the great bunch of people that is the Napier Community Orchestra all the way up to the concert that we performed today. Thank you to my fellow flutes (Belinda, Naomi) and oboe (Anne) for allowing me to come along, as rusty as I was.

It’s not like I hadn’t been doing anything musical for the last twenty years, and performing with choirs in the intervening time turned out to have really helped my sight-reading. Also, never underestimate the advantage a “mature age student” has over young students in self-directed learning.

Still, it was with a lot of excitement and perhaps even more terror, I sat down on stage this afternoon and played in a concert where, for the first time ever, I was the accompaniment to a choir. It was great, and I hope I get the opportunity to continue with it. Having a musical outlet is very satisfying.

If others out there in Internet-land are interested in opening that dusty flute case that they’ve had stashed under the bed and getting some music on, then I hope the information below will be of some use and encourage you to try getting into the flute again.

Playing the old instrument

If you’re like me, you’ll probably discover that your flute doesn’t quite hit all the notes as well as it used to, at least not without a lot of pressure on the keys. Unfortunately, while the metal parts of the flute are likely to survive well, the cork and pads can degrade. In particular, the pads can go hard over the years and then no longer seal the holes when you press on the keys. To fix this, I had to get my flute serviced, at a cost of a couple of hundred dollars.

You can get flute services at places like Wombat Woodwind & Brass or The Music Place. You can also speak to a flute teacher or the like for their recommendations.

Another thing I found was that, compared to when I was learning flute at high school, electronic tuners are now widely available at reasonable prices. I found it incredibly useful to practice my long notes with one in front of me to help me learn which notes I needed to adjust to keep in pitch. It was a real eye-opener.

You should be able to find something like the Temby Smart Tuner or Korg CA-1 in most music shops for $20-$30.

Another thing that I didn’t expect when I picked up the flute again is that my ability to assume the traditional flute playing posture (flute held out straight to the right) was not what it used to be. This made it harder to keep in pitch at the beginning.

You may also want to check out Jennifer Cluff who has some helpful info on returning to the flute.

Playing with a group

One of the things that Jennifer recommends in her link is finding a reason to play regularly, such as with a partner, with a teacher, or in a group. Since my opportunity to resume playing was based on playing with a group, that clearly helped me.

I had forgotten many aspects of playing in an orchestra. It was strange and interesting to rediscover them.

Firstly, there was the counting. In a choir, I had the music for other parts (or at least the accompaniment) to look at when I wasn’t singing. However, orchestral parts are full of rests. So, I had to learn to count again.

It reminded me of dancing, where you need to really learn the basic steps for your feet, so that they could unconsciously go at it while you focus on all the leading-following stuff. For the orchestra, I needed to be always tracking the beat and my count through the rests. It was something I’ve been working hard at, and can still improve.

Secondly, there was tuning. Again, I worked hard at this and can still improve. Learning how the different notes on my instrument needed to be adjusted up or down as I played them was extremely helpful. I also found marking that info on my score to remind me was also good for when the playing got intense.

I’ve come across some fascinating information on the physics of flutes by the University of NSW that helped me understand the finer aspects of flute tuning. I’m not sure if it was helpful, but I like to have the background knowledge.

Lastly, it was amazing when all the different parts came in together, but it was also very distracting and made it difficult to hear if the instrument was behaving (over/underblowing, etc.). I think the brass section knows exactly how distracting and loud they are, but what can they do – they’re brass. This, in particular, made playing in a rehearsal (or performance) very different to playing at home for practice. I really had forgotten this. Practicing against a recording of the piece helped me deal with this somewhat. I think repeated exposure at rehearsals will help more.

However, playing your flute with a group is only possible if you can find a group. It sounds like there aren’t so many in the northern / western suburbs of Melbourne, so here are the ones that I have heard about. Of course, they require different levels of proficiency to join, but may be a useful place to start. In no particular order:

If you give it a go, all the best!

Microsoft Research finally solves it: computer generated humour

This is brilliant, and you NEED to check it out right now. Microsoft Research has produced software for your computer called Songsmith that automagically generates synthesised accompaniment to songs that you sing into it. Or, more amusingly, to famous songs that you play into it. There are a number of these now cropping up on YouTube, and someone called Tim has produced most of the good ones so far. Here are a couple of my favourites: a techno version of Oasis’ Wonderwall and a latin version of Roxanne by The Police. Enjoy!

YouTube Preview Image YouTube Preview Image

Real Christmas Carolling

I saw this clip on a friend’s Wall in Facebook, but I’ve stolen it and put it here instead. It took me back to my carolling days when, during the 1,000th rendition of O Little Town Of Bethleham you could easily forget what verse you were meant to be singing. Except these guys are doing the 12 Days Of Christmas, and a couple of others besides. And they have talent!

YouTube Preview Image

The other cool thing is that I’ve actually sung Africa in a choir too.