home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
AMOS PD CD
/
amospdcd.iso
/
sourcecode
/
subroutines
/
music-merger.amos
/
music-merger.amosSourceCode
Wrap
AMOS Source Code
|
1991-08-06
|
8KB
|
334 lines
'--------------------------------------------------------------
' MELANGEUR DE MUSIQUES: plusieurs musiques dans une banque...
' (c) 1991 F.Lionet / A.N.T.
'--------------------------------------------------------------
Set Buffer 16
'
Dim I2(256),SUM1(256),SUM2(256)
Global APOKE,SPOKE
'
Do
'
Screen Open 0,640,200,2,Hires : Curs Off : Colour 1,$FF4
Centre At(,0)+">>> Merger of Music <<<"
'
Erase 3
'
F1$=Fsel$("*.Abk","","Select Music Bank -1.","QUIT to Exit")
If F1$="" : Edit : End If
F2$=Fsel$("*.Abk","","Select Music Bank -2.","QUIT to Exit")
If F2$="" : Edit : End If
Open In 1,F1$
Open In 2,F2$
'
' Verification de la validite des banques
A$=Input$(1,20)
If Left$(A$,4)<>"AmBk" : Print At(0,10),"File -1 Not An AMOS Bank!" : End : End If
If Right$(A$,8)<>"Music " : Print At(0,10),"File -1 Not A MUSIC Bank!" : End : End If
A$=Input$(2,20)
If Left$(A$,4)<>"AmBk" : Print At(0,10),"File -2 Not An AMOS Bank!" : End : End If
If Right$(A$,8)<>"Music " : Print At(0,10),"File -1 Not A MUSIC Bank!" : End : End If
'
' Reservation de la banque de travail
LM1=Lof(1)
LM2=Lof(2)
Reserve As Chip Data 3,LM1+LM2+256
ABANK=Start(3)+20
'
' Charge les entetes
APOKE=ABANK
HEAD1$=Input$(1,16)
HEAD2$=Input$(2,16)
'
' Adresses des diff�rentes parties
AINST1=Leek(Varptr(HEAD1$))+20
AINST2=Leek(Varptr(HEAD2$))+20
AMUS1=Leek(Varptr(HEAD1$)+4)+20
AMUS2=Leek(Varptr(HEAD2$)+4)+20
APAT1=Leek(Varptr(HEAD1$)+8)+20
APAT2=Leek(Varptr(HEAD2$)+8)+20
EPAT1=Leek(Varptr(HEAD1$)+12)+20 : If EPAT1=20 : EPAT1=Lof(1) : End If
EPAT2=Leek(Varptr(HEAD2$)+12)+20 : If EPAT2=20 : EPAT2=Lof(2) : End If
'
' Va faire le travail
Print At(0,10);"Merging- ";F1$;" (";LM1;" Bytes.)"
Print At(0,11);" and ";F2$;" (";LM2;" Bytes.)"
Print "Total Length =";LM1+LM2;" Bytes."
Print
Print "Total Number Of Instruments:";
Gosub MERGE_SAMPLES
Print NTI;
If NTI<NI1+NI2
Print " - Discarding";NI1+NI2-NTI;" instrument(s)!";
End If
Print
'
Print "Total Number Of Songs :";
MUMU=SPOKE : Gosub MERGE_MUSICS
Print NMU
'
Print "Total Number Of Patterns :";
Gosub MERGE_PATTERNS : EBANK=APOKE
Print NPAT
'
APOKE=MUMU : Gosub MERGE_MUSICS
'
Close
'
LBANK=EBANK-ABANK+8
E=LM1+LM2-LBANK
If E>0
Print : Print "Saved ";E;" Bytes! Making Final Bank";LBANK;" Bytes."
End If
Print
Print "Hit Mouse Key!"
Repeat : Until Mouse Click>0
'
' Sauve la banque...
APOKE=ABANK-20
STRPOKE["AmBk"]
BDOKE[3] : BDOKE[0] : BLOKE[$80000000+LBANK]
STRPOKE["Music "]
BLOKE[AINST-ABANK]
BLOKE[AMUS-ABANK]
BLOKE[APAT-ABANK]
BLOKE[EBANK-ABANK]
'
F$=Fsel$("*.Abk","","Select A File Name To Save Bank As...")
If F$<>""
Bsave F$,ABANK-20 To EBANK
End If
'
Erase 3
'
Loop
'
'----------------------------------------------------------------------------
MERGE_SAMPLES:
'
' Copie les instruments de la premiere banque, en stockant les noms
Pof(1)=AINST1 : A$=Input$(1,2) : NI1=Deek(Varptr(A$))
Pof(2)=AINST2 : A$=Input$(2,2) : NI2=Deek(Varptr(A$))
INST1$=Input$(1,NI1*32)
INST2$=Input$(2,NI2*32)
'
' Pour chaque instrument, calcule une somme de controle des 512 1ers samples
For N=0 To NI1-1
A=Varptr(INST1$)+N*32
AI=Leek(A)+AINST1 : LI=Min(512,Deek(A+8)*2)
Pof(1)=AI : A$=Input$(1,LI)
S=0 : SA=Varptr(A$)
For L=0 To LI-1
Add S,Peek(SA+L)
Next
SUM1(N)=S
Next
For N=0 To NI2-1
A=Varptr(INST2$)+N*32
AI=Leek(A)+AINST2 : LI=Min(512,Deek(A+8)*2)
Pof(2)=AI : A$=Input$(2,LI)
S=0 : SA=Varptr(A$)
For L=0 To LI-1
Add S,Peek(SA+L)
Next
SUM2(N)=S
Next
'
' Compte les instruments semblables
NTI=NI1
For N2=0 To NI2-1
A2=Varptr(INST2$)+N2*32
L2=Leek(A2+8)
FLAG=-1
For N1=0 To NI1-1
A1=Varptr(INST1$)+N1*32
L1=Leek(A1+8)
If L1=L2 and SUM1(N1)=SUM2(N2)
I2(N2)=N1
FLAG=0 : Exit
End If
Next
If FLAG
I2(N2)=NTI : Inc NTI
End If
Next
'
' Recopie les instruments
AINST=ABANK+16
APOKE=AINST : BDOKE[NTI]
SVIDE=APOKE+NTI*32
SPOKE=SVIDE+4
'
For N=0 To NI1-1
AI=Varptr(INST1$)+N*32
A1=SPOKE : S1=AINST1+Leek(AI) : L1=Deek(AI+8)*2
A2=SPOKE+L1 : S2=AINST1+Leek(AI+4) : L2=Deek(AI+10)*2
If L2<=4
A2=SVIDE : L2=4
End If
BLOKE[A1-AINST] : BLOKE[A2-AINST]
BDOKE[L1/2] : BDOKE[L2/2]
For O=0 To 16 Step 4
BLOKE[Leek(AI+12+O)]
Next
SCOPY[1,S1,L1]
If A2<>SVIDE
SCOPY[1,S2,L2]
End If
Next
'
For N=0 To NI2-1
If I2(N)>=NI1
AI=Varptr(INST2$)+N*32
A1=SPOKE : S1=AINST2+Leek(AI) : L1=Deek(AI+8)*2
A2=SPOKE+L1 : S2=AINST2+Leek(AI+4) : L2=Deek(AI+10)*2
If L2<=4
A2=SVIDE : L2=4
End If
BLOKE[A1-AINST] : BLOKE[A2-AINST]
BDOKE[L1/2] : BDOKE[L2/2]
For O=0 To 16 Step 4
BLOKE[Leek(AI+12+O)]
Next
SCOPY[2,S1,L1]
If A2<>SVIDE
SCOPY[2,S2,L2]
End If
End If
Next
'
INST1$="" : INST2$=""
APOKE=SPOKE
Return
'
'----------------------------------------------------------------------------
MERGE_MUSICS:
'
LMU1=APAT1-AMUS1 : Pof(1)=AMUS1
MU1$=Input$(1,LMU1) : NMU1=Deek(Varptr(MU1$))
LMU2=APAT2-AMUS2 : Pof(2)=AMUS2
MU2$=Input$(2,LMU2) : NMU2=Deek(Varptr(MU2$))
NMU=NMU1+NMU2 : AMUS=APOKE : BDOKE[NMU]
SPOKE=APOKE+NMU*4
'
' Recopie les musiques de la banque 1
For N=0 To NMU1-1
BLOKE[SPOKE-AMUS]
A=Varptr(MU1$) : AM=Leek(A+N*4+2)
If N<NMU1-1
FM=Leek(A+N*4+6)
Else
FM=LMU1
End If
Copy A+AM,A+FM To SPOKE
Add SPOKE,FM-AM
Next
'
' Recopie les musiques de la banque 2, en pointant les nouveaux patterns
For N=0 To NMU2-1
BLOKE[SPOKE-AMUS]
A=Varptr(MU2$) : AM=Leek(A+N*4+2)
If N<NMU2-1
FM=Leek(A+N*4+6)
Else
FM=LMU2
End If
Copy A+AM,A+FM To SPOKE
' Change les numeros de patterns
For P=0 To 3
AP=SPOKE+Deek(SPOKE+P*2)
Do
B=Deek(AP)
Exit If Btst(15,B)
Doke AP,B+NPAT1
Add AP,2
Loop
Next
Add SPOKE,FM-AM
Next
'
MU1$="" : MU2$=""
APOKE=SPOKE
Return
'
'----------------------------------------------------------------------------
MERGE_PATTERNS:
'
' Recopie les patterns
Pof(1)=APAT1 : A$=Input$(1,2) : NPAT1=Deek(Varptr(A$))
Pof(2)=APAT2 : A$=Input$(2,2) : NPAT2=Deek(Varptr(A$))
NPAT=NPAT1+NPAT2 : APAT=APOKE : BDOKE[NPAT] : SPOKE=APAT+NPAT*8+2
PAT1$=Input$(1,NPAT1*8) : SPAT1=Pof(1)
PAT2$=Input$(2,NPAT2*8) : SPAT2=Pof(2)
'
' Recopie betement les patterns de la premiere banque
For N=0 To NPAT1-1
For P=0 To 3
BDOKE[Deek(Varptr(PAT1$)+N*8+P*2)+NPAT2*8]
Next
Next
LPAT1=EPAT1-SPAT1
SCOPY[1,SPAT1,LPAT1]
'
' Recopie les patterns de la deuxieme de la meme maniere...
For N=0 To NPAT2-1
For P=0 To 3
BDOKE[Deek(Varptr(PAT2$)+N*8+P*2)+NPAT1*8+LPAT1]
Next
Next
LPAT2=EPAT2-SPAT2
SCOPY[2,SPAT2,LPAT2]
'
' Analyse les patterns de la deuxieme banque pour changer les instruments...
' Etiquette SET_INST=$900
For N=0 To NPAT2-1
For P=0 To 3
AP=Deek(APAT+2+NPAT1*8+N*8+P*2)+APAT
Do
B=Deek(AP) : Add AP,2
Exit If B=$8000
If Btst(15,B)=0
If Btst(14,B)
Add AP,2
End If
Else
If(B and $7F00)=$900
I=B and $FF
B=$8900+I2(I)
Doke AP-2,B
End If
End If
Loop
Next
Next
'
PAT1$="" : PAT2$=""
APOKE=SPOKE
Return
Procedure STRPOKE[S$]
For P=1 To Len(S$)
Poke APOKE,Asc(Mid$(S$,P,1))
Inc APOKE
Next
End Proc
'
Procedure BDOKE[P]
Doke APOKE,P
Add APOKE,2
End Proc
'
Procedure BLOKE[P]
Loke APOKE,P
Add APOKE,4
End Proc
'
Procedure SCOPY[FILE,POS,LONG]
Pof(FILE)=POS : A=0
While A<LONG
L=1024 : If A+L>LONG : L=LONG-A : End If
A$=Input$(FILE,L)
Copy Varptr(A$),Varptr(A$)+L To SPOKE+A
Add A,L
Wend
Add SPOKE,LONG
End Proc