Example Code to Play Music and Sound FX at the same time on ZX Spectrum 128k

What is Arkos Tracker? Forums Arkos Tracker forum General discussion Example Code to Play Music and Sound FX at the same time on ZX Spectrum 128k

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #29482
    robpearmain
    Participant

    The following demo plays a different FX every time you press ‘1’

            org #8000
    
            di
    
            ;Initializes the music.
            ld hl,Music
            xor a                                   ;Subsong 0.
            call PLY_LW_Init
    
            ;Initializes the sound effects.
            ld hl,SoundEffects
            call PLY_LW_InitSoundEffects
    
    Sync:   
            ei
            nop
            halt
            halt
    
            di
    
           ld bc,63486         ; keyboard row 1-5/joystick port 2.
           in a,(c)            ; see what keys are pressed.
           rra                 ; outermost bit = key 1.
           jr nc, playfx
            ; if carry then no key pressed
    
            
           xor a
           ld (keypressed),a
           jr playmusic
    
    playfx:
    
           ld a,(keypressed)
           and 255
           jr nz,playmusic
    
            ld a,(SelectedSoundEffect)
            inc a
            ld (SelectedSoundEffect),a
            cp 8
            jr nz, playfx2
            xor a
             ld (SelectedSoundEffect),a
    playfx2:
           ld c,1
           ld b,0          ;Full volume.
           call PLY_LW_PlaySoundEffect
           ld a,1
           ld (keypressed),a
    
    playmusic:      
            call PLY_LW_Play
        
            jp Sync
            
            ret
    
    SelectedSoundEffect: db 1                       ;The selected sound effect (>=1).
    
    KeyboardMaskLine0: db 255
    KeyboardMaskLine1: db 255
    KeyboardMaskLine2: db 255
    KeyboardMaskLine5: db 255
    keypressed: db 0
    
    Player:
            ;IMPORTANT: enables the sound effects in the player. This must be declared BEFORE the player itself.
            PLY_LW_MANAGE_SOUND_EFFECTS = 1
            
            ;Include here the Player Configuration source of the songs and sound effects (you can generate them with AT2 while exporting the them).
            ;If you don't have any, the player will use a default Configuration (full code used), which may not be optimal.
            ;If you have several songs, include all their configuration here, their flags will stack up!
            ;Warning, this must be included BEFORE the player is compiled.
            ;include "../resources/MusicDeadOnTime_playerconfig.asm"
            ;include "../resources/MusicMolusk_playerconfig.asm"
            ;include "../resources/SoundEffectsDeadOnTime_playerconfig.asm"
            
    
            include "../PlayerLightweight_SPECTRUM.asm"
    
    Music:
            ;Choose a music, or maybe silence?
            include "../resources/MusicDeadOnTime.asm"                     ;25Hz! Change the flag at the top to 1.
            ;include "../resources/MusicEmpty.asm"
            ;include "../resources/MusicMolusk.asm"                         ;50Hz! Change the flag at the top to 0.
    
    SoundEffects:
            include "../resources/SoundEffectsDeadOnTime.asm"
    
    #29484
    Targhan
    Keymaster

    Hey, that’s great, thanks a lot. I’ll test/include it as soon as I can, and integrate it to the package (with your credit of course). Thanks!

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