diff options
| author | zlago | 2025-02-03 17:52:34 +0100 | 
|---|---|---|
| committer | zlago | 2025-02-03 17:52:34 +0100 | 
| commit | 4efa9f571e84cda3741e524fb21a3a22cdbc13fb (patch) | |
| tree | a562d9b9efcc5f396f659c6ca11e38335a498534 /src | |
| parent | 04cbd877cddabf1d7e4bbfd0f4f7553f6fc57899 (diff) | |
bugfixes
Diffstat (limited to 'src')
| -rw-r--r-- | src/SDL2.c | 8 | ||||
| -rw-r--r-- | src/common/common.c | 2 | ||||
| -rw-r--r-- | src/modules/fluidsynth.c | 56 | 
3 files changed, 36 insertions, 30 deletions
@@ -39,21 +39,21 @@ int (*file_ext(char *file))(struct blob *, struct userdata *);  int main(int argc, char **argv) {  	if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO)) { -		eprintf("failed to init SDL: %s\n"); +		eprintf("failed to init SDL: %s\n", SDL_GetError());  		return EXIT_FAILURE;  	}  	SDL_StopTextInput();  	if ((window = SDL_CreateWindow("mu-sdl", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, WINDOW_WIDTH, WINDOW_HEIGHT, SDL_WINDOW_RESIZABLE | SDL_WINDOW_HIDDEN)) == NULL) { -		eprintf("failed to create a window: %s\n"); +		eprintf("failed to create a window: %s\n", SDL_GetError());  		SDL_Quit();  		return EXIT_FAILURE;  	}  	SDL_Renderer *renderer;  	if ((renderer = SDL_CreateRenderer(window, -1, 0)) == NULL) { -		eprintf("failed to create a renderer: %s\n"); +		eprintf("failed to create a renderer: %s\n", SDL_GetError());  		SDL_DestroyWindow(window);  		SDL_Quit();  		return EXIT_FAILURE; @@ -150,7 +150,7 @@ int main(int argc, char **argv) {  					SDL_free(evt.drop.file);  					break; -				default: +				default:;  			}  		}  	} diff --git a/src/common/common.c b/src/common/common.c index a944f8f..8628cd2 100644 --- a/src/common/common.c +++ b/src/common/common.c @@ -23,7 +23,7 @@ struct blob load_file(char const *const name) {  	if (file == NULL) {  		return (struct blob) {.data = NULL};  	} -	void *data = malloc(START_SIZE); +	char *data = malloc(START_SIZE);  	size_t allocated = START_SIZE;  	size_t used = 0;  	while (1) { diff --git a/src/modules/fluidsynth.c b/src/modules/fluidsynth.c index 9eedc2c..eeaa795 100644 --- a/src/modules/fluidsynth.c +++ b/src/modules/fluidsynth.c @@ -4,54 +4,60 @@  #include <fluidsynth.h> -struct fluidsynth_userdata { +static struct fluidsynth_userdata {  	fluid_settings_t *settings;  	fluid_synth_t *synth; -	fluid_player_t *player;  	int soundfont; -}; +} *fs;  static void fluidsynth_callback(void *userdata, unsigned char *stream, int const length) { -	struct fluidsynth_userdata *fs = userdata; +	//fluid_player_t *player = userdata; +	(void) userdata;  	fluid_synth_write_float(fs->synth, length / sizeof (float) / 2, stream, 0, 2, stream, 1, 2);  }  static void fluidsynth_free(void *ptr) { -	struct fluidsynth_userdata *fs = ptr; -	fluid_player_stop(fs->player); -	delete_fluid_player(fs->player); -	fluid_player_play(fs->player); +	fluid_player_t *player = ptr; +	fluid_player_stop(player); +	delete_fluid_player(player); +	//fluid_synth_all_notes_off(fs->synth, -1); +	fluid_synth_system_reset(fs->synth); +	#if 0  	fluid_synth_sfunload(fs->synth, fs->soundfont, 0);  	delete_fluid_synth(fs->synth);  	delete_fluid_settings(fs->settings);  	free(fs); +	#endif  }  int module_fluidsynth(struct blob *file, struct userdata *userdata) { -	struct fluidsynth_userdata *fs = malloc(sizeof (struct fluidsynth_userdata));  	if (fs == NULL) { -		return 1; -	} -	fs->settings = new_fluid_settings(); // wasteful, but when trying to 'fix' it it just caused more errors -	fluid_settings_setnum(fs->settings, "synth.gain", 0.5); -	fluid_settings_setint(fs->settings, "player.reset-synth", 0); -	fluid_settings_setnum(fs->settings, "synth.sample-rate", SAMPLE_RATE); -	fs->synth = new_fluid_synth(fs->settings); -	char *soundfont_path = getenv("SOUNDFONT"); -	if (soundfont_path == NULL) { -		soundfont_path = "/usr/share/sounds/sf2/default-GM.sf2"; +		fs = malloc(sizeof (struct fluidsynth_userdata)); +		if (fs == NULL) { +			return 1; +		} +		fs->settings = new_fluid_settings(); // wasteful, but when trying to 'fix' it it just caused more errors +		fluid_settings_setnum(fs->settings, "synth.gain", 0.5); +		fluid_settings_setint(fs->settings, "player.reset-synth", 0); +		fluid_settings_setnum(fs->settings, "synth.sample-rate", SAMPLE_RATE); +		fs->synth = new_fluid_synth(fs->settings); +		char *soundfont_path = getenv("SOUNDFONT"); +		if (soundfont_path == NULL) { +			soundfont_path = "/usr/share/sounds/sf2/default-GM.sf2"; +		} +		fs->soundfont = fluid_synth_sfload(fs->synth, soundfont_path, 1); // ugly hack  	} -	fs->soundfont = fluid_synth_sfload(fs->synth, soundfont_path, 1); // ugly hack -	fs->player = new_fluid_player(fs->synth); -	fluid_player_set_loop(fs->player, -1); -	if (fluid_player_add_mem(fs->player, file->data, file->size) == FLUID_FAILED) { +	fluid_player_t *player = new_fluid_player(fs->synth); +	fluid_player_set_loop(player, -1); +	if (fluid_player_add_mem(player, file->data, file->size) == FLUID_FAILED) {  		fluidsynth_free(fs); +		fs = NULL;  		return 1;  	} -	fluid_player_play(fs->player); +	fluid_player_play(player);  	userdata->callback = fluidsynth_callback; -	userdata->user = fs; +	userdata->user = player;  	userdata->freefunc = fluidsynth_free;  	return 0;  }  | 
