don't click here

SMPS PSG Voice envelopes

Discussion in 'Engineering & Reverse Engineering' started by Oerg866, Feb 4, 2010.

Thread Status:
Not open for further replies.
  1. How do dem SMPS PSG volume envelopes work?


    PSG1: 00 00 00 01 01 01 02 02 02 03 03 03 04 04 04 05 05 05 06 06 06 07 80
    PSG2: 00 02 04 06 08 10 80
    PSG3: 00 00 01 01 02 02 03 03 04 04 05 05 06 06 07 07 80
    PSG4: 00 00 02 03 04 04 05 05 05 06 80
    PSG5: 00 00 00 00 00 00 00 00 00 00 01 01 01 01 01 01 01 01 01 01 01 01 01 01 02 02 02 02 02 02 02 02 03 03 03 03 03 03 03 03 04 80
    PSG6: 03 03 03 02 02 02 02 01 01 01 00 00 00 00 80
    PSG7: 00 00 00 00 00 00 01 01 01 01 01 02 02 02 02 02 03 03 03 04 04 04 05 05 05 06 07 80
    PSG8: 00 00 00 00 00 01 01 01 01 01 02 02 02 02 02 02 03 03 03 03 03 04 04 04 04 04 05 05 05 05 05 06 06 06 06 06 07 07 07 80
    PSG9: 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 80


    Wat's that?
     
  2. nineko

    nineko

    I am the Holy Cat Tech Member
    6,309
    486
    63
    italy
    PSG are always square waves. 00 means no attenuation (aka full powered square wave). 80 means end.
    I'm not sure how attenuation works, I think it's inversely proportional, or something.
    Anyway.

    00 00 00 01 01 01 02 02 02 03 03 03 04 04 04 05 05 05 06 06 06 07 80
    Starts loud, gets a bit quieter, another bit quieter, etc.

    03 03 03 02 02 02 02 01 01 01 00 00 00 00 80
    Starts quiet, but then gets louder.
     
  3. Code (Text):
    1. 1)
    2. Volume
    3.     ^
    4. 100% ###
    5.      |  ###
    6.      |     ###
    7.      |        ###
    8.      |           ###
    9.      |              ###
    10.      |                 ###
    11.  50% |                    #
    12.      |
    13.      |
    14.      |
    15.      |
    16.      |
    17.      |
    18.   0% '---------------------#----------------------------------------->Time unit
    19.      # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    20.  
    21. 2)
    22. Volume
    23.     ^
    24. 100% #
    25.      |
    26.      |#
    27.      |  
    28.      | #
    29.      |  
    30.      |  #
    31.  50% |    
    32.      |   #
    33.      |    
    34.      |    #
    35.      |      
    36.      |
    37.      |
    38.   0% '-----#--------------------------------------------------------->Time unit
    39.      # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    40.  
    41. 3)
    42. Volume
    43.     ^
    44. 100% ##
    45.      | ##
    46.      |   ##
    47.      |     ##
    48.      |       ##
    49.      |         ##
    50.      |           ##
    51.  50% |             ##
    52.      |            
    53.      |
    54.      |
    55.      |
    56.      |
    57.      |
    58.   0% '---------------#----------------------------------------------->Time unit
    59.      # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    60.  
    61. 4)
    62. Volume
    63.     ^
    64. 100% ##
    65.      | #
    66.      |  #
    67.      |   ##
    68.      |     ###
    69.      |        #
    70.      |
    71.  50% |
    72.      |
    73.      |
    74.      |
    75.      |
    76.      |
    77.      |
    78.   0% '---------#----------------------------------------------------->Time unit
    79.      # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    80.  
    81. 5)
    82. Volume
    83.     ^
    84. 100% ##########
    85.      |         ##############
    86.      |                       ########
    87.      |                               ########
    88.      |                                       #
    89.      |
    90.      |
    91.  50% |
    92.      |
    93.      |
    94.      |
    95.      |
    96.      |
    97.      |
    98.   0% '----------------------------------------#---------------------->Time unit
    99.      # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    100.  
    101. 6)
    102. Volume
    103.     ^
    104. 100% |         ####
    105.      |      ###
    106.      |  ####
    107.      ###
    108.      |
    109.      |
    110.      |
    111.  50% |
    112.      |
    113.      |
    114.      |
    115.      |
    116.      |
    117.      |
    118.   0% '-------------#------------------------------------------------->Time unit
    119.      # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    120.  
    121. 7)
    122. Volume
    123.     ^
    124. 100% ######
    125.      |     #####
    126.      |          #####
    127.      |               ###
    128.      |                  ###
    129.      |                     ###
    130.      |                        #
    131.  50% |                         #
    132.      |
    133.      |
    134.      |
    135.      |
    136.      |
    137.      |
    138.   0% '--------------------------#------------------------------------>Time unit
    139.      # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    140.  
    141. 8)
    142. Volume
    143.     ^
    144. 100% #####
    145.      |    #####
    146.      |         ######
    147.      |               #####
    148.      |                    #####
    149.      |                         #####
    150.      |                              #####
    151.  50% |                                   ###
    152.      |
    153.      |
    154.      |
    155.      |
    156.      |
    157.      |
    158.   0% '--------------------------------------#------------------------>Time unit
    159.      # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    160.  
    161. 9)
    162. Volume
    163.     ^
    164. 100% #
    165.      |#
    166.      | #
    167.      |  #
    168.      |   #
    169.      |    #
    170.      |     #
    171.  50% |      #
    172.      |       #
    173.      |        #
    174.      |         #
    175.      |          #
    176.      |           #
    177.      |            #
    178.   0% '-------------#------------------------------------------------->Time unit
    179.      # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
    Like this?
     
  4. Mairtrus

    Mairtrus

    Get a load of this!! Tech Member
    27
    0
    0
    Mendoza, Argentina
    Sonic Z. The Z DOESN'T means nothing.
    Both are right. Here is the commented part of SMPS code that manages the atenuation(sub_72926 in whatever disassembly):
    Code (ASM):
    1. DoPSGInstrument:                ; XREF: Sound_PlayPSG
    2.         tst.b   $B(a5)      ; is zero the current instrument?
    3.         beq.w   locret_7298A    ; if yes, branch...
    4.  
    5. DoPSGInstrument_2:              ; XREF: Sound_PlayPSG
    6.         move.b  9(a5),d6    ; load the volume
    7.         moveq   #0,d0
    8.         move.b  $B(a5),d0   ; load the number of instrument
    9.         beq.s   PSG_ChgVolume   ; is zero (again)?. If yes, branch...
    10.         movea.l (Go_PSGIndex).l,a0 ; loads the PSG instruments offset
    11.         subq.w  #1,d0
    12.         lsl.w   #2,d0       ; get the fixed index
    13.         movea.l (a0,d0.w),a0    ; load the current offset of the instrument
    14.         move.b  $C(a5),d0   ; load the instrument's counter
    15.         move.b  (a0,d0.w),d0    ; load the modifier byte
    16.         addq.b  #1,$C(a5)   ; augment the counter
    17.         btst    #7,d0       ; is a negative value?
    18.         beq.s   loc_72960   ; if not, branch...
    19.         cmpi.b  #$80,d0     ; is specificly $80?
    20.         beq.s   LoopPSGInstrument ; if yes branch...
    21.  
    22. loc_72960:
    23.         add.w   d0,d6       ; modifies the volume
    24.         cmpi.b  #$10,d6     ; is it higher than the maximun (phisically, the lowest) PSG volume?
    25.         bcs.s   PSG_ChgVolume   ; if not, branch...
    26.         moveq   #$F,d6      ; set the maximun (lower) volume
    27. ; End of function DoPSGInstrument
    28.  
    29. [...]
    30.  
    31. LoopPSGInstrument:              ; XREF: DoPSGInstrument
    32.         subq.b  #1,$C(a5)   ; decreases the counter (loops it at the last byte)
    33.         rts
     
  5. Mikel

    Mikel

    Member
    Yes, that is how controlling the volume in PSG envelopes work, it starts out loud for most (Look at PSG9), but quiet for some (Look at PSG6), and it ends quiet for most (Look at PSG9), but loud for some (Look at PSG6).
     
  6. nineko

    nineko

    I am the Holy Cat Tech Member
    6,309
    486
    63
    italy
    Also I just found out something funny.
    Oerg doesn't miss a chance to annoy everyone saying that the FM "Voices" are actually FM "Instruments" and that everyone on Retro is doing it wrong, and now he says "PSG Voices", when the wiki has been saying "PSG Instruments" since years ago.
    How ironic :v:
     
  7. BUMP I DON'T CARE.

    That would be because actually in total a the psg always carries the same instrument (except for the noise channel but w/e): Square wave, while a FM isntrument can have many different sounds.
     
  8. Andlabs

    Andlabs

    「いっきまーす」 Wiki Sysop
    2,175
    1
    0
    Writing my own MD/Genesis sound driver :D
    Sorry for bumping this thread, but what is the time unit in those graphs? It isn't obvious from the code above (in fact, I think the code above is called from whatever does the timing). I'm planning a sound driver and would like to do something similar. Thanks.
     
  9. Chilly Willy

    Chilly Willy

    Tech Member
    751
    11
    18
    Doom 32X
    Iffen I 'member correctly, the PSG envelope is processed once each vertical blank using the vblank int handler.
     
Thread Status:
Not open for further replies.