Shop OBEX P1 Docs P2 Docs Learn Events
New WAV player (V2) — Parallax Forums

New WAV player (V2)

KyeKye Posts: 2,200
edited 2014-08-20 09:28 in Propeller 1
Hey all,

I made a new WAV player using the noise shaping technique described here:

http://forums.parallax.com/showthread.php/148280-Prop-sound-quality-question

It sounds great and doesn't need a dither cog anymore. Additionally, I have a bunch of nice things built around the WAV Player to make it fast and responsive.

The WAV player can switch between wav files with zero delay because I queue up the next file to play in the code before the first file has finished playing.

---

I've include 2 demos in the file. One of which just plays a WAV file in a loop (top.spin), and one of which that plays some sounds over and over again very fast (gun.spin).

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2013-10-01 15:01
    In your original player you had a method called, wavePlayerState which let you know if a WAV file was playing or not. In this version it appears you have to use getByteSize and getBytePosition to accomplish the same thing. Does this sound right? I was looking at the documentation view and didn't see any comments for the different methods.
  • KyeKye Posts: 2,200
    edited 2013-10-01 17:53
    Yeah, those will do the job. They are non-zero while the wav player is playing.

    The code for this wav player is much easier to tinker with than the previous one because I didn't try to optimize everything.

    ...

    This code was developed on commission. I'm just releasing it for others to use. My aim is not really to write extensive documentation here. All the functions work pretty much like you would expect.
  • Dr_AculaDr_Acula Posts: 5,484
    edited 2013-10-01 21:05
    More code from Kye. Life is good :)
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2013-10-02 09:27
    Okay, I will try it out. Thanks.
  • WBA ConsultingWBA Consulting Posts: 2,934
    edited 2013-11-10 23:00
    Just downloaded this tonight for a project I am working on for prop for a Christmas play. I love how simple it is to use. I recall seeing this thread about an updated version of the KISS WAV player, but had a bit of trouble finding this thread today. Finally found it with Google with a site restricted search and several key words (KISS WAV PLAYER V2 SITE: PARALLAX.COM). I could easily find the version in the OBEX, KISS WAV Player Driver, but I know this one was supposed to be better. Should this one be loaded up to the OBEX as a replacement of the original or loaded up as a separate version?
  • pik33pik33 Posts: 2,366
    edited 2013-11-11 06:01
    Now we have sophisticated noise free wave player instead of my far-from-ending piece of code - good.
  • KyeKye Posts: 2,200
    edited 2013-11-11 10:10
    Should I put this on the OBEX? I'm really not to motivated to write a whole bunch of comments for it like my other code. But, I'll put it on the OBEX if everyone doesn't think that will be a problem.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2013-11-11 10:44
    You should definitely upload it. Be sure if it is a replacement for the other that you edit you description on the old one to indicate this.
  • Mark_TMark_T Posts: 1,981
    edited 2013-11-11 11:07
    Ooh, lovely, I'm acknowledged in the code :) Good to see it working for people and all the work you've done Kye - shall have to dig out an SDcard
    breakout and check it out.
  • KyeKye Posts: 2,200
    edited 2013-11-11 17:52
    I'm surprised on how good that noise shaping technique works. It boosts the volume by 4X and it sounds beautiful!

    I had to do a bunch of work to get it to run up to 48 KHz * 4 = 192 KHz, so, the code hits basically every hub window. I also made the code able to switch seamlessly between files.

    Thanks for the work Mark_T!
  • lonesocklonesock Posts: 917
    edited 2013-11-11 20:49
    Regarding the lack of comments: Kye, I have always found your code to be very readable, with good logic flow and good variable names, and this code is no exception. Maybe naming a few of those "magic numbers" with constants would be beneficial, but other than that I say definitely upload it!

    Jonathan
  • pik33pik33 Posts: 2,366
    edited 2013-11-12 03:57
    Kye wrote: »
    I'm surprised on how good that noise shaping technique works. It boosts the volume by 4X and it sounds beautiful!

    I had to do a bunch of work to get it to run up to 48 KHz * 4 = 192 KHz, so, the code hits basically every hub window. I also made the code able to switch seamlessly between files.

    Thanks for the work Mark_T!

    The more oversample, the better will be the sound. In my code here: http://forums.parallax.com/showthread.php/148280-Prop-sound-quality-question you have 7x oversampling @44100 Hz.When overclocked, it can do 10x oversampling and the difference between 7x and 10x is hearable.

    Your code seems to be universal, playing 1- or 2-channel WAVs at different sample rates and it can do online volume changes. All of this stuff eats the precious loop time. Maybe there will be a better solution to limit the code to 2-channel, 16-bit, 32000, 44100 and 48000 kHz WAV's. 99.9% of all wav files will then still be played. The volume change can be made outside of the main DAC loop. The transfer size can be made at 512 bytes (=SD sector size). The goal is of course make one worst case loop in less than 256 clocks because this is the one full PWM time.

    We have 1814 clocks for one 44100 Hz sample and 1666 clocks for one 48000 Hz sample when the Propeller is clocked at 80 MHz. An integer number of loops has to be done for one sample. If we can do one loop at 256 clocks, we may have 7 loops@259 clocks=1813 clocks for 44100 and 6 loops @ 277 clocks for 48000. This is theoretical maximum for non-overclocked Propeller.

    Because the Propeller can be easily overclocked, I recommend to do it when using for wave playing application. The more Mhz, the more overclocking and the better sound quality. Of course, even 4x oversampling gives enough SNR gain to give better sound than any dithered duty dac.
  • KyeKye Posts: 2,200
    edited 2013-11-13 07:24
    Thanks pik33, your help also made the wav player possible.

    However, I'm going to leave it with universal support. I'd rather it just "work" versus it only working for a few wave files. The person who commissioned me to do this wanted to play back short clips of low quality audio as fast as possible. Possibly for a toy.

    Okay, I'll get to uploading this as it is, I'll leave the old wav player up and put a forwarding link to this new one.

    ---

    @lonesock - Thanks for the kind words.
  • LtechLtech Posts: 380
    edited 2014-06-01 12:56
    I get trouble sound with Wav2. It sound like clipping/bathroom/harmonising
    Using a propeller platform sd on 0,1,2,3 output L26 R27 xtal 5Mhz

    When using on same hardware and wav file , with Wav player (one) it sound better but with noise ?
    Same sound with embedded gun examples?

    Somebody a path ?

    Thanks
  • KyeKye Posts: 2,200
    edited 2014-06-02 06:23
    Hi,

    I don't know what your problem is. The audio is find on an activity board. Maybe your RC filter is not good.
  • LtechLtech Posts: 380
    edited 2014-06-02 12:16
    I missed you use WAVplayer2 with an activity board, I analyse the schematics.
    I don't use the op-ams ..... Only resistor and capa.

    Strange it works with wavplayer(one) litle noisy
  • KyeKye Posts: 2,200
    edited 2014-06-02 13:49
    Hi,

    The V2 version uses a new technique: http://forums.parallax.com/showthrea...ality-question
  • LtechLtech Posts: 380
    edited 2014-06-02 14:18
    thanks for replay, Kye

    But I do not understand.

    -Wav player1 play nice on board. SD on pin 0-4. Output on pin 26&27.

    -On the same board, same sd memory, same RC output, the only difference is Wav player2 spin. The wav play very bad, metallic, saturating,

    Only change of original files are the SD pining on 0-4 in stead of 22-25 (used gun.spin an included wav)

    Is in an issue on pin 0 ?
  • KyeKye Posts: 2,200
    edited 2014-06-03 09:44
    Hi,

    I can't guess what the problem is. Have you tried playing music? The gun.wav is just the sound of a gun firing very quickly. I would just keep using the original wav player if the new one is causing issues.
  • pik33pik33 Posts: 2,366
    edited 2014-06-21 00:00
    Maybe it is saturated. The noise shaper has to have some "free place" to run and if the sample is normalized, or even worse: clipped - this can cause distortions.

    Try reducing aplitude of the sample to 0.9 (for example with Audacity) and check if it helped.
  • JonnyMacJonnyMac Posts: 9,105
    edited 2014-06-22 12:51
    Thought I'd give the update a try. Here's the deal: I would like to restart an audio before it finishes (e.g., turn a single shot into a machine gun). Calling play after the desired delay does not have the desired effect. What am I missing? I tried .overrideSong(true) thinking that would stop the current audio, but it didn't. Sorry if I've missed something obvious.
  • PublisonPublison Posts: 12,366
    edited 2014-08-20 08:56
    JonnyMac wrote: »
    Thought I'd give the update a try. Here's the deal: I would like to restart an audio before it finishes (e.g., turn a single shot into a machine gun). Calling play after the desired delay does not have the desired effect. What am I missing? I tried .overrideSong(true) thinking that would stop the current audio, but it didn't. Sorry if I've missed something obvious.

    I am trying to do the same thing. Any resolution thus far?
  • KyeKye Posts: 2,200
    edited 2014-08-20 09:23
    The driver queues up songs. You have to have another song in the queue for the override function to work. Calling the play function does not block unless the queue is full.

    http://forums.parallax.com/showthread.php/156354-Kye-s-WAV-driver-question.?p=1277866&viewfull=1#post1277866

    Note that you can make the queue larger if you want. This takes more memory however.
  • KyeKye Posts: 2,200
    edited 2014-08-20 09:28
    @JonnyMac - No, you haven't missed anything. I just kinda tacked the override functionality on at the end of development. When I was hired to write this driver the goal was to just be able to play songs without gaps. However, once this worked my customer wanted to be able to quickly switch to the next song. I didn't design that feature into the driver when I started coding so I just put a quick fix in to get it working. Otherwise, I would have made it easier to use.
Sign In or Register to comment.