Changeset 3424
- Timestamp:
- Nov 14, 2012 8:31:04 AM (6 months ago)
- Files:
-
- 5 edited
-
cpu/arm/olpc/sound.fth (modified) (10 diffs)
-
cpu/x86/pc/olpc/plot.fth (modified) (1 diff)
-
dev/geode/ac97/selftest.fth (modified) (3 diffs)
-
dev/hdaudio/noiseburst.fth (modified) (7 diffs)
-
dev/hdaudio/test.fth (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
cpu/arm/olpc/sound.fth
r3394 r3424 220 220 : master-rx ( -- ) h# 0c sspa@ h# 8004.0001 or h# 0c sspa! ; \ Master, on 221 221 : 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 222 223 : disable-sspa-rx ( -- ) h# 0c sspa@ h# 8000.0004 or h# 4.0001 invert and h# 0c sspa! ; 223 224 … … 261 262 : master-tx ( -- ) h# 8c sspa@ h# 8004.0001 or h# 8c sspa! ; \ Master, on 262 263 : 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 263 265 : disable-sspa-tx ( -- ) h# 8c sspa@ h# 8000.0004 or h# 4.0001 invert and h# 8c sspa! ; 264 266 … … 290 292 out-desc to my-out-desc 291 293 ; 294 295 0 value use-packmod? 296 292 297 : start-out-ring ( -- ) 293 298 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! 295 302 ; 296 303 : stop-out-ring ( -- ) h# 100000 h# 40 adma! 0 h# 80 adma! ; … … 305 312 1 h# 84 adma! \ Enable DMA completion interrupts 306 313 \ 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! 308 318 ; 309 319 : stop-in-ring ( -- ) h# 100000 h# 44 adma! 0 h# 84 adma! ; 310 320 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 311 337 : 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 ) 318 351 out-len if 319 352 r> 3 la+ l@ to my-out-desc … … 324 357 325 358 : 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 ( ) 331 369 my-in-desc 3 la+ l@ to my-in-desc 332 370 ; … … 568 606 loop 569 607 ; 570 : out-in ( out-adr out-len in-adr in-len -- ) 608 code 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 614 c; 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 -- ) 571 619 open-out-in 572 620 … … 579 627 \ Resetting the clock at this point seems to prevent intermittent channel 580 628 \ reversal on reception. 581 audio-clock-on drop ( ) \ This will mess up any frequency settings629 \ audio-clock-on drop ( ) \ This will mess up any frequency settings 582 630 583 631 setup-sspa-tx ( ) … … 592 640 start-out-ring ( ) 593 641 594 master-rx ( ) \ Now the clock is on 595 slave-tx ( ) 642 xstartoutin 643 \ slave-tx ( ) 644 \ master-rx ( ) \ Now the clock is on 596 645 597 646 true to playing? … … 613 662 mono? if collapse-in then ( ) 614 663 ; 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 710 d# 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 760 defer out-in ' out-in0 to out-in 761 762 0 [if] 763 working recipe: only one out-in in test-common 764 out-in2 765 disable-interrupts before audio-clock-on and enable after reset-rx 766 dly 73 us 767 read and discard rx fifo depth before flush-rx 768 769 also works with dly 10 us 770 reliably swaps with dly 1 us 771 swaps with dly 5 772 swap with dly 7 773 not swap with dly 8 774 775 Hmmm, maybe the basic issue is the double out-in in test-common - 776 Try out-in0 using one out-in 777 Try out-in2 without read/discard fifo depth using one out-in 778 779 Swap alternates every 10 or so us, flipping at about 8 or 9 mod 10 780 An extra 2 samples appear ever 10 or so us, at about 1 or 2 mod 10 781 782 04 us is stable with swapping 783 14 us is stable with no swapping 784 785 If you remove flush-rx from fr ( : fr 1c sspa@ foo ! flush-rx ; ) 786 swapping 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] 615 790 616 791 0 [if] \ Interactive test words for out-in … … 730 905 fload ${BP}/dev/hdaudio/test.fth 731 906 warning ! 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 ; 732 926 733 927 finish-device -
cpu/x86/pc/olpc/plot.fth
r2740 r3424 31 31 ; 32 32 33 : wave0 ( -- ) screen-height wave-height - ; 33 0 value wave# 34 : set-wave# ( n -- ) to wave# ; 35 36 : wave0 ( -- ) screen-height wave# 2* 1+ wave-height * - ; 34 37 35 38 : clear-waveform ( -- ) -
dev/geode/ac97/selftest.fth
r2019 r3424 127 127 bounds ?do i w@ i wa1+ w! /l +loop 128 128 ; 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 ; 129 137 130 138 \ The recording data format is stereo, but usually there is only one mic. … … 141 149 ; 142 150 151 0 value skip-sweep? 143 152 : selftest ( -- error? ) 144 153 open 0= if ." Failed to open /audio" cr true exit then 145 154 wav-test 146 155 record-len la1+ " dma-alloc" $call-parent to record-base 147 s weep-test156 skip-sweep? 0= if sweep-test then 148 157 mic-test 149 158 record-base record-len la1+ " dma-free" $call-parent … … 151 160 false 152 161 ; 162 alias st1 selftest 153 163 154 164 \ LICENSE_BEGIN -
dev/hdaudio/noiseburst.fth
r2740 r3424 309 309 i wa1+ <w@ over - h# 7fff min h# -7fff max i wa1+ w! 310 310 /l +loop ( mean ) 311 drop( )311 2drop ( ) 312 312 ; 313 313 : lose-6db ( adr len -- ) … … 448 448 : rb load-base 1meg + ; 449 449 450 : pb+ pb wa1+ ; 451 : rb+ rb wa1+ ; 452 450 453 : d.. ( -- ) <# # # # # ascii . hold # # # # ascii . hold #s #> type space ; 451 454 : find-max-mono ( -- ) … … 460 463 461 464 : #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 466 defer mono-rb ' rb to mono-rb 467 468 defer left-rb ' rb to left-rb 469 defer right-rb ' rb+ to right-rb 470 471 defer left-pb ' pb to left-pb 472 defer 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 ; 466 487 467 488 : fixture-analyze-left ( -- ) … … 538 559 : calc-sm-impulse ( offset -- adr ) \ offset is 0 for left or 2 for right 539 560 ?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 ) 542 563 3dup swap i wa+ swap stereo-mono-covar ( adr1 adr2 #samples d.covar ) 543 564 d# 500,000,000 m/mod nip ( adr1 adr2 #samples n.covar ) … … 548 569 ; 549 570 : 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 ) 553 574 3dup swap i la+ swap stereo-covar ( adr1 adr2 #samples d.covar ) 554 575 d# 50,000,000 m/mod nip ( adr1 adr2 #samples n.covar ) … … 576 597 \ This version puts the tone first into the left channel for 577 598 \ 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 578 603 : make-2tones ( adr len freq sample-rate -- ) 604 2over erase ( adr len freq sample-rate ) 579 605 2dup set-freq ( adr len freq sample-rate ) 580 606 … … 608 634 pb /pb lose-6db 609 635 pb /pb rb /rb 610 disable-interrupts636 \ disable-interrupts 611 637 ; 612 638 : analyze-signal ( -- error? ) 613 enable-interrupts639 \ enable-interrupts 614 640 rb /rb fix-dc 615 641 false ( error? ) 616 642 analyze-left if ( error? ) 617 ." Left channel failure" cr618 643 1+ 619 644 then 620 645 621 646 analyze-right if 622 ." Right channel failure" cr623 647 2+ 624 648 then -
dev/hdaudio/test.fth
r2814 r3424 96 96 " prepare-signal" $call-analyzer ( pb /pb rb /rb ) 97 97 \ 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 ) 99 99 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 102 107 false value plot? \ Set to true to plot the impulse response, for debugging 103 108 : plot-impulse ( adr -- ) 104 109 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? ) 110 117 \ " setup-case" $call-analyzer 111 118 \ xxx - this needs to use the internal speakers and mic even though the loopback cable is attached … … 115 122 output-test-settings case-test-volume set-volume 116 123 ." Testing internal speakers and microphone" cr 117 " setup-case" test-common 124 " setup-case" test-common .test-error 118 125 false to force-speakers? false to force-internal-mic? 119 126 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 122 129 then 123 130 ; … … 128 135 output-test-settings fixture-test-volume set-volume \ -23 prevents obvious visible clipping 129 136 ." Testing internal speakers and microphone with fixture" cr 130 " setup-fixture" test-common 137 " setup-fixture" test-common .test-error 131 138 false to force-speakers? false to force-internal-mic? 132 139 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 ; 144 true 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? ) 136 159 ; 137 160 : test-with-loopback ( -- error? ) … … 140 163 output-test-settings loopback-test-volume set-volume 141 164 ." 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 143 169 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 146 172 then 147 173 ;
Note: See TracChangeset
for help on using the changeset viewer.
