libmp3splt: minimal.c

| libmp3splt 0.9.3.1519 Lossless library for splitting audio formats like mp3, ogg vorbis and FLAC. |

Loading...
Searching...
No Matches
minimal.c

A minimal usage example.

A minimal usage example.

#include <stdio.h>
#include <stdlib.h>
#include <libmp3splt/mp3splt.h>
static void print_confirmation_and_exit_if_error(splt_state *state, splt_code error);
static void print_message_from_library(const char *message, splt_message_type type, void *data);
static void print_split_filename(const char *filename, void *data);
//Main program
//Please note that not all errors are handled in this example.
//Compile with:
// $ gcc minimal.c -o minimal -lmp3splt
int main(int argc, char *argv[])
{
if (argc != 2)
{
fprintf(stderr, "Please provide the input file to be split as the first argument.\n");
fflush(stderr);
return EXIT_FAILURE;
}
splt_code error = SPLT_OK;
//initialisation of the main state
splt_state *state = mp3splt_new_state(NULL);
//register callback functions
mp3splt_set_message_function(state, print_message_from_library, NULL);
mp3splt_set_split_filename_function(state, print_split_filename, NULL);
//look for the available plugins
error = mp3splt_find_plugins(state);
print_confirmation_and_exit_if_error(state, error);
//set the input filename to be split
mp3splt_set_filename_to_split(state, argv[1]);
//append two splitpoints
splt_point *first_point = mp3splt_point_new(0, NULL);
mp3splt_append_splitpoint(state, first_point);
splt_point *second_point = mp3splt_point_new(100 * 60 * 1, NULL);
mp3splt_append_splitpoint(state, second_point);
//do the effective split
error = mp3splt_split(state);
print_confirmation_and_exit_if_error(state, error);
//free the memory of the main state
mp3splt_free_state(state);
return EXIT_SUCCESS;
}
//Callback function that handles error code from libmp3splt.
static void print_confirmation_and_exit_if_error(splt_state *state, splt_code error)
{
char *message = mp3splt_get_strerror(state, error);
if (!message)
{
return;
}
if (error < 0)
{
fprintf(stderr, "%s\n", message);
fflush(stderr);
mp3splt_free_state(state);
exit(1);
}
else
{
fprintf(stdout, "%s\n", message);
fflush(stdout);
}
free(message);
}
//Callback function printing any messages from libmp3splt.
static void print_message_from_library(const char *message, splt_message_type type, void *data)
{
if (type == SPLT_MESSAGE_INFO)
{
fprintf(stdout, message);
fflush(stdout);
return;
}
fprintf(stderr, message);
fflush(stderr);
}
//Callback function printing the created filenames.
static void print_split_filename(const char *filename, void *data)
{
fprintf(stdout, " %s created.\n", filename);
fflush(stdout);
}
mp3splt_set_split_filename_function
splt_code mp3splt_set_split_filename_function(splt_state *state, void(*file_cb)(const char *filename, void *cb_data), void *cb_data)
Register callback function that is called when an output file is created.
splt_message_type
splt_message_type
Type of the message sent to the client.
Definition mp3splt.h:1113
mp3splt_set_message_function
splt_code mp3splt_set_message_function(splt_state *state, void(*message_cb)(const char *message, splt_message_type type, void *cb_data), void *cb_data)
Register callback function used to send text messages to the client.
SPLT_MESSAGE_INFO
@ SPLT_MESSAGE_INFO
Info message.
Definition mp3splt.h:1117
mp3splt_get_strerror
char * mp3splt_get_strerror(splt_state *state, splt_code error)
Returns the error message of the error.
splt_code
splt_code
Confirmation and error codes.
Definition mp3splt.h:107
mp3splt_set_filename_to_split
splt_code mp3splt_set_filename_to_split(splt_state *state, const char *filename)
Sets the input filename to split.
mp3splt_split
splt_code mp3splt_split(splt_state *state)
Executes the main split process.
splt_point
struct _splt_point splt_point
Structure defining one splitpoint.
Definition mp3splt.h:1331
mp3splt_point_new
splt_point * mp3splt_point_new(long splitpoint_value, splt_code *error)
Creates a new splitpoint with the splitpoint_value.
mp3splt_append_splitpoint
splt_code mp3splt_append_splitpoint(splt_state *state, splt_point *splitpoint)
Append a new splitpoint to the state.
splt_state
struct _splt_state splt_state
Main structure used in libmp3splt.
Definition mp3splt.h:231
mp3splt_find_plugins
splt_code mp3splt_find_plugins(splt_state *state)
Finds the plugins in the plugins directories.
mp3splt_new_state
splt_state * mp3splt_new_state(splt_code *error)
Creates a new splt_state structure.
mp3splt_free_state
splt_code mp3splt_free_state(splt_state *state)
Free the memory of the state.
mp3splt.h
libmp3splt API