# Suggestions for playing music from real-time data generated in Julia

**URL:** https://discourse.julialang.org/t/suggestions-for-playing-music-from-real-time-data-generated-in-julia/46448
**Category:** Signal and Image Processing
**Created:** [September 11, 2020, 11:32am UTC](https://discourse.julialang.org/t/suggestions-for-playing-music-from-real-time-data-generated-in-julia/46448 "2020-09-11T11:32:51Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)
#### Post date: [September 11, 2020, 11:32am UTC](https://discourse.julialang.org/t/suggestions-for-playing-music-from-real-time-data-generated-in-julia/46448/1 "2020-09-11T11:32:51Z")

</div>

A little project I have in mind requires making data in real time (well, maybe 100 times a second at most) that is used to output music in real time. Details are scant because I haven’t really done anything yet, I’m trying to see what my options are and would love suggestions from the more experienced. So far I envision two vague approaches:

1. Computing a MIDI stream that an existing software synthesizer can use to make music. I like the idea of this because of functionality (especially audio effects like reverb) I honestly have no idea how to implement from scratch. However, I haven’t been able to find any way to stream MIDI from a Julia script to a software synthesizer. JuliaMusic has some options for playing MIDI files, but I don’t know if that’s at all applicable for MIDI data I’m making on the fly.  
I found pyfluidsynth, a Python binding for FluidSynth, and it made me wonder if I need a Julia binding for a synthesizer to do this with Julia.

2. Computing a waveform from periodic pitch and volume data, and streaming samples of it regularly. I pulled this off with PyAudio’s callback mode a few years ago. I’m not stoked about this option because, again, I would rather use existing software instead of reinventing the wheel. Still, if I must, I need a way to play WAV-like audio data. So far I’ve found PortAudio.jl (but Pkg.add isn’t working for it, not sure why). If the 1st approach is unfeasible, I’m open to suggestions for this one.

---

<div class="post-metadata">

### Author: ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)
#### Post date: [September 11, 2020, 1:17pm UTC](https://discourse.julialang.org/t/suggestions-for-playing-music-from-real-time-data-generated-in-julia/46448/2 "2020-09-11T13:17:51Z")

</div>

It looks like

[https://github.com/JuliaMusic/MIDI.jl](https://github.com/JuliaMusic/MIDI.jl)

has all the building blocks to emit a stream of MIDI chunks — I would suggest asking how to connect to a midi server in an issue.

---

<div class="post-metadata">

### Author: ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)
#### Post date: [September 12, 2020, 11:05am UTC](https://discourse.julialang.org/t/suggestions-for-playing-music-from-real-time-data-generated-in-julia/46448/3 "2020-09-12T11:05:18Z")

</div>

I’m unsure about how to ask this because I don’t know what a MIDI server is. I do see an open issue that seems related: #8 [Allow midi events to be written directly to a midi device](https://github.com/JuliaMusic/MIDI.jl/issues/8).

---

<div class="post-metadata">

### Author: ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)
#### Post date: [September 12, 2020, 1:37pm UTC](https://discourse.julialang.org/t/suggestions-for-playing-music-from-real-time-data-generated-in-julia/46448/4 "2020-09-12T13:37:55Z")

</div>

It’s a sink that can receive MIDI events and convert them to an audio signal. You may be able to use a network connection via [RTP-MIDI](https://en.wikipedia.org/wiki/RTP-MIDI) too, but I am not familiar with the details (all my MIDI knowledge comes from having musician friends who ask me for computer setup help occasionally, which I provide [along these lines](https://xkcd.com/627/)).

---

<div class="post-metadata">

### Author: ![kevbonham](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kevbonham/32/216165_2.png) [@kevbonham](https://discourse.julialang.org/u/kevbonham)
#### Post date: [September 12, 2020, 1:59pm UTC](https://discourse.julialang.org/t/suggestions-for-playing-music-from-real-time-data-generated-in-julia/46448/5 "2020-09-12T13:59:21Z")

</div>

> [@Benny](#):
>
> So far I’ve found PortAudio.jl (but Pkg.add isn’t working for it, not sure why). If the 1st approach is unfeasible, I’m open to suggestions for this one.

I don’t see this package in the general registry, so it likely hasn’t been registered. You can use Pkg to just add the GitHub repo directly though `] add https://github.com/JuliaAudio/PortAudio.jl`
