Background Music  (a Kind of ASCII ART)


Author Message
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 5994
Posted: 07:26pm 24 Oct 2022      

CPU load is 48% now (from 51%).
Apparently there is a lot of CPU in the play commands themselves.
You can still shave 2% CPU power off, when you change the ADSR from 10 steps to 6 steps, without much loss of sound quality. SETTICK to 36ms.
Manual mentions that some 25% is used simply by playing. Not sure if we can improve any further.

Volhout


  Martin H. said  
  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-25 06:22 by Volhout