libpd has moved to GitHub: https://github.com/libpd

General information on embedding Pd can be found on the Libpd page

libpd seems to be geared towards IOS and Android, but could be useful on regular Linux systems as well. For those, ALSA or JACK support would be needed.

The original pd contained various audio drivers such as JACK, ALSA, etcetera. These have been replaced by one ‘dummy’ driver in libpd: instead of using builtin audio drivers, the ‘process’ functions from libpd can be used to process the audio. This way a client can pass that to any actual audio framework (such as JACK or ALSA) as he wishes.

A (rather crude) adaptation of the ‘pdtest’ example connecting to JACK is as follows:

#include <stdio.h>
#include <stdlib.h>
#include <jack/jack.h>
#include "z_libpd.h"

jack_port_t *input_port;
jack_port_t *output_port;

int process (jack_nframes_t nframes, void *arg)
{
  jack_nframes_t current;
  jack_default_audio_sample_t *out = (jack_default_audio_sample_t *) jack_port_get_buffer (output_port, nframes);
  jack_default_audio_sample_t *in  = (jack_default_audio_sample_t *) jack_port_get_buffer (input_port, nframes);
  // it seems libpd expects chunks of 64 longs (per port) - for now we assume nframes >= 64
  if (nframes < 64)
  {
    fprintf(stderr, "Support for nframes < 64 not implemented yet\n");
    exit(-1);
  }
  if (nframes % 64 != 0)
  {
    fprintf(stderr, "nframes is not a multiple of 64\n");
    exit(-1);
  }

  for (current = 0; current < nframes; current+=64)
  {
    libpd_process_float(in + current, out + current);
  }
  return 0;
}

void pdprint(const char *s) {
  printf("%s", s);
}

void pdnoteon(int ch, int pitch, int vel) {
  printf("noteon: %d %d %d\n", ch, pitch, vel);
}

int main(int argc, char **argv) {
  if (argc < 3) {
    fprintf(stderr, "usage: %s file folder\n", argv[0]);
    return -1;
  }

  jack_client_t *client;
  if ((client = jack_client_open (argv[1], JackNullOption, NULL)) == 0) {
    fprintf (stderr, "jack server not running?\n");
    return 1;
  }

  input_port = jack_port_register (client, "input", JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0);
  output_port = jack_port_register (client, "output", JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0);

  jack_set_process_callback (client, process, 0);

  // init pd
  int srate = 44100;
  libpd_printhook = (t_libpd_printhook) pdprint;
  libpd_noteonhook = (t_libpd_noteonhook) pdnoteon;
  libpd_init();
  libpd_init_audio(1, 1, srate, 1);
  // compute audio    [; pd dsp 1(
  libpd_start_message(32); // allocate ample space for message elements
  libpd_add_float(1.0f);
  libpd_finish_message("pd", "dsp");

  // open patch
  libpd_openfile(argv[1], argv[2]);

  if (jack_activate (client))
  {
    fprintf (stderr, "cannot activate client");
    return 1;
  }

  sleep(1000);

  return 0;
}

PulseAudio & PortAudio & WxWidgets C++ GUI implementation are available here:
http://www.workinprogress.ca/libpd