Jump to content
  • 0

Making simple sound?


Wertzui
 Share

Question

I know that the sound specifiations are not finalized yet, but for the BASIC program I'm porting, it needs to have some sound.

Nothing fancy, all needed is some single-channel beeping with pitch and duration control. And volume just set to max. I've already done this on C64, VIC, PET, and C16 (via register poking).

For duration, I have a timer-based delay subroutine taken from C64Wiki, it seems to work on the X16 emulator too.

Anyone to point me somewhere?

Link to comment
Share on other sites

14 answers to this question

Recommended Posts

  • 0

Agree with Matt, VERA PSG is way to get started. I implemented very simple, rudimentary sounds in my version of Tetris in BASIC:

https://www.8bitcoding.com/p/crazy-tetrominoes.html

If you don't want to deal with programming you can also just import and call four basic sounds in my Simplest Sound Effects Library for BASIC:

https://www.8bitcoding.com/p/simplest-sound-effects-library-for.html

 

Later if you want to add music that plays independently in the background of BASIC program you can opt to a bit more complex Music Library:

https://www.8bitcoding.com/p/music-player-library-for-basic-programs.html

  • Like 1
Link to comment
Share on other sites

  • 0
Posted (edited)

On a side note, here is a weird bug:

When there is a print statement (line 52) in the FOR I loop, the sound pitch wouldn't rise, it just prints the I value!

Quote

01 REM RISING PITCH SCALE
20 POKE $9F25,0 : POKE $9F20,$C0 : POKE $9F21,$F9 : POKE $9F22,17
30 POKE $9F23,10 : POKE $9F23,10 : POKE $9F23,255 : POKE $9F23,63
40 POKE $9F20,$C1 : POKE $9F22,1 : DU=.1

50 FOR I=1 TO 255
51 POKE $9F23,I
52 PRINT I
53 GOSUB 200
54 NEXT I

60 POKE $9F20,$C2 : POKE $9F23,0
70 END

200 REM DELAYSUB:
210 T0=TI : T=DU
220 FOR T=T0+T*60 TO T
230 T=TI
240 T=T-5184E3*(T<T0)
250 NEXT T
260 RETURN

Edited by Wertzui
Link to comment
Share on other sites

  • 0

I think you are overcomplicating a bit. You don't need to program VERA registers when using BASIC, you can use VPOKE to write data to VRAM directly and let BASIC interpreter deal with VERA registers.

A simple program to turn on square wave (pulse) and increases frequency can be written as below:

10 VPOKE 1,$F9C3,%00111111:REM     SET WAVEFORM FOR VOICE 0
20 VPOKE 1,$F9C2,%11111111:REM     SET LEFT AND RIGHT CHANNEL AT MAX VOLUME
30 FOR N=200 TO 2000 STEP 5
40 VPOKE 1,$F9C1,INT(N/256):REM    SET HIGH BYTE OF FREQUENCY
50 VPOKE 1,$F9C0,N AND 255:REM     SET LOW BYTE OF FREQUENCY
60 FOR I=1 TO 200:NEXT I:REM       DELAY
70 NEXT N
80 VPOKE 1,$F9C0,0:VPOKE 1,$F9C1,0

 

 

 

  • Like 1
Link to comment
Share on other sites

  • 0
9 hours ago, Wertzui said:

On a side note, here is a weird bug:

When there is a print statement (line 52) in the FOR I loop, the sound pitch wouldn't rise, it just prints the I value!

If you do want to do it that way, take out the PRINT statement (line 52).  your output to $9f23 is colliding with PRINT which is using the VERA channel(s) as well.

Or use VPOKEs, as @DusanStrakl mentioned.

  • Like 1
Link to comment
Share on other sites

  • 0
4 minutes ago, Wertzui said:

@DusanStrakl So that's what I was doing wrong. When I first tried VPOKEs, I didn't write it in the proper format, and wondered why it gives me "illegal quantity error"-s.

Yeah, I am playing with X16 Emulator for more than a year and still mix them up occasionally 🙂

Actually I saw so many questions about this I just started writing another post for my blog to explain how to use PSG in BASIC.

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.

Guest
Answer this question...

×   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.

 Share

×
×
  • Create New...

Important Information

Please review our Terms of Use