Shop OBEX P1 Docs P2 Docs Learn Events
Flexible wav player with keyboard control — Parallax Forums

Flexible wav player with keyboard control

selcukselcuk Posts: 7
edited 2014-05-14 11:01 in Propeller 1
Thanks for all help and very very thanks graham....
I finished flexible wav player with keyboard control..
But code have got a small bug.
When I press a keyboard button, speakers· stop and start again.
how can I mask the starting noise, I need help for this problem...

 

CON _clkmode = xtal1 + pll16x
    _xinfreq = 6_400_000       '80 MHz 
    

OBJ
    ses : "voice"
    kb    : "Keyboard"
PUB Main | i, z, t, sing
  sing := 1
  ses.play_wav(sing)
  kb.start(26, 27)

                                        
  repeat
     if(kb.gotkey)
        handlekey
     waitcnt(cnt + 6_400_000)
PRI HandleKey|key,bShift
  'user pressed a key, see what to do
  key:=kb.getkey
  bShift:=key&$100
  key&=$FF 'strip flags
  'turn lower case letters to uppper case
  case key
    $61..$7A:
      key-=$20
  case key
    $41 :
      ses.play_wav(0)
    $42 :
      ses.play_wav(1)
    $43 :
      ses.play_wav(2)
    $44 :
      ses.play_wav(3)
    $0D :
      ses.play_wav(4)

····
voice rutines listed of below

CON
  buffSize = 100 
VAR long parameter1  'to pass @buff1 to ASM
    long parameter2  'to pass @buff2 to ASM
    long parameter3  'to pass sample rate to ASM
    long parameter4  'to pass #samples to ASM
    long buff1[noparse][[/noparse]buffSize]
    long buff2[noparse][[/noparse]buffSize]
    long stack1[noparse][[/noparse]100]
    byte Header[noparse][[/noparse]44]
    byte cog,cogasm
    long stackwav[noparse][[/noparse]80]
OBJ
    SD  : "FSRW"

PUB play_wav(section): Success
  stop_wav
  Success := ( cog := cognew(run(section), @stackwav) + 1)
PUB stop_wav
  if cog
    cogstop(cog~ - 1)
PUB run(section)|n,i,j, SampleRate,Samples
  sd.pclose
  
  i:=sd.mount(0)
  if (i<>0)
    repeat

  'open file
  case section
    0:
     i:=sd.popen(string("1.wav"), "r")                         
    1:
     i:=sd.popen(string("2.wav"), "r")                
    2:
     i:=sd.popen(string("3.wav"), "r")
    3:
     i:=sd.popen(string("mtest.wav"), "r")                
    4:
     i:=sd.popen(string("ytest.wav"), "r")                

  if (i<>0)
    repeat
  i:=sd.pread(@Header, 44) 'read data words to input stereo buffer
  'Get sample rate from header
  SampleRate:=Header[noparse][[/noparse]27]<<24+Header[noparse][[/noparse]26]<<16+Header[noparse][[/noparse]25]<<8+Header[noparse][[/noparse]24]
  'get # samples from header
  Samples:=Header[noparse][[/noparse]43]<<24+Header[noparse][[/noparse]42]<<16+Header[noparse][[/noparse]41]<<8+Header[noparse][[/noparse]40]
  Samples:=Samples>>2
    
  'Start ASM player in a new cog
  parameter1:=@buff1[noparse][[/noparse]0]
  parameter2:=@buff2[noparse][[/noparse]0]
  parameter3:=CLKFREQ/SampleRate  '#clocks between samples'1814'for 44100ksps,  5000 'for 16ksps
  parameter4:=Samples
  if cogasm
    cogstop(cogasm~ -1)
  cogasm := cognew(@asmwav,@parameter1) + 1   
  
 
  n:=buffSize-1
  j:=buffsize*4   'number of bytes to read
  repeat while (j==buffsize*4)  'repeat until end of file
    if (buff1[noparse][[/noparse]n]==0)
      j:=sd.pread(@buff1, buffSize*4) 'read data words to input stereo buffer   
    if (buff2[noparse][[/noparse]n]==0)
      j:=sd.pread(@buff2, buffSize*4) 'read data words to input stereo buffer  
  sd.pclose
DAT
  ORG 0
ASMWAV
'load input parameters from hub to cog given address in par
        movd    :par,#pData1             
        mov     x,par
        mov     y,#4  'input 4 parameters
:par    rdlong  0,x
        add     :par,dlsb
        add     x,#4
        djnz    y,#:par
setup
        'setup output pins
        MOV DMaskR,#1
        ROL DMaskR,OPinR
        OR DIRA, DMaskR
        MOV DMaskL,#1
        ROL DMaskL,OPinL
        OR DIRA, DMaskL
        'setup counters
        OR CountModeR,OPinR
        MOV CTRA,CountModeR
        OR CountModeL,OPinL
        MOV CTRB,CountModeL
        'Wait for SPIN to fill table
        MOV WaitCount, CNT
        ADD WaitCount,BigWait
        WAITCNT WaitCount,#0
        'setup loop table
        MOV LoopCount,SizeBuff  
        'ROR LoopCount,#1    'for stereo
        MOV pData,pData1
        MOV nTable,#1
        'setup loop counter
        MOV WaitCount, CNT
        ADD WaitCount,dRate

MainLoop
        SUB nSamples,#1
        CMP nSamples,#0 wz
        IF_Z JMP #Done
        waitcnt WaitCount,dRate
        RDLONG Right,pData
        ADD Right,twos      'Going to cheat a bit with the LSBs here...  Probably shoud fix this!    
        MOV FRQA,Right
        ROL Right,#16       '16 LSBs are left channel...
        MOV FRQB,Right
        WRLONG Zero,pData
        ADD pData,#4
        'loop
        DJNZ LoopCount,#MainLoop
        
        MOV LoopCount,SizeBuff        
        'switch table       ?
        CMP nTable,#1 wz
        IF_Z JMP #SwitchToTable2
SwitchToTable1
        MOV nTable,#1
        MOV pData,pData1
        JMP #MainLoop
SwitchToTable2
        MOV nTable,#2
        MOV pData,pData2
        JMP #MainLoop
        
                
Done
         'now stop
        COGID thisCog
        COGSTOP thisCog          
'Working variables
thisCog long 0
x       long 0
y       long 0
dlsb    long    1 << 9
BigWait long 100000
twos    long $8000_8000
        
'Loop parameters
nTable  long 0
WaitCount long 0
pData   long 0
LoopCount long 0
SizeBuff long buffsize
'Left    long 0
Right   long 0
Zero    long 0          
'setup parameters
DMaskR  long 0 'right output mask
OPinR   long 10 'right channel output pin #
DMaskL  long 0 'left output mask 
OPinL   long 11 'left channel output pin #
CountModeR long %00011000_00000000_00000000_00001010
CountModeL long %00011000_00000000_00000000_00001011

'input parameters
pData1   long 0 'Address of first data table        
pData2   long 0 'Address of second data table
dRate    long 5000  'clocks between samples
nSamples long 2000

Thanks for all reply again...
Regards.


Post Edited (selcuk) : 6/12/2008 3:21:54 PM GMT

Comments

  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2008-06-12 15:15
    Wow.. Great minds think alike! [noparse]:)[/noparse]

    I'm working on the exact same thing, only with Playstation controller as the input device.
    Rayman will have to weigh in on the noise issue...

    When you post your code use [noparse][[/noparse]code ] and [noparse][[/noparse]/code ] (without the space) above and below your code.
    Strange.. Looking again, I can't figure out why the [noparse][[/noparse]code ] didn't take..

    OBC

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    New to the Propeller?

    Getting started with the Protoboard? - Propeller Cookbook 1.4
    Updates to the Cookbook are now posted to: Propeller.warrantyvoid.us
    Got an SD card? - PropDOS
    Need a part? Got spare electronics? - The Electronics Exchange
  • ColeyColey Posts: 1,110
    edited 2008-06-12 15:27
    Hey Ragip!!

    I'm glad you got it working!!

    A good win for your country Turkey last night!!! yeah.gif

    Regards,

    Coley

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    PropGFX Forums - The home of the Hybrid Development System and PropGFX Lite
  • selcukselcuk Posts: 7
    edited 2008-06-12 15:38
    Hi Coley;

    Yes, Turkey win the last night game, We have got too chance, I hope Our chance will continue all tournament...
    Thanks..

    Regards...
  • RaymanRayman Posts: 14,658
    edited 2008-06-12 15:54
    I don't think the pop sound at startup has been resolved although a couple people have tried all the ideas off the top of my head...

    Hopefully, I'll have time one day to fix that...
  • BaggersBaggers Posts: 3,019
    edited 2008-06-12 17:12
    selcuk,
    you're stopping and starting the cog, which is also turning the pin to input, then pausing while it loads the cog with the program, then sets it back to an output, what you'd be better off doing is in the sample player cog, have it check for a restart variable in hub ram, which then jumps back to the start and reloads the samples header info etc. if you see what I mean.
    this should help stop the crackling.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    http://www.propgfx.co.uk/forum/·home of the PropGFX Lite

    ·
  • Beau SchwabeBeau Schwabe Posts: 6,566
    edited 2008-06-12 21:18
    "I don't think the pop sound at startup has been resolved although a couple people have tried all the ideas off the top of my head..."
    ·
    I admit, that I have not looked at the code in detail, or how the wav files are sourced, but if you are not jumping past the 54 Byte header in the wav file, or if the software your wave files are generated from does not chop this header off, then you will hear a distinctive "POP" at the beginning of each wav file if you have a “RAW” wav file player.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
  • BaggersBaggers Posts: 3,019
    edited 2008-06-12 22:11
    yeah, good call Beau, that's another gotcha with playing wavs, but it does read the header into a header section, although only 44 bytes not 54 [noparse]:)[/noparse]

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    http://www.propgfx.co.uk/forum/·home of the PropGFX Lite

    ·
  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2008-06-12 23:03
    I was looking at the source code thinking, "Could it be that simple and we all just missed it?!" Leave it to Beau!

    OBC

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    New to the Propeller?

    Getting started with the Protoboard? - Propeller Cookbook 1.4
    Updates to the Cookbook are now posted to: Propeller.warrantyvoid.us
    Got an SD card? - PropDOS
    Need a part? Got spare electronics? - The Electronics Exchange
  • RaymanRayman Posts: 14,658
    edited 2008-06-12 23:28
    I'm pretty sure it's 44 bytes till the data...

    Here's one of my sources:

    http://ccrma.stanford.edu/CCRMA/Courses/422/projects/WaveFormat/
  • RaymanRayman Posts: 14,658
    edited 2008-06-12 23:44
    I'll just add that the reason I'm not particularly motivated to fix it myself is that for the application that this was developed for (making announcements over PA system) it actually sounds natural to have a little pop at the beginning!
  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2008-06-13 00:42
    It's not helping to advance the read 10...

    It almost sounds like the POP is at the end of the track on test8a.wav

    OBC

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    New to the Propeller?

    Getting started with the Protoboard? - Propeller Cookbook 1.4
    Updates to the Cookbook are now posted to: Propeller.warrantyvoid.us
    Got an SD card? - PropDOS
    Need a part? Got spare electronics? - The Electronics Exchange
  • Beau SchwabeBeau Schwabe Posts: 6,566
    edited 2008-06-13 04:50
    Ok, so it's 44 bytes... It's been awhile and I’ve slept several times since then.

    It's important to make sure that the audio is biased to a midpoint ($7F) at the BEGINNING and at the END of the wav file. This is especially true if you are concatenating several files to form words or phrases from phonetic sound bites. The "POP" could also be caused by this difference in beginning and end bias.

    Also, is the Propeller wav player·biased at $7F or does it start from $00 ? It should probably initialize from $7F instead if that is indeed the case.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.

    Post Edited (Beau Schwabe (Parallax)) : 6/13/2008 4:57:39 AM GMT
  • RaymanRayman Posts: 14,658
    edited 2008-06-13 13:27
    Somebody recently tried ramping up the DAC output to midlevel before playing and it didn't help. They also tried an external bias network without success...

    It could be that I picked a poor value (zero) for the flag to indicate a used up buffer... It could be that the beginning of the wav contains this value several times on both channels.

    Or, maybe the player is starting before the buffers are filled...
  • Forest GodfreyForest Godfrey Posts: 38
    edited 2008-06-13 20:42
    I've poked at this a bit because I am trying to design a theater sound playback system (with 8 channels - it'll probably use *three* Prop's!).

    I had the pop issue with Rayman's player which nothing I tried seemed to solve. I recently switched to an external DAC (AD1851) since that's what the final "product" will use. The pop on wave startup, of course, went away *but*... Turning an LED on and off causes a pop on both the "on" and the "off" leading me to wonder if the pop is really a power supply issue, not a digital side issue.

    I don't have an oscilloscope (yet) but that's the next thing I intend to look at the problem with.
  • RaymanRayman Posts: 14,658
    edited 2008-06-13 22:48
    Well, I guess that eliminates the player code as the problem!

    Maybe it is a power surge...
  • selcukselcuk Posts: 7
    edited 2008-06-14 05:39
    Thanks for all helps...

    If somebody solve this problem,please send to form..

    Regards..
  • Bob Lawrence (VE1RLL)Bob Lawrence (VE1RLL) Posts: 1,720
    edited 2008-07-04 04:02
    Interesting Popping comment

    "The disabling circuit 62 includes a pair of drivers coupled to a reference
    potential within the audio codec 14. In operation, the disabling circuit
    switches are closed such that the center points of the resistive networks
    of the 3-D audio circuitry are coupled to the reference potential. This
    prevents cross coupling of the line-in signals via the resistive network
    and keeps the left side of the rear output capacitors biased to prevent
    turn on popping sounds.
    In addition, the left and right channel drivers 58
    and 60 may be placed in a high impedance state. When multiple channel
    operation is indicated, the switches of the disabling circuit are opened
    thereby allowing the multiple channel driver 30 to provide surround sound
    audio signals to the line-in audio jack 16. I"

    Source:
    www.patentstorm.us/patents/6885900/description.html

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Aka: CosmicBob
  • BTL24BTL24 Posts: 54
    edited 2014-05-13 09:03
    Has anyone solved this DAC popping issue on start up and stopping of a wave player?

    I am particularly interested in a solution for the Propeller Activity Board's DACs.

    Thanks,
    Brian (BTL24)
  • kuronekokuroneko Posts: 3,623
    edited 2014-05-13 16:51
    Judging by the file date it's been a while when I last posted this (can't find the thread right now). It's not a 100% solution but it sounds alright to me. Basically it drives the outputs (from floating) in decreasing intervals until full on (with a 50% DUTY wave). See if that helps. The force'd bit of code is for comparison.
  • BTL24BTL24 Posts: 54
    edited 2014-05-14 08:59
    kuroneko wrote: »
    Judging by the file date it's been a while when I last posted this (can't find the thread right now). It's not a 100% solution but it sounds alright to me. Basically it drives the outputs (from floating) in decreasing intervals until full on (with a 50% DUTY wave). See if that helps. The force'd bit of code is for comparison.

    Thanks. I will have to investigate your code.

    I am using the C library wav_player and activity board and was hoping there may be a hardware fix...like biasing the low pass filter. The propeller output pins are pulled low (through 100K resistor) on activity board...so they aren't floating.

    Regards,
    Brian (BTL24)
  • PublisonPublison Posts: 12,366
    edited 2014-05-14 11:01
    BTL24 wrote: »
    Thanks. I will have to investigate your code.

    I am using the C library wav_player and activity board and was hoping there may be a hardware fix...like biasing the low pass filter. The propeller output pins are pulled low (through 100K resistor) on activity board...so they aren't floating.

    Regards,
    Brian (BTL24)

    Here's how Jon got it fixed in SPIN, (see post # 3)

    http://forums.parallax.com/showthread.php/148280-Prop-sound-quality-question
Sign In or Register to comment.