{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "04cba77c",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/tmp/ipykernel_252797/4199785080.py:9: WavFileWarning: Chunk (non-data) not understood, skipping it.\n",
      "  fs, x = wavfile.read(f'data/a3_short_opus_{br}bps.wav')\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 163260 characters]",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 7724 characters]",
      "text/plain": [
       "<Figure size 513.2x360 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 7636 characters]",
      "text/plain": [
       "<Figure size 513.2x360 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 7716 characters]",
      "text/plain": [
       "<Figure size 513.2x360 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 7672 characters]",
      "text/plain": [
       "<Figure size 513.2x360 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 7900 characters]",
      "text/plain": [
       "<Figure size 513.2x360 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 7916 characters]",
      "text/plain": [
       "<Figure size 513.2x360 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 8092 characters]",
      "text/plain": [
       "<Figure size 513.2x360 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 219688 characters]",
      "text/plain": [
       "<Figure size 513.2x360 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "from scipy.io import wavfile\n",
    "import scipy.signal\n",
    "from playback import make_playback_animation\n",
    "\n",
    "# coding noise demonstration\n",
    "for br in [\"inf\", 24000, 15000, 12000, 9000, 8000, 7000, 6000]:\n",
    "    fs, x = wavfile.read(f'data/a3_short_opus_{br}bps.wav')\n",
    "    spec, freqs, t, im = plt.specgram(x, NFFT=512, cmap='inferno', noverlap=256 + 128, pad_to=4096)\n",
    "    spec = 10*np.log10(spec)\n",
    "    \n",
    "    make_playback_animation(f'animations/opus_{br}bps.mp4', spec, len(x)/16)\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b8408ca1",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
