sintetizador_fm_para_archivos_midi_en_python
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| sintetizador_fm_para_archivos_midi_en_python [2025/01/13 16:16] – oso | sintetizador_fm_para_archivos_midi_en_python [2025/01/13 21:25] (current) – [Overview] oso | ||
|---|---|---|---|
| Line 10: | Line 10: | ||
| <code python: | <code python: | ||
| - | |||
| - | <code python> | ||
| import mido | import mido | ||
| import numpy as np | import numpy as np | ||
| Line 254: | Line 252: | ||
| - | ===== Appendix: Monophonic Synthesizer ===== | + | ====== Appendix: Monophonic Synthesizer |
| This section covers a **simple mono synthesizer** that processes a single piano track from a MIDI file, synthesizing FM-based audio for each note and playing it in real time. | This section covers a **simple mono synthesizer** that processes a single piano track from a MIDI file, synthesizing FM-based audio for each note and playing it in real time. | ||
| <code python> | <code python> | ||
| - | def read_midi(file_path): | + | import mido # For MIDI parsing |
| - | midi = mido.MidiFile(file_path) | + | import numpy as np # For waveform synthesis |
| - | | + | import sounddevice as sd # For real-time audio playback |
| - | def fm_synth(note, | + | def read_midi(file_path): |
| - | carrier_freq = 440 * 2**((note - 69) / 12) | + | midi = mido.MidiFile(file_path) |
| - | modulator_freq = carrier_freq * 2 | + | return midi |
| - | modulation_index = 0.33 | + | |
| + | def fm_synth(note, | ||
| + | # Example parameters for FM synthesis | ||
| + | carrier_freq = 440 * 2**((note - 69) / 12) | ||
| + | modulator_freq = carrier_freq * 2 + carrier_freq * 4 + carrier_freq * 6 + carrier_freq * 8 | ||
| + | modulation_index = 0.33 | ||
| | | ||
| - | t = np.linspace(0, | + | t = np.linspace(0, |
| - | modulator = np.sin(2 * np.pi * modulator_freq * t) * modulation_index | + | modulator = np.sin(2 * np.pi * modulator_freq * t) * modulation_index |
| - | carrier = np.sin(2 * np.pi * carrier_freq * t + modulator) | + | carrier = np.sin(2 * np.pi * carrier_freq * t + modulator) |
| | | ||
| - | return carrier * velocity / 127 | + | return carrier * velocity / 127 |
| + | |||
| + | def process_piano_track(midi): | ||
| + | sample_rate = 44100 | ||
| + | for track in midi.tracks: | ||
| + | for msg in track: | ||
| + | if msg.type == ' | ||
| + | duration = msg.time / midi.ticks_per_beat | ||
| + | note_audio = fm_synth(msg.note, | ||
| + | |||
| + | # Play the synthesized audio for the note | ||
| + | sd.play(note_audio, | ||
| + | sd.wait() | ||
| - | def process_piano_track(midi): | + | midi = read_midi(" |
| - | sample_rate | + | process_piano_track(midi) |
| - | for track in midi.tracks: | + | |
| - | for msg in track: | + | |
| - | if msg.type == ' | + | |
| - | duration = msg.time | + | |
| - | note_audio = fm_synth(msg.note, | + | |
| - | | + | |
| - | sd.wait() | + | |
| </ | </ | ||
| ===== Overview ===== | ===== Overview ===== | ||
| - | - **Purpose: | + | * **Purpose: |
| - | - **Limitations: | + | |
| - | - **Mono Only:** The synthesizer processes and plays a single note at a time. Overlapping notes or chords are not supported. | + | - **Mono Only:** The synthesizer processes and plays a single note at a time. Overlapping notes or chords are not supported. |
| - | - **No Envelope Control:** The FM synthesis does not include dynamic ADSR envelopes, which might result in abrupt starts/ | + | - **No Envelope Control:** The FM synthesis does not include dynamic ADSR envelopes, which might result in abrupt starts/ |
| - | - **Simplistic Waveform Modulation: | + | - **Simplistic Waveform Modulation: |
| ===== Customizing the Modulation Signal ===== | ===== Customizing the Modulation Signal ===== | ||
sintetizador_fm_para_archivos_midi_en_python.1736784972.txt.gz · Last modified: 2025/01/13 16:16 by oso
