Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programming a music sequencer [closed]

Tags:

midi

audio

I would like to build an audio multitrack sequencer similar to a drum machine. What do you think is the best way to implement this?

At the moment I have 2 tracks represented by 2 arrays: 2 x [tick, samplePointer]. I merge these 2 tracks in a main array to be played [tick, samplePointer] and sort it by tick. An audio callback fires every tick (4 ticks per beat) and checks the first element in the array and if its tick is equal to the global song position (in ticks) then i play it. If I add or delete a note in one of the 2 tracks(arrays) i then merge both tracks(arrays) and sort them again.

It works but I have the feeling that there is a better way to do it. What would be the best practice to implement such a project? How would a professional app like Logic, Ableton, Cubase, Reason etc implement audio/midi event lists and manage what has been played, what needs to be played?

Thank you in advance for your thoughts.

Brice

like image 432
Brice Avatar asked Mar 19 '11 14:03

Brice


People also ask

How does a music sequencer work?

Sequencers allow you to program a combination of notes, rhythms, articulations and effects that can be sent to anything from your DAW of choice to hardware synths. By programming your patterns, melodies and loops, you free yourself up to experiment with mixing, dynamics and performing with other instruments.

Can sequencers record sound?

A music sequencer (or audio sequencer or simply sequencer) is a device or application software that can record, edit, or play back music, by handling note and performance information in several forms, typically CV/Gate, MIDI, or Open Sound Control (OSC), and possibly audio and automation data for DAWs and plug-ins.

How do MIDI sequencers work?

The MIDI sequencer allows the user to record and edit a musical performance without using an audio-based input source. The performance is recorded as a series of events that would ordinarily be played in from a keyboard instrument.

What is music sequencing software?

Sequencing software can be used for creating compositions using MIDI or audio sounds. Music created by synthesising sound, such as sounds created 'artificially' using electronic devices. The development of this approach, known as Elektronische Musik, has its origins in Germany in the early 1950s.


1 Answers

Would need more details to better answer you. What language are you using? What tempo range are you targeting? What audio interface will you be programming against (important to know when it comes to the latency you will be dealing with).

Also, is it just a drum sequencer? Or is it something more complex? How many "instruments"/"voices" are you planning on supporting? If you are going to be supporting <32 voices, it's possible to have a single array of [int(tick), int(voices)]. Each individual voice is a bit in the 32-bit number. Then to determine whether a voice is playing, you just need to "&" the voice flag against the voices int in the array. This would avoid the array sorting/copying/building.

Latency is an important issue to understand here. If you have a tempo of 240bpm for instance, and four "ticks" per beat (really, we're talking about one measure with each beat subdivided into sixteenth notes):

  • There are 4 beats per second (240 beats per minute / 60 seconds) -> Each beat occurs every 250 milliseconds -> Each "tick" occurs every 62.5 milliseconds

If the audio interface has a high latency (for example, shared mode WASAPI in Windows Vista+ has a latency of around 30ms), you will have different "windows" that will need to be generated.

If you're processing MIDI events, this becomes even more important because you can be receiving MIDI events within individiual ticks.

Most DAWs (Digital Audio Workstations) I have worked with typically think of the world in two different "types": audio data, and midi data. Audio data tends to be more "realtime" (or as realtime as you can get, hence the importance for sub-3ms latencies). Midi is still fairly "fast paced". Eventually, you'll likely be thinking in terms of midi data.

However, the best way to get started on a project like this is to build a very simple drum sequencer. Take four drums, and the stuff you are doing, and go from there :). Good luck!

like image 139
Jason Olson Avatar answered Sep 28 '22 08:09

Jason Olson