diff options
Diffstat (limited to 'posts')
| -rw-r--r-- | posts/2022-07-05-what-would-dna-sound-if-synthesized.md | 65 |
1 files changed, 64 insertions, 1 deletions
diff --git a/posts/2022-07-05-what-would-dna-sound-if-synthesized.md b/posts/2022-07-05-what-would-dna-sound-if-synthesized.md index a44b516..2d3afd9 100644 --- a/posts/2022-07-05-what-would-dna-sound-if-synthesized.md +++ b/posts/2022-07-05-what-would-dna-sound-if-synthesized.md | |||
| @@ -18,7 +18,8 @@ Tags: [] | |||
| 18 | 2. [Mouse](#mouse) | 18 | 2. [Mouse](#mouse) |
| 19 | 3. [Bison](#bison) | 19 | 3. [Bison](#bison) |
| 20 | 4. [Taurus](#taurus) | 20 | 4. [Taurus](#taurus) |
| 21 | 8. [Going even further](#going-even-further) | 21 | 8. [Making a drummer out of a DNA sequence](#making-a-drummer-out-of-a-dna-sequence) |
| 22 | 9. [Going even further](#going-even-further) | ||
| 22 | 23 | ||
| 23 | ## Introduction | 24 | ## Introduction |
| 24 | 25 | ||
| @@ -228,6 +229,68 @@ This is part of a taurus genome `Bos_taurus.ARS-UCD1.2.cdna`. You can get [genom | |||
| 228 | 229 | ||
| 229 |  | 230 |  |
| 230 | 231 | ||
| 232 | ## Making a drummer out of a DNA sequence | ||
| 233 | |||
| 234 | To make things even more interesting, I decided to send this data via MIDI to my [Elektron Model:Samples](https://www.elektron.se/en/model-samples). This is a really cool piece of equipment that supports MIDI in via USB and 3.5 mm audio jack. | ||
| 235 | |||
| 236 | Elektron is connected to my MacBook via USB cable and audio out is patched to a Sony Bluetooth speaker I have that supports 3.5 mm audio in. Elektron doesn't have internal speakers. | ||
| 237 | |||
| 238 |  | ||
| 239 | |||
| 240 |  | ||
| 241 | |||
| 242 |  | ||
| 243 | |||
| 244 | For communicating with Elektron, I choose `pygame` Python module that has MIDI built in. With this, it was rather simple to send notes to the device. All I did was map MIDI notes to the actual Nucleotides. | ||
| 245 | |||
| 246 | Before all of this I also checked Audio MIDI Setup app under MacOS and checked MIDI Studio by pressing ⌘-2. | ||
| 247 | |||
| 248 |  | ||
| 249 | |||
| 250 | The whole script that parses and send notes to the Elektron looks like this. | ||
| 251 | |||
| 252 | ```python | ||
| 253 | import pygame.midi | ||
| 254 | import time | ||
| 255 | |||
| 256 | pygame.midi.init() | ||
| 257 | |||
| 258 | print(pygame.midi.get_default_output_id()) | ||
| 259 | print(pygame.midi.get_device_info(0)) | ||
| 260 | |||
| 261 | player = pygame.midi.Output(1) | ||
| 262 | player.set_instrument(2) | ||
| 263 | |||
| 264 | def send_note(note, velocity): | ||
| 265 | global player | ||
| 266 | player.note_on(note, velocity) | ||
| 267 | time.sleep(0.3) | ||
| 268 | player.note_off(note, velocity) | ||
| 269 | |||
| 270 | |||
| 271 | nucleotide_midi_map = { | ||
| 272 | 'A': 60, | ||
| 273 | 'C': 90, | ||
| 274 | 'G': 160, | ||
| 275 | 'T': 180, # is D | ||
| 276 | } | ||
| 277 | |||
| 278 | with open("quote.fa") as f: | ||
| 279 | sequence = f.read().replace('\n', '') | ||
| 280 | |||
| 281 | for nucleotide in [char for char in sequence]: | ||
| 282 | print("Playing nucleotide {} with MIDI note {}".format( | ||
| 283 | nucleotide, nucleotide_midi_map[nucleotide])) | ||
| 284 | send_note(nucleotide_midi_map[nucleotide], 127) | ||
| 285 | |||
| 286 | del player | ||
| 287 | pygame.midi.quit() | ||
| 288 | ``` | ||
| 289 | |||
| 290 | <video src="/assets/dna-synthesized/elektron/elektron.mp4" controls></video> | ||
| 291 | |||
| 292 | All of this could be made much more interesting if I choose different instruments for different Nucleotides, or doing more funky stuff with Elektron. But for now, this should be enough. It is just a proof of concept. Something to play around with. | ||
| 293 | |||
| 231 | ## Going even further | 294 | ## Going even further |
| 232 | 295 | ||
| 233 | As you probably notice, the end results are quite similar to each other. This is to be expected because we are operating only with 4 notes essentially. What could make this more interesting is using something like [Supercollider](https://supercollider.github.io/) to create more interesting sounds. By transposing notes or using effects based on repeated data in a sequence. Possibilities are endless. | 296 | As you probably notice, the end results are quite similar to each other. This is to be expected because we are operating only with 4 notes essentially. What could make this more interesting is using something like [Supercollider](https://supercollider.github.io/) to create more interesting sounds. By transposing notes or using effects based on repeated data in a sequence. Possibilities are endless. |
