I've been playing with LAAGA, I wrote a simple client that just sends a
440Hz sin to ALSA I/O:Output 1. It usually works fine unless you Ctrl-C
the client, then, the next time you run it the output is garbled, theres
still a signal there but its been distorted.
occasionally it will just glitch of its own accord, then there's tell tale
glitch at the end of the buffer when the client disconnects before the
next one comes out distorted.
Stopping engine and starting it again fixes it.
I've attached the client code incase its a client bug (its broadly the
same as Paul's ae_client.c).
I'm using cvs ALSA from Jul 2nd, the card is an ens1371.
- Steve
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#include <math.h>
#include <laaga/laaga.h>
#define TABLE_SIZE 4096
#define FREQ 440.0f
laaga_port_t *sin_output_port;
unsigned int sample_rate;
unsigned int phase = 0;
unsigned int inc = 0;
sample_t sin_tbl[TABLE_SIZE];
int process (nframes_t nframes, void *arg)
{
sample_t *out = (sample_t *) laaga_port_get_buffer(sin_output_port, nframes);
unsigned int i;
for(i=0; i<nframes; i++) {
out[i] = sin_tbl[phase];
phase += inc;
phase &= TABLE_SIZE - 1;
}
return 0;
}
int srate (nframes_t nframes, void *arg)
{
printf ("the sample rate is now %lu/sec\n", nframes);
sample_rate = nframes;
inc = FREQ * TABLE_SIZE / sample_rate;
return 0;
}
int main (int argc, char *argv[])
{
laaga_client_t *client;
unsigned int i;
if ((client = laaga_client_new("sin_client")) == 0) {
fprintf (stderr, "laaga server not running?\n");
return 1;
}
/* Create wavetable */
for (i=0; i<TABLE_SIZE; i++) {
sin_tbl[i] = sin((float)i / (float)TABLE_SIZE * 2.0f * M_PI);
}
laaga_set_process_callback (client, process, 0);
laaga_set_sample_rate_callback (client, srate, 0);
sample_rate = laaga_get_sample_rate(client);
inc = FREQ * TABLE_SIZE / sample_rate;
printf ("engine sample rate: %u\n", sample_rate);
sin_output_port = laaga_port_register (client, "sin_wave",
LAAGA_DEFAULT_AUDIO_TYPE, LaagaPortIsOutput, 0);
if (laaga_activate(client)) {
fprintf (stderr, "cannot activate client\n");
exit(1);
}
printf("client activated\n");
if (laaga_port_connect (client, sin_output_port->shared->name, "ALSA
I/O:Output 1")) {
fprintf (stderr, "cannot connect output ports\n");
}
sleep (5);
printf ("done sleeping, now closing...\n");
laaga_client_close (client);
exit (0);
}