Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- #include <SDL2/SDL.h>
- #include "lilv/lilv.h"
- void audio_callback(void *data, uint8_t *stream, int bytes)
- {
- float *buffer = (float*)stream;
- int length = bytes / sizeof(float);
- int i;
- for (i = 0; i < length; ++i) {
- buffer[i] = 0;
- }
- }
- int main()
- {
- // if (SDL_Init(SDL_INIT_AUDIO) < 0) {
- // printf("SDL could not initialize audio.\n");
- // exit(EXIT_FAILURE);
- // }
- // SDL_AudioSpec want, have;
- // SDL_AudioDeviceID dev;
- // SDL_zero(want);
- // want.freq = 44100;
- // want.format = AUDIO_F32;
- // want.channels = 2;
- // want.samples = 4096;
- // want.callback = audio_callback;
- // want.userdata = NULL;
- // dev = SDL_OpenAudioDevice(NULL, 0, &want, &have,
- // SDL_AUDIO_ALLOW_FORMAT_CHANGE);
- // if (!dev) {
- // printf("SDL could not open audio.\n");
- // exit(EXIT_FAILURE);
- // }
- // if (have.format != want.format) {
- // printf("Did not get float 32 audio.\n");
- // exit(EXIT_FAILURE);
- // }
- LilvWorld *lworld = lilv_world_new();
- if (!lworld) {
- printf("Failed to create a lilv world.\n");
- goto jmp_main_exit;
- }
- lilv_world_load_all(lworld);
- const LilvPlugins *plugs = lilv_world_get_all_plugins(lworld);
- LilvState *state = NULL;
- LilvNode *pluguri = lilv_new_uri(lworld, "https://sine.synth.love/");
- const LilvPlugin *plug = lilv_plugins_get_by_uri(plugs, pluguri);
- // LilvState *initstate = lilv_state_new_from_world(lworld, 0, pluguri);
- lilv_node_free(pluguri);
- if (!plug) {
- printf("Could not find the synth.\n");
- goto jmp_main_exit;
- }
- LilvInstance *synth = lilv_plugin_instantiate(plug, 44100, NULL);
- if (!synth) {
- printf("Failed to instantiate the synth.\n");
- goto jmp_main_exit;
- }
- float freq, *out;
- freq = 440;
- out = malloc(4096 * sizeof(float));
- lilv_instance_connect_port(synth, 0, &freq);
- lilv_instance_connect_port(synth, 1, out);
- lilv_instance_run(synth, 4096);
- printf("Successfully ran\n");
- // int i;
- // for (i = 0; i < 4096; ++i) {
- // printf("%f\n", out[i]);
- // }
- // SDL_PauseAudioDevice(dev, 0);
- // SDL_Delay(2000);
- // SDL_CloseAudioDevice(dev);
- lilv_instance_free(synth);
- jmp_main_exit:
- lilv_world_free(lworld);
- // SDL_Quit();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment