Commit 7ee0bbec authored by valentin.emiya's avatar valentin.emiya

update tutorial waveform.ipynb

parent 7666a1f2
Pipeline #554 passed with stages
in 2 minutes and 8 seconds
......@@ -503,7 +503,7 @@
"source": [
"Note that:\n",
"\n",
"* sampling frequency: only a restricted set of sampling frequencies are allowed for input/output \n",
"* sampling frequency: only a restricted set of sampling frequencies are allowed for input/output (see set of supported frequencies `waveform.VALID_IO_FS`)\n",
"* *dtype*: float/int data types are conserved when exporting a *Waveform*, since the .wav format allows many data types. However, many audio players only read .wav files coded with int16 values so you may not be able to listen to your exported sound with your favorite player. In that case, you may convert the data type of your *Waveform* using the optional *dtype* argument of method *to_wavfile*.\n",
"* mask: the mask is lost when exporting to a .wav file.\n"
]
......@@ -554,7 +554,7 @@
"metadata": {},
"source": [
"### Integer-valued waveforms\n",
"Method *Waveform.astype* not only converts data types but also scale values to the range of the target type."
"Method *Waveform.astype* not only converts data types but also scale values to the range of the target type. The choice among the available integer types will result in different ranges. The following figures show integer-valued waveforms with different types: on the first row, waveforms created without conversion, from integer-valued data arrays where the full `dtype` range is used; on the second row, similar waveforms are created with a conversion from a float-valued array with entries in [-1, 1]."
]
},
{
......@@ -605,7 +605,8 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### Real-valued waveforms"
"### Real-valued waveforms\n",
"The choice among the available float types will not affect the range of the values but the precision. In the following example, one may observe how the floating-point precision varies, depending on the float type, when the fractionnal part is very small compared to the exponent part, which equals 1 here (see right column)."
]
},
{
......@@ -623,14 +624,14 @@
"w_float32 = Waveform(np.cos(2*np.pi*f0*t).astype(np.float32) + 1, fs=fs)\n",
"w_float64 = Waveform(np.cos(2*np.pi*f0*t).astype(np.float64) + 1, fs=fs)\n",
"\n",
"plt.figure(figsize=(20, 5))\n",
"plt.subplot(131)\n",
"plt.figure(figsize=(20, 15))\n",
"plt.subplot(321)\n",
"plt.title('float16')\n",
"w_float16.plot()\n",
"plt.subplot(132)\n",
"plt.subplot(323)\n",
"plt.title('float32')\n",
"w_float32.plot()\n",
"plt.subplot(133)\n",
"plt.subplot(325)\n",
"plt.title('float64')\n",
"w_float64.plot()\n",
"\n",
......@@ -643,16 +644,18 @@
"w_float32 = Waveform(np.cos(2*np.pi*f0*t).astype(np.float32) * eps32 + 1, fs=fs)\n",
"w_float64 = Waveform(np.cos(2*np.pi*f0*t).astype(np.float64) * eps64 + 1, fs=fs)\n",
"\n",
"plt.figure(figsize=(20, 5))\n",
"plt.subplot(131)\n",
"plt.subplot(322)\n",
"plt.title('float16')\n",
"w_float16.plot()\n",
"plt.subplot(132)\n",
"plt.subplot(324)\n",
"plt.title('float32')\n",
"w_float32.plot()\n",
"plt.subplot(133)\n",
"plt.subplot(326)\n",
"plt.title('float64')\n",
"w_float64.plot()\n"
"w_float64.plot()\n",
"plt.ylim(1 - 1.2 * eps64, 1 + 1.2 * eps64)\n",
"\n",
"pass"
]
},
{
......@@ -729,6 +732,15 @@
"w_float32.astype('uint8').plot()\n",
"pass"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
......@@ -747,7 +759,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.5"
"version": "3.6.2"
},
"latex_envs": {
"LaTeX_envs_menu_present": true,
......
......@@ -405,6 +405,9 @@ class Waveform(MadArray):
------
UserWarning
If the signal is complex.
ValueError
If the sampling frequency is not supported (see set of supported
frequencies `waveform.VALID_IO_FS`).
NotImplementedError
If dtype is not supported by the current implementation.
......@@ -549,7 +552,14 @@ class Waveform(MadArray):
self[-len(w):] *= w[-1::-1]
def show_player(self):
"""Show the player when using jupyter notebook."""
"""
Show the player when using jupyter notebook.
Raises
------
ValueError
If sampling frequency is 1.
"""
try:
from IPython.display import Audio
if self.fs == 1:
......@@ -577,6 +587,11 @@ class Waveform(MadArray):
-------
`simpleaudio.PlayObject`
Object useful to handle the played audio stream.
Raises
------
ValueError
If sampling frequency is 1.
"""
if self.fs == 1:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment