mirror of
https://github.com/ZDoom/fluidsynth.git
synced 2025-01-31 13:40:35 +00:00
Removed all but the synth parameter from new_fluid_file_renderer(), which now accesses the synth's settings directly.
Fixed incorrect order with synth.device-id setting.
This commit is contained in:
parent
ebd21b4dd9
commit
16a6d7ef63
6 changed files with 38 additions and 62 deletions
|
@ -67,10 +67,7 @@ FLUIDSYNTH_API void delete_fluid_audio_driver(fluid_audio_driver_t* driver);
|
|||
|
||||
FLUIDSYNTH_API void fluid_audio_driver_get_names(char* buf, size_t buflen, const char* separator);
|
||||
|
||||
FLUIDSYNTH_API fluid_file_renderer_t *new_fluid_file_renderer(fluid_synth_t* synth,
|
||||
char* filename, char* type,
|
||||
char* format, char* endian,
|
||||
int period_size);
|
||||
FLUIDSYNTH_API fluid_file_renderer_t *new_fluid_file_renderer(fluid_synth_t* synth);
|
||||
FLUIDSYNTH_API int fluid_file_renderer_process_block(fluid_file_renderer_t* dev);
|
||||
FLUIDSYNTH_API void delete_fluid_file_renderer(fluid_file_renderer_t* dev);
|
||||
FLUIDSYNTH_API const char **fluid_file_renderer_get_type_names (void);
|
||||
|
|
|
@ -102,7 +102,6 @@ new_fluid_file_audio_driver(fluid_settings_t* settings,
|
|||
{
|
||||
fluid_file_audio_driver_t* dev;
|
||||
int err;
|
||||
char* filename = NULL, *type = NULL, *format = NULL, *endian = NULL;
|
||||
int msec;
|
||||
|
||||
dev = FLUID_NEW(fluid_file_audio_driver_t);
|
||||
|
@ -119,25 +118,10 @@ new_fluid_file_audio_driver(fluid_settings_t* settings,
|
|||
dev->callback = (fluid_audio_func_t) fluid_synth_process;
|
||||
dev->samples = 0;
|
||||
|
||||
if (fluid_settings_dupstr(settings, "audio.file.name", &filename) == 0) { /* ++ alloc filename */
|
||||
FLUID_LOG(FLUID_ERR, "No file name specified");
|
||||
dev->renderer = new_fluid_file_renderer(synth);
|
||||
|
||||
if (dev->renderer == NULL)
|
||||
goto error_recovery;
|
||||
}
|
||||
|
||||
fluid_settings_dupstr (settings, "audio.file.type", &type); /* ++ alloc file type */
|
||||
fluid_settings_dupstr (settings, "audio.file.format", &format); /* ++ alloc file format */
|
||||
fluid_settings_dupstr (settings, "audio.file.endian", &endian); /* ++ alloc file endian */
|
||||
|
||||
dev->renderer = new_fluid_file_renderer(synth, filename, type, format, endian,
|
||||
dev->period_size);
|
||||
if (filename) FLUID_FREE (filename); /* -- free filename */
|
||||
if (type) FLUID_FREE (type); /* -- free type */
|
||||
if (format) FLUID_FREE (format); /* -- free format */
|
||||
if (endian) FLUID_FREE (endian); /* -- free endian */
|
||||
|
||||
if (dev->renderer == NULL) {
|
||||
goto error_recovery;
|
||||
}
|
||||
|
||||
msec = (int) (0.5 + dev->period_size / dev->sample_rate * 1000.0);
|
||||
dev->timer = new_fluid_timer(msec, fluid_file_audio_run_s16, (void*) dev, TRUE, FALSE, TRUE);
|
||||
|
|
|
@ -128,26 +128,31 @@ const char *endian_names[] = {
|
|||
/**
|
||||
* Create a new file renderer and open the file.
|
||||
* @param synth The synth that creates audio data.
|
||||
* @param filename Output filename
|
||||
* @param type File type string or NULL for default "auto", which tries to
|
||||
* determine format from filename extension or uses "wav".
|
||||
* @param format Audio format string (can be empty or NULL for default format "s16")
|
||||
* @param endian Endian specification or NULL for default "auto", which uses
|
||||
* the file type's usual byte order.
|
||||
* @param period_size Sample count, amount of samples to write to the file at
|
||||
* every call to fluid_file_renderer_process_block().
|
||||
* @return the new object, or NULL on failure
|
||||
* @since: 1.1.0
|
||||
*
|
||||
* NOTE: Uses the following settings from the synth object:
|
||||
* audio.file.name: Output filename
|
||||
* audio.file.type: File type, "auto" tries to determine type from filename
|
||||
* extension with fallback to "wav".
|
||||
* audio.file.format: Audio format
|
||||
* audio.file.endian: Endian byte order, "auto" for file type's default byte order
|
||||
* audio.period-size: Size of audio blocks to process
|
||||
* synth.sample-rate: Sample rate to use
|
||||
*/
|
||||
fluid_file_renderer_t *
|
||||
new_fluid_file_renderer(fluid_synth_t* synth, char* filename, char* type,
|
||||
char* format, char* endian, int period_size)
|
||||
new_fluid_file_renderer(fluid_synth_t* synth)
|
||||
{
|
||||
fluid_file_renderer_t* dev;
|
||||
#if LIBSNDFILE_SUPPORT
|
||||
char *filename, *type, *format, *endian;
|
||||
SF_INFO info;
|
||||
double samplerate;
|
||||
int retval;
|
||||
#endif
|
||||
fluid_file_renderer_t* dev;
|
||||
|
||||
fluid_return_val_if_fail (synth != NULL, NULL);
|
||||
fluid_return_val_if_fail (synth->settings != NULL, NULL);
|
||||
|
||||
dev = FLUID_NEW(fluid_file_renderer_t);
|
||||
if (dev == NULL) {
|
||||
|
@ -157,7 +162,7 @@ new_fluid_file_renderer(fluid_synth_t* synth, char* filename, char* type,
|
|||
FLUID_MEMSET(dev, 0, sizeof(fluid_file_renderer_t));
|
||||
|
||||
dev->synth = synth;
|
||||
dev->period_size = period_size;
|
||||
fluid_settings_getint (synth->settings, "audio.period-size", &dev->period_size);
|
||||
|
||||
#if LIBSNDFILE_SUPPORT
|
||||
dev->buf_size = 2 * dev->period_size * sizeof (float);
|
||||
|
@ -182,8 +187,19 @@ new_fluid_file_renderer(fluid_synth_t* synth, char* filename, char* type,
|
|||
|
||||
info.format = FLUID_FILE_RENDERER_DEFAULT_FILE_TYPE | SF_FORMAT_PCM_16;
|
||||
|
||||
if (!fluid_file_renderer_parse_options (type, format, endian, filename, &info))
|
||||
goto error_recovery;
|
||||
fluid_settings_dupstr (synth->settings, "audio.file.name", &filename);
|
||||
fluid_settings_dupstr (synth->settings, "audio.file.type", &type);
|
||||
fluid_settings_dupstr (synth->settings, "audio.file.format", &format);
|
||||
fluid_settings_dupstr (synth->settings, "audio.file.endian", &endian);
|
||||
|
||||
retval = fluid_file_renderer_parse_options (type, format, endian, filename, &info);
|
||||
|
||||
if (filename) FLUID_FREE (filename);
|
||||
if (type) FLUID_FREE (type);
|
||||
if (format) FLUID_FREE (format);
|
||||
if (endian) FLUID_FREE (endian);
|
||||
|
||||
if (!retval) goto error_recovery;
|
||||
|
||||
fluid_settings_getnum (synth->settings, "synth.sample-rate", &samplerate);
|
||||
info.samplerate = samplerate + 0.5;
|
||||
|
|
|
@ -1324,6 +1324,7 @@ fluid_settings_foreach_option_alpha (fluid_settings_t* settings, char* name, voi
|
|||
* @param name Name of setting
|
||||
* @return Count of options for this string setting (0 if none, -1 if not found
|
||||
* or not a string setting)
|
||||
* @since 1.1.0
|
||||
*/
|
||||
int
|
||||
fluid_settings_option_count (fluid_settings_t *settings, char *name)
|
||||
|
|
|
@ -222,7 +222,7 @@ void fluid_synth_settings(fluid_settings_t* settings)
|
|||
44100.0f, 22050.0f, 96000.0f,
|
||||
0, NULL, NULL);
|
||||
fluid_settings_register_int(settings, "synth.device-id",
|
||||
0, 126, 0, 0, NULL, NULL);
|
||||
0, 0, 126, 0, NULL, NULL);
|
||||
fluid_settings_register_int(settings, "synth.cpu-cores", 1, 1, 256, 0, NULL, NULL);
|
||||
}
|
||||
|
||||
|
|
|
@ -201,31 +201,9 @@ static void
|
|||
fast_render_loop(fluid_settings_t* settings, fluid_synth_t* synth, fluid_player_t* player)
|
||||
{
|
||||
fluid_file_renderer_t* renderer;
|
||||
char* filename = NULL, *type = NULL, *format = NULL, *endian = NULL;
|
||||
int period_size = 0;
|
||||
|
||||
fluid_settings_getint(settings, "audio.period-size", &period_size);
|
||||
fluid_settings_dupstr(settings, "audio.file.name", &filename); /* ++ alloc file name */
|
||||
fluid_settings_dupstr (settings, "audio.file.type", &type); /* ++ alloc file type */
|
||||
fluid_settings_dupstr (settings, "audio.file.format", &format); /* ++ alloc file format */
|
||||
fluid_settings_dupstr (settings, "audio.file.endian", &endian); /* ++ alloc file endian */
|
||||
|
||||
if (filename == NULL || type == NULL || format == NULL || endian == NULL || period_size <= 0) {
|
||||
fprintf(stderr, "Failed to fetch parameters for file renderer\n");
|
||||
if (filename) FLUID_FREE (filename); /* -- free file name */
|
||||
return;
|
||||
}
|
||||
|
||||
renderer = new_fluid_file_renderer (synth, filename, type, format, endian, period_size);
|
||||
|
||||
FLUID_FREE (filename); /* -- free file name */
|
||||
FLUID_FREE (type); /* -- free file type */
|
||||
FLUID_FREE (format); /* -- free format */
|
||||
FLUID_FREE (endian); /* -- free endian */
|
||||
|
||||
if (!renderer) {
|
||||
return;
|
||||
}
|
||||
renderer = new_fluid_file_renderer (synth);
|
||||
if (!renderer) return;
|
||||
|
||||
while (fluid_player_get_status(player) == FLUID_PLAYER_PLAYING) {
|
||||
if (fluid_file_renderer_process_block(renderer) != FLUID_OK) {
|
||||
|
|
Loading…
Reference in a new issue