1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
|
/* gap_gve_sox.c
* Audio resampling Modules based on calls to UNIX Utility Program sox
*/
/*
* Copyright
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <config.h>
#include <glib/gstdio.h>
#include "gap_gve_sox.h"
#include "gap_audio_wav.h"
#include "gap-intl.h"
/* --------------------------------
* gap_gve_sox_init_default
* --------------------------------
*/
void
gap_gve_sox_init_default(GapGveCommonValues *cval)
{
g_snprintf(cval->util_sox, sizeof(cval->util_sox), "%s"
, GAP_STORY_SOX_DEFAULT_UTIL_SOX);
g_snprintf(cval->util_sox_options, sizeof(cval->util_sox_options), "%s"
, GAP_STORY_SOX_DEFAULT_UTIL_SOX_OPTIONS);
} /* end gap_gve_sox_init_default */
/* --------------------------------
* gap_gve_sox_save_config
* --------------------------------
*/
void
gap_gve_sox_save_config(GapGveCommonValues *cval)
{
gimp_gimprc_set("video_encode_com_util_sox", cval->util_sox);
gimp_gimprc_set("video_encode_com_util_sox_options", cval->util_sox_options);
} /* end gap_gve_sox_save_config */
/* --------------------------------
* gap_gve_sox_init_config
* --------------------------------
*/
void
gap_gve_sox_init_config(GapGveCommonValues *cval)
{
char *value_string;
gap_gve_sox_init_default(cval);
value_string = gimp_gimprc_query("video_encode_com_util_sox");
if(value_string)
{
g_snprintf(cval->util_sox, sizeof(cval->util_sox), "%s", value_string);
g_free(value_string);
}
value_string = gimp_gimprc_query("video_encode_com_util_sox_options");
if(value_string)
{
g_snprintf(cval->util_sox_options, sizeof(cval->util_sox_options), "%s", value_string);
g_free(value_string);
}
} /* end gap_gve_sox_init_config */
/* --------------------------------
* gap_gve_sox_chk_and_resample
* --------------------------------
*/
gint
gap_gve_sox_chk_and_resample(GapGveCommonValues *cval)
{
long samplerate;
long channels;
long bytes_per_sample;
long bits;
long samples;
long all_playlist_references;
long valid_playlist_references;
int l_rc;
gchar *l_msg;
if(gap_debug) printf("gap_gve_sox_chk_and_resample\n");
all_playlist_references = 0;
valid_playlist_references = 0;
cval->tmp_audfile[0] = '\0';
if(cval->audioname1[0] == '\0')
{
return 0;
}
/* check for WAV file or valid audio playlist, and get audio informations */
l_rc = gap_audio_playlist_wav_file_check(cval->audioname1
, &samplerate
, &channels
, &bytes_per_sample
, &bits
, &samples
, &all_playlist_references
, &valid_playlist_references
, cval->samplerate
);
if (valid_playlist_references > 0)
{
return 0; /* OK, valid audio playlist */
}
if (all_playlist_references > 0)
{
return -1; /* non matching playlist */
}
if ((l_rc !=0)
|| (bits != 16)
|| (cval->samplerate != cval->wav_samplerate1))
{
if((cval->tmp_audfile[0] != '\0') && (cval->wav_samplerate_tmp == cval->samplerate))
{
if(g_file_test(cval->tmp_audfile, G_FILE_TEST_EXISTS))
{
if(gap_debug) printf("resample needed, tmpfile is already there %s\n", cval->tmp_audfile);
return 0;
}
}
g_snprintf(cval->tmp_audfile, sizeof(cval->tmp_audfile), "%s_tmp.wav", cval->audioname1);
if(gap_debug) printf("resample needed, try to call sox to create tmpfile: %s\n", cval->tmp_audfile);
/* delete tmp file */
g_remove(cval->tmp_audfile);
if(g_file_test(cval->tmp_audfile, G_FILE_TEST_EXISTS))
{
l_msg = g_strdup_printf(_("ERROR: Can't overwrite temporary workfile\nfile: %s")
, cval->tmp_audfile);
if(cval->run_mode == GIMP_RUN_INTERACTIVE)
{
g_message("%s", l_msg);
}
return -1;
}
gap_story_sox_exec_resample( cval->audioname1
, cval-> tmp_audfile
, cval->samplerate
, cval->util_sox
, cval->util_sox_options
);
if(!g_file_test(cval->tmp_audfile, G_FILE_TEST_EXISTS))
{
l_msg = g_strdup_printf(_("ERROR: Could not create resampled WAV workfile\n\n"
"1.) check write permission on \n file: %s\n"
"2.) check if SOX (version >= 12.16) is installed:\n prog: %s\n")
, cval->tmp_audfile
, cval->util_sox
);
if(cval->run_mode == GIMP_RUN_INTERACTIVE)
{
g_message("%s", l_msg);
}
g_free(l_msg);
return -1;
}
}
return 0;
} /* end gap_gve_sox_chk_and_resample */
|