Shop OBEX P1 Docs P2 Docs Learn Events
Kye's WAV driver question. — Parallax Forums

Kye's WAV driver question.

TCTC Posts: 1,019
edited 2014-07-18 08:47 in Propeller 1
Hello all,

This is my first time having the prop play WAV files, and I seam to have hit a brick wall.

I have been trying to find a way to stop the current (playing) WAV file, and play something else. Right now, once the first file is done playing, the next one will start. I don't want that. I don't want to wait until the other file is done playing.

I have tried
      IF AUDIO_FILE <> NULL
        AUDIO.OVERRIDESONG(TRUE)
        AUDIO_PLAY(AUDIO_FILE)


PRI AUDIO_PLAY(ACTION)

  RESULT := \AUDIO.PLAY(@@AUDIO_LIST[ACTION])

I know there is something I am missing, but I just cant see it.

Thanks for any ideas
TC

Comments

  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2014-07-06 01:21
    Well, you might have to start another cog to monitor an i/o pin or serial input (whichever you desire to provide a break condition); and then there is a main loop for the audio that will have to have a line of code that tests for a request to jump out of it.

    It seems that once you are in a play mode, the main audio output loop ignores all human inputs. That may be because the timing is critical. Adding a line of code might throw off the timing and affect the audio quality. But you can try.

    This is all theory, I need to look at the actual OBEX object for specifics.
  • TCTC Posts: 1,019
    edited 2014-07-06 07:18
    Well, you might have to start another cog to monitor an i/o pin or serial input (whichever you desire to provide a break condition); and then there is a main loop for the audio that will have to have a line of code that tests for a request to jump out of it.

    I am monitoring an encoder (detent encoder), and I want it to be with every click of the encoder, the prop will play*a sound. It works a little now, but if you spin the encoder fast, the audio has to catch up. It just does not sound right.


    It seems that once you are in a play mode, the main audio output loop ignores all human inputs. That may be because the timing is critical. Adding a line of code might throw off the timing and affect the audio quality. But you can try.

    This is all theory, I need to look at the actual OBEX object for specifics.

    With all the other stuff running, cogs are at a premium. The WAVE player uses 2 just by its self. Then add on the encoder, display, SD card driver, etc...

    I would think there is a way to flush the RAM, then reload it with the new data. But I don't know.
  • Mark_TMark_T Posts: 1,981
    edited 2014-07-06 11:48
    Does the driver have a stop method? This should stop the cog completely...
  • TCTC Posts: 1,019
    edited 2014-07-06 13:12
    Mark_T wrote: »
    Does the driver have a stop method? This should stop the cog completely...

    I agree, and I would like it to. I have a lite amount of noise that is only there while the driver is on. It can only be heard when there is nothing playing. I am just wondering if there would be any down side of starting and stopping the driver constantly.

    EDIT... That did not answer your question. No, the driver does not have to stop a method. Just to immediately stop the current playing file.
  • TCTC Posts: 1,019
    edited 2014-07-06 14:10
    Here is a video of what I am talking about.
  • TCTC Posts: 1,019
    edited 2014-07-07 18:06
    Well, I figured out how to end the current audio file, and start it again. Now no matter how fast, or slow you turn the encoder knob, the audio matches.
          IF AUDIO_FILE <> NULL                             ''DOES AN AUDIO FILE NEED TO BE PLAYED?      
            AUDIO.OVERRIDESONG(TRUE)                        ''END CURRENT PLAYING AUDIO FILE        
            AUDIO_PLAY(AUDIO_FILE)                          ''PLAY NEW AUDIO FILE
            [COLOR="#FF0000"]AUDIO.OVERRIDESONG(FALSE)                       ''ALLOW NEW AUDIO FILE TO BE PLAYED[/COLOR]
    

    What I did is turn off "OVERRIDESONG" right after I requested to play the audio file.
  • base2designbase2design Posts: 78
    edited 2014-07-08 09:35
    Cool TC, how about a youtube video with it fixed?
  • TCTC Posts: 1,019
    edited 2014-07-08 14:14
    Cool TC, how about a youtube video with it fixed?

    I was so happy I figured out what to do, I compleatly forgot to upload a video. Here you go
  • base2designbase2design Posts: 78
    edited 2014-07-08 15:53
    Very nice. Thanks for solving this... I'll benefit from your question eventually.
    -joe
  • TCTC Posts: 1,019
    edited 2014-07-08 16:09
    Thanks, and no problem.
  • base2designbase2design Posts: 78
    edited 2014-07-09 09:27
    One other question... did you solve the high-pitch noise issue too? If so, what was the issue/solution?
  • KyeKye Posts: 2,200
    edited 2014-07-09 13:24
    The play(...) method puts a song into a queue of depth 1. This means executing play(...) twice will start playing one song and ready the next song to be played. Calling the overrideSong(true) method instantly switches to the next song in the queue.

    So...
    PUB onSwitchChange(fileName)
    
      player.play(fileName)
    
      if(getByteSize) ' Previous song playing
        overrideSong(true)
    

    Note... there's not really anyway to call the overrideSong(...) method without running into possible race conditions. There's always a chance that overrideSong(...) could cancel the next song to be played instead of the currently playing song if the currently playing song finishes right before overrideSong(...) is executed. I think the V2 wav player needs to be redesigned to fix this. However, doing so is not on my radar right now.

    If you want, you can modify the wavPlayer function in the driver to fix this issue. It's in SPIN. You would need to change the code so that above function executes more or less atomically with respect to the wavPlayer cog. This will require some form of locking I think since the override function bypasses the lockless queue structure.

    ...

    If everything I said sounds hard just keep doing what you are doing and be happy :).
  • TCTC Posts: 1,019
    edited 2014-07-09 18:58
    One other question... did you solve the high-pitch noise issue too? If so, what was the issue/solution?

    I fixed it somewhat, I had to filter it out. The speakers I am using, have a frequency response of 240Hz to 20,000Hz. I first made a high pass filter to remove the low end distortion. I started with a 1kΩ resistor, and found a cap that sounded the best. Then I added a low pass filter to remove the noise (not the best idea, but it works), I kept trying different parts until I found ones that removed the noise, but did not remove to much of the upper end. In turn, I made a band pass filter. What I want to do is, remove the low pass filter, and add a passive notch filter (band stop). That way I can remove the noise, and keep the upper end.

    2014-07-09_21-49-24.jpg



    Kye wrote: »
    The play(...) method puts a song into a queue of depth 1. This means executing play(...) twice will start playing one song and ready the next song to be played. Calling the overrideSong(true) method instantly switches to the next song in the queue.

    So...
    PUB onSwitchChange(fileName)
    
      player.play(fileName)
    
      if(getByteSize) ' Previous song playing
        overrideSong(true)
    

    Note... there's not really anyway to call the overrideSong(...) method without running into possible race conditions. There's always a chance that overrideSong(...) could cancel the next song to be played instead of the currently playing song if the currently playing song finishes right before overrideSong(...) is executed. I think the V2 wav player needs to be redesigned to fix this. However, doing so is not on my radar right now.

    If you want, you can modify the wavPlayer function in the driver to fix this issue. It's in SPIN. You would need to change the code so that above function executes more or less atomically with respect to the wavPlayer cog. This will require some form of locking I think since the override function bypasses the lockless queue structure.

    ...

    If everything I said sounds hard just keep doing what you are doing and be happy :).

    I think I might just do that. And thank you for the approval to modify your code. One thing I do want to add is an "amplifier enable". My amplifier has an enable pin. It would be nice that if there is no audio to be played, it would turn off the amplifier.

    What is hard, is a beginner trying to understand your style of coding. I have been getting a good grip on it though. So much so, I have started to code somewhat like you. It is making my code more understandable. For that, I thank you.
    1024 x 370 - 20K
  • KyeKye Posts: 2,200
    edited 2014-07-10 06:56
    Good to hear!

    The V2 wav player is a bit terse in the coding style. However, it's optimized at least so stray lines of code aren't floating around that would confuse you.

    Just modify the wavPlayer function in the driver to add an amplifierEnable signal. Whenever the wavPlayer driver is not idling it's playing something. If you want to be more precise modify the ASM code. But, I don't think you'll need to.
  • TCTC Posts: 1,019
    edited 2014-07-10 14:48
    Kye wrote: »
    it's optimized at least so stray lines of code aren't floating around that would confuse you.

    That is exactly one thing I copied.

    Just modify the wavPlayer function in the driver to add an amplifierEnable signal. Whenever the wavPlayer driver is not idling it's playing something. If you want to be more precise modify the ASM code. But, I don't think you'll need to.

    I don't know PSAM yet. I am still learning. But I will do what you suggested. Thanks
  • SavageCircuitsSavageCircuits Posts: 256
    edited 2014-07-14 13:20
    TC,

    Are you using the V1 or V2 player? Also, which encoder object are you using? I've been playing with the one I wrote and the one Jeff Martin wrote so far.
  • TCTC Posts: 1,019
    edited 2014-07-16 04:28
    TC,

    Are you using the V1 or V2 player? Also, which encoder object are you using? I've been playing with the one I wrote and the one Jeff Martin wrote so far.

    I am nowhere close to a computer so I can't link the objects. But,

    I am using Kye's wave driver V2. And using jonnymac's grey scale encoder.

    I can post the objects later next week when I get back home.
  • SavageCircuitsSavageCircuits Posts: 256
    edited 2014-07-16 15:26
    TC,

    No need. I just wondered which ones you were using, though I do want to mention to Kye that neither object can be easily found. I wonder if both could be linked once so I can archive them both on my S///C machine and my Parallax work PC? :nerd:
  • KyeKye Posts: 2,200
    edited 2014-07-17 11:55
    Version 1 and 2 are right here:

    http://obex.parallax.com/object/329
  • SavageCircuitsSavageCircuits Posts: 256
    edited 2014-07-18 08:47
    Thanks Kye. I didn't realize both versions were on the same page.
Sign In or Register to comment.