Shop OBEX P1 Docs P2 Docs Learn Events
Pop and click with Audio — Parallax Forums

Pop and click with Audio

drazmodrazmo Posts: 21
edited 2008-09-02 01:16 in Propeller 1
When I play audio there is an pop-click on startup and in some cases when the file is finished. I am working with wav files. I don't mind an initial power up pop but every time I play a wav sound it has the pop sound. If I play a wav file in a continuous loop then there is no pop sound. If there is just the slightest gap between the end and start of the file then you here the pop on start of the wav file and end of the wav file. I am using Rayman's SPIN WAV Player Ver. 1a. The pop sound is also present on startup if I run the singing demo. I have connected the board directly to a TV and most recently to a MAX4364 amp with built in pop-click suppression but the pop-click is still quite loud and very noticeable. I have looked through the forums and have seen different posts that mention the pop but no information on how to eliminate it. The HSS Demo doesn't appear to have this problem. I looked and there is a function "VolumeInterpol" that seems to be the way he eliminated the pop but I don't understand how it works since there is so much going on with the hss engine. I am using the Proto Board. Following the Propeller cookbook I connected a 200ohm resitor, .1uF capacitor and 10uf capacitor.

Comments

  • RaymanRayman Posts: 14,589
    edited 2008-04-04 00:01
    I think this is due to the fact that the DAC asserts Vcc/2 output as soon as started... So, the DAC output makes a sudden jump from 0 to Vcc/2... I think we discussed this problem in an earlier thread... I suppose the solution is to more slowly ramp up the DAC output before starting the wav player, but I don't think anybody actually did this yet...
  • drazmodrazmo Posts: 21
    edited 2008-04-04 01:53
    Yes, that is what you mentioned on another post. I have tried to ramp it but have had no luck... I am new to the Propeller and have a very limited understanding of how to go about it. This is what I have so far....I placed this right before it goes into its FAST loop and if the program is stopped right after this loop there is no pop. As soon as it jumps into the fast loop, the pop happens on the first cycle. I tried to have it skip over the first set of buffers but any code such as "p=p+1" I put in the loop does something that kills the audio.

    NextCnt:=cnt+1005000
    FRQA:=$000F_FFFF
    repeat while FRQA < $8FFF_FFFF
          FRQA:=FRQA + $FFFF
          NextCnt+=5000   ' need this to be 5000 for 16KSPS   @ 80 MHz
          waitcnt(NextCnt)
            
    
    



    In the above code if I set FRQA to anything higher than $000F_FFFF then you hear the pop. I think you are on the right track but there seems to be something else I just can't grasp.
  • Paul BakerPaul Baker Posts: 6,351
    edited 2008-04-04 05:31
    What about using a bias network? Use high resistance resistors, like 100k and tie one to Vdd and the other to Vss. This will lightly bias the line to vdd/2 and may help with the beginning click. It may not help with ending clicks.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.
  • drazmodrazmo Posts: 21
    edited 2008-04-04 16:34
    Tried bias network with no change. I have tried ramping FREQA and at best I get the pop then a gap then the start of the wav perfectly. On one wav file if I skip the first buffer then it starts perfectly. If I replay that same wav then it plays fine again...over and over...but as soon as I play a different wav then the pop happens and it happens with the first replay of the first wav.
  • RaymanRayman Posts: 14,589
    edited 2008-04-04 17:06
    Strange... I'm surprised the bias network didn't fix it... Can you measure the output capacitor voltage before you start playing to make sure it's at Vdd/2?
  • drazmodrazmo Posts: 21
    edited 2008-04-04 19:28
    Meter shows 1.58V before music starts and it still has pop-click before startup.
  • RaymanRayman Posts: 14,589
    edited 2008-04-04 20:26
    Perhaps my code isn't giving enough time for data to get loaded before starting to play... Or, maybe the DAC counter is intialized to a state where it wants to put out 0 volts?
  • drazmodrazmo Posts: 21
    edited 2008-04-04 20:28
    Partial solution....I get the initial pop but if make the play loop stop after the file ends and just have it wait then when the next file plays it doesn't have an end or begining pop. I can play different files and no pop. The problems is that adding the line "if notEOF == 1" breaks the loop and causes it not to play. If I remove the "waitcnt(NextCnt)" then everything plays but obvious at a faster rate with nice squeaky voices. If I set the NextCNT to 6000 or above I get really low slow audio but it only plays the first sound and then maybe a minute later plays the next. My guess is that I need to do this with assembly, to be able to add that line to the audio?

    repeat
         if notEOF ==1 
          repeat i from 0 to buffSize-1
            
            NextCnt+=5000   ' need this to be 5000 for 16KSPS   @ 80 MHz
            waitcnt(NextCnt)
            if (j)
              'if (p > 0)               
                FRQA:=buff1[i]~
                FRQB:=FRQA
                
            else
             ' if (buff2[i] < 0)  
                FRQA:=buff2[i]~
                FRQB:=FRQA
                  
          NOT j
    [/i][/i][/i]
    
  • RaymanRayman Posts: 14,589
    edited 2008-04-04 22:05
    There's an assembly version here:

    http://www.rayslogic.com/propeller/Programming/dac/dac.htm

    The SPIN loop is very tight, no room for anything extra...
  • johnfl68johnfl68 Posts: 72
    edited 2008-04-04 22:52
    Ok - I 'm new to the Prop, but I am an Audio person.

    If you have 1.58V before the audio starts, in most cases this is bad - the wav file should have a DC offset of 0V, so the pop you here is the the output changing from 1.58V to 0V. The output should always be at 0 when there is no audio, and most wav files should also have a DC offset of 0V

    I hope this helps.

    John
  • RaymanRayman Posts: 14,589
    edited 2008-04-04 23:34
    Just to clarify... I hope we are biasing the output pin of the Prop. Since, the DAC output range is 0 to 3.3 volts, you want to sit at 3.3/2 so that you can go both positive and negative. This DC level is eliminated by using a large output bypass capacitor...
  • drazmodrazmo Posts: 21
    edited 2008-04-07 20:52
    Ok...here is what I have....I am using P10


    When the board starts up before the cap I am show 1.5v. Still get the pop on startup and when starting a new wav file.

    Post Edited (drazmo) : 4/7/2008 8:58:15 PM GMT
    395 x 89 - 4K
  • drazmodrazmo Posts: 21
    edited 2008-04-08 14:31
    Partial solution. I am still using Ray's Wav Player Version 1.a. I created a function play which is part of the original Main function and placed it in an infinite loop. It plays a wav and stores the last value from the buffer and continues to feed that to the COG running the fast loop after the wav finishes playing. This keeps FRQA from being dropped to 0. Now I am able to switch from 4 wav's with no pop-click while it changes from 1 to another even if there is a small delay. I also had to make sure the wav's ended with silence. If not there was a slight pop when the next wav would start. With a little more tweaking this should be able to run on its own COG and be called from another to play specific wav file. The only problems I see is that the if (j==buffsize * 2) that forces the loop to start using the last buffer value may keep the last part of the wav from playing. It doesn't seem to affect anything now but should I worry about the lost data? I still have the pop when the program starts but I can live with that. Thanks to everyone for their support!

    PUB Play(s) | n,i,j,p
      i:=sd.mount(0)         
      p:=0
      repeat
        ' if PlayNow =1, play song stored based on s
        if (playNow==1) 
           if (s==0)
             i:=sd.popen(string("Intro16.wav"), "r")                '   <---------  Change .wav filename here !!!!!!!!!!!!!!
           elseif (s==1)
             i:=sd.popen(string("carry16s.wav"), "r")                '   <---------  Change .wav filename here !!!!!!!!!!!!!!
           elseif (s==2)
             i:=sd.popen(string("test1.wav"), "r")
           else
             i:=sd.popen(string("test2.wav"), "r")
            
           'ignore the file header (so you better have the format right!)
           'See here for header format:  http://ccrma.stanford.edu/CCRMA/Courses/422/projects/WaveFormat/
           i:=sd.pread(@MonoData, 44) 'read data words to input stereo buffer
         
           'Keep filling buffers until end of file
           ' note:  using alternating buffers to keep data always at the ready...
         ' repeat 
           n:=buffSize-1
           j:=buffsize*2
           repeat while (j==buffsize*2)  'repeat until end of file
             if (buff1[noparse][[/noparse]n]==0)
               j:=sd.pread(@MonoData, buffSize*2) 'read data words to input stereo buffer          
              'fill table 1 if buffer incomplete with last known value
               if (j==buffsize * 2)
                repeat i from 0 to n
                  buff1[i]:=($8000+MonoData[i])<<16
                bufflast:=buff1[noparse][[/noparse]n]
               else
                  repeat i from 0 to n
                   buff1[i]:=bufflast
                   
             if (buff2[noparse][[/noparse]n]==0)
               j:=sd.pread(@MonoData, buffSize*2) 'read data words to input stereo buffer  
               'fill table 2 if buffer incomplete with last known value
               if (j==buffsize * 2)
                repeat i from 0 to n
                  buff2[i]:=($8000+MonoData[i])<<16
                bufflast:=buff1[noparse][[/noparse]n]
               else
                  repeat i from 0 to n
                   buff2[i]:=bufflast
                   
           'must have reached the end of the file, so close it
           playNow:=0  
           'sd.pclose
       ' keep buffer filled...while idle
        
        if (buff1[noparse][[/noparse]n]==0)   
               'fill table 1
           repeat i from 0 to n
                  buff1[i]:=bufflast 
        if (buff2[noparse][[/noparse]n]==0)  
               'fill table 2
               repeat i from 0 to n
                  buff2[i]:=bufflast
    
        ' Pause before going to next wav
        p++
        if (p==200)
          playNow:=1
          p:=0
          s++
          if s >3 
            s:=0
        else
          text.str(num.ihex(bufflast,8))
    [/i][/i][/i][/i][/i][/i][/i][/i]
    
  • Paul BakerPaul Baker Posts: 6,351
    edited 2008-04-08 18:51
    Dramzo, do you have an oscilloscope to monitor the output? Using one should help illustrate what the circuit is doing to cause the click.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.
  • drazmodrazmo Posts: 21
    edited 2008-04-08 23:35
    No...I don't have oscilloscope. shakehead.gif
  • drazmodrazmo Posts: 21
    edited 2008-09-02 01:16
    Update....
    I have been able to eliminate the pop when a file starts to play with this code right after the "setup" in the asm routine. The code was posted on a mono wav player in the forums I just adapted it.

            ' Declick
            mov val, #0
    :declick                            ' ramp up the audio DC output voltage from 0 to midway (0.5 VDD)
            'waitcnt nexttime, delta
            mov nexttime, cnt
            add nexttime, delay
    
            waitcnt nexttime, delta
           
            mov frqa, val
            mov frqb, val
            add val,fadeval
            cmp val,midval wz          ' midway yet?
            if_ne jmp #:declick
    
    
    



    The pop at the end of playback can be removed if I remove 1000 from the samples read from the header. With...

            SUBS nSamples,#500
            SUBS nSamples,#500
    
    MainLoop
            SUB nSamples,#1
            .......
    
    



    It seems to play the entire audio file and no pop at the end. I just don't understand...why? Any suggestions? Some files end without the pop and some due if I leave the samples alone. If I remove the 1000 then it works. I am using GoldWave to edit my wav files.
Sign In or Register to comment.