C Programma per la conversione di due file .WAV stereo in uno B-format (4 canali) C Program MAKEBFOR Include 'flib.fi' Include 'flib.fd' Character*80 Outfile,Leftfile,Rightfile CHARACTER RIFF*4,FMT*8,DAT*4,ch*1 INTEGER*4 FILELEN,BOH,FSAMP,BYTERATE,NBYTES,i INTEGER*4 FILELEN2,FSAMP2,BYTERATE2,NBYTES2 INTEGER*2 UNO,NoutCHANN,BYTESxPOINT,BITSxWORD,NinCHANN,NinCHANN2 INTEGER*2 BITSxWORD2 INTEGER*4 Lwav,Rwav,N Integer*2 LL,RR REAL*4 L1wav,L2wav,R1wav,R2wav write(6,1) 1 format(1x,'*** Make B-format - Converts 2 WAV Stereo Files', 1' into a 4-chan. WAV file ***',/) write (6,2) 2 format(1x,' Copyright (2000) by Angelo Farina - University of', 1' Parma (Italy)',/) CHR0=0 Narg=NARGS() IF (Narg.LT.3) THEN Write(6,'(1H ,39HName of the WX stereo .WAV file = ,\)') Read(5,'(A40)')Leftfile Write(6,'(1H ,39HName of the YZ stereo .WAV file = ,\)') Read(5,'(A40)')RIGHTfile Write(6,'(1H ,39HName of the B-form .WAV output file = ,\)') Read(5,'(A40)')Outfile ELSE call GetArg(1,LeftFile,Len) Write(6,'(1H ,36HFile Name of the WX stereo file = ,A40)') 1 LeftFile call GetArg(2,RightFile,Len) Write(6,'(1H ,36HFile Name of the YZ stereo file = ,A40)') 1 RIGHTFile call GetArg(3,OutFile,Len) Write(6,'(1H ,36HFile Name of the .WAV output file = ,A40)') 1 OutFile END IF C Apro i files di Input e di Output Open(Unit=1,Form='BINARY',File=Leftfile,Mode='READ',Status='OLD') read(1)RIFF,FILELEN,FMT READ(1)BOH,UNO,NinCHANN if (NinCHANN.NE.2) then Write(6,*)'ERROR - The input files must be stereo' STOP END IF READ(1)FSAMP,BYTERATE READ(1)BYTESxPOINT,BITSxWORD,DAT,NBYTES c DO WHILE (DAT.ne.'data') c read(1)(dummybyte,i=1,NBYTES) c READ(1)DATA,NBYTES c END DO N=NBYTES/BYTESxPOINT C N è il numero di punti da leggere del file .WAV write(6,*) 'Number of data points #1 :',N,' with ',NinCHANN, 1' Channels' write(6,*) 'Sampling Frequency #1 (Hz):',Fsamp,' with ', 1BitsxWord,' Bits' C apro il secondo file Open(Unit=2,Form='BINARY',File=Rightfile,Mode='READ',Status='OLD') read(2)RIFF,FILELEN2,FMT READ(2)BOH,UNO,NinCHANN2 READ(2)FSAMP2,BYTERATE2 if (NinCHANN2.NE.NinCHANN) then Write(6,*)'ERROR - Nchannels mismatch' STOP END IF if (Fsamp2.NE.Fsamp) then Write(6,*)'ERROR - Fsampling mismatch' STOP END IF if (Byterate2.NE.Byterate) then Write(6,*)'ERROR - Byterate mismatch' STOP END IF READ(2)BYTESxPOINT,BITSxWORD2,DAT,NBYTES2 if (NBYTES2.NE.NBYTES) then Write(6,*)'ERROR - Lenght mismatch' STOP END IF if (BITSxWORD2.NE.BITSxWORD) then Write(6,*) 'ERROR - Bit resolution mismatch' STOP END IF c DO WHILE (DAT.ne.'data') c read(2)(dummybyte,i=1,NBYTES) c READ(2)DAT,NBYTES c END DO N=NBYTES/BYTESxPOINT C N è il numero di punti da leggere del file .WAV write(6,*) 'Number of data points #2 :',N,' with ',NinCHANN, 1' Channels' write(6,*) 'Sampling Frequency #2 (Hz):',Fsamp,' with ', 1BitsxWord,' Bits' C Scrittura del file .WAV Open(Unit=9,Form='BINARY',File=Outfile,Mode='WRITE') Rewind(9) C Preparo le costanti write(6,139) FSAMP 139 format(1x,'Outfile Fsampling =',I8,' Hz') FILELEN=FILELEN+NBYTES NoutCHANN=4 BYTESxPOINT=BYTESxPOINT*2 BYTERATE=FSAMP*BYTESxPOINT NBYTES=N*BYTESxPOINT Write(9) RIFF,FILELEN,FMT Write(9) BOH,UNO,NoutCHANN Write(9) FSAMP,BYTERATE Write(9) BYTESxPOINT,BITSxWORD,DAT,NBYTES C Inizio a trasferire i dati write (6,'(1h )') write(6,11) 11 format(1x,'Saving data to output file (s)...') if (BITSxWORD.eq.16) then do i=1,N read(1) Lwav read(2) Rwav write(9) Lwav,Rwav end do elseif (BITSxWORD.eq.32) then do i=1,N read(1) L1wav,L2wav read(2) R1wav,R2wav write(9) L1wav,L2wav,R1wav,R2wav end do elseif (BITSxWORD.eq.24) then do i=1,N read(1) LL,Lwav read(2) RR,Rwav write(9) LL,Lwav,RR,Rwav end do end if if (.not.eof(1)) then do while (.not.eof(1)) read(1) ch write(9) ch end do end if C Chiusura dei files e fine write (6,*) ' Conversion terminated OK !!!!' close(1) close(2) close(9) END