comparison src/lame/out_lame.c @ 981:d801d8ce24fb trunk

[svn] - replace almost all of outlame_write() with standard code from disk_writer in hope of fixing endianness problem. - make use of audacious vfs functions.
author yaz
date Fri, 27 Apr 2007 02:29:33 -0700
parents 9429121d61ec
children cc0c5c9ad2b9
comparison
equal deleted inserted replaced
980:6ba4a4bfd127 981:d801d8ce24fb
26 26
27 #include <audacious/plugin.h> 27 #include <audacious/plugin.h>
28 #include <audacious/beepctrl.h> 28 #include <audacious/beepctrl.h>
29 #include <audacious/configdb.h> 29 #include <audacious/configdb.h>
30 #include <audacious/util.h> 30 #include <audacious/util.h>
31 #include <audacious/vfs.h>
31 32
32 #include <lame/lame.h> 33 #include <lame/lame.h>
33 34
34 #define ENCBUFFER_SIZE 35000 35 #define ENCBUFFER_SIZE 35000
35 #define OUT_LAME_VER "0.2" 36 #define OUT_LAME_VER "0.3"
36 /* #define DEBUG 1 */ 37 /* #define DEBUG 1 */
37 38
38 GtkWidget *configure_win = NULL, *path_vbox; 39 GtkWidget *configure_win = NULL, *path_vbox;
39 GtkWidget *path_hbox, *path_label, *path_entry, *path_browse, 40 GtkWidget *path_hbox, *path_label, *path_entry, *path_browse,
40 *path_dirbrowser = NULL; 41 *path_dirbrowser = NULL;
75 GtkWidget *tags_id3_frame, *tags_id3_vbox, *tags_id3_hbox, 76 GtkWidget *tags_id3_frame, *tags_id3_vbox, *tags_id3_hbox,
76 *tags_force_id3v2_toggle, *tags_only_v1_toggle, *tags_only_v2_toggle; 77 *tags_force_id3v2_toggle, *tags_only_v1_toggle, *tags_only_v2_toggle;
77 78
78 GtkWidget *enc_quality_vbox, *hbox1, *hbox2; 79 GtkWidget *enc_quality_vbox, *hbox1, *hbox2;
79 80
80 // will be used in flushing 81 struct format_info {
81 AFormat oldfmt; 82 AFormat format;
82 gint oldrate, oldnch; 83 int frequency;
84 int channels;
85 };
86 struct format_info input;
83 87
84 static gchar *file_path = NULL; 88 static gchar *file_path = NULL;
85 static FILE *output_file = NULL; 89 static VFSFile *output_file = NULL;
86 static guint64 written = 0; 90 static guint64 written = 0;
87 static guint64 olen = 0; 91 static guint64 olen = 0;
88 static AFormat afmt; 92 static AFormat afmt;
89 gint ctrlsocket_get_session_id(void); 93 gint ctrlsocket_get_session_id(void);
90 94
188 p->genre = NULL; 192 p->genre = NULL;
189 p->year = NULL; 193 p->year = NULL;
190 p->track_number = NULL; 194 p->track_number = NULL;
191 195
192 }; 196 };
193
194 197
195 OutputPlugin *get_oplugin_info(void) 198 OutputPlugin *get_oplugin_info(void)
196 { 199 {
197 outlame_op.description = g_strdup_printf("Out-Lame %s", OUT_LAME_VER); 200 outlame_op.description = g_strdup_printf("Out-Lame %s", OUT_LAME_VER);
198 return &outlame_op; 201 return &outlame_op;
301 gchar *filename, *title = NULL, *temp; 304 gchar *filename, *title = NULL, *temp;
302 gint pos; 305 gint pos;
303 int b_use_path_anyway = 0; 306 int b_use_path_anyway = 0;
304 gchar *tmpfilename = NULL; 307 gchar *tmpfilename = NULL;
305 308
306 /* store open paramators for reopen */ 309 /* store open paramators */
307 oldfmt = fmt; oldrate = rate; oldnch = nch; 310 input.format = fmt;
311 input.frequency = rate;
312 input.channels = nch;
308 313
309 /* So all the values will be reset to the ones saved */ 314 /* So all the values will be reset to the ones saved */
310 /* Easier than to implement a tmp variable for every value */ 315 /* Easier than to implement a tmp variable for every value */
311 outlame_init(); 316 outlame_init();
312 317
378 } 383 }
379 384
380 #ifdef DEBUG 385 #ifdef DEBUG
381 printf("filename = %s\n", filename); 386 printf("filename = %s\n", filename);
382 #endif 387 #endif
383 output_file = fopen(filename, "w"); 388 output_file = vfs_fopen(filename, "w");
384 g_free(filename); 389 g_free(filename);
385 390
386 if (!output_file) 391 if (!output_file)
387 return 0; 392 return 0;
388 393
389 if ((int) (gfp = lame_init()) == -1) 394 if ((gfp = lame_init()) == (void *)-1)
390 return 0; 395 return 0;
391 396
392 srate = rate; 397 srate = rate;
393 inch = nch; 398 inch = nch;
394 399
478 return 0; 483 return 0;
479 484
480 return 1; 485 return 1;
481 } 486 }
482 487
488 static void convert_buffer(gpointer buffer, gint length)
489 {
490 gint i;
491
492 if (afmt == FMT_S8)
493 {
494 guint8 *ptr1 = buffer;
495 gint8 *ptr2 = buffer;
496
497 for (i = 0; i < length; i++)
498 *(ptr1++) = *(ptr2++) ^ 128;
499 }
500 if (afmt == FMT_S16_BE)
501 {
502 gint16 *ptr = buffer;
503
504 for (i = 0; i < length >> 1; i++, ptr++)
505 *ptr = GUINT16_SWAP_LE_BE(*ptr);
506 }
507 if (afmt == FMT_S16_NE)
508 {
509 gint16 *ptr = buffer;
510
511 for (i = 0; i < length >> 1; i++, ptr++)
512 *ptr = GINT16_TO_LE(*ptr);
513 }
514 if (afmt == FMT_U16_BE)
515 {
516 gint16 *ptr1 = buffer;
517 guint16 *ptr2 = buffer;
518
519 for (i = 0; i < length >> 1; i++, ptr2++)
520 *(ptr1++) = GINT16_TO_LE(GUINT16_FROM_BE(*ptr2) ^ 32768);
521 }
522 if (afmt == FMT_U16_LE)
523 {
524 gint16 *ptr1 = buffer;
525 guint16 *ptr2 = buffer;
526
527 for (i = 0; i < length >> 1; i++, ptr2++)
528 *(ptr1++) = GINT16_TO_LE(GUINT16_FROM_LE(*ptr2) ^ 32768);
529 }
530 if (afmt == FMT_U16_NE)
531 {
532 gint16 *ptr1 = buffer;
533 guint16 *ptr2 = buffer;
534
535 for (i = 0; i < length >> 1; i++, ptr2++)
536 *(ptr1++) = GINT16_TO_LE((*ptr2) ^ 32768);
537 }
538 }
539
483 static void outlame_write(void *ptr, gint length) 540 static void outlame_write(void *ptr, gint length)
484 { 541 {
542 AFormat new_format;
543 int new_frequency, new_channels;
544 EffectPlugin *ep;
545
546 new_format = input.format;
547 new_frequency = input.frequency;
548 new_channels = input.channels;
549
550 ep = get_current_effect_plugin();
551 if ( effects_enabled() && ep && ep->query_format ) {
552 ep->query_format(&new_format,&new_frequency,&new_channels);
553 }
554
555 if ( effects_enabled() && ep && ep->mod_samples ) {
556 length = ep->mod_samples(&ptr,length,
557 input.format,
558 input.frequency,
559 input.channels );
560 }
561
562 if (afmt == FMT_S8 || afmt == FMT_S16_BE ||
563 afmt == FMT_U16_LE || afmt == FMT_U16_BE || afmt == FMT_U16_NE)
564 convert_buffer(ptr, length);
565 #ifdef WORDS_BIGENDIAN
566 if (afmt == FMT_S16_NE)
567 convert_buffer(ptr, length);
568 #endif
485 569
486 if (inch == 1) { 570 if (inch == 1) {
487 encout = 571 encout =
488 lame_encode_buffer(gfp, (short *)ptr, (short *)ptr, length / 2, encbuffer, 572 lame_encode_buffer(gfp, ptr, ptr, length / 2, encbuffer,
489 ENCBUFFER_SIZE); 573 ENCBUFFER_SIZE);
490 } 574 }
491 else { 575 else {
492 encout = 576 encout =
493 lame_encode_buffer_interleaved(gfp, (short *)ptr, length / 4, encbuffer, 577 lame_encode_buffer_interleaved(gfp, ptr, length / 4, encbuffer,
494 ENCBUFFER_SIZE); 578 ENCBUFFER_SIZE);
495 } 579 }
496 fwrite(encbuffer, 1, encout, output_file); 580
581 vfs_fwrite(encbuffer, 1, encout, output_file);
497 written += encout; 582 written += encout;
498 olen += length; 583 olen += length;
499
500 } 584 }
501 585
502 static void outlame_close(void) 586 static void outlame_close(void)
503 { 587 {
504 if (output_file) { 588 if (output_file) {
505 589
506 encout = lame_encode_flush_nogap(gfp, encbuffer, ENCBUFFER_SIZE); 590 encout = lame_encode_flush_nogap(gfp, encbuffer, ENCBUFFER_SIZE);
507 fwrite(encbuffer, 1, encout, output_file); 591 vfs_fwrite(encbuffer, 1, encout, output_file);
508 592
509 // lame_mp3_tags_fid(gfp, output_file); // will erase id3v2 tag?? 593 // lame_mp3_tags_fid(gfp, output_file); // will erase id3v2 tag??
510 594
511 fclose(output_file); 595 vfs_fclose(output_file);
512 lame_close(gfp); 596 lame_close(gfp);
513 597
514 free_lameid3(&lameid3); 598 free_lameid3(&lameid3);
515 599
516 written = 0; 600 written = 0;
531 // it would break lame context. 615 // it would break lame context.
532 if (time < 0) { 616 if (time < 0) {
533 return; 617 return;
534 } 618 }
535 outlame_close(); 619 outlame_close();
536 outlame_open(oldfmt, oldrate, oldnch); 620 outlame_open(input.format, input.frequency, input.channels);
537 #ifdef DEBUG 621 #ifdef DEBUG
538 printf("flush %d\n", time); 622 printf("flush %d\n", time);
539 #endif 623 #endif
540 offset = time; 624 offset = time;
541 } 625 }
2103 TRUE, TRUE, 0); 2187 TRUE, TRUE, 0);
2104 2188
2105 vbr_quality_adj = gtk_adjustment_new(4, 0, 9, 1, 1, 1); 2189 vbr_quality_adj = gtk_adjustment_new(4, 0, 9, 1, 1, 1);
2106 vbr_quality_spin = 2190 vbr_quality_spin =
2107 gtk_spin_button_new(GTK_ADJUSTMENT(vbr_quality_adj), 8, 0); 2191 gtk_spin_button_new(GTK_ADJUSTMENT(vbr_quality_adj), 8, 0);
2108 gtk_widget_set_usize(vbr_quality_spin, 20, 20); 2192 gtk_widget_set_usize(vbr_quality_spin, 20, -1);
2109 gtk_box_pack_start(GTK_BOX(vbr_options_hbox3), vbr_quality_spin, 2193 gtk_box_pack_start(GTK_BOX(vbr_options_hbox3), vbr_quality_spin,
2110 TRUE, TRUE, 0); 2194 TRUE, TRUE, 0);
2111 gtk_signal_connect(GTK_OBJECT(vbr_quality_adj), "value-changed", 2195 gtk_signal_connect(GTK_OBJECT(vbr_quality_adj), "value-changed",
2112 GTK_SIGNAL_FUNC(vbr_qual), NULL); 2196 GTK_SIGNAL_FUNC(vbr_qual), NULL);
2113 2197