robertesler / Pd4P3

A real-time audio synthesis library for Processing 3. Pd4P3 implements Pure Data's signal processing objects via Pd++ native code. Pd4P3 stands for "Pd++ for Processing 3".
GNU Lesser General Public License v2.1
7 stars 1 forks source link

how to write samples directly to sound output? #2

Closed molo32 closed 3 years ago

molo32 commented 3 years ago

I would like to synthesize sounds generating samples and listen to it directly.

robertesler commented 3 years ago

Hi @molo32! If I understand what you are asking you want to make your own synthesized sounds then send it to the audio driver. Below I've copied the code from the DummyTemplate.pde sketch. But all the examples do the same thing. The outputL and outputR variables inherited from the class PdAlgorithm write the values it receives directly to the audio block.
Any number from -1 to 1 will go to your hardware (actually on some OSs numbers larger than that will work and distort tremendously so be careful with your ears).
If I have misunderstood your question please correct me. Thank you for your interest in Pd4P3.


class MyMusic extends PdAlgorithm {
   float dummy = 0;

   //All DSP code goes here
   void runAlgorithm(double in1, double in2) {
     outputL = outputR = 0; //write any numbers from -1 to 1 here
   }
  //We use synchronized to communicate with the audio thread
   synchronized void setFloat(float f1) {
     dummy = f1;
   }

   synchronized float getFloat() {
     return dummy;
   }

   //Free all objects created from Pd4P3 lib
   void free() {

   } 
 }