Jump to content
IGNORED

IntyBASIC Sound Playing Routine Optimization Help


Recommended Posts

Hey gurus. Can you take a look at this and recommend a way to make this code more compact? The sound plays as I want, but I am sure the calling code could be more efficient. Rather than "programming the PSG", I am just blasting words at it to get the sound to play.

 

Thanks.

 

 

 

 

 


	Include "Constants.bas"
	Wait
	Mode 0 , 0,0,0,0
	Wait
	CLS

	LoopMain:
		Gosub PlayDis
  		For #spinWait = 0 to 120
        	Wait
     	Next #spinWait
     	Wait
     	Goto LoopMain


SoundResetAll:	Procedure
	SOUND 0,1,0
	SOUND 1,1,0
	SOUND 2,1,0
	SOUND 4,,$38
	RETURN
	END


	PlayDis: Procedure
		Print At 200 Color CS_DARKGREEN     ,  "Sound Begin"
		GoSub SoundResetAll
		#seekAddr = 40960
		#valTemp = 1
		#sndCounter = 0
		#soundVol = 15
		Sound 2 ,1 , 0
		While PEEK(#seekAddr) <> $FFFF
			#toneTemp = Peek(#seekAddr)
			If #toneTemp = $1000 Then
				Wait
				#seekAddr = #seekAddr + 1
			ElseIf #toneTemp = $0 Then
				Sound 2 , 1 , 0
				Wait
				#seekAddr = #seekAddr + 1
			ElseIf #toneTemp <> $FFFF Then
				#seekAddr = #seekAddr + 1
				#soundVol = Peek(#seekAddr)
				Sound 2  ,  #toneTemp    ,  #soundVol
				Wait
				#seekAddr = #seekAddr + 1
			End If
		Wend
		Sound 2 ,1 , 0
		For #spinWait = 0 to 30
			Wait
		Next #spinWait
		Print At 200 Color CS_WHITE  ,  "Sound End   "
		For #spinWait = 0 to 50
			Wait
		Next #spinWait
		CLS
		Return
	End


ASM ORG $A000



Guuooiiii:
Data $0c1, $d , $0b1, $d , $0a1, $d , $091, $d , $081, $d , $071, $d , $061, $d , $051, $d , $041, $d , $031, $d , $021, $d , $011, $d , $001, $d , $FFFF

 

 

 

 

PlayDis0.bas

Link to comment
Share on other sites

Hi! I posted a while ago a Sound demo. My unused sound routine is compact enough, although I use odd values to lower volume instead of reading volume data.

http://atariage.com/forums/topic/261295-tron-sounds-and-music/

 

I rewrote your sound loop (sorry for the gotos), I eliminated the $1000 check, just repeat sound/volume values in your data.

 

 

SoundLoop:
        #toneTemp = Peek(#seekAddr)
        If #toneTemp = $0 Then
            Sound 2 , 1 , 0
        ElseIf #toneTemp = $FFFF Then
            GOTO SoundEnd
        ELSE
            #seekAddr = #seekAddr + 1
            #soundVol = Peek(#seekAddr)
            Sound 2  ,  #toneTemp    ,  #soundVol
        End If
        WAIT
        #seekAddr = #seekAddr + 1
        GOTO SoundLoop
SoundEnd:

 

 

 

Link to comment
Share on other sites

  • 7 months later...

I made an interactive PSG sound envelope utility that also displays the Sound commands to use. I included binary and source. Usage: Up/down to select option, right/left to pick digit, then up/down to change it. B1/B2 is faster, B0 to replay. Any keypad starts input. Red numbers numbers means it's GUI value, PSG value is displayed next to them. Sound statements are shown hex, GUI values are in Dec.

I recommend experimenting with tones, using cycle/triangle envelopes with low envelope frequency values for interesting sounds (motor-like). If there's any error compiling, please use the newest version of IntyBasic, and fix 2 "bugs" in constants.bas. (comments ends with line continuation "\", my fix is "...")

CONST PSG_ENVELOPE_CYCLE_RAMP_DOWN_SAWTOOTH            =$08 '\\\\\\\...
CONST PSG_ENVELOPE_CYCLE_RAMP_DOWN_TRIANGLE            =$0A '\/\/\/\...

post-35249-0-23979300-1507516176.png

psg(source).zip

PSG.rom

  • Like 4
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...