Changeset 3424


Ignore:
Timestamp:
Nov 14, 2012, 8:31:04 AM (3 years ago)
Author:
wmb
Message:

OLPC ARM audio test - workaround channel-swapping problem (trac #12096). Also added some experimental code.

Files:
5 edited

Legend:

Unmodified
Added
Removed
  • cpu/arm/olpc/sound.fth

    r3394 r3424  
    220220: master-rx  ( -- )  h# 0c sspa@  h# 8004.0001 or  h# 0c sspa!  ;  \ Master, on
    221221: slave-rx  ( -- )  h# 0c sspa@  h# 8000.0001 or  h# 0c sspa!  ;  \ Slave, on
     222: flush-rx  ( -- )  h# 0c sspa@  h# 8000.0004 or  h# 0c sspa!  ;  \ Hit the flush bit
    222223: disable-sspa-rx  ( -- )  h# 0c sspa@  h# 8000.0004 or  h# 4.0001 invert and    h# 0c sspa!  ;
    223224
     
    261262: master-tx  ( -- )  h# 8c sspa@  h# 8004.0001 or  h# 8c sspa!  ;  \ Master, on
    262263: slave-tx  ( -- )  h# 8c sspa@  h# 8000.0001 or  h# 8c sspa!  ;  \ Slave, on
     264: flush-tx  ( -- )  h# 8c sspa@  h# 8000.0004 or  h# 8c sspa!  ;  \ Hit the flush bit
    263265: disable-sspa-tx  ( -- )  h# 8c sspa@  h# 8000.0004 or  h# 4.0001 invert and  h# 8c sspa!  ;
    264266
     
    290292   out-desc to my-out-desc
    291293;
     294
     2950 value use-packmod?
     296
    292297: start-out-ring  ( -- )
    293298   1 h# 80 adma!           \ Enable DMA completion interrupts
    294    h# 0081.3020   h# 40 adma! \ 16 bits, pack, fetch next, enable, chain, hold dest, inc src
     299   h# 0080.3020   \ 16 bits, fetch next, enable, chain, hold dest, inc src
     300   use-packmod?  if  h# 1.0000 or   then
     301   h# 40 adma!
    295302;
    296303: stop-out-ring  ( -- )  h# 100000 h# 40 adma!  0 h# 80 adma!  ;
     
    305312   1 h# 84 adma!           \ Enable DMA completion interrupts
    306313\   h# 0081.3008   h# 44 adma! \ 16 bits, pack, fetch next, enable, chain, inc dest, hold src
    307    h# 00a1.31c8   h# 44 adma! \ 16 bits, pack, fetch next, enable, chain, burst32, inc dest, hold src
     314
     315   h# 00a0.31c8  \ 16 bits, fetch next, enable, chain, burst32, inc dest, hold src
     316   use-packmod?  if  h# 1.0000 or  then
     317   h# 44 adma!
    308318;
    309319: stop-in-ring  ( -- )  h# 100000 h# 44 adma!  0 h# 84 adma!  ;
    310320
     321: unpack-move  ( src dst packed-len -- )
     322   1 rshift  0  ?do       ( src dst )
     323      over i wa+ w@       ( src dst sample )
     324      over i la+ wa1+ w!  ( src dst )
     325   loop                   ( src dst )
     326   2drop                  ( )
     327;
     328
     329: pack-move  ( src dst packed-len -- )
     330   1 rshift  0  ?do       ( src dst )
     331      over i la+ wa1+ w@  ( src dst sample )
     332      over i wa+ w!       ( src dst )
     333   loop                   ( src dst )
     334   2drop                  ( )
     335;
     336
    311337: copy-out  ( -- )
    312    my-out-desc >r                        ( r: desc )
    313    out-len /audio-buf min                ( this-len r: desc )
    314    dup r@ l!                             ( this-len r: desc )
    315    out-adr  r@ la1+ l@  third  move      ( this-len r: desc )
    316    out-adr  over +  to out-adr           ( this-len r: desc )
    317    out-len  swap -  to out-len           ( r: desc )
     338   my-out-desc >r                          ( r: desc )
     339   use-packmod?  if
     340      out-len /audio-buf min                  ( this-packed-len r: desc )
     341      dup r@ l!                               ( this-packed-len r: desc )
     342      out-adr  r@ la1+ l@  third  move        ( this-packed-len r: desc )
     343   else
     344      out-len  /audio-buf 2/  min             ( this-packed-len r: desc )
     345      dup 2* r@ l!                            ( this-packed-len r: desc )
     346      out-adr  r@ la1+ l@  third  unpack-move ( this-packed-len r: desc )
     347   then
     348
     349   out-adr  over +  to out-adr             ( this-packed-len r: desc )
     350   out-len  swap -  to out-len             ( r: desc )
    318351   out-len  if
    319352      r> 3 la+ l@  to my-out-desc
     
    324357
    325358: copy-in  ( -- )
    326    in-len /audio-buf min                       ( this-len )
    327    my-in-desc 2 la+ l@  in-adr  third  move    ( this-len )
    328    in-adr  over +  to in-adr                   ( this-len )
    329    in-len  over -  to in-len                   ( this-len )
    330    drop                                        ( )
     359   use-packmod?  if
     360      in-len /audio-buf min                          ( this-packed-len )
     361      my-in-desc 2 la+ l@  in-adr  third  move       ( this-packed-len )
     362   else
     363      in-len  /audio-buf 2/ min                      ( this-packed-len )
     364      my-in-desc 2 la+ l@  in-adr  third  pack-move  ( this-packed-len )
     365   then
     366   in-adr  over +  to in-adr                      ( this-packed-len )
     367   in-len  over -  to in-len                      ( this-packed-len )
     368   drop                                           ( )
    331369   my-in-desc 3 la+ l@ to my-in-desc
    332370;
     
    568606   loop
    569607;
    570 : out-in  ( out-adr out-len in-adr in-len -- )
     608code startit  ( sspa-adr -- )
     609   set r0,#0x80f101f1
     610   set r1,#0x80f501f1
     611   str r0,[tos,#0x8c]
     612   str r1,[tos,#0x0c]
     613   pop tos,sp
     614c;
     615: startoutin  ( -- )  disable-interrupts  sspa-base startit  enable-interrupts  ;
     616: xstartoutin  ( -- )  slave-tx master-rx  ;
     617
     618: out-in0  ( out-adr out-len in-adr in-len -- )
    571619   open-out-in
    572620
     
    579627   \ Resetting the clock at this point seems to prevent intermittent channel
    580628   \ reversal on reception.
    581    audio-clock-on drop         ( ) \ This will mess up any frequency settings
     629\   audio-clock-on drop         ( ) \ This will mess up any frequency settings
    582630
    583631   setup-sspa-tx               ( )
     
    592640   start-out-ring              ( )
    593641
    594    master-rx                   ( )  \ Now the clock is on
    595    slave-tx                    ( )
     642   xstartoutin
     643\   slave-tx                    ( )
     644\   master-rx                   ( )  \ Now the clock is on
    596645
    597646   true to playing?
     
    613662   mono?  if  collapse-in  then  ( )
    614663;
     664
     665: out-in1  ( out-adr out-len in-adr in-len -- )
     666   open-out-in
     667
     668   to in-len0  to in-adr0      ( out-adr out-len )
     669   to out-len  to out-adr      ( )
     670
     671   in-adr0 to in-adr           ( )
     672   in-len0  mono?  if  2*  then  to in-len     
     673
     674   \ Resetting the clock at this point seems to prevent intermittent channel
     675   \ reversal on reception.
     676\   audio-clock-on drop         ( ) \ This will mess up any frequency settings
     677
     678   make-out-ring               ( )
     679   copy-out                    ( )  \ Prefill the first Tx buffer
     680   out-len  if  copy-out  then ( )  \ Prefill the second Tx buffer
     681
     682   setup-sspa-rx               ( )
     683   make-in-ring                ( )
     684   start-in-ring               ( )
     685   master-rx                   ( )  \ Now the clock is on
     686
     687   start-out-ring              ( )
     688   setup-sspa-tx               ( )
     689   slave-tx                    ( )
     690
     691   true to playing?
     692
     693   begin  in-len playing? or  while  ( )
     694      in-ready?  if  copy-in  then   ( )
     695      playing?  if  ?end-playing  then   ( )
     696   repeat                      ( )
     697   disable-sspa-rx             ( )
     698   disable-sspa-tx             ( )
     699
     700   stop-in-ring
     701   stop-out-ring
     702
     703   reset-rx
     704   reset-tx
     705
     706   close-out-in
     707   mono?  if  collapse-in  then  ( )
     708;
     709
     710d# 20 value audio-dly
     711: out-in2  ( out-adr out-len in-adr in-len -- )
     712   open-out-in
     713
     714   to in-len0  to in-adr0      ( out-adr out-len )
     715   to out-len  to out-adr      ( )
     716
     717   in-adr0 to in-adr           ( )
     718   in-len0  mono?  if  2*  then  to in-len     
     719
     720   \ Resetting the clock at this point seems to prevent intermittent channel
     721   \ reversal on reception.
     722\   audio-clock-on drop         ( ) \ This will mess up any frequency settings
     723
     724   setup-sspa-tx               ( )
     725   setup-sspa-rx               ( )
     726
     727   make-in-ring                ( )
     728   make-out-ring               ( )
     729   copy-out                    ( )  \ Prefill the first Tx buffer
     730   out-len  if  copy-out  then ( )  \ Prefill the second Tx buffer
     731
     732   xstartoutin
     733
     734   audio-dly us
     735   flush-rx
     736   flush-tx
     737   start-in-ring               ( )
     738   start-out-ring              ( )
     739
     740
     741   true to playing?
     742
     743   begin  in-len playing? or  while  ( )
     744      in-ready?  if  copy-in  then   ( )
     745      playing?  if  ?end-playing  then   ( )
     746   repeat                      ( )
     747   disable-sspa-rx             ( )
     748   disable-sspa-tx             ( )
     749
     750   stop-in-ring
     751   stop-out-ring
     752
     753   reset-rx
     754   reset-tx
     755
     756   close-out-in
     757   mono?  if  collapse-in  then  ( )
     758;
     759
     760defer out-in  ' out-in0 to out-in
     761
     7620 [if]
     763working recipe:  only one out-in in test-common
     764out-in2
     765disable-interrupts before audio-clock-on and enable after reset-rx
     766dly 73 us
     767read and discard rx fifo depth before flush-rx
     768
     769also works with dly 10 us
     770reliably swaps with dly 1 us
     771swaps with dly 5
     772swap with dly 7
     773not swap with dly 8
     774
     775Hmmm, maybe the basic issue is the double out-in in test-common -
     776Try out-in0 using one out-in
     777Try out-in2 without read/discard fifo depth using one out-in
     778
     779Swap alternates every 10 or so us, flipping at about 8 or 9 mod 10
     780An extra 2 samples appear ever 10 or so us, at about 1 or 2 mod 10
     781
     78204 us is stable with swapping
     78314 us is stable with no swapping
     784
     785If you remove flush-rx from fr  ( : fr 1c sspa@ foo !  flush-rx ; )
     786swapping always happens - 04, 14, 24 us all swap
     787   This is because when you flush-rx with fifo depth 2, 6, a, etc,
     788   that loses an odd number of channel samples
     789[then]
    615790
    6167910 [if]  \ Interactive test words for out-in
     
    730905fload ${BP}/dev/hdaudio/test.fth
    731906warning !
     907
     908: wro 
     909   wlan-reset-gpio# gpio-dir-in  \ So it doesn't fight the cross-wire
     910;
     911: input-normal  ( -- )
     912   \ Reconnect pin 36 to WLAN_RESET#
     913   wlan-reset-gpio# af@ 7 invert and  wlan-reset-gpio# af!
     914
     915   \ Reconnect pin 26 back to SSPA1 I2S_DATA_IN
     916   d# 28 af@  7 invert and  1 or  d# 28 af!
     917;
     918: input-from-lrclk  ( -- )
     919   \ Move pin 26 from SSPA1 I2S_DATA_IN to SSPA2 I2S_DATA_IN
     920   \ so it doesn't conflict with pin 36.
     921   d# 28 af@  7 invert and  3 or  d# 28 af!
     922
     923   \ Connect pin 36 to SSPA1 I2S_DATA_IN
     924   wlan-reset-gpio# af@ 7 invert and  2 or  wlan-reset-gpio# af!
     925;
    732926
    733927finish-device
  • cpu/x86/pc/olpc/plot.fth

    r2740 r3424  
    3131;
    3232
    33 : wave0  ( -- )  screen-height wave-height -  ;
     330 value wave#
     34: set-wave#  ( n -- )  to wave#  ;
     35
     36: wave0  ( -- )  screen-height wave# 2* 1+  wave-height *  -  ;
    3437
    3538: clear-waveform  ( -- )
  • dev/geode/ac97/selftest.fth

    r2019 r3424  
    127127   bounds  ?do  i w@  i wa1+ w!  /l +loop
    128128;
     129: copy-pack  ( adr len -- )
     130   0 ?do              ( adr )
     131      dup i + w@      ( adr w )
     132      dup wljoin      ( adr l )
     133      over i 2/ + l!  ( adr )
     134   8 +loop            ( adr )
     135   drop               ( )
     136;
    129137
    130138\ The recording data format is stereo, but usually there is only one mic.
     
    141149;
    142150
     1510 value skip-sweep?
    143152: selftest  ( -- error? )
    144153   open 0=  if  ." Failed to open /audio" cr true exit  then
    145154   wav-test
    146155   record-len la1+  " dma-alloc" $call-parent to record-base
    147    sweep-test
     156   skip-sweep? 0=  if  sweep-test  then
    148157   mic-test
    149158   record-base record-len la1+  " dma-free" $call-parent
     
    151160   false
    152161;
     162alias st1 selftest
    153163
    154164\ LICENSE_BEGIN
  • dev/hdaudio/noiseburst.fth

    r2740 r3424  
    309309      i wa1+ <w@ over   - h# 7fff min  h# -7fff max  i wa1+ w!
    310310   /l +loop           ( mean )
    311    drop               ( )
     311   2drop              ( )
    312312;
    313313: lose-6db  ( adr len -- )
     
    448448: rb  load-base  1meg +  ;
    449449
     450: pb+ pb wa1+  ;
     451: rb+ rb wa1+  ;
     452
    450453: d..  ( -- )  <# # # # # ascii . hold # # # # ascii . hold #s #> type space  ;
    451454: find-max-mono  ( -- )
     
    460463
    461464: #samples  ( -- n )  /pb 4 / h# 100 -  ;
    462 : left-range   ( -- stereo-adr mono-adr #points )  pb      rb  #samples  ;
    463 : right-range  ( -- stereo-adr mono-adr #points )  pb wa1+ rb  #samples  ;
    464 : left-stereo-range   ( -- stereo-adr mono-adr #points )  pb      rb        #samples  ;
    465 : right-stereo-range  ( -- stereo-adr mono-adr #points )  pb wa1+ rb  wa1+  #samples  ;
     465
     466defer mono-rb  ' rb  to mono-rb
     467
     468defer left-rb  ' rb  to left-rb
     469defer right-rb ' rb+ to right-rb
     470
     471defer left-pb  ' pb  to left-pb
     472defer right-pb ' pb+ to right-pb
     473
     474: swap-lr-pb  ( -- )
     475   ['] pb  to right-pb
     476   ['] pb+ to left-pb
     477;
     478: unswap-lr-pb  ( -- )
     479   ['] pb  to left-pb
     480   ['] pb+ to right-pb
     481;
     482
     483: left-range   ( -- stereo-adr mono-adr #points )  left-pb   mono-rb  #samples  ;
     484: right-range  ( -- stereo-adr mono-adr #points )  right-pb  mono-rb  #samples  ;
     485: left-stereo-range   ( -- stereo-adr mono-adr #points )  left-pb    left-rb   #samples  ;
     486: right-stereo-range  ( -- stereo-adr mono-adr #points )  right-pb   right-rb  #samples  ;
    466487
    467488: fixture-analyze-left  ( -- )
     
    538559: calc-sm-impulse  ( offset -- adr )  \ offset is 0 for left or 2 for right
    539560   ?alloc-impulse-buf
    540    pb +  rb  #samples                         ( adr1 adr2 #samples )
    541    #impulse-response 0  do
     561   if  right-range  else  left-range  then    ( adr1 adr2 #samples )
     562   #impulse-response 0  do                    ( adr1 adr2 #samples )
    542563      3dup swap i wa+ swap stereo-mono-covar  ( adr1 adr2 #samples d.covar )
    543564      d# 500,000,000 m/mod nip                ( adr1 adr2 #samples n.covar )
     
    548569;
    549570: calc-stereo-impulse  ( offset -- adr )  \ offset is 0 for left or 2 for right
    550    ?alloc-impulse-buf
    551    dup pb +  swap rb +  #samples              ( adr1 adr2 #samples )
    552    #impulse-response 0  do
     571   ?alloc-impulse-buf                         ( offset )
     572   if  right-stereo-range  else  left-stereo-range  then  ( adr1 adr2 #samples )
     573   #impulse-response 0  do                    ( adr1 adr2 #samples )
    553574      3dup swap i la+ swap stereo-covar       ( adr1 adr2 #samples d.covar )
    554575      d#  50,000,000 m/mod nip                ( adr1 adr2 #samples n.covar )
     
    576597\ This version puts the tone first into the left channel for
    577598\ half the time, then into the right channel for the remainder
     599
     600\ This version puts a tone at one frequency in the left channel
     601\ and a tone at twice that frequency in the right channel
     602
    578603: make-2tones  ( adr len freq sample-rate -- )
     604   2over erase          ( adr len freq sample-rate )
    579605   2dup set-freq        ( adr len freq sample-rate )
    580606
     
    608634   pb /pb lose-6db
    609635   pb /pb  rb /rb
    610    disable-interrupts
     636\   disable-interrupts
    611637;
    612638: analyze-signal  ( -- error? )
    613    enable-interrupts
     639\   enable-interrupts
    614640   rb /rb fix-dc
    615641   false                        ( error? )
    616642   analyze-left  if             ( error? )
    617       ." Left channel failure" cr
    618643      1+
    619644   then
    620645
    621646   analyze-right  if
    622       ." Right channel failure" cr
    623647      2+
    624648   then
  • dev/hdaudio/test.fth

    r2814 r3424  
    9696   " prepare-signal" $call-analyzer  ( pb /pb rb /rb )
    9797   \ First shorter run lets the input channel settle
    98    2over 4 /  2over 4 /  out-in      ( pb /pb rb /rb )
     98\   2over 4 /  2over 4 /  out-in      ( pb /pb rb /rb )
    9999   out-in                            ( )
    100    " analyze-signal" $call-analyzer  ( okay? )
    101 ;
     100   " analyze-signal" $call-analyzer  ( error? )
     101;
     102: .test-error  ( error? -- error? )
     103    dup 1 and  if   ." Left channel failure" cr  then
     104    dup 2 and  if   ." Right channel failure" cr  then
     105;
     106
    102107false value plot?  \ Set to true to plot the impulse response, for debugging
    103108: plot-impulse  ( adr -- )
    104109   d# 600              ( adr #samples )
    105    " 0 set-fg  h# ffffffff set-bg single-drawing clear-drawing wave" evaluate
    106    key ascii d = if debug-me then
    107 ;
    108 
    109 : test-with-case  ( -- )
     110   " 0 set-fg  h# ffffffff set-bg single-drawing ( clear-drawing ) wave" evaluate
     111\   key ascii d = if debug-me then
     112;
     113: plot-impulse0  ( adr -- )   0 " set-wave#" $call-screen plot-impulse  ;
     114: plot-impulse1  ( adr -- )   1 " set-wave#" $call-screen plot-impulse  ;
     115
     116: test-with-case  ( -- error? )
    110117\   " setup-case" $call-analyzer
    111118\   xxx - this needs to use the internal speakers and mic even though the loopback cable is attached
     
    115122   output-test-settings  case-test-volume set-volume
    116123   ." Testing internal speakers and microphone" cr
    117    " setup-case" test-common
     124   " setup-case" test-common  .test-error
    118125   false to force-speakers?  false to force-internal-mic?
    119126   plot?  if
    120       0 " calc-sm-impulse" $call-analyzer  plot-impulse
    121       2 " calc-sm-impulse" $call-analyzer  plot-impulse
     127      0 " calc-sm-impulse" $call-analyzer  plot-impulse0
     128      2 " calc-sm-impulse" $call-analyzer  plot-impulse1
    122129   then
    123130;
     
    128135   output-test-settings  fixture-test-volume set-volume  \ -23 prevents obvious visible clipping
    129136   ." Testing internal speakers and microphone with fixture" cr
    130    " setup-fixture" test-common
     137   " setup-fixture" test-common  .test-error
    131138   false to force-speakers?  false to force-internal-mic?
    132139   plot?  if
    133       0 " calc-sm-impulse" $call-analyzer  plot-impulse
    134       2 " calc-sm-impulse" $call-analyzer  plot-impulse
    135    then
     140      0 " calc-sm-impulse" $call-analyzer  plot-impulse0
     141      2 " calc-sm-impulse" $call-analyzer  plot-impulse1
     142   then
     143;
     144true value allow-swapping?
     145: ?try-swapped   ( error? -- error?' )
     146   allow-swapping?  0=  if  exit  then   ( error? )
     147   dup  if                               ( error? )
     148       " swap-lr-pb" $call-analyzer      ( error? )
     149       " analyze-signal" $call-analyzer  ( error? swapped-error? )
     150       " unswap-lr-pb" $call-analyzer    ( error? swapped-error? )
     151       0=  if                            ( error? )
     152          \ If swapping left and right "fixes" the problem, we
     153          \ don't report an error.  This works around a hard-to-fix
     154          \ random channel-swapping problem with Marvell MMP3.
     155          ." Channel swap!" cr           ( error? )
     156          drop false                     ( 0 )
     157       then                              ( error? )
     158   then                                  ( error? )
    136159;
    137160: test-with-loopback  ( -- error? )
     
    140163   output-test-settings  loopback-test-volume set-volume
    141164   ." Testing headphone and microphone jacks with loopback cable" cr
    142    " setup-loopback" test-common
     165   " setup-loopback" test-common         ( error? )
     166   ?try-swapped
     167   .test-error
     168
    143169   plot?  if
    144       0 " calc-stereo-impulse" $call-analyzer  plot-impulse
    145       2 " calc-stereo-impulse" $call-analyzer  plot-impulse
     170      0 " calc-stereo-impulse" $call-analyzer  plot-impulse0
     171      2 " calc-stereo-impulse" $call-analyzer  plot-impulse1
    146172   then
    147173;
Note: See TracChangeset for help on using the changeset viewer.