Music fade out

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #30510
    thegeps
    Participant

    I need to fade a song before stop it. Time ago you wrote me this:

    “As for the fade out itself, simply decrease the volume from 0 to 16 (move from one value to another after a few frames, it will sound smoother), with a threshold detection:

    ld a,(PLY_AKG_PSGReg8) ;Then 9 and 10.

    sub 1

    jr nc, NoDeb

    xor a

    NoDeb ld (PLY_AKG_PSGReg8),a

    Do that before the call to PLY_AKG_SendPSGRegisters is done, it will be simpler (warning, this method needs A, so save it first if you modify it).”

    well, I found

    PLY_AKG_PSGREG8

    and

    PLY_AKG_PSGREG10

    but no reg9 variable?

    and by “Do that before the call to PLY_AKG_SendPSGRegisters is done” you mean that I have to put some code inside your player? O_o (like putting there a variable check and call the regs decrease before that calling?)

    #30511
    Targhan
    Keymaster

    Yes, you have to modify the player. I may add this as a build-in feature in a next version (with a conditional flag, most people don’t want to use this).

    I guess you’re using the ROM player? Check the PLY_AKG_PSGReg9_10_Instr label… But even in this case the PLY_AKG_PSGReg9 is present, from what I read.

    #30512
    thegeps
    Participant

    Yep, I’m using the ROM player. There isn’t the reg9 label…
    The 9_10instr is there, and I saw that is used to stop the song by resetting bot H and L and then doing

    Ld (ply_akg_psgreg9_10instr),hl

    So, how can I use that? L byte is for reg9 and H byte for reg10?

    #30514
    thegeps
    Participant

    ok, I’m actually doing this, and it works.
    Not the best or most elegant solution but I’m fine with it.

    First of all I’ve set two variables

    mfade: equ 0e7f1h
    volume equ 0e7f2h

    mfade is a flag: 1-do a fade, 0-play as usual

    in the ROM player I’ve done this mod, just after the ply_akg_sendpsgregisters label

    ;original code
    PLY_AKG_SENDPSGREGISTERS
    push af
    ld a,(mfade)
    or a
    call nz,fade_music
    pop af
    ;original code

    in my source I have the routine to be called:

    fade_music:
    ld a,(volume)
    ld (PLY_AKG_PSGREG8),a
    ld (PLY_AKG_PSGREG9_10_INSTR),a
    ld (PLY_AKG_PSGREG9_10_INSTR+1),a
    ret

    and this piece of code where I need to have the fade out:

    ld a,11 ;this set start volume value
    ld (volume),a
    ld a,1 ;set the fade flag
    ld (mfade),a
    volume_fading:
    ld b,25
    call wait ;wait is a routine synched with vblank that wait b vlaue * 1/50th. so, before decreasing the volume by 1, half sec will pass
    ld a,(volume)
    dec a
    ld (volume),a
    jp nz,volume_fading
    ld b,25
    call wait ; wait another half sec after the fade out is completed
    xor a
    ld (mfade),a ;remove the fade flag
    call PLY_AKG_STOP ;and stop the music

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.