About Pitch Correction Plugins

Since the introduction of Antares Auto-Tune, in 1997 [1], pitch correction algorithms have considerably changed popular music and music production. This technology allows producers to change the intonation of a vocal performance to be perfectly in tune, based on a tuning reference (usually A-440 Hz). The wide dissemination of pitch correction plugins, from different vendors and at all price ranges, have made this technology easily available for professional and amateur producers.

In the present day, it is possible that the majority of popular music recordings use pitch correction algorithms, to some extent [2]. New products, like Melodyne, allow producers to go even further and manipulate not just pitch, but intensity, duration, breath sounds, etc. These new technologies have changed the paradigms of music production, and are subject to a lot of criticism, since it is possible to make an unskilled vocalists performance — even one with big intonation problems — perfectly in tune.

On the other hand, pitch correction can be really time saving, for example, when you have an awesome take with some minor intonation issues, and you don’t have time or budget to redo the recording. Tools like Melodyne also enable producers to create vocal harmonies from the original take, with no need to record any extra voice, which might reduce the production costs considerably. Even though the recording might loose some of it’s potential in terms of expressiveness, it can come in handy in certain situations where you don’t have a singer available to record an extra voice.

Another common use of pitch correction is for manipulating the voice sound itself, creating an effect that sounds a bit like a ´robotic voice´. This particular use of pitch correction was made famous by the 1998 hit Believe, from Cher (see below). Since then, many other artists have used it in a similar way, specially in electronic music genres.

In conclusion, the use of pitch correction algorithms such as Auto-Tune and Melodyne have become widely spread. It changed popular music in several different aspects, and it keeps changing as new technology becomes available. Even though there is lot of criticism around it, it can’t be denied that it is a useful technology, and that it’s use can’t neglected by music producers.


References

[1] http://www.antarestech.com/about/history.php

[2] https://worldpopmusics.wordpress.com/casestudies/pitch-correction/

Advertisement

Ruby operators: plus-equals (+=) and shovel (<<)

A few days ago I started solving the Ruby Koans, which is an amazing way to learn Ruby by solving problems (I highly recommend anyone interested in Ruby to check it out). It is basically a set of Ruby files with a series of errors (intentionally made) that you have to fix for the code to execute.

One of the steps of the Ruby Koans (step 57 to be exact, method test_the_shovel_operator_will_also_append_content_to_a_string) helped me to understand the difference between the plus-equal (+=) and the shovel (<<) operators. I decided to write this post to explain it. For the sake of readability and compactness, I’ll omit the irb output when desirable. Consider the following variables:

>> a="foo"
>> b="bar"
>> a_=a

Suppose we want to concatenate the strings a_ and b, and store the resulting value in the variable a_ itself. We could use the plus-equal operator to accomplish that:

>> a_ += b

The plus-equal operator concatenates the strings a_ and b, and stores the resulting value in the variable a_. Let’s check the value of the three strings after the operation:

>> a
=> "foo"
>> b
=> "bar"
>> a_
=> "foobar"

As you can see, the variable a_ stores the concatenated string. The values of a and b are still the original values.

Now let’s reinitialize our variables and check the results obtained with the shovel operator:

>> a="foo"
>> b="bar"
>> a_=a
>> a_ << b
>> a.to_s
=> "foobar"
>> b.to_s
=> "bar"
>> a_.to_s
=> "foobar"

Surprisingly, the string stored in the variable a changed after we used the shovel operator. This side-effect is the difference between the two operators. In ruby, when one variable is assigned to another (like in a_=a), both of them will point to the same object (will have the same object id).

>> a="foo"
>> a_=a
>> a.object_id
=> 2230175300
>> a_.object_id
=> 2230175300

When the plus-equal operator is used, a new string is created and assigned to the variable a_(a new reference), thus keeping the string stored in the variable a unmodified.

The shovel operator, on the other hand, updates the value of the object referenced by a_, but not the reference itself. Since both variables (a and a_) reference the same object, the value of a will be changed when using the shovel operator.

Converting Audio Files Using Mac OS X Terminal

I just figured out Mac OS X has a nice command line utility to convert audio files called afconvert . This is a great way to do batch audio conversion with total control over what you’re converting. The basic syntax is:

afconvert -d DATAFORMAT -f FILEFORMAT INPUTFILE OUTPUTFILE

To list the data and file formats supported, simply type:

afconvert -hf

The following script lists all the AIFF file on a directory and converts them to WAV.

ls *.aiff | while read file
do
afconvert -d LEI16 -f 'WAVE' $file `echo $file | sed 's/.aiff/.wav/'`
done

Sound: Propagation, Amplitude, Frequency and Timbre

Propagation
Sound waves travel in air through the compression and rarefaction of air molecules. This compression and rarefaction happens in the same direction the sound travels. Therefore, sound propagates in air as a longitudinal wave.

However, sound propagates through solids in a different manner. In a string, for example, the vibration propagates as a transverse wave.

image

The speed of sound depends on the properties of the material through which the wave is traveling. Differences of temperature or air pressure can affect the speed of sound in air. In dry air at 20 °C the speed of sound is 343.2 m/s.

Amplitude
Amplitude represents the intensity of the sound wave and is related to the volume of the sound (though it is not exactly a direct relation). If the average square of the amplitude of a sound wave increases, the volume perception will also increase. In fact, the energy of a signal can be calculated using its’ amplitude.

Brief and drastic changes in amplitude might not cause a big change in volume perception, but they do cause an audible click. This sudden change in amplitude is known as pulse.

Frequency
The frequency of a sound wave traveling in air is the number of cycles of compression/rarefaction per second, and is measure in Hertz (Hz).

image

Although in real condition there are always multiple different frequencies traveling together in a sound wave, there is a fundamental frequency, which is usually the lower frequency of that sound wave, and it’s related to the perceived pitch. Basically, the higher the fundamental frequency is, the higher the perceived pitch.

Timbre
The perceived timbre of a sound wave depends on multiple factors, and probably the most important of them is the distribution of the harmonic partials of the wave. The harmonic partials are basically frequencies that are integer multiples of the fundamental frequency of the sound wave. The image bellow shows the harmonic partials of a vibration propagating in a string.

image

The timbre will be different according to the distribution of intensities between the harmonic partials of a sound wave. The image bellow shows the difference in the distribution of the harmonic partials for two different music instruments: a guitar and an alto saxophone.

image

Overriding Back Button Behavior in Android Applications

Sometimes you might want to change the default behavior of the back button in your android application. For example, you might have a screen in which after filling out some information, the user has to press a button to send it to a remote server. In this situation, if the user accidentaly press the back button, he will loose all the info he had entered. So you should override its default behaviour and show a dialog box, so he can confirm he wants to quit the screen before it closes.

Android system navigation buttons

This is quite easy to accomplish. All you’ve got to do is override an event called onBackPressed() on your activity. In my example, I’m gonna show a dialog box for the user to confirm if he really wanna quit the screen. If the user chooses ‘Yes’, the activity will be finished immediately. Instead, if the chooses ‘No’, the dialog box will be closed and he will be able to keep navigating on the screen.

@Override
public void onBackPressed()
{
	// instantiates an alert dialog object and sets its properties
	AlertDialog.Builder alert = new AlertDialog.Builder(this);

	alert.setTitle("Leave screen?");
	alert.setMessage("Are you sure you wanna leave without saving?");

	// setting the alert caption and the event listener
	alert.setPositiveButton("Yes", 
		new DialogInterface.OnClickListener()
		{
			@Override
			public void onClick(DialogInterface dialog, int which) 
			{
				// closes the current activity
				finish();
			}
		});

	alert.setNegativeButton("No", 
		new DialogInterface.OnClickListener() 
		{
			@Override
			public void onClick(DialogInterface dialog, int which) 
			{
				// cancel the dialog
				dialog.cancel();
			}
		});

	// show the alert
	alert.show();
}

Regular Expressions in Ruby

Regular Expressions are a powerful tool to process text and extract information from it. The idea behind regular expressions is that you can define an expression to check if an input string matches a certain pattern. And you can manipulate or extract pieces of information from the string according to your needs. It’s very useful because instead of coding a long program to manipulate a string, you just have to create an expression.

In Ruby, the =~ operator is used for matching regular expressions. Example:

 >> sentence = "This is just a test."
=> "This is just a test."
>> sentence =~ /^[A-Z].*[?!.]$/
=> 0

In the example above, the regular expression matches the string provided (remember that in Ruby zero evaluates to true). The regular expression in the example is /^[A-Z].*[?!.]$/ . When using the =~ operator, the regular expression must be provided between slashes. This expression checks the following pattern:

  • ^: this character anchors the pattern to the beginning of the string.
  • [A-Z]: the first character in the sentence has to be in the range A-Z (uppercase letters only).
  • .*: the dot matches any character, and the asterisk means that this pattern can repeat zero or many times. Therefore, it will match any sequence of characters, or no characters at all.
  • [?!.]: matches one ocurrence of any of these punctuation marks.
  • $: anchors the pattern to the end of the string.

So, in resume, this regular expression will match any string that starts with an uppercase letter (A-Z) and finishes with a punctuation mark (dot, interrogation or exclamation). Note that the square brackets are used to define ranges or lists of characters in the expression.

You can find more information about Ruby’s regular expressions at http://www.tutorialspoint.com/ruby/ruby_regular_expressions.htm.

Ruby

After a long time dealing with boring programming languages, I’m really excited for having been introduced to Ruby. In my opinion, programming languages have to be compact, or, to use a better word: minimalist. And this is a great characteristic of Ruby. You don’t have to spend ages to learn it, specially if you already know how to program in another Object-Oriented language.

I’m gonna list some of the great characteristics of Ruby:

  1. It’s a minimalist language, as I already noted. The syntax is easy to learn.
  2. Strong Object-Orientation. Everything is an object!
  3. Since everything is an object, every operation is a method call. Even basic arithmetic operations (+, -, etc.) are method calls.
  4. Metaprogramming: you can alter methods and classes at any time, even when the program is running. You can even change the methods from the basic classes of the language such as String or Integer.

Other positive points (in my subjective opinion) are that it’s extremelly compatible Linux, BSD or any other Unix-based operating system; you can use an interactive interpreter to develop, which makes it really easy to test and run pieces of code; and there is an excellent framework for agile web development available for Ruby, called Rails. It’s more usual to see the term Ruby on Rails; just remember that Ruby is the language, and Rails is the framework.

Arrays in Ruby

Let’s start this post creating an array in Ruby (notice we are using the irb environment for our examples):

>> array=["a","b","c","d"]
=> ["a", "b", "c", "d"]

You just put a list of items separated by commas between square brackets, assign it to a variable, and the array is created. In Ruby, the array indexes start at 0, so if you want to retrieve the first item from the array you just created, simply type:

>> array[0]
=> "a"

Let’s try to access an index out of range in the array.

>> array[4]
=> nil

You will get the nil object as return value.

You can retrieve several items at once using array[i,n] in which i is the starting index for the items you want, and n is the number of items you want.

>> array[2,2]
=> ["c", "d"]

You can make assignments to your array, replacing multiple items at once. Let’s start modifying the array we created above.

>> array[1,2]=["B","C"]
=> ["B", "C"]
>> array
=> ["a", "B", "C", "d"]

It’s possible to replace multiple items by a different number of items.

>> array[1,2]=["X","Y","Z"]
=> ["X", "Y", "Z"]
>> array
=> ["a", "X", "Y", "Z", "d"]

It’s also possible delete them using the same technique.

>> array[2,3]=[]
=> []
>> array
=> ["a", "X"]

You can even insert new elements between the other elements of the array using array[i,n] with n=0. Let’s create another array with symbols and insert one element between the others.

>> a=[:a,:b,:d,:e]
=> [:a, :b, :d, :e]
>> a[2,0]=[:c]
=> [:c]
>> a
=> [:a, :b, :c, :d, :e]

You can think that the array[i,n] syntax means: retrieve n elements from the array starting by the i-th position. If you try to access elements from the array using n=0, you will get [] as a result (within the range of the array).

>> a[1,0]
=> []

Actually, what is happening on the situation above, is that n=0 will define a place between elements of the array, just between the indexes i-1 and i.

For retrieving elements, you may see no reason to use array[i,n] with n=0. But, for inserting elements, it can be really useful. As you saw in the examples above, instead of replacing elements, you can insert new elements on the array using n=0. So, to insert a new element at the end of an array we can do the following:

>> b=[:x,:y]
=> [:x, :y]
>> b[2,0]=:z
=> :z
>> b
=> [:x, :y, :z]

Now, one interesting point to finish this article, observe the behaviours showed bellow:

>> b[3]
=> nil

In the example above the index 3 is out of range, since the array b has three elements.

>> b[3,0]
=> []

In the example showed above, we are on the tail of the array, so we’re not out of range yet.

>> b[4,0]
=> nil

Now we are out of the range, so we received a nil object as return value.