Background Music  (a Kind of ASCII ART)


Author Message
Martin H.

Guru

Joined: 04/06/2022
Location: Germany
Posts: 1485
Posted: 06:27pm 19 Oct 2022      

  Volhout said  Hi Martin,

I have profiled your code in the first post, and it is impressive sound with all the ADSR and chorus. But it consumes 51% CPU power at 252MHz.

Volhout

well ...  Time for optimisation  
The cent calculation for the Pseudo Chorus is done every 20 mS (with every call of the Sub).
This is not necessary
If we move the Chorus calculation within the IF statement,
then the Chorus will be calculated only every 10th call (every 200 mS) without loosing the ADSR and the "Chorus".
This should reduse the CPU Consumption. but we lose our local variables


Sub music
'Local Fcent%,F1%,F2%,FL%,FR%
If mt%=1 Then
   nt%=Asc(Mid$(AA$,CNT%,1))
   If nt%=35 Then CNT%=1:nt%=Asc(Mid$(AA$,CNT%,1))
   Freq1%=FRQ%(nt%)
   Freq2%=FRQ%(Asc(Mid$(AB$,CNT%,1)))
   'Pseudo Chorus
   Fcent%=Int(Freq1%/100)
   FL%=Freq1% - Fcent%
   FR%=Freq1% + Fcent%
   Inc cnt%
 EndIf
 If Freq1%>1 Then Play sound 1,"L","q",FL%,adsr%(mt%):Play sound 3,"R","q",FR%,a
dsr%(mt%)
If Freq2%>1  Then Play sound 2,"B","w",Freq2%,adsr2%(mt%)
Inc mt%:If mt%>10 Then mt%=1
End Sub

Edited 2022-10-20 04:30 by Martin H.