From f95d7aa6aaef78659ee5edda8a5f2e04d60f6726 Mon Sep 17 00:00:00 2001 From: Thomas Schmitt Date: Tue, 24 Oct 2006 10:20:35 +0000 Subject: [PATCH] Enabled byte swapping for audio track sources, added anti option -swab --- cdrskin/README | 4 ++-- cdrskin/cdrskin.c | 30 +++++++++++++++++++++++------- cdrskin/cdrskin_timestamp.h | 2 +- libburn/libburn.h | 10 ++++++++++ libburn/sector.c | 16 ++++++++++++---- libburn/structure.c | 14 ++++++++++++++ libburn/structure.h | 4 ++++ 7 files changed, 66 insertions(+), 14 deletions(-) diff --git a/cdrskin/README b/cdrskin/README index ccc2d7b..5b1c6be 100644 --- a/cdrskin/README +++ b/cdrskin/README @@ -184,7 +184,7 @@ Anything except .wav files has to be converted into raw format first mppdec --raw-le /path/to/track5.mpc track05.cd cdrskin dev=1,1,0 blank=fast fs=0 -eject \ - -audio track0[1-5].cd /path/to/track6.wav + -audio -swab track0[1-5].cd /path/to/track6.wav Usage example with http://scdbackup.sourceforge.net @@ -357,7 +357,7 @@ results with audio data files which are : 44100 Hz sampling rate 16 bits per sample stereo (2 channels) - little-endian byte order + little-endian byte order with option -swab Files with name extension .wav get examined wether they are in Microsoft WAVE format with above parameters and eventually get extracted by cdrskin itself. All other formats (including SUN's format .au) are to be extracted by commands diff --git a/cdrskin/cdrskin.c b/cdrskin/cdrskin.c index ac87454..4369e19 100644 --- a/cdrskin/cdrskin.c +++ b/cdrskin/cdrskin.c @@ -776,6 +776,7 @@ struct CdrtracK { int track_type; double sector_size; int track_type_by_default; + int swap_audio_bytes; /** Optional fifo between input fd and libburn. It uses a pipe(2) to transfer data to libburn. @@ -812,7 +813,8 @@ int Cdrtrack_new(struct CdrtracK **track, struct CdrskiN *boss, int Cdrskin_get_source(struct CdrskiN *skin, char *source_path, double *fixed_size, double *padding, int *set_by_padsize, int *track_type, - int *track_type_by_default, int flag); + int *track_type_by_default, int *swap_audio_bytes, + int flag); int Cdrskin_get_fifo_par(struct CdrskiN *skin, int *fifo_enabled, int *fifo_size, int *fifo_start_empty, int flag); @@ -831,6 +833,7 @@ int Cdrtrack_new(struct CdrtracK **track, struct CdrskiN *boss, o->track_type= BURN_MODE1; o->sector_size= 2048.0; o->track_type_by_default= 1; + o->swap_audio_bytes= 0; o->fifo_enabled= 0; o->fifo= NULL; o->fifo_outlet_fd= -1; @@ -839,7 +842,8 @@ int Cdrtrack_new(struct CdrtracK **track, struct CdrskiN *boss, o->libburn_track= NULL; ret= Cdrskin_get_source(boss,o->source_path,&(o->fixed_size),&(o->padding), &(o->set_by_padsize),&(skin_track_type), - &(o->track_type_by_default),0); + &(o->track_type_by_default),&(o->swap_audio_bytes), + 0); if(ret<=0) goto failed; Cdrtrack_set_track_type(o,skin_track_type,0); @@ -964,8 +968,10 @@ int Cdrtrack_extract_audio(struct CdrtracK *track, int *fd, off_t *xtr_size, ret= libdax_audioxtr_detach_fd(xtr,fd,0); if(ret<=0) {ret= -1*!!ret; goto ex;} - fprintf(stderr,"cdrskin: NOTE : %.f audio bytes in '%s'\n", - (double) *xtr_size, track->source_path); + track->swap_audio_bytes= !!msb_first; + fprintf(stderr,"cdrskin: NOTE : %.f %saudio bytes in '%s'\n", + (double) *xtr_size, (msb_first ? "" : "(-swab) "), + track->source_path); ret= 1; ex: libdax_audioxtr_destroy(&xtr,0); @@ -1179,7 +1185,8 @@ int Cdrtrack_add_to_session(struct CdrtracK *track, int trackno, } burn_track_define_data(tr,0,(int) lib_padding,sector_pad_up, track->track_type); - + burn_track_set_byte_swap(tr, + (track->track_type==BURN_AUDIO && track->swap_audio_bytes)); fixed_size= track->fixed_size; if((flag&2) && track->padding>0) { if(flag&1) @@ -1983,6 +1990,8 @@ see_cdrskin_eng_html:; "\t-data\t\tSubsequent tracks are CD-ROM data mode 1 (default)\n"); fprintf(stderr,"\t-pad\t\tpadsize=30k\n"); fprintf(stderr,"\t-nopad\t\tDo not pad (default)\n"); + fprintf(stderr, + "\t-swab\t\tAudio data source is byte-swapped (little-endian/Intel)\n"); fprintf(stderr,"\t-help\t\tprint this text to stderr and exit\n"); fprintf(stderr, "Option -audio does automatic extraction of .wav but not of .au .\n"); @@ -2241,6 +2250,7 @@ struct CdrskiN { /** track_type may be set to BURN_MODE1, BURN_AUDIO, etc. */ int track_type; int track_type_by_default; /* 0= explicit, 1=not set, 2=by file extension */ + int swap_audio_bytes; /** The list of tracks with their data sources and parameters */ struct CdrtracK *tracklist[Cdrskin_track_maX]; @@ -2343,6 +2353,7 @@ int Cdrskin_new(struct CdrskiN **skin, struct CdrpreskiN *preskin, int flag) o->padding= 0.0; o->set_by_padsize= 0; o->track_type= BURN_MODE1; + o->swap_audio_bytes= 0; /* >>> ??? does this have to be 1 ? */ o->track_type_by_default= 1; for(i=0;itracklist[i]= NULL; @@ -2413,7 +2424,8 @@ int Cdrskin_destroy(struct CdrskiN **o, int flag) int Cdrskin_get_source(struct CdrskiN *skin, char *source_path, double *fixed_size, double *padding, int *set_by_padsize, int *track_type, - int *track_type_by_default, int flag) + int *track_type_by_default, int *swap_audio_bytes, + int flag) { strcpy(source_path,skin->source_path); *fixed_size= skin->fixed_size; @@ -2421,6 +2433,7 @@ int Cdrskin_get_source(struct CdrskiN *skin, char *source_path, *set_by_padsize= skin->set_by_padsize; *track_type= skin->track_type; *track_type_by_default= skin->track_type_by_default; + *swap_audio_bytes= skin->swap_audio_bytes; return(1); } @@ -4368,7 +4381,7 @@ int Cdrskin_setup(struct CdrskiN *skin, int argc, char **argv, int flag) "-immed", "-force", "-raw", "-raw96p", "-raw16", "-clone", "-text", "-mode2", "-xa", "-xa1", "-xa2", "-xamix", "-cdi", "-isosize", "-preemp", "-nopreemp", "-copy", "-nocopy", - "-scms", "-shorttrack", "-noshorttrack", "-swab", "-packet", "-noclose", + "-scms", "-shorttrack", "-noshorttrack", "-packet", "-noclose", "" }; @@ -4745,6 +4758,9 @@ set_speed:; if(skin->verbosity>=Cdrskin_verbose_cmD) printf("cdrskin: speed : %f\n",skin->x_speed); + } else if(strcmp(argv[i],"-swab")==0) { + skin->swap_audio_bytes= 0; + } else if(strcmp(argv[i],"-tao")==0) { if(skin->tao_to_sao_tsize<=0.0) { fprintf(stderr,"cdrskin: FATAL : libburn does not support -tao yet.\n"); diff --git a/cdrskin/cdrskin_timestamp.h b/cdrskin/cdrskin_timestamp.h index facd8ee..0299754 100644 --- a/cdrskin/cdrskin_timestamp.h +++ b/cdrskin/cdrskin_timestamp.h @@ -1 +1 @@ -#define Cdrskin_timestamP "2006.10.24.075039" +#define Cdrskin_timestamP "2006.10.24.102107" diff --git a/libburn/libburn.h b/libburn/libburn.h index 559a3be..981a8ee 100644 --- a/libburn/libburn.h +++ b/libburn/libburn.h @@ -849,6 +849,16 @@ int burn_session_remove_track(struct burn_session *s, struct burn_track *t); void burn_track_define_data(struct burn_track *t, int offset, int tail, int pad, int mode); + +/* ts A61024 */ +/** Define wether a track shall swap bytes of its input stream. + @param t The track to change + @param swap_source_bytes 0=do not swap, 1=swap byte pairs + @return 1=success , 0=unacceptable value +*/ +int burn_track_set_byte_swap(struct burn_track *t, int swap_source_bytes); + + /** Set the ISRC details for a track @param t The track to change @param country the 2 char country code. Each character must be diff --git a/libburn/sector.c b/libburn/sector.c index 6bdb49b..5fed2c5 100644 --- a/libburn/sector.c +++ b/libburn/sector.c @@ -79,7 +79,7 @@ static int get_outmode(struct burn_write_opts *o) static void get_bytes(struct burn_track *track, int count, unsigned char *data) { - int valid, shortage, curr; + int valid, shortage, curr, i, tr; /* no track pointer means we're just generating 0s */ if (!track) { @@ -147,9 +147,17 @@ static void get_bytes(struct burn_track *track, int count, unsigned char *data) curr += valid; } } - if (!shortage) - return; - memset(data + curr, 0, shortage); +ex:; + /* ts A61024 : general finalizing processing */ + if(shortage) + memset(data + curr, 0, shortage); /* this is old icculus.org */ + if (track->swap_source_bytes == 1) { + for (i = 1; i < count; i += 2) { + tr = data[i]; + data[i] = data[i-1]; + data[i-1] = tr; + } + } } /* ts A61009 : seems to hand out sector start pointer in opts->drive->buffer diff --git a/libburn/structure.c b/libburn/structure.c index 22c1bc8..8898969 100644 --- a/libburn/structure.c +++ b/libburn/structure.c @@ -118,6 +118,9 @@ struct burn_track *burn_track_create(void) t->postgap = 0; t->pregap1 = 0; t->pregap2 = 0; + + /* ts A61024 */ + t->swap_source_bytes = 0; return t; } @@ -227,6 +230,17 @@ void burn_track_define_data(struct burn_track *t, int offset, int tail, t->tail = tail; } + +/* ts A61024 */ +int burn_track_set_byte_swap(struct burn_track *t, int swap_source_bytes) +{ + if(swap_source_bytes!=0 && swap_source_bytes!=1) + return 0; + t->swap_source_bytes = swap_source_bytes; + return 1; +} + + void burn_track_set_isrc(struct burn_track *t, char *country, char *owner, unsigned char year, unsigned int serial) { diff --git a/libburn/structure.h b/libburn/structure.h index 61f083f..f935284 100644 --- a/libburn/structure.h +++ b/libburn/structure.h @@ -41,6 +41,10 @@ struct burn_track /** The track contains a postgap */ int postgap; struct isrc isrc; + + /* ts A61024 */ + /** Byte swapping on source data stream : 0=none , 1=pairwise */ + int swap_source_bytes; }; struct burn_session