int main (int argc, char **argv) { Lyd *lyd; LydVoice *voice; LydProgram *instrument; int i; const char *code = "saw(hz=440.0) * adsr(0.1, 0.2, 0.8, 0.50) * 2"; float scale[]={261.63, 293.66, 329.63, 349.23, 392.0, 440.0, 493.88, 523.25, 493.88, 440.0, 392.0, 349.23, 329.63, 293.66, 261.0}; lyd = lyd_new (); if (!lyd_audio_init (lyd, "auto")) { lyd_free (lyd); printf ("failed to initialize lyd (audio output)\n"); return -1; } instrument = lyd_compile (lyd, code); for (i = 0; i<14;i++) { voice = lyd_voice_new (lyd, instrument, 0.3 * i, 0); lyd_voice_set_param (voice, "hz", scale[i]); lyd_voice_set_duration (voice, 0.2); } lyd_program_free (instrument); sleep (5); lyd_free (lyd); return 0; }
int main (int argc, char **argv) { Lyd *lyd; long length; char *mididata; FILE *file; int i; lyd = lyd_new (); if (!argv[1]) { argv[1]="/home/pippin/mid/popcorn.mid"; } printf ("initing sound\n"); if (!lyd_audio_init (lyd, "auto", NULL)) { lyd_free (lyd); printf ("failed to initialize lyd (audio output)\n"); return -1; } file = fopen (argv[1], "r"); fseek (file, 0, SEEK_END); length = ftell (file); fseek (file, 0, SEEK_SET); mididata = malloc (length); if (fread (mididata, length, 1, file) != 1) { printf ("Failed to read midi data from %s\n", argv[1]); return -1; } else { printf ("Loaded %li bytes midi data from %s\n", length, argv[1]); fclose (file); } lyd_midi_load (lyd, (void*)mididata, length); lyd_midi_set_playing (lyd, 1); sleep (3); lyd_midi_set_playing (lyd, 0); sleep (2); lyd_midi_set_playing (lyd, 1); sleep (2); lyd_midi_seek (lyd, 0); lyd_midi_set_playing (lyd, 1); for (i=0; i<40;i ++) /* speed up sequencer speed using midi meta tempo events */ { static int tempo = 198436; unsigned char mididata[] = {0xff, 0x51, tempo >> 16, (tempo >> 8) & 0xff, tempo & 0xff}; tempo /= 1.2; lyd_midi_out (lyd, mididata, 5); sleep (1); } lyd_midi_set_playing (lyd, 1); sleep (40); lyd_free (lyd); return 0; }