Keyboard Synthesizer

So you have written that new, must have program. Let us see it here.
Post Reply
User avatar
Cedron
Posts: 156
Joined: Thursday 21st February 2019 5:02pm
Location: The Mitten State
Contact:

Keyboard Synthesizer

Post by Cedron »

This project is in rudimentary form, but sufficiently developed that it is actually already useful. The GUI interface is a blank slate. Most of the code is in a shared C++ library, included, which needs to be compiled separately.

After the source code is unzipped, open the ./libNotes directory in a terminal. g++ needs to be installed on you machine. Then create a working RAM disk with:

sudo sh ram_disk.sh

This isn't necessary, but you will have to adjust the makefile and the Gambas code to do it differently. Since I tend to recompile a lot, a RAM disk is faster and saves reads and writes on my SSD.

Assuming you have, then:

make

The Gambas code should now be able to find the library and run just fine. The code structure looks like this:

         Gambas:                     Sound Board
                                         |
                                         V 
         Shared lib:                 libNotes          .cpp 
                                         |
                                         V 
         Support code:               NotesClasses      .cpp, .hpp


This is the core of the API will likely stay the same with new features added. Support for many of the features has already been built or stubbed in, so you can see what is coming by looking at the code.

Feature requests are encouraged. This is very MIDI-ish, and thus its feature set is likely to be incorporated so it can be as compatible as possible.

I very much recommend this code structure if you want to make C/C++ libraries to use from Gambas programs. They can also be called from other languages like C or Python.

I am using the PulseAudio API, rather than the traditional ALSA API, for sound rendering. Apparently, in most Linux distros, including Ubuntu which I use, PulseAudio is installed and provides an emulation layer intercepting ALSA calls, making them no longer native. On machines without PulseAudio, this program won't work.

One technical detail some may wonder about. Gambas is calling the Tick event 100 times a second based on the system clock. The audio plays audio based on the sound board clock. What about clock drift?

It doesn't seem to be a problem. If it results in underruns during silence, no one would be able to tell. If it results in overruns, over time, a pause should develop between hitting a key and hearing the note. After running for more than a full day, there is no sign of this.

Of course, controlling this, meaning monitoring and either skipping or double feeding a few Ticks is in the plans. This should also be suitable library for adding sound effects to game or other programs.
Attachments
SoundBoard-0.0.3.tar.gz
(16.74 KiB) Downloaded 288 times
.... and carry a big stick!
User avatar
cogier
Site Admin
Posts: 1127
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: Keyboard Synthesizer

Post by cogier »

Your instructions worked perfectly for me. At first, I couldn't work out what to do once I ran the program, so I had to mess with the code and add a keyboard!

Image

I'm not sure that it's perfect, but it's a start. Just click on a key to get the note.
SoundBoard_CO.tar.gz
(38.34 KiB) Downloaded 288 times
User avatar
Cedron
Posts: 156
Joined: Thursday 21st February 2019 5:02pm
Location: The Mitten State
Contact:

Re: Keyboard Synthesizer

Post by Cedron »

Thanks, that's a lot in a little time!

Unfortunately, it didn't work for me. Apparently my Gambas version is too old. So, I created a new project, copied all the code into the form file, and all I got were white rectangles. They played, though.

Something like that is what I have in mind as well. I'm going to spend my effort on getting the library completed then set this aside for a little while to return to another project. That's why I wanted to get this out there in case somebody wanted to make a nice interface for it, or several somebodies.

It's a lot easier to understand the code of a library when it is much smaller. It's going to get bigger, but the core functionality is there.

For those who want to install the library permanently so they don't have to recompile after a restart:

sudo cp /tmp/R/libNotes.so /usr/lib

You may want to make sure there isn't already a library by that name there first. Wasn't on my machine.

Here is a slightly upgraded version to make the mouse more fun to use. You should be able to incorporate it.
Attachments
SoundBoard-0.0.4.tar.gz
(16.87 KiB) Downloaded 277 times
.... and carry a big stick!
User avatar
cogier
Site Admin
Posts: 1127
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: Keyboard Synthesizer

Post by cogier »

Try the code with gb.gui and not gb.gui.qt.
User avatar
Cedron
Posts: 156
Joined: Thursday 21st February 2019 5:02pm
Location: The Mitten State
Contact:

Re: Keyboard Synthesizer

Post by Cedron »

Yes, that worked, looks much nicer.

Here is the routine from libNotes.cpp which defines the keyboard notes.

The first is the default. The second puts the low notes on the left hand side, like a piano player is used to. I am will also be adding a Major Scale Notes on the left, others on the right (white vs black on a C scale) option.

Waveform and intensity profiles will be user definable with simple text files.

I will also be adding another class like the PlayingNote, called a Siren for now, which will have a frequency variation profile, varying waveform capability, and a way to parameterize a location trajectory.

I'm finding it fun just playing on the keys.



//=============================================================================
void notes_AssignKeyboardLayout( int argBoardType )
{
        switch( argBoardType )
        {
          case NOTES_BOARD_ACROSS:
                                  //   C D_EF_G A B    
            notes_SetFrequencies( 48, "1234567890-=" );     // 3
            notes_SetFrequencies( 60, "QWERTYUIOP[]" );     // 4
            notes_SetFrequencies( 72, "ASDFGHJKL;'\n" );    // 5 
            notes_SetFrequencies( 84, "ZXCVBNM,./" );       // 6 
            break;

          case NOTES_BOARD_SPLIT:
                                  //   C D_EF
                                  //   _G A B    
            notes_SetFrequencies( 48, "123456" );     // 3
            notes_SetFrequencies( 54, "QWERTY" );     // 4
            notes_SetFrequencies( 60, "ASDFGH" );     // 5
            notes_SetFrequencies( 66, "ZXCVBN" );     // 6

            notes_SetFrequencies( 72, "7890-=" );     // 3
            notes_SetFrequencies( 78, "UIOP[]" );     // 4
            notes_SetFrequencies( 84, "JKL;'\n" );    // 5 
            notes_SetFrequencies( 90, "M,./" );       // 6 
            break;
        }

    
}
//=============================================================================

.... and carry a big stick!
User avatar
Cedron
Posts: 156
Joined: Thursday 21st February 2019 5:02pm
Location: The Mitten State
Contact:

Re: Keyboard Synthesizer

Post by Cedron »

There is more technical detail in this posting:

https://www.dsprelated.com/thread/16925 ... ynthesizer

It's already out of date as I am restructuring some. I've got a rough interface worked out, in progress. Please be patient.
Screenshot at 2023-11-28 13-22-20.png
Screenshot at 2023-11-28 13-22-20.png (21.95 KiB) Viewed 10904 times
It is still worth downloading the earlier versions if you want to understand how the code works. You don't have to install Gambas to download and look at the code. It is all in text files.
.... and carry a big stick!
vuott
Posts: 263
Joined: Wednesday 5th April 2017 6:07pm
Location: European Union

Re: Keyboard Synthesizer

Post by vuott »

Hi, Cedron,
I want to express my congratulations for your commitment to the topic of music-it is rare to find someone who is dedicated to such a topic.
I also find the keyboard interface created by cogier interesting - from a code and graphical point of view.
Europaeus sum !

Amare memorentes atque deflentes ad mortem silenter labimur.
Post Reply