Just Jeff Posted April 27, 2017 Share Posted April 27, 2017 (edited) I'm trying to figure out how to write in-tune music with the 2600 so as a first step, I wrote this little routine that changes frequency without changing the frequency register- AUDFx. There are little hiccups in the sound that so far have me stumped. All of the NOPs in there were to lower the frequency for a less annoying "siren" sound. DigitalNoise.bin DigitalNoise.asm Edited April 27, 2017 by BNE Jeff Quote Link to comment Share on other sites More sharing options...
+SpiceWare Posted April 27, 2017 Share Posted April 27, 2017 Sounds OK to me: Digital Noise.m4a.zip 1 Quote Link to comment Share on other sites More sharing options...
Just Jeff Posted April 27, 2017 Author Share Posted April 27, 2017 That sounds a lot better than mine. Strange. Maybe its my version of Stella. Any Idea? I get 2 or 3 little breaks each time it cycles through fom high to low. Quote Link to comment Share on other sites More sharing options...
+SpiceWare Posted April 27, 2017 Share Posted April 27, 2017 That was on my 2600. While Stella's audio emulation is much better than it used to be, it's still not all the way there. Stella's undergoing a major overhaul right now. From that topic: Thank you! Audio is currently unchanged from the old implementation, but we have plans to hook up a new audio implementation once we've stabilized Stella 5. Initial work (based on work by Chris Brenner) on this was done by Steve more than one year ago, but he stopped as the new code was very difficult to integrate with the old TIA. Things should be much smoother with the new core. Quote Link to comment Share on other sites More sharing options...
Just Jeff Posted April 27, 2017 Author Share Posted April 27, 2017 Ah.. I'll try it on my Harmony then. I guess I need to figure out how to record audio on Windows 10 at some point if I'm going to do this. Here's a Fraps video of what I'm getting: https://www.youtube.com/watch?v=Ky70LOBv-P0&feature=youtu.be Quote Link to comment Share on other sites More sharing options...
+stephena Posted April 27, 2017 Share Posted April 27, 2017 In the most current pre-release (5.0.0-pre6), the sound is a little better than the last stable release (4.7.3), in that there are no 'gaps' in the sound. But it's still not perfect, which will hopefully be fixed in the TIA audio overhaul as Spiceware mentioned. I should also add that in Stella 4.7.3, the scanline count is all over the place, which could account for the sound being off. In the 5.0.0-pre6, it runs at a consistent 342 scanlines, with no gaps in the playback. Turn on the scanline counter with Alt-L to see what I mean. 1 Quote Link to comment Share on other sites More sharing options...
Just Jeff Posted April 27, 2017 Author Share Posted April 27, 2017 Thanks.. I have 4.7.3 so I'll check into the pre-release. Also, I tried my .bin on the Harmony and it worked correctly for me as well. Quote Link to comment Share on other sites More sharing options...
Just Jeff Posted April 27, 2017 Author Share Posted April 27, 2017 Update: I download 5.0.0 and yes the lines are now stable and the gaps are much less noticeable. Quote Link to comment Share on other sites More sharing options...
Just Jeff Posted May 2, 2017 Author Share Posted May 2, 2017 OK.. I created a digital version of Mary Had a Little Lamb that is working, but is way,way out of tune. I've re-checked my math but can't quite figure out where I went wrong, Can anyone see where I went wrong? My frequency calculations (I explain where I define C5) or cycle counts maybe? I also found the song using different notes, put them in and it made little or no difference. ; Digital Mary Had a Little Lamb ; ; 29 April 2017 ; Mary Had A Little Lamb ; EDCDEEE ; DDDEGG ; EDCDEEEa ; EDDEDC ;or is it ;BAGABBB ;AAABDD ;BAGABBBB ;AABAG ; dasm MHALL.asm -f3 -v0 -sMHALL.sym -lMHALL.lst -oMHALL.bin ; Attempt to produce a simple in-tune song PROCESSOR 6502 include vcs.h ;============================================================================== ; Define Notes ;============================================================================== C_FIVE = 141 ; 141 C5 is 523.25 Hz. 6507 runs at 1,193,333 Hz. ; 1,193,333/523.25= 2280.6 machine cycles ; Divide by 2 for each half of the square wave ; equals 1140.3 machine cycles ; the wait loops are 8 cycles which means I need to loop ; through approximately 142 times for each half wave ; Subtract 1 for the 5 cycle delay in initial AUDV0 loadings D_FIVE = 125 ; 125 E_FIVE = 112 ; 112 F_FIVE = 105 ; 105 G_FIVE = 94 ; 94 A_FIVE = 83 ; 83 B_FIVE = 74 ; 74 END_SONG = 0 ; WHOLE_NOTE = 255 HALF_NOTE = 128 QUARTER_NOTE = 64 SEG.U VARS ORG $80 ; Start of Cartridge ; Tell DASM to start here. RAM begins at $80 Hold5: ds 1 ; Used to hold wave high or low CurrentNoteDuration: ds 1 ; Quarter note, half note, etc CurrentNote: ds 1 ; Which note the song is on ; define the segment for code SEG CODE ; 2K ROM starts at $F800, 4K ROM starts at $F000 ORG $F800 InitSystem: sei ; Set Interrupt cld ; Clear the decimal bit. ldx #$FF ; Start at the top of the stack txs ; Transfer to the stack lda #0 ClearMem: sta 0,X ; Store zero at (0+X) dex ; Do all of RAM bne ClearMem ; Repeat if we are not down to zero ;============================================================================== ; Load Tune ;============================================================================== LoadTune: lda Song,y ; Load the current note of the song (half wave value) sta Hold5 ; Store it in RAM lda Song+1,y ; Load the duration of the note sta CurrentNoteDuration ; Store it in RAM Tone: lda #$0F ; 2 set volume high for high part of square wave sta AUDV0 ; 3 ;============================================================================== ; Wave High ;============================================================================== WaitHigh: ; Loop to hold high part of wave dec Hold5 ; 5 bne WaitHigh ; 3 8 8 machine cycles per loop through WaitHighFine: ; Future use for fine tuning notes with a 5 cycle loop ;dex ; Future use for fine tuning notes with a 5 cycle loop ;bne WaitHighFine ; lda Song,y ; 4 Re-load the current note of the song sta Hold5 ; 3 Store it in RAM for low half of the wave ;============================================================================== ; Wave Low ;============================================================================== Interval: lda #$00 ; 2 Turn off volume for bottom of square wave sta AUDV0 ; 3 WaitLow: ; dec Hold5 ; 5 bne WaitLow ; 3 8 Holds 8 with the branch taken WaitLowFine: ;dex ; Future use ;bne WaitLowFine ; ;============================================================================== ; Next CurrentNote? ;============================================================================== dec CurrentNoteDuration ; 5 bne Tone ; 3 ;============================================================================== ; Get Next CurrentNote ;============================================================================== inc CurrentNote ; Increment to next note inc CurrentNote ; Again to skip over duration lda CurrentNote tay ; Put it in index lda Song,y ; Load the note beq StartOver ; if END_SONG then go to reset sta Hold5 ; otherwise, store in RAM lda Song+1,y ; load the note duration sta CurrentNoteDuration ; Store it in RAM jmp LoadTune ; Back to the top StartOver: ldy #0 sty CurrentNote sty Hold5 sty CurrentNoteDuration jmp LoadTune Song: byte E_FIVE,HALF_NOTE,D_FIVE,HALF_NOTE,C_FIVE,HALF_NOTE byte D_FIVE,HALF_NOTE,E_FIVE,HALF_NOTE,E_FIVE,HALF_NOTE,E_FIVE,WHOLE_NOTE byte D_FIVE,HALF_NOTE,D_FIVE,HALF_NOTE,D_FIVE,WHOLE_NOTE byte E_FIVE,HALF_NOTE,G_FIVE,HALF_NOTE,G_FIVE,WHOLE_NOTE byte E_FIVE,HALF_NOTE,D_FIVE,HALF_NOTE,C_FIVE,HALF_NOTE byte D_FIVE,HALF_NOTE,E_FIVE,HALF_NOTE,E_FIVE,HALF_NOTE,E_FIVE,HALF_NOTE byte E_FIVE,HALF_NOTE,D_FIVE,HALF_NOTE,D_FIVE,HALF_NOTE byte E_FIVE,HALF_NOTE,D_FIVE,HALF_NOTE,C_FIVE,WHOLE_NOTE byte END_SONG ; End of Cartridge ORG $FFFA ; set address to 6507 Interrupt Vectors .WORD InitSystem ; NMI .WORD InitSystem ; RESET .WORD InitSystem ; IRQ MHALL.bin MHALL.asm Quote Link to comment Share on other sites More sharing options...
Just Jeff Posted May 3, 2017 Author Share Posted May 3, 2017 New theory. I focused on frequency but not wavelength. As far as I can tell, my frequencies are correct but my wavelengths are only half of the normal wavelengths for any given frequency. Looking at graphs of frequencies, you see the waves goes from positive to negative and and back again. If I understand AUDF0 correctly, it goes from positive to zero, never negative, so the wavelength is only half the height. Does this sound plausible? Quote Link to comment Share on other sites More sharing options...
DirtyHairy Posted May 3, 2017 Share Posted May 3, 2017 (edited) New theory. I focused on frequency but not wavelength. As far as I can tell, my frequencies are correct but my wavelengths are only half of the normal wavelengths for any given frequency. Looking at graphs of frequencies, you see the waves goes from positive to negative and and back again. If I understand AUDF0 correctly, it goes from positive to zero, never negative, so the wavelength is only half the height. Does this sound plausible? Nope or yup, depending on whether I understand correclty A full wavelength is defined by the full period of the signal. For a square wave, thats the full length between two rising edges like this: --------- - | | | | | | | | | | |________| In particular, it is irrelevant between which levels the signal oscillates. The actual electrical signal generated by the audio circuit should be symmetrical (alternating between positive and negative polarity), and any constant offset would be imperceptible anyway. Edited May 3, 2017 by DirtyHairy Quote Link to comment Share on other sites More sharing options...
Just Jeff Posted May 3, 2017 Author Share Posted May 3, 2017 (edited) Hmm yeah I read through the stuff again and I think I just applied the term wavelength to it myself. It looks like I was actually noticing the differences in amplitude, not wavelength. Thanks! Edited May 3, 2017 by BNE Jeff Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.