{
 "metadata": {
  "name": "",
  "signature": "sha256:06a01c7defee6116c6bbb1fd895c49a6b3b4dfbaaa094f95f91bfbb0b1a490dc"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Onset Detection"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "Automatic detection of musical events in an audio signal is one of the most fundamental tasks in music information retrieval. Here, we will show how to detect an *onset*, the start of a musical event.\n",
      "\n",
      "For more reading, see [this tutorial on onset detection by Juan Bello](https://files.nyu.edu/jb2843/public/Publications_files/2005_BelloEtAl_IEEE_TSALP.pdf)."
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "Load the audio file `simpleLoop.wav` into the NumPy array `x` and sampling rate `fs`. "
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from essentia.standard import MonoLoader\n",
      "x = MonoLoader(filename='simpleLoop.wav')()\n",
      "print x.shape"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "(132300,)\n"
       ]
      }
     ],
     "prompt_number": 1
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "Plot the signal:"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "fs = 44100.0\n",
      "t = arange(len(x))/fs\n",
      "plot(t, x)\n",
      "xlabel('Time (seconds)')"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 2,
       "text": [
        "<matplotlib.text.Text at 0x11438f410>"
       ]
      },
      {
       "metadata": {},
       "output_type": "display_data",
       "png": "iVBORw0KGgoAAAANSUhEUgAAAX4AAAEPCAYAAABFpK+YAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3XmYHFW9//H3ZDJJJiwh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OqEyzwc+ktC867Gc6meT3grsmk5VRETSdQnw2YTLaME2LGles2ogy6ge/O/ErrsuUrc0\nr9UjMlju9PpO4Lf+4xnY5Wf/iLWO3wNcgZ3ReDtBiL8Fu4jVfOAO7HrtUdOxG+ds8X+/ALuRxyPY\nmbxg94q+EbvS4wLs8rdgl8a9ArvEwyPYngPYqfQL/PrcgF2+A7+uM4D/8V/b039+LHAXdkbpdaFl\n3ga7JstCv4xT/Oe7sNPzRURK5xLgc/7jTnoH/x+x4H0zdtGto/3XZmH3QGjDTskf6z9/KhbCUReH\nygC7qFWb/3h7f/r/gQ/6j3fALskxEjgX63ZxjafR2J2S/gHs7j/3E+wqkWAt+fP8x+diIQ/Wend3\ngjoOu+zAGOC9wA9Ddds+9PgP9L0OlEjN1OKXovGwlv1WrJU8BLtMLVjLeDJ2qd03AXdjXTlfoO+9\nEQDegB1LcBYBv8CCfqv/3FHYBuJh7Drow/2/OwK4FgtqsJu47IkF/BL/uZ8A7wjNf5Y/XeDXE+zO\nXzf5j+cS3AxmEdat83XsOjRrQ/N5NvT3IoOWp75NkVpt8qc92N3OCP0+FOsueQy76cZAwtcwPx4L\n6hOwjcVU//n3YPcyrfa30Pf65y2R5zb60630/u5VuivUYuxmIscDXwXuAS4Lvb+nwt+I1EQtfima\nWm6d9ySwI8HVF9uofLelvxP0/bdgLfkurIU/Crupx530vnG3u4n177ErI7b6v48GnsJa4rv5z52J\ndctU80fgdP/xsf58ACYCrwM/x44lhK+2ONGvu0hdFPySZ15oWukx9G1le9hewPuAbxBcpvftFeZ/\nP8ENLYYCP8O6WBYA38FuenEZtuFYhHUtXeq//3qsP3+RX8ZpWFB/FPil//wW4JoK9Qwvw6XYXsaj\nwMkEgT4VO6D8MPAlgtZ+G3aTje4KyyMiIgNwwzmHDfTGHDkK2yiJiEidPoW10oviVnRgV0RERERE\nREREREREREREREREREREpMj+F7GuHma8F7KdAAAAAElFTkSuQmCC\n",
       "text": [
        "<matplotlib.figure.Figure at 0x1104f0610>"
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "Listen:"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from IPython.display import Audio\n",
      "Audio(x, rate=fs)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "html": [
        "\n",
        "                <audio controls=\"controls\" >\n",
        "                    <source src=\"data:audio/wav;base64,[encoded data, 352860 characters]\" type=\"audio/wav\" />\n",
        "                    Your browser does not support the audio element.\n",
        "                </audio>\n",
        "              "
       ],
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 3,
       "text": [
        "<IPython.lib.display.Audio at 0x1104f0890>"
       ]
      }
     ],
     "prompt_number": 3
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "`essentia.standard.OnsetRate`"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "The easiest way in Essentia to detect onsets given a time-domain signal is using [`OnsetRate`](http://essentia.upf.edu/documentation/reference/std_OnsetRate.html). It returns a list of onset times and the onset rate, i.e. number of onsets per second."
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from essentia.standard import OnsetRate\n",
      "find_onsets = OnsetRate()\n",
      "onset_times, onset_rate = find_onsets(x)\n",
      "print onset_times\n",
      "print onset_rate"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "[ 0.01160998  0.48761904  0.98684806  1.24226761  1.48607707]\n",
        "1.66666662693\n"
       ]
      }
     ],
     "prompt_number": 4
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "`essentia.standard.AudioOnsetsMarker`"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "To verify our results, we can use [`AudioOnsetsMarker`](http://essentia.upf.edu/documentation/reference/std_AudioOnsetsMarker.html) to add a sound at the moment of each onset."
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from essentia.standard import AudioOnsetsMarker\n",
      "onsets_marker = AudioOnsetsMarker(onsets=onset_times, type='beep')\n",
      "x_beeps = onsets_marker(x)\n",
      "Audio(x_beeps, rate=fs)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "html": [
        "\n",
        "                <audio controls=\"controls\" >\n",
        "                    <source src=\"data:audio/wav;base64,[encoded data, 352860 characters]\" type=\"audio/wav\" />\n",
        "                    Your browser does not support the audio element.\n",
        "                </audio>\n",
        "              "
       ],
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 5,
       "text": [
        "<IPython.lib.display.Audio at 0x11531d890>"
       ]
      }
     ],
     "prompt_number": 5
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "Sounds good!\n",
      "\n",
      "For more control over the onset detection algorithm, see [`OnsetDetection`](http://essentia.upf.edu/documentation/reference/std_OnsetDetection.html), [`OnsetDetectionGlobal`](http://essentia.upf.edu/documentation/reference/std_OnsetDetectionGlobal.html), and [`Onsets`](http://essentia.upf.edu/documentation/reference/std_Onsets.html)."
     ]
    }
   ],
   "metadata": {}
  }
 ]
}