Shop OBEX P1 Docs P2 Docs Learn Events
Conditional loop (Repeat X times) in the PASM — Parallax Forums

Conditional loop (Repeat X times) in the PASM

Hello All

In the "jm_wav_checkout.spin2" Object I would like to control the number of times the file play but in the SPIN method - repeat / play_wav(p_dat, 100) it did´nt the conditional repeat.
Ccould that be altered in the Spin Methd or in the Assembly code?
The ideia is to define how much time to play the .wav file.

Thank you in advance.

Comments

  • JonnyMacJonnyMac Posts: 8,927
    edited 2022-12-04 21:03

    You could do something like this:

    pub play_wav_x(p_wav, volume, n)
      repeat (1 #> n <# 10)
        play_wav(p_wav, volume)
    

    This allows you to repeat without sending a negative or excessive repeat value.

    Once @cgracey has a uSD driver for Spin2 working, I'll update my P1 audio player to the P2. The WAV playback is in a separate cog which allows one to stop and start sounds clearly. For example, the military shot sound is from a laser tag project I coded on the P1. In full auto, we can make that single sound become a machine gun by restarting it before the file finishes.

  • Great Jon McPhalen
    Thanks a lot!

  • I tested it but it didn´t interruped the looking.
    Question: could it be in constant loop in the Assembly code?

  • That inline code cannot be interrupted. As I said, when we have a reliable uSD driver that works with Spin, I will convert my AP-16+ (a board built by EFX-TEK) audio player code to the P2. That code runs in a separate cog so it can be interrupted. This is how I can turn a single shot sound into a machine gun sound.

  • @Jon McPhalen
    Very good!
    I am waiting.

Sign In or Register to comment.