Jump to content
IGNORED

Need help with my music player code


Recommended Posts

Ok ...

 

Having a bit of trouble.  I am using zeros in the music data of this, to get them to silence ... problem is, the code I use to filter them out and replace with silence, is destroying the timing of the track.  Can anyone have a look at this and see what is going wrong?  Thanks ...

 

 

strangerthings.asm strangerthings.s strangerthings.xex

Edited by Synthpopalooza
Link to comment
Share on other sites

Had a quick look, can't see anything obvious yet, but will have another look later.

 

One thing I did notice, in your deferred VBI routine, you save A,X and Y on the stack , then restore them, I believe

the OS does this anyway, so no real need for you to do it, DLI routines need to do it tho.

Link to comment
Share on other sites

maybe it would be good if you put some comments to your code so there would be no time wasted by guessing what you mean :)

 

btw the *.asm file made my day, mixed caps, 4types of indentation ... looks like intentional joke to me :D

  • Haha 1
Link to comment
Share on other sites

  • 2 weeks later...

One thing I noticed is that the volume is not protected against decrementing below 0.

 

I changed:

	DEC FREQCNT,X                               ;REDUCE THE NUMBER OF FRAMES UNTIL NEXT DECAY
	BNE TUNNEXT                                 ;IF WE AREN'T AT ZERO YET, DON'T DECAY
	LDA DCYSTOR,X                               ;RESET THE DECAY FOR THE NEXT COUNT
	STA FREQCNT,X
	DEC CTLVOL,X                                ;DECREMENT THE VOLUME
	LDA CTLVOL,X
	LDY TUNCHANNEL
	AND MUTEMASK,Y
	STA AUDC0,Y
	JMP TUNNEXT                                 ;GO TO NEXT CHANNEL

To:

	DEC FREQCNT,X                               ;REDUCE THE NUMBER OF FRAMES UNTIL NEXT DECAY
	BEQ DEC_VOLUME
	JMP TUNNEXT                                 ;IF WE AREN'T AT ZERO YET, DON'T DECAY

DEC_VOLUME
	LDA DCYSTOR,X                               ;RESET THE DECAY FOR THE NEXT COUNT
	STA FREQCNT,X

	LDA CTLVOL,X                                ;IF VOLUME ALREADY 0 DO NOT DECREMENT
	AND #$0F
	BEQ TUNNEXT
	
	DEC CTLVOL,X                                ;DECREMENT THE VOLUME
	LDA CTLVOL,X
	LDY TUNCHANNEL
	AND MUTEMASK,Y
	STA AUDC0,Y
	JMP TUNNEXT                                 ;GO TO NEXT CHANNEL

I'm not sure it affects timing, but it sounds cleaner to me, see what you think.

strangerthings.s strangerthings.obx

  • Thanks 1
Link to comment
Share on other sites

  • 3 months later...
  • 1 month later...

So I have fixed the zero frequency problem ...

 

Resurrecting this again though, because I am wanting to use this code to address double POKEY.  That is have the channel indexes 4 thru 7 to address second POKEY.  Apart from adding in the extra equates,  what code mods would I need to do to make the second POKEY play?

Link to comment
Share on other sites

21 hours ago, Synthpopalooza said:

what code mods would I need to do to make the second POKEY play?

Proper init. From the RMT player source code:

 

    IFT STEREOMODE>0
    lda #0
    sta $d208
    sta $d218
    ldy #3
    sty $d20f
    sty $d21f
    ldy #8
si1 sta $d200,y
    sta $d210,y
    dey
    bpl si1
    ELS
    lda #0
    sta $d208
    ldy #3
    sty $d20f
    ldy #8
si1 sta $d200,y
    dey
    bpl si1
    EIF

HTH :)

  • Like 1
Link to comment
Share on other sites

2 hours ago, Synthpopalooza said:

Yep, I kinda got all that ... I'll look through the code and see what I can wrangle.   My code is not RMT based, as I want to use a lot of non-RMT settings such as 16-bit $Cx, two-tone, reverse 16-bit, etc.

Yeah, I know it's your own player. But not properly initializing the second pokey (first is done by the OS) bit me in the behind once with atarisid4 or something sid2gumby not working on Altirra and real hardware, so I thought I'd mention it. Just in case. I merely checked the RMT source to see what Raster did and posted that as an example :)

 

Edit: BTW what is reverse 16-bit?

 

Edit2: it was sid2gumby, obviously, as that one uses a second pokey.

Edited by ivop
  • Like 1
  • Thanks 1
Link to comment
Share on other sites

Standard 16-bit usage silences the first channel and plays the second.  This is usually accompanied by a 1.79 mhz clock setting.

 

Reverse 16-bit silences the second channel and plays the first.  This setting may or may not necessarily use the 1.79 mhz clock.  Some unusual properties can be had.

 

I have a WIP POKEY note table on the 7800 forum that has documented three such settings.  In the $Ax setting you use the standard 64 khz clock.  You get the standard 8-bit note table, then an octave of 25% duty cycle pulse wave notes from about A#2 to B3, then some lower range 25% bass notes starting at about A#1 or so.

 

On $4x or $8x plus poly 9, you get guitar distortions with a pulsing vibrato that can be modulated by vibration rate.  These require the 1.79 clock to work properly.

 

Edited by Synthpopalooza
  • Like 3
Link to comment
Share on other sites

Are you composing these new tables all by hand or do you use some sort of FFT to determine the base frequency of each setting?

 

8-bit, 16-bit and reverse 16-bit (and maybe "double" 16-bit i.e. set both channels to non silent)

Then for each all combinations of poly 9/poly17 with all three clocks (15kHz, 64kHz, 1.79MHz) for each distortion :D

 

7 distortions * 3 clocks * 2 polys * 256 audfs = 10752

7 * 3 * 2 * 65536 = 2752512

 

10752 + 2752512 + 2752512 = 5515776, which is well over 5.5 milion combinations.

 

If it took you one second to evaluate one setting, and work 24/7, it'll take ~64 days. If it took you one minute to evaluate one setting, and work 24/7, it'll take you ~10.5 years :)

 

Edit: btw do you use real hardware or a pokey emulation?

Edited by ivop
  • Haha 1
Link to comment
Share on other sites

Good, that Stephen found this amusing :)  Partly it was meant as such.

 

But my questions were serious. Do you tune acoustically or use software to determine the base freqeuncy, and do you use a real pokey or emulation?

 

I think it could largely be automated, but I don't want to reinvent the wheel if you have already done so.

Link to comment
Share on other sites

5 hours ago, ivop said:

Good, that Stephen found this amusing :)  Partly it was meant as such.

 

But my questions were serious. Do you tune acoustically or use software to determine the base freqeuncy, and do you use a real pokey or emulation?

 

I think it could largely be automated, but I don't want to reinvent the wheel if you have already done so.

Sorry - I only "laughed" at that post because it was so "math nerd" cool.  Fascinating topic, one that I am interested in but probably have nothing to contribute.  Sorry for the diversion.

Link to comment
Share on other sites

11 hours ago, Stephen said:

Sorry - I only "laughed" at that post because it was so "math nerd" cool.  Fascinating topic, one that I am interested in but probably have nothing to contribute.  Sorry for the diversion.

No worries :) My math is not complete BTW I forgot high pass filtering and two tone mode. If you would work 8 hours a day, it will take you a life time. So hopefully @Synthpopalooza has already some automation in place. If not, it might be interesting to look into myself.

  • Like 1
Link to comment
Share on other sites

It's done by hand so far ... and I have managed to eliminate some settings which don't produce music tones, so that cuts down the numbers some.  Also 16-bit and 2-tone don't work together.

Everything is tuned using Altirra which has a very good pokey emulation, and by ear using standard $Ax tables as a reference. 

 

 

Link to comment
Share on other sites

30 minutes ago, Synthpopalooza said:

If you've any ideas for automating this process I am all for it.  :)

My idea is to write a small (basic) program that loops through, say, 256 AUDF values and plays each note for a short period of time, followed by an equal amount of silence. Record as WAV and run through a FFT (Fast Fourier Transform) to determine the lowest dominant frequency. Dump to CSV file.

 

Depending on the window size of the FFT needed to reliably determine the frequency, it could still take quite a while, but you can do something else in the mean time :)

 

For example, 0.1s window (4410 samples; hopefully enough) and a 16-bit pokey configuration:

 

65536 * 0.1 / 60 / 60 = 1.82 hours (~1 hour and 50 minutes)

 

 

Also, it would be nice to have a small program which alows you to manipulate all pokey registers by either typing in its new value or go up/down. That way it would be easier to find settings that might be interesting to fully explore with automation.

 

What would happen if you set Pokey to two 16-bit channels (1/2 and 3/4) and enable high pass filtering (either 1/3 or 2/4 or both)? Do you end up with a single channel? :)

 

Edited by ivop
  • Like 1
Link to comment
Share on other sites

I have written some basic programs which do some of that.  Will post those later.  They've helped cut some of the work.

 

And yes, double 16 bit with hi pass on 2nd and 4th in $Ax is one huge channel.  Among other things you can get the swirling hum effect and repeating hum effects in Defender this way. and commodore 64 SID swirls.  I've already documented standard hi pass mode in $Ax anyway, so this one will not be too hard.  You have to extend the standard $Ax note table down several octaves though.

  • Like 2
Link to comment
Share on other sites

49 minutes ago, ivop said:

Depending on the window size of the FFT needed to reliably determine the frequency, it could still take quite a while, but you can do something else in the mean time :)

 

For example, 0.1s window (4410 samples; hopefully enough) and a 16-bit pokey configuration:

 

65536 * 0.1 / 60 / 60 = 1.82 hours (~1 hour and 50 minutes)

A sample that's the period of 1/10th of a second will net you an effective FFT resolution of 10Hz, which doesn't cut it for music frequencies. This is a bit more obvious if you think about your bucket of 4410 samples turning into a bucket of 2205 FFT values that represent the power spread across the entire frequency spectrum your sample rate can represent. (The less obvious underlying physical reason for this limitation, is the smaller capture length makes nearby frequencies indistinguishable from each other, because the FFT never sees a full cycle of difference between those nearby frequencies. i.e. FFT can't detect a partial frequency cycle.)

 

I became fairly well acquainted with this limitation in FFT resolution when attempting WAV to TIA conversion at 60Hz. In your case you at least have the workaround to just increase the length of capture, though you'll need a full second of capture to get a frequency resolution of 1Hz. (i.e. a bucket size of 22048 FFT values)

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

Did some quick research and reading up on FFTs and 4410 samples won't cut it. Frequency resolution is Fs/N, where Fs is the sample frequency (44100Hz) and N are the number of data points (4410). The frequency resolution in this case is 10Hz, which is too high for the lower notes. We need at least 1Hz, maybe even less for the lower bass frequencies.

 

Edit: LOL that's what RevEng said at about the same time :)

 

Edit2: so we need at least 36.4 hours of data for a full 16-bit sweep. The "generator" program should disable all interrupts and ANTIC, and then run Altirra at turbo mode :) Resulting WAV (mono) will be around 5.38 GB :D 

 

Edit3: the pause between notes could be made shorter, as long as it is predictable where each new note begins.

Edited by ivop
  • Like 2
Link to comment
Share on other sites

Well, if it helps ... I will post my program tonight that I am using to make the tables.  To begin with, I am doing the reverse 16-bit and two-tone modes.  Of these, I have documented the following already:

 

Reverse 16-bit:  $Ax @64 @15, $4x @1.79, $8x @1.79 9-bit

 

Two-tone:  $Ax @64, @64+1.79, @15, $4x @1.79 (partially)

 

Hi-pass:  $Ax @64 @15, working on $2x ones now.

 

Some of these are already on my POKEY table on the 7800 forum.

  • Like 1
Link to comment
Share on other sites

1 minute ago, Synthpopalooza said:

The real tricky part is, some of these settings will have multiple tables, especially $4x in two-tone, which behaves alot like $Cx with it's mod 3 polycounter properties.

I understand. That's why I mentioned a possible program similar to what you already have :) If you can raise/lower the AUDF registers and hear what happens, I reckon mod 3 or 5 etc... can easily be detected. That information could also be fed to a program that determines base frequencies.

 

I wonder what an FFT would make of our pink noise distortions.

 

In 16-bit mode, does it matter if both channels have the same distortion or are different? Perhaps in reverse 16-bit mode it does? That's something I would not ask if I had a program to easily test it myself :)

 

 

 

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