diff --git a/Manual/4_Module_2.ipynb b/Manual/4_Module_2.ipynb index 87475a5..15be43e 100644 --- a/Manual/4_Module_2.ipynb +++ b/Manual/4_Module_2.ipynb @@ -603,40 +603,7 @@ "execution_count": null, "source": [ "for i, device in enumerate(sounddevice.query_devices()):\n", - " print(i, device['name'])\n" - ] - }, - { - "metadata": {}, - "cell_type": "markdown", - "source": [ - "Once you have identified the index of the microphone array device from the list, you can initialize it by specifying the device index (`device_index`) and the desired sampling frequency (`Fs`).\n", - "\n", - "Here’s how you can open the audio stream using Sounddevice:" - ] - }, - { - "metadata": {}, - "cell_type": "code", - "outputs": [], - "execution_count": null, - "source": [ - "import sounddevice as sd\n", - "\n", - "#device_index = 15 # your input device index\n", - "#Fs = 48000 # sample rate\n", - "\n", - "# Open 5‑channel float32 input stream on that device\n", - "#stream = sd.InputStream(\n", - "# device=device_index, # or device=(device_index, None) for in/out\n", - "# channels=5,\n", - "# samplerate=Fs,\n", - "# dtype='float32', # 16‑bit would be 'int16'\n", - " # or True, depending on how you use it\n", - "#)\n", - "\n", - "#stream.start()\n", - "#stream.stop()" + " print(i, device['name'])" ] }, { @@ -659,45 +626,17 @@ "execution_count": null, "source": [ "Fs = 48000\n", - "duration = 30\n", + "duration = 5\n", "N = int(Fs * duration)\n", "\n", - "sd.default.device = 15 # or a substring of its name\n", - "sd.default.samplerate = Fs\n", + "sounddevice.default.device = 15 # or a substring of its name\n", + "sounddevice.default.samplerate = Fs\n", "\n", - "samples = sd.rec(N, samplerate=Fs, channels=5)\n", - "sd.wait()\n", + "samples = sounddevice.rec(N, samplerate=Fs, channels=5)\n", + "sounddevice.wait()\n", "print(samples.shape)" ] }, - { - "metadata": {}, - "cell_type": "markdown", - "source": [ - "At this point, the microphone data is **interleaved**. This means that the first value (`data[0]`) corresponds to the first sample of microphone 0, the second value (`data[1]`) corresponds to the first sample of microphone 1, and so on. For example, `data[5]` contains the second sample of microphone 0, and the pattern continues. To visualize the interleaving of the data, refer to the table below:\n", - "\n", - "| data[0] | data[1] | data[2] | data[3] | data[4] | data[5] | data[6] | data[7] | ... |\n", - "|---------|---------|---------|---------|---------|---------|---------|---------|-----|\n", - "| mic 0 | mic 1 | mic 2 | mic 3 | mic 4 | mic 0 | mic 1 | mic 2 | ... |\n", - "| frame 0 | frame 0 | frame 0 | frame 0 | frame 0 | frame 1 | frame 1 | frame 1 | ... |\n", - "\n", - "#### Deinterleaving the data\n", - "\n", - "To work with the data from each microphone independently, the **interleaved data** must be split into separate streams for each microphone. This process is called **deinterleaving**.\n", - "\n", - "Write a function to deinterleave the audio data and store the samples from each microphone in a separate numpy array:" - ] - }, - { - "metadata": {}, - "cell_type": "code", - "outputs": [], - "execution_count": null, - "source": [ - "### Student Version ###\n", - "# TODO: Reshape the data into a matrix with 5 columns (one for each microphone)" - ] - }, { "metadata": {}, "cell_type": "markdown", @@ -723,14 +662,14 @@ "ax[2].plot(t,samples_reshaped[:,2])\n", "ax[3].plot(t,samples_reshaped[:,3])\n", "ax[4].plot(t,samples_reshaped[:,4])\n", - "for ax_in in ax:\n", + "for i,ax_in in enumerate(ax):\n", " ax_in.set_xlabel('Time (s)')\n", " ax_in.set_ylabel('Amplitude')\n", + " ax_in.set_title(f'Mic {i}')\n", "fig.show()\n", "\n", "from scipy.io import wavfile\n", - "wavfile.write(\"./audio_beacon_67676767_10s_driving.wav\", Fs, samples_reshaped.astype(np.float32))\n", - "# TODO: Plot the data for each microphone" + "wavfile.write(\"./audio_beacon_67676767_at_x345_y101.wav\", Fs, samples_reshaped.astype(np.float32))" ] }, { diff --git a/Manual/audio_beacon_67676767_10s.wav b/Manual/audio_beacon_67676767_10s.wav new file mode 100644 index 0000000..2287aa3 Binary files /dev/null and b/Manual/audio_beacon_67676767_10s.wav differ diff --git a/Manual/audio_beacon_67676767_10s_driving.wav b/Manual/audio_beacon_67676767_10s_driving.wav new file mode 100644 index 0000000..1082f05 Binary files /dev/null and b/Manual/audio_beacon_67676767_10s_driving.wav differ diff --git a/Manual/audio_beacon_67676767_at_x180_y333.wav b/Manual/audio_beacon_67676767_at_x180_y333.wav new file mode 100644 index 0000000..b33a56d Binary files /dev/null and b/Manual/audio_beacon_67676767_at_x180_y333.wav differ diff --git a/Manual/audio_beacon_67676767_at_x345_y101.wav b/Manual/audio_beacon_67676767_at_x345_y101.wav new file mode 100644 index 0000000..591845b Binary files /dev/null and b/Manual/audio_beacon_67676767_at_x345_y101.wav differ diff --git a/Manual/clapping.wav b/Manual/clapping.wav new file mode 100644 index 0000000..914aa63 Binary files /dev/null and b/Manual/clapping.wav differ