60
60
static GList *file_types = NULL;
61
static struct file_type *raw_type,*mplayer_type;
62
63
static gboolean wav_check(gchar *filename);
63
64
static Chunk *wav_load(gchar *filename, int dither_mode, StatusBar *bar);
64
static gboolean wav_save(Chunk *chunk, gchar *filename, gpointer settings,
65
struct file_type *type, int dither_mode,
66
StatusBar *bar,gboolean *fatal);
65
static gint wav_save(Chunk *chunk, gchar *filename, gpointer settings,
66
struct file_type *type, int dither_mode,
67
StatusBar *bar,gboolean *fatal);
68
69
#ifdef HAVE_LIBSNDFILE
69
70
static gboolean sndfile_check(gchar *filename);
70
71
static Chunk *sndfile_load(gchar *filename, int dither_mode, StatusBar *bar);
71
static gboolean sndfile_save(Chunk *chunk, gchar *filename, gpointer settings,
72
struct file_type *type, int dither_mode,
73
StatusBar *bar, gboolean *fatal);
72
static gint sndfile_save(Chunk *chunk, gchar *filename, gpointer settings,
73
struct file_type *type, int dither_mode,
74
StatusBar *bar, gboolean *fatal);
74
75
static gboolean sndfile_save_main(Chunk *chunk, gchar *filename,
75
76
int format, int dither_mode, StatusBar *bar,
79
80
static Chunk *raw_load(gchar *filename, int dither_mode, StatusBar *bar);
80
static gboolean raw_save(Chunk *chunk, gchar *filename, gpointer settings,
81
struct file_type *type, int dither_mode,
82
StatusBar *bar, gboolean *fatal);
81
static gint raw_save(Chunk *chunk, gchar *filename, gpointer settings,
82
struct file_type *type, int dither_mode,
83
StatusBar *bar, gboolean *fatal);
84
85
static Chunk *ogg_load(gchar *filename, int dither_mode, StatusBar *bar);
85
static gboolean ogg_save(Chunk *chunk, gchar *filename, gpointer settings,
86
struct file_type *type,
87
int dither_mode, StatusBar *bar, gboolean *fatal);
86
static gint ogg_save(Chunk *chunk, gchar *filename, gpointer settings,
87
struct file_type *type,
88
int dither_mode, StatusBar *bar, gboolean *fatal);
90
91
static gpointer mp3_get_settings(void);
91
92
static Chunk *mp3_load(gchar *filename, int dither_mode, StatusBar *bar);
92
static gboolean mp3_save(Chunk *chunk, gchar *filename, gpointer settings,
93
struct file_type *type,
94
int dither_mode, StatusBar *bar, gboolean *fatal);
93
static gint mp3_save(Chunk *chunk, gchar *filename, gpointer settings,
94
struct file_type *type,
95
int dither_mode, StatusBar *bar, gboolean *fatal);
96
97
static Chunk *try_mplayer(gchar *filename, int dither_mode, StatusBar *bar);
121
122
(gchar *name, gchar *ext, gboolean lossy,
122
123
gboolean (*typecheck)(gchar *filename),
123
124
Chunk *(*load)(gchar *filename, int dither_mode, StatusBar *bar),
124
gboolean (*save)(Chunk *chunk, gchar *filename,gpointer settings,
125
struct file_type *type,int dither_mode,
126
StatusBar *bar,gboolean *fatal),
125
gint (*save)(Chunk *chunk, gchar *filename,gpointer settings,
126
struct file_type *type,int dither_mode,
127
StatusBar *bar,gboolean *fatal),
129
130
struct file_type *t;
176
177
t->get_settings = mp3_get_settings;
177
178
t->free_settings = g_free;
179
register_file_type(_("Raw PCM data"), ".raw", FALSE,NULL, raw_load,
180
raw_type = register_file_type(_("Raw PCM data"), ".raw", FALSE,NULL,
181
raw_load, raw_save, 0);
182
mplayer_type = register_file_type(_("Open with MPlayer"), NULL,TRUE,NULL,
183
try_mplayer, NULL, 0);
183
186
guint fileformat_count(void)
557
if (fmt->type == DATAFORMAT_PCM) {
558
/* Check that the sign and endian-ness is correct */
559
if (fmt->samplesize == 1) q = FALSE;
561
if (XOR(fmt->sign,q) || fmt->bigendian) {
562
memcpy(&cfmt,fmt,sizeof(cfmt));
564
cfmt.bigendian = FALSE;
565
c = chunk_convert(chunk,&cfmt,DITHER_UNSPEC,bar);
566
b = wav_save(c,filename,settings,type,dither_mode,bar,fatal);
567
gtk_object_sink(GTK_OBJECT(c));
546
573
if (fmt->type == DATAFORMAT_PCM && fmt->samplesize==1 && fmt->sign) {
547
user_error(_("8-bit wav-files must be in unsigned format!"));
574
/* user_error(_("8-bit wav-files must be in unsigned format!")); */
575
g_assert_not_reached();
550
577
if (fmt->type == DATAFORMAT_PCM && fmt->samplesize>1 && !fmt->sign) {
551
user_error(_("16/24/32-bit wav-files must be in signed format!"));
578
/*user_error(_("16/24/32-bit wav-files must be in signed format!"));
580
g_assert_not_reached();
554
582
if (fmt->type == DATAFORMAT_PCM && fmt->bigendian == TRUE) {
555
user_error(_("wav files must be in little endian format!"));
583
/* user_error(_("wav files must be in little endian format!")); */
584
g_assert_not_reached();
559
587
/* Give a warning once if we're saving a file larger than 2GB */
622
fmt = rawdialog_execute(filename);
623
if (!fmt) return NULL;
624
653
i = errdlg_filesize(filename);
625
654
if (i==-1) return NULL;
655
fmt = rawdialog_execute(filename,i,&offs);
656
if (!fmt) return NULL;
626
657
ds = (Datasource *)gtk_type_new(datasource_get_type());
627
658
memcpy(&(ds->format),fmt,sizeof(Dataformat));
629
ds->length = i/fmt->samplebytes;
660
ds->length = (i-offs)/fmt->samplebytes;
630
661
ds->type = DATASOURCE_VIRTUAL;
631
662
ds->data.virtual.filename = g_strdup(filename);
632
ds->data.virtual.offset = 0;
663
ds->data.virtual.offset = offs;
633
664
return chunk_new_from_datasource(ds);
636
static gboolean raw_save(Chunk *chunk, gchar *filename, gpointer settings,
667
static gint raw_save(Chunk *chunk, gchar *filename, gpointer settings,
637
668
struct file_type *type, int dither_mode,
638
669
StatusBar *bar, gboolean *fatal)
641
674
f = e_fopen(filename,EFILE_WRITE);
642
675
if (!f) return TRUE;
643
if (chunk_dump(chunk,f,IS_BIGENDIAN,dither_mode,bar)) {
677
i = chunk_dump(chunk,f,IS_BIGENDIAN,dither_mode,bar);
678
if (i < 0) *fatal = TRUE;
829
862
for (i=0; i<chunk->length; i+=n) {
830
863
/* FIXME: Use chunk_read_array for FP chunks */
831
n = chunk_read_array_fp(ch,i,1024,samplebuf,dither_mode);
864
n = chunk_read_array_fp(ch,i,1024,samplebuf,dither_mode,&clipcount);
835
868
g_free(samplebuf);
872
clipcount += unnormalized_count(samplebuf,n*chunk->format.channels);
839
873
if (sf_writef_sample_t(s,samplebuf,n) != n) {
840
874
c = g_strdup_printf(_("Failed to write to '%s'!"),filename);
845
879
g_free(samplebuf);
849
883
if (status_bar_progress(bar, n*chunk->format.samplebytes)) {
852
886
g_free(samplebuf);
853
887
xunlink(filename);
859
893
g_free(samplebuf);
894
return clipwarn(clipcount,TRUE);
865
static gboolean sndfile_save(Chunk *chunk, gchar *filename, gpointer settings,
866
struct file_type *type, int dither_mode,
867
StatusBar *bar, gboolean *fatal)
898
static gint sndfile_save(Chunk *chunk, gchar *filename, gpointer settings,
899
struct file_type *type, int dither_mode,
900
StatusBar *bar, gboolean *fatal)
869
902
return sndfile_save_main(chunk,filename,type->extra_data,dither_mode,
972
1006
y->format.samplesize*8,
973
1007
y->format.channels, y->format.samplerate,
974
1008
y->format.bigendian?1:0);
975
b = pipe_dialog_send_chunk(y,c,FALSE,dither_mode,bar);
1009
b = pipe_dialog_send_chunk(y,c,FALSE,dither_mode,bar,&clipcount);
977
1011
if (x != NULL) gtk_object_sink(GTK_OBJECT(x));
978
1012
if (!xunsetenv("OUTFILE")) g_free(d);
979
1013
if (b || !file_exists(filename)) {
1017
return clipwarn(clipcount,TRUE);
1208
1242
return (XOR(fmt->samplesize == 1, fmt->sign));
1211
static gboolean mp3_save(Chunk *chunk, gchar *filename, gpointer settings,
1212
struct file_type *type,
1213
int dither_mode, StatusBar *bar, gboolean *fatal)
1245
static gint mp3_save(Chunk *chunk, gchar *filename, gpointer settings,
1246
struct file_type *type,
1247
int dither_mode, StatusBar *bar, gboolean *fatal)
1216
1250
Dataformat fmt;
1253
off_t clipcount = 0;
1219
1254
xunlink(filename);
1220
1255
c = g_strdup_printf("OUTFILE=%s",filename);
1221
if (xputenv(c)) { g_free(c); return TRUE; }
1256
if (xputenv(c)) { g_free(c); return -1; }
1222
1257
c = g_strdup_printf("LAMEFLAGS=%s",(settings == NULL) ?
1223
1258
"--preset standard" : (gchar *)settings);
1224
if (xputenv(c)) { g_free(c); return TRUE; }
1259
if (xputenv(c)) { g_free(c); return -1; }
1225
1260
if (wav_regular_format(&(chunk->format)))
1226
1261
b = pipe_dialog_send_chunk(chunk,
1227
1262
"lame --silent $LAMEFLAGS - "
1228
"\"$OUTFILE\"",TRUE,dither_mode,bar);
1263
"\"$OUTFILE\"",TRUE,dither_mode,bar,
1230
1266
memcpy(&fmt,&(chunk->format),sizeof(Dataformat));
1231
1267
if (fmt.type == DATAFORMAT_FLOAT || fmt.samplesize == 3) {
1241
1277
b = pipe_dialog_send_chunk(x,
1242
1278
"lame --silent --preset standard - "
1243
"\"$OUTFILE\"",TRUE,dither_mode,bar);
1279
"\"$OUTFILE\"",TRUE,dither_mode,bar,
1244
1281
gtk_object_sink(GTK_OBJECT(x));
1247
1284
if (!xunsetenv("OUTFILE")) g_free(c);
1248
1285
if (b || !file_exists(filename)) {
1289
return clipwarn(clipcount,TRUE);