Author: wmb Date: Sat Jun 4 22:40:52 2011 New Revision: 2246 URL: http://tracker.coreboot.org/trac/openfirmware/changeset/2246
Log: OLPC XO-1.75 - checkin audio changes in support of trac #10886. Autocorrelation has not been tested yet, but the changes are in place and compile cleanly.
Modified: cpu/arm/muldiv.fth cpu/arm/olpc/1.75/alc5631.fth cpu/arm/olpc/1.75/fw.bth cpu/arm/olpc/1.75/sound.fth dev/hdaudio/noiseburst.fth dev/hdaudio/test.fth
Modified: cpu/arm/muldiv.fth ============================================================================== --- cpu/arm/muldiv.fth Sat Jun 4 22:25:49 2011 (r2245) +++ cpu/arm/muldiv.fth Sat Jun 4 22:40:52 2011 (r2246) @@ -336,6 +336,15 @@ mov tos,r5 c;
+: m/mod (s d# n1 -- rem quot ) + dup >r 2dup xor >r >r dabs r@ abs um/mod + swap r> 0< if negate then + swap r> 0< if + negate over if 1- r@ rot - swap then + then + r> drop +; + : / ( dividend divisor -- quotient ) /mod nip ; : mod ( dividend divisor -- modulus ) /mod drop ; : */mod ( n1 n2 n3 -- n.mod n.quot ) >r m* r> fm/mod ;
Modified: cpu/arm/olpc/1.75/alc5631.fth ============================================================================== --- cpu/arm/olpc/1.75/alc5631.fth Sat Jun 4 22:25:49 2011 (r2245) +++ cpu/arm/olpc/1.75/alc5631.fth Sat Jun 4 22:40:52 2011 (r2246) @@ -92,8 +92,10 @@ : set-headphone-volume ( n -- ) \ DONE gain>lr if h# 8080 then h# 9f9f 4 codec-field ; + +false value force-speakers? : set-volume ( n -- ) - headphones-inserted? if + headphones-inserted? force-speakers? 0= and if set-headphone-volume else set-speaker-volume @@ -105,6 +107,11 @@ d# 0 constant default-speaker-volume \ 0 dB - range is -46.5 to +12 d# -10 constant default-headphone-volume \ -10 dB - range is -46.5 to 0
+: speakers-on ( -- ) default-speaker-volume set-speaker-volume ; +: speakers-off ( -- ) d# -100 set-speaker-volume ; +: headphones-on ( -- ) default-headphone-volume set-headphone-volume ; +: headphones-off ( -- ) d# -100 set-headphone-volume ; + : adc-mute-all ( -- ) h# f0f0 h# 14 codec! ; : adc-mute-mic ( -- ) h# 4040 h# 14 codec-set ; : adc-unmute-mic ( -- ) h# 4040 h# 14 codec-clr ; @@ -172,12 +179,12 @@ : mic+20db ( -- ) d# 20 set-mic-gain ; : set-default-gains ( -- ) output-config - headphones-inserted? if - default-headphone-volume set-headphone-volume - mute-speakers + headphones-inserted? force-speakers? 0= and if + headphones-on + speakers-off else - default-speaker-volume set-speaker-volume - mute-headphones + speakers-on + headphones-off then default-dac-gain set-dac-gain default-mic-gain set-mic-gain
Modified: cpu/arm/olpc/1.75/fw.bth ============================================================================== --- cpu/arm/olpc/1.75/fw.bth Sat Jun 4 22:25:49 2011 (r2245) +++ cpu/arm/olpc/1.75/fw.bth Sat Jun 4 22:40:52 2011 (r2246) @@ -81,8 +81,7 @@
standalone? if disable-interrupts - d# 1000 -\ i-key-wait if +\ d# 1000 i-key-wait if rotate-button? if protect-fw ." Interacting" cr hex interact @@ -300,7 +299,7 @@
fload ${BP}/ofw/core/countdwn.fth \ Startup countdown
-\ fload ${BP}/dev/hdaudio/noiseburst.fth \ audio-test support package +fload ${BP}/dev/hdaudio/noiseburst.fth \ audio-test support package
: console-start ( -- ) install-mux-io
Modified: cpu/arm/olpc/1.75/sound.fth ============================================================================== --- cpu/arm/olpc/1.75/sound.fth Sat Jun 4 22:25:49 2011 (r2245) +++ cpu/arm/olpc/1.75/sound.fth Sat Jun 4 22:40:52 2011 (r2246) @@ -206,8 +206,11 @@ [ifdef] cl2-a1 fload ${BP}/cpu/arm/olpc/1.75/alc5624.fth \ Realtek ALC5624 CODEC [else] -: headphones-inserted? ( -- flag ) d# 97 gpio-pin@ ; -: microphone-inserted? ( -- flag ) d# 96 gpio-pin@ ; +d# 97 constant headphone-jack +d# 96 constant external-mic +: pin-sense? ( gpio# -- flag ) gpio-pin@ ; +: headphones-inserted? ( -- flag ) headphone-jack pin-sense? ; +: microphone-inserted? ( -- flag ) external-mic pin-sense? ;
fload ${BP}/cpu/arm/olpc/1.75/alc5631.fth \ Realtek ALC5631Q CODEC [then] @@ -480,6 +483,10 @@ fload ${BP}/forth/lib/tones.fth fload ${BP}/dev/geode/ac97/selftest.fth
+false value force-internal-mic? \ Can't be implemented on XO-1.75 +2 value #channels +fload ${BP}/dev/hdaudio/test.fth + end-package
\ LICENSE_BEGIN
Modified: dev/hdaudio/noiseburst.fth ============================================================================== --- dev/hdaudio/noiseburst.fth Sat Jun 4 22:25:49 2011 (r2245) +++ dev/hdaudio/noiseburst.fth Sat Jun 4 22:40:52 2011 (r2246) @@ -3,6 +3,122 @@
support-package: audio-test
+[ifdef] arm-assembler +code mono-covar ( adr1 adr2 #samples -- d.sum ) + ldmia sp!,{r1,r2} \ tos: #samples, r1: adr2, r2: adr1 + + adds tos,tos,tos \ #bytes + + psheq tos,sp \ Return 0. if #samples is 0 + nxteq + + mov r3,#0 \ Zero accumulator + mov r4,#0 + + dec tos,#2 + begin + ldrsh r5,[r1,tos] + ldrsh r6,[r2,tos] + smlal r3,r4,r5,r6 + decs tos,#2 + 0< until + + psh r3,sp + mov tos,r4 +c; +code stereo-mono-covar ( stereo-adr1 mono-adr2 #samples -- d.sum ) + ldmia sp!,{r1,r2} \ tos: #samples, r1: adr2, r2: adr1 + + adds tos,tos,tos \ #bytes for mono samples + add r8,tos,tos \ Index for stereo samples + + psheq tos,sp \ Return 0. if #samples is 0 + nxteq + + mov r3,#0 \ Zero accumulator + mov r4,#0 + + dec tos,#2 + dec r8,#4 + begin + ldrsh r5,[r1,tos] \ Mono + ldrsh r6,[r2,r8] \ Stereo sample + dec r8,#4 + smlal r3,r4,r5,r6 + decs tos,#2 + 0< until + + psh r3,sp + mov tos,r4 +c; +code stereo-covar ( stereo-adr1 stereo-adr2 #samples -- d.sum ) + ldmia sp!,{r1,r2} \ tos: #samples, r1: adr2, r2: adr1 + + movs tos,tos,lsl #2 \ #bytes + + psheq tos,sp \ Return 0. if #samples is 0 + nxteq + + mov r3,#0 \ Zero accumulator + mov r4,#0 + + dec tos,#4 + begin + ldrsh r5,[r1,tos] + ldrsh r6,[r2,tos] + smlal r3,r4,r5,r6 + decs tos,#4 \ Stride is 4 + 0< until + + psh r3,sp + mov tos,r4 +c; +code mono-wsum ( adr #samples -- d.sum ) + pop r1,sp \ tos: len, r1: adr + movs tos,tos,lsl #1 + + psheq tos,sp \ Return 0. if #samples is 0 + nxteq + + mov r3,#0 \ Zero accumulator + mov r4,#0 + + dec tos,#2 + begin + ldrsh r5,[r1,tos] + mov r6,r5,asr #31 \ Sign extend long word to 64 bits + adds r3,r3,r5 + adc r4,r4,r6 + decs tos,#2 + 0< until + + psh r3,sp + mov tos,r4 +c; +code stereo-wsum ( adr #samples -- d.sum ) + pop r1,sp \ tos: len, r1: adr + movs tos,tos,lsl #2 + + psheq tos,sp \ Return 0. if #samples is 0 + nxteq + + mov r3,#0 \ Zero accumulator + mov r4,#0 + + dec tos,#4 + begin + ldrsh r5,[r1,tos] + mov r6,r5,asr #31 \ Sign extend long word to 64 bits + adds r3,r3,r5 + adc r4,r4,r6 + decs tos,#4 + 0< until + + psh r3,sp + mov tos,r4 +c; +[then] +[ifdef] x86-assembler code mono-covar ( adr1 adr2 #samples -- d.sum ) cx pop
@@ -39,7 +155,7 @@ bx push ax push c; -code stereo-mono-covar ( stereo-adr1 stereo-adr2 #samples -- d.sum ) +code stereo-mono-covar ( stereo-adr1 mono-adr2 #samples -- d.sum ) cx pop
ax pop \ adr2 in ax @@ -169,6 +285,7 @@ bx push ax push c; +[then] : mono-wmean ( adr len -- n ) 2/ tuck mono-wsum ( d.sum len ) rot m/mod nip ( mean ) @@ -419,7 +536,7 @@ defer fix-dc
: prepare-signal ( -- out-adr, len in-adr,len ) - pb /pb bounds do random-byte i c! loop + pb /pb bounds do random-long i l! /l +loop pb /pb -stereo-wmean pb wa1+ /pb -stereo-wmean pb /pb lose-6db
Modified: dev/hdaudio/test.fth ============================================================================== --- dev/hdaudio/test.fth Sat Jun 4 22:25:49 2011 (r2245) +++ dev/hdaudio/test.fth Sat Jun 4 22:40:52 2011 (r2246) @@ -105,12 +105,20 @@ " 0 set-fg h# ffff set-bg single-drawing clear-drawing wave" evaluate key ascii d = if debug-me then ; -: input-common-settings ( -- ) +defer input-common-settings +defer output-common-settings +[ifdef] with-adc +\ XXX this is hd-audio specific. Factore it out +: (input-common-settings) ( -- ) open-in 48kHz 16bit with-adc d# 73 input-gain ; -: output-common-settings ( -- ) +' (input-common-settings) to input-common-settings +: (output-common-settings) ( -- ) open-out 48kHz 16bit stereo ; +' (output-common-settings) to output-common-settings +[then] + : test-with-case ( -- ) " setup-case" $call-analyzer \ xxx - this needs to use the internal speakers and mic even though the loopback cable is attached
openfirmware@openfirmware.info