In [122]:
from IPython.html.widgets import interact
from IPython.display import display, Math, Latex 
from matplotlib.pyplot import *
from numpy import *
from numpy.random import *
%matplotlib inline

In [149]:
def bitreduce(f,N):
    fret = zeros(len(f))
    for i in range(len(f)):
        fret[i] = int((N+1)*f[i])/float(N+1) 
    return fret


def f(f,samples, phase, bitdepth, dithering):
    N = bitdepth #int(2**bitdepth) 
    t = samples+1
    d = uniform(-dithering,dithering,1000)
    d = dithering*sin(linspace(0,400000,1000))
    
    signal1000 = d + sin(phase + 2*pi*f*linspace(0,1,1000))
    signal_N = bitreduce(signal1000[list(linspace(0,999,t))], N)
    #signal_N = bitreduce(sin(phase + 2*pi*f*linspace(0,1,t)), N)
    figure(1)
    plot(linspace(0,1,1000), signal1000, "-", color = (.8,.8,.8))    
    hold("on")
    plot(linspace(0,1,t), signal_N, ".")
    plot(linspace(0,1,t), signal_N, color = (.8,.3,.3))
    hold("off")


interact(f, f=(1,10,1), samples=(2,100,1), phase = (0,pi, .1), bitdepth = (2,16,1), dithering = (0,1,.01))



In [116]:
from IPython.core.display import HTML
from scipy.io import wavfile

def wavPlayer(filepath):
    """ will display html 5 player for compatible browser

    Parameters :
    ------------
    filepath : relative filepath with respect to the notebook directory ( where the .ipynb are not cwd)
               of the file to play

    The browser need to know how to play wav through html5.

    there is no autoplay to prevent file playing when the browser opens
    """
    
    src = """
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Simple Test</title>
    </head>
    
    <body>
    <audio controls="controls" style="width:600px" >
      <source src="files/%s" type="audio/mp3" />
      Your browser does not support the audio element.
    </audio>
    </body>
    """%(filepath)
    display(HTML(src))

In [117]:
pwd()


Out[117]:
u'/Users/kinealicegulbrandsen/Dropbox/Master Thesis Audun Skau Hansen/Notebooks'

In [118]:
wavPlayer("/../../Privat/Media/")


Simple Test

In [145]:
wavPlayer(u"/Users/kinealicegulbrandsen/Dropbox/Privat/Media/")


Simple Test

In [130]:
x = linspace(0,10,10+1)
print list(x)


[0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0]

In [143]:
import cv2


---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-143-72fbbcfe2587> in <module>()
----> 1 import cv2

ImportError: No module named cv2

In [ ]: