Skip to content

Starting Off

Samuel H edited this page Jul 22, 2021 · 1 revision

BEFORE PROCEEDING, PLEASE SEE THE Building Programs PAGE FOR MORE INFORMATION ON HOW TO COMPILE AND RUN A PROGRAM WITH TSAL CODE!!!

Congrats on installing TSAL! If you have not yet installed TSAL, you can look into our installing TSAL page.

Linux/Mac/Cygwin users: Start off by creating a folder and name it "Tutorial1". Create a file inside of Tutorial1 and name it "hello.cpp". Then, navigate to the cloned TSAL folder and into the genericMakefile folder. Copy the Makefile into Tutorial1 and change the "TARGET" line so that "program" is now "hello". Follow the steps in the Building Programs page on how to compile and run the program (this is a single-file program).

  • Mixer - It is the engine of TSAL. It initializes all the necessary things to start an audio stream. It contains the master channel which other channels and instruments are routed to.
  • Synth - A very basic audio synthesizer. It can only play one note at a time (monophonic), and it can choose from 3 basic waveforms: sine, saw, and square.

Let us start with a basic "Hello World!" application for TSAL

Since we will be writing in C++, let's place our #include and using directives:

#include "tsal.hpp"
using namespace tsal;

tsal.hpp contains #include directives for all of the necessary header files needed in order to use the TSAL library. This includes vital class header files such as those for the Mixer, Channel, AudioBuffer, and Synth class. TSAL also has its own namespace which must be used when using the TSAL library.

Let's add some code that will create the mixer and synthesizer objects.

#include "tsal.hpp"
using namespace tsal;

int main() {
  // Create the mixer object
  Mixer mixer;

  // Create the synthesizer object
  PolySynth synth(&mixer);

  // Add the synth to the mixer
  mixer.add(synth);

The above code creates the setup needed for the synth to play. Now we add the code to play the note:

#include "tsal.hpp"
using namespace tsal;

int main() {
  // Create the mixer object
  Mixer mixer;

  // Create the synthesizer object
  PolySynth synth(&mixer);

  // Add the synth to the mixer
  mixer.add(synth);

  // Play a note on the synth
  synth.play(C7);

  // Wait for the user to stop the synth
  char input;
  std::cout << "Press <enter> to quit:" << std::flush;
  std::cin.get(input);

  return 0;

After writing and saving the above code, compile it using make and run it using ./hello.cpp.

You should hear a sound play. To stop it press <enter>

Congratulations! You have just made you're first TSAL project!

Next up in Multithreading, we will see how to use threads in TSAL.

Clone this wiki locally