| www.retrosoftware.co.uk http://www.retrosoftware.co.uk/forum/ |
|
| Making sounds from 6502? http://www.retrosoftware.co.uk/forum/viewtopic.php?f=73&t=201 |
Page 1 of 1 |
| Author: | StuartA [ Sat Oct 18, 2008 6:09 pm ] |
| Post subject: | Making sounds from 6502? |
Is there some 6502 code to make some sounds using the different channels ? I'm quite tempted to try and have a go at writing a tracker... but first just need to be able to make some noises using the seperate channels... (Is there a doc somewhere with some info on the sound capabilities too?) |
|
| Author: | FrancisL [ Sun Oct 19, 2008 12:53 am ] |
| Post subject: | Re: Making sounds from 6502? |
Hi Stuart, I've got a pile of notes somewhere. If I get a chance I will dig them out. Failing that you could have a look at the Advanced User Guide for the BBC which is available to download from the internet. Kind regards, Francis. |
|
| Author: | DaveF [ Sun Oct 19, 2008 8:31 pm ] |
| Post subject: | Re: Making sounds from 6502? |
Tom Walker's your man here, he's pretty good on the sound stuff. He's helping me out on my little pet project though so don't nick him! |
|
| Author: | TomW [ Sun Oct 19, 2008 8:47 pm ] |
| Post subject: | Re: Making sounds from 6502? |
If you avoid using the OS routines (which I suggest you do), the following code outputs to the sound chip : Code: ldy #&ff sty &fe43 sta &fe4f iny sty &fe40 ldy #2 .sndwait dey bne sndwait ldy #8 sty &fe40 rts You would probably want to disable interrupts during this routine. http://www.smspower.org/dev/docs/sound/SN76489-20030421.txt is a good document on the sound chip. |
|
| Author: | FrancisL [ Mon Oct 20, 2008 9:51 am ] |
| Post subject: | Re: Making sounds from 6502? |
Hi Tom, Just a little side question regarding sound output. Is there any method that you can recommend to playback a sampled sound at a given frequency? E.g., if I want a frequency of say 8000Hz, how can I playback a sample at that rate? Kind regards, Francis. |
|
| Author: | DaveJ [ Mon Oct 20, 2008 10:39 am ] |
| Post subject: | Re: Making sounds from 6502? |
This article may be of interest: http://bbc.nvg.org/doc/Speech.html |
|
| Author: | TomW [ Mon Oct 20, 2008 11:23 am ] |
| Post subject: | Re: Making sounds from 6502? |
FrancisL wrote: Hi Tom, Just a little side question regarding sound output. Is there any method that you can recommend to playback a sampled sound at a given frequency? E.g., if I want a frequency of say 8000Hz, how can I playback a sample at that rate? Use timer interrupts. You want timer 1 on either VIA (probably User), set it to your sample frequency, and output new samples each interrupt. I've got some sample playback code somewhere if you want it. |
|
| Author: | FrancisL [ Mon Oct 20, 2008 12:00 pm ] |
| Post subject: | Re: Making sounds from 6502? |
DaveJ wrote: I already have a copy of that article, but thanks anyway. My main problem is that I am not clear on how to equate the playback speed in the program to the frequency of the waveform. Kind regards, Francis. |
|
| Author: | FrancisL [ Mon Oct 20, 2008 12:01 pm ] |
| Post subject: | Re: Making sounds from 6502? |
TomW wrote: Use timer interrupts. You want timer 1 on either VIA (probably User), set it to your sample frequency, and output new samples each interrupt. I've got some sample playback code somewhere if you want it. That could be useful to have a look at your code. Kind regards, Francis |
|
| Author: | TomW [ Mon Oct 20, 2008 7:52 pm ] |
| Post subject: | Re: Making sounds from 6502? |
Okay, you first want some code to set up the timer (all C64-style, not too hard to change): Code: setuptimer sei lda #$7f ;Disable all VIA ints sta $fe4e sta $fe6e lda #$c0 ;Enable timer 1 sta $fe4e lda $fe4b ora #$40 ;Set bit 6 for free running timer 1 sta $fe4b lda #150 ;1000000/152=6578hz sta $fe44 ;change these lines to change frequency! lda #0 sta $fe45 lda $204 ;set our IRQ handler sta OLDIRQ1V lda $205 sta OLDIRQ1V+1 lda #<irq1v sta $204 lda #>irq1v sta $205 cli rts then the interrupt handler : Code: irq1v tya pha txa pha lda #$40 ;Clear interrupt sta $fe4d lda SAMPLE ;(insert your own code here to load 4-bit sample) ora #VOLCONST ;(&90,&B0,&D0, or &F0 depending on what channel) jsr soundwrite pla tax pla tay lda $FC rti That's the basics of it. You can modify the routines as you like, eg change sample frequency, write more than one volume register at a time to boost volume/quality, optimise the interrupt handler etc etc. |
|
| Author: | TomW [ Wed Jan 21, 2009 11:49 pm ] |
| Post subject: | Re: Making sounds from 6502? |
Francis - Don't know if you've got sample playback working yet, but I've disassembled a beeb sample player that could be useful. It's from The Yorkshire Boys' Retribution demo demo, it's got all sorts of problems (only 4-bit, iffy timing, all interrupts disabled) but it works, it's standalone, and I think it's simple enough to post here. I've attempted to comment it where possible. Code: $00001C00: sei
$00001C01: lda #$FF ;set VIA DDR to output $00001C03: sta $FE43 $00001C06: lda #$84 ;set all voices to max frequency $00001C08: jsr $1C65 $00001C0B: lda #$00 $00001C0D: jsr $1C65 $00001C10: lda #$A4 $00001C12: jsr $1C65 $00001C15: lda #$00 $00001C17: jsr $1C65 $00001C1A: lda #$C4 $00001C1C: jsr $1C65 $00001C1F: lda #$00 $00001C21: jsr $1C65 $00001C24: lda #$00 $00001C26: sta $70 $00001C28: lda $75 ;set to $1D by loader, ie sample start $1D00 $00001C2A: sta $71 $00001C2C: ldy #$00 $00001C2E: lda ($70),y $00001C30: and #$0F $00001C32: jsr $1C79 $00001C35: ldy #$04 $00001C37: dey $00001C38: bne $1C37 $00001C3A: lda ($70),y $00001C3C: and #$F0 $00001C3E: lsr a $00001C3F: lsr a $00001C40: lsr a $00001C41: lsr a $00001C42: jsr $1C79 $00001C45: inc $70 $00001C47: bne $1C2C $00001C49: inc $71 $00001C4B: lda $71 $00001C4D: cmp $76 ;set to $76, ie sample end at $75FF $00001C4F: beq $1C00 $00001C51: lda #$81 ;check if key is pressed $00001C53: ldx #$9D ;this actually causes a delay $00001C55: ldy #$80 ;resulting in a minor bump every 256 samples $00001C57: jsr $FFF4 $00001C5A: cpx #$FF $00001C5C: bne $1C2C $00001C5E: lda #$0F ;set all voices to no volume - not strictly necessary $00001C60: jsr $1C79 $00001C63: cli $00001C64: rts $00001C65: sta $FE4F ;write data to soundchip $00001C68: ldy #$00 $00001C6A: sty $FE40 $00001C6D: nop ;in a proper player, you'd do something useful with this time $00001C6E: nop ;instead of just nop-ing $00001C6F: nop $00001C70: nop $00001C71: nop $00001C72: nop $00001C73: ldy #$08 $00001C75: sty $FE40 $00001C78: rts $00001C79: tay $00001C7A: lda $1C92,y ;grab adjusted volume from lookup table $00001C7D: ora #$90 ;write to all 3 volume registers $00001C7F: jsr $1C65 $00001C82: ora #$20 $00001C84: jsr $1C65 $00001C87: eor #$60 $00001C89: jsr $1C65 $00001C8C: ldy $74 ;set to 35 by loader $00001C8E: dey ;horrible delay loop $00001C8F: bne $008E $00001C91: rts ;lookup table to convert linear 4-bit sample to log 4-bit sample $00001C92: .DB $00,$00,$01,$01,$01,$02,$02,$03,$04,$05,$06,$07,$08,$09,$0C,$0F |
|
| Page 1 of 1 | All times are UTC [ DST ] |
| Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |
|