Guest User

Untitled

a guest
Aug 26th, 2016
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.21 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4.  
  5. #include <SDL2/SDL.h>
  6. #include "lilv/lilv.h"
  7.  
  8. void audio_callback(void *data, uint8_t *stream, int bytes)
  9. {
  10.     float *buffer = (float*)stream;
  11.     int length = bytes / sizeof(float);
  12.     int i;
  13.  
  14.     for (i = 0; i < length; ++i) {
  15.         buffer[i] = 0;
  16.     }
  17. }
  18.  
  19. int main()
  20. {
  21. //  if (SDL_Init(SDL_INIT_AUDIO) < 0) {
  22. //      printf("SDL could not initialize audio.\n");
  23. //      exit(EXIT_FAILURE);
  24. //  }
  25.  
  26. //  SDL_AudioSpec want, have;
  27. //  SDL_AudioDeviceID dev;
  28. //  SDL_zero(want);
  29. //  want.freq = 44100;
  30. //  want.format = AUDIO_F32;
  31. //  want.channels = 2;
  32. //  want.samples = 4096;
  33. //  want.callback = audio_callback;
  34. //  want.userdata = NULL;
  35.  
  36. //  dev = SDL_OpenAudioDevice(NULL, 0, &want, &have,
  37. //          SDL_AUDIO_ALLOW_FORMAT_CHANGE);
  38. //  if (!dev) {
  39. //      printf("SDL could not open audio.\n");
  40. //      exit(EXIT_FAILURE);
  41. //  }
  42.  
  43. //  if (have.format != want.format) {
  44. //      printf("Did not get float 32 audio.\n");
  45. //      exit(EXIT_FAILURE);
  46. //  }
  47.  
  48.     LilvWorld *lworld = lilv_world_new();
  49.     if (!lworld) {
  50.         printf("Failed to create a lilv world.\n");
  51.         goto jmp_main_exit;
  52.     }
  53.  
  54.     lilv_world_load_all(lworld);
  55.     const LilvPlugins *plugs = lilv_world_get_all_plugins(lworld);
  56.     LilvState  *state   = NULL;
  57.    
  58.     LilvNode *pluguri = lilv_new_uri(lworld, "https://sine.synth.love/");
  59.     const LilvPlugin *plug = lilv_plugins_get_by_uri(plugs, pluguri);
  60. //  LilvState *initstate = lilv_state_new_from_world(lworld, 0, pluguri);
  61.     lilv_node_free(pluguri);
  62.     if (!plug) {
  63.         printf("Could not find the synth.\n");
  64.         goto jmp_main_exit;
  65.     }
  66.  
  67.  
  68.     LilvInstance *synth = lilv_plugin_instantiate(plug, 44100, NULL);
  69.     if (!synth) {
  70.         printf("Failed to instantiate the synth.\n");
  71.         goto jmp_main_exit;
  72.     }
  73.  
  74.     float freq, *out;
  75.     freq = 440;
  76.     out = malloc(4096 * sizeof(float));
  77.  
  78.     lilv_instance_connect_port(synth, 0, &freq);
  79.     lilv_instance_connect_port(synth, 1, out);
  80.  
  81.     lilv_instance_run(synth, 4096);
  82.     printf("Successfully ran\n");
  83.  
  84. //  int i;
  85. //  for (i = 0; i < 4096; ++i) {
  86. //      printf("%f\n", out[i]);
  87. //  }
  88.  
  89. //  SDL_PauseAudioDevice(dev, 0);
  90. //  SDL_Delay(2000);
  91. //  SDL_CloseAudioDevice(dev);
  92.     lilv_instance_free(synth);
  93.  
  94. jmp_main_exit:
  95.     lilv_world_free(lworld);
  96. //  SDL_Quit();
  97.     return 0;
  98. }
Advertisement
Add Comment
Please, Sign In to add comment