Copy metadata
Without cover art yet
This commit is contained in:
parent
9dfb188d8a
commit
9a77ac6e26
3 changed files with 35 additions and 4 deletions
|
@ -2,8 +2,10 @@
|
|||
#define AUDIOFILE_H
|
||||
|
||||
#include <sndfile.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
SNDFILE *audiofile_read(const char *path, SF_INFO *sfinfo);
|
||||
SNDFILE *audiofile_open_for_write(const char *path, SF_INFO *og_info);
|
||||
int audiofile_copy_metadata(SNDFILE *source, SNDFILE *target);
|
||||
|
||||
#endif
|
|
@ -39,3 +39,30 @@ SNDFILE *audiofile_open_for_write(const char *path, SF_INFO *og_info) {
|
|||
|
||||
return sndfile;
|
||||
}
|
||||
|
||||
int audiofile_copy_metadata(SNDFILE *source, SNDFILE *target) {
|
||||
int err;
|
||||
SF_BROADCAST_INFO binfo;
|
||||
|
||||
if ((err = sf_command(source, SFC_GET_BROADCAST_INFO, &binfo, sizeof(binfo))) != 0) {
|
||||
printf("Failed reading BROADCAST_INFO: %s\n", sf_error_number(err));
|
||||
return 1;
|
||||
}
|
||||
if ((err = sf_command(target, SFC_SET_BROADCAST_INFO, &binfo, sizeof(binfo))) != 0) {
|
||||
printf("Failed writing BROADCAST_INFO: %s\n", sf_error_number(err));
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
for (int i=SF_STR_FIRST; i<=SF_STR_LAST; i++) {
|
||||
const char *data = sf_get_string(source, i);
|
||||
if (data != NULL) {
|
||||
if ((err = sf_set_string(target, i, data)) != 0) {
|
||||
printf("Failed writing metadata %d (%s): %s\n", i, data, sf_error_number(err));
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
10
src/main.c
10
src/main.c
|
@ -38,8 +38,8 @@ int main(int argc, char *argv[]) {
|
|||
// load audio file
|
||||
|
||||
SF_INFO sfinfo = {0};
|
||||
SNDFILE *sndfile;
|
||||
if ((sndfile = audiofile_read(input_filename, &sfinfo)) == NULL) {
|
||||
SNDFILE *in_sndfile;
|
||||
if ((in_sndfile = audiofile_read(input_filename, &sfinfo)) == NULL) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -48,6 +48,8 @@ int main(int argc, char *argv[]) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
audiofile_copy_metadata(in_sndfile, out_sndfile);
|
||||
|
||||
// load lilv plugin
|
||||
|
||||
const LilvPlugin* plugin = easy_load_plugin(world, "http://lsp-plug.in/plugins/lv2/comp_delay_x2_stereo");
|
||||
|
@ -90,7 +92,7 @@ int main(int argc, char *argv[]) {
|
|||
float input_buffer[BUFFER_SIZE * 2];
|
||||
float output_buffer[BUFFER_SIZE * 2];
|
||||
int frames_read;
|
||||
while ((frames_read = sf_readf_float(sndfile, input_buffer, BUFFER_SIZE))) {
|
||||
while ((frames_read = sf_readf_float(in_sndfile, input_buffer, BUFFER_SIZE))) {
|
||||
// a frame is 2 samples and a sample is a number basically and it go left right left right (or how many channels)
|
||||
for (sf_count_t i = 0; i < frames_read; i++) {
|
||||
input_left[i] = input_buffer[i * 2];
|
||||
|
@ -117,7 +119,7 @@ int main(int argc, char *argv[]) {
|
|||
|
||||
lilv_world_free(world);
|
||||
|
||||
sf_close(sndfile);
|
||||
sf_close(in_sndfile);
|
||||
sf_close(out_sndfile);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue