[OpenBIOS] r410 - cpu/x86 cpu/x86/pc/olpc dev/geode/ac97

svn at openbios.org svn at openbios.org
Mon May 21 09:20:58 CEST 2007


Author: wmb
Date: 2007-05-21 09:20:51 +0200 (Mon, 21 May 2007)
New Revision: 410

Modified:
   cpu/x86/adpcm.fth
   cpu/x86/pc/olpc/fw.bth
   cpu/x86/pc/olpc/gui.fth
   dev/geode/ac97/ac97.fth
   dev/geode/ac97/selftest.fth
Log:
OLPC - incorporate startup sound into fast-boot startup sequence.















Modified: cpu/x86/adpcm.fth
===================================================================
--- cpu/x86/adpcm.fth	2007-05-20 22:59:57 UTC (rev 409)
+++ cpu/x86/adpcm.fth	2007-05-21 07:20:51 UTC (rev 410)
@@ -115,8 +115,8 @@
 
 : adpcm-decode-blk  ( in out #sample -- )
    #ch #output-ch min 0  ?do            ( in out #sample )
-      2 pick i /l * +                   ( in out #sample in' )
-      2 pick i /w * +                   ( in out #sample in out' )
+      2 pick i /l* +                    ( in out #sample in' )
+      2 pick i /w* +                    ( in out #sample in out' )
       init-ch-vars			( in out #sample in' out' )
       2 pick 1-                         ( in out #sample in out #sample-1 )
       adpcm-decode-ch                   ( in out #sample )
@@ -130,8 +130,8 @@
    dup to blk-size                      ( in out #sample #ch blk-size )
    over 4 * - 2* over / 1+ to #sample/blk ( in out #sample #ch )
    dup to #ch                           ( in out #sample #ch )
-   /l * to in-skip                      ( in out #sample )
-   #output-ch /w * to out-skip          ( in out #sample )
+   /l* to in-skip                       ( in out #sample )
+   #output-ch /w* to out-skip           ( in out #sample )
 
    begin  dup 0>  while                 ( in out #sample )
       3dup #sample/blk min adpcm-decode-blk
@@ -204,65 +204,91 @@
 : wav-#sample   ( -- #sample )   wav-fact-adr dup  if      8 + le-l@  then  ;
 : wav-blk-size  ( -- blk-size )  wav-fmt-adr  dup  if  h# 14 + le-w@  then  ;
 
+: set-volume  ( -- )   " set-volume" $call-audio  ;
 : set-sample-rate  ( -- )
    wav-fmt-adr ?dup  if  h# c + le-l@ " set-sample-rate" $call-audio  then
 ;
 
 0 value out-move
+
+\ Collapse a sample array with "#output-ch" channels/sample into a smaller
+\ array with "wav-in-#ch" channels/sample, discarding the excess channels.
+
 : condense-pcm  ( adr -- )
-   wav-in-#ch #output-ch - /w * to in-skip
-   #output-ch /w * to out-move
+   wav-in-#ch #output-ch - /w* to in-skip
+   #output-ch /w* to out-move
    dup dup 4 - le-l@  bounds  ?do          ( out )
       i over out-move move                 ( out )
       out-move +                           ( out' )
    in-skip +loop  drop                     ( )
 ;
+
+\ Spread a sample array with "wav-in-#ch" channels/sample into a larger
+\ array with "#output-ch" channels/sample, zeroing the new channels.
+
 : expand-pcm  ( adr -- )
-   #output-ch wav-in-#ch - /w * to out-skip
-   wav-in-#ch /w * to out-move
-   dup dup 4 - le-l@  bounds  swap out-move -  ( out in-begin in-end )
-   begin  2dup u<  while                   ( out in-begin in )
-      dup 3 pick out-move move             ( out in-begin in )
-      out-move - rot out-move + -rot       ( out' in-begin in' )
-      2 pick out-skip erase                ( out in-begin in )
-      rot out-skip + -rot                  ( out' in-begin in )
-   repeat  3drop                           ( )
+   #output-ch wav-in-#ch - /w* to out-skip    ( adr )
+   wav-in-#ch /w* to out-move                 ( adr )
+   dup /l -  le-l@                            ( adr in-len ) 
+   2dup  wav-in-#ch /  #output-ch *           ( adr in-len adr out-len )
+   +  -rot                                    ( out-adr in-start in-len )
+   over +  out-move -  do                     ( out-adr )
+      out-skip -  dup out-skip erase          ( out-adr' )
+      out-move -  i over out-move move        ( out-adr' )
+   out-move negate +loop                      ( out-adr )
+   drop
 ;
 
-: play-pcm-once  ( adr len -- )  " write" $call-audio drop " write-done" $call-audio  ;
+\ Given a sample array of the form L0, R0, L1, R1, ..., copy the left
+\ channel into the right, giving L0, L0, L1, L1, etc.  This is
+\ particularly useful when the R samples are initially 0.
+
+: mono16>stereo16  ( adr len -- )  bounds  ?do  i w@  i wa1+ w!  /l +loop  ;
+
+: play-wait  ( -- )  " write-done" $call-audio  ;
+
+: play-pcm-once  ( adr len -- )  " write" $call-audio drop  ;
+
 : play-pcm-loop  ( adr len -- )
-   ." Press a key to abort" cr
-   begin  2dup play-pcm-once  key?  until  key drop  2drop
+   ." Press a key to stop" cr
+   begin  2dup play-pcm-once play-wait  key?  until  key drop  2drop
 ;
 ' play-pcm-once to (play-pcm)
 
+d# -9 value playback-volume  \ -9 is clipping threshold
+
 : play-pcm  ( adr -- error? )
    wav-in-#ch 0=  if  drop true exit  then
+   playback-volume set-volume
    set-sample-rate
-   wav-data-adr 4 - le-l@ to /pcm-output
-   wav-in-#ch #output-ch =  if
-      /pcm-output (play-pcm)                 \ Play straight from the source
-   else
-   /pcm-output wav-in-#ch / #output-ch * to /pcm-output
-   #output-ch wav-in-#ch <  if
-      dup condense-pcm                       \ Skip extra channel data
-      /pcm-output (play-pcm)
-   else
-      dup expand-pcm                         \ Convert mono to stereo
-      /pcm-output (play-pcm)
-   then  then
+   wav-data-adr 4 - le-l@  to /pcm-output
+   wav-in-#ch #output-ch <>  if
+      /pcm-output wav-in-#ch /  #output-ch *  to /pcm-output
+      #output-ch wav-in-#ch <  if
+         dup condense-pcm                       \ Skip extra channel data
+      else
+         dup expand-pcm                         \ Convert mono to stereo
+      then
+   then
+   /pcm-output (play-pcm)
    false
 ;
 
 : play-ima-adpcm  ( adr -- error? )
    wav-fact-adr 0=  if  drop true exit  then
+   playback-volume set-volume
    set-sample-rate
-   wav-#sample #output-ch * /w * to /pcm-output
+   wav-#sample #output-ch *  /w*  to /pcm-output
+
    \ Because alloc-mem does not guarantee contiguous physical memory, use load-base area.
    loaded + pagesize round-up tuck          ( out in out )
+
    dup /pcm-output erase                    ( out in out )
    wav-#sample wav-in-#ch wav-blk-size      ( out in out #sample #ch blk-size )
    adpcm-decoder                            ( out )
+   #output-ch 2 =  wav-in-#ch 1 =  and  if  ( out )
+      dup /pcm-output mono16>stereo16       ( out )
+   then                                     ( out )
    /pcm-output (play-pcm)                   ( )
    false                                    ( error? )
 ;

Modified: cpu/x86/pc/olpc/fw.bth
===================================================================
--- cpu/x86/pc/olpc/fw.bth	2007-05-20 22:59:57 UTC (rev 409)
+++ cpu/x86/pc/olpc/fw.bth	2007-05-21 07:20:51 UTC (rev 410)
@@ -500,6 +500,15 @@
    ?usb-keyboard
 ;
 
+: start-sound  ( -- )
+   playback-volume >r  d# -21 to playback-volume
+   ['] load-started behavior  >r
+   ['] noop to load-started
+   " rom:splash" ['] $play-wav catch  if  2drop  then
+   r> to load-started
+   r> to playback-volume
+;
+
 : open-keyboard  ( -- )
    " keyboard" open-dev  ?dup  if  set-stdin  then
 ;
@@ -513,6 +522,7 @@
    fast-boot?   if
       stdout off
       probe-pci
+      start-sound
       ['] false to interrupt-auto-boot?
       interpreter-init
 [ifndef] lx-devel

Modified: cpu/x86/pc/olpc/gui.fth
===================================================================
--- cpu/x86/pc/olpc/gui.fth	2007-05-20 22:59:57 UTC (rev 409)
+++ cpu/x86/pc/olpc/gui.fth	2007-05-21 07:20:51 UTC (rev 410)
@@ -373,7 +373,7 @@
 
     drop
 ;
-: (?show-device)  ( adr len -- ihandle )
+: (?show-device)  ( adr len -- adr len )
    not-screen? 0=  if  2dup ?show-icon  then
 ;
 ' (?show-device) to ?show-device

Modified: dev/geode/ac97/ac97.fth
===================================================================
--- dev/geode/ac97/ac97.fth	2007-05-20 22:59:57 UTC (rev 409)
+++ dev/geode/ac97/ac97.fth	2007-05-21 07:20:51 UTC (rev 410)
@@ -231,22 +231,23 @@
    h# 8000 h# 26  amp-default-on?  if  codec-set  else  codec-clr  then
 ;
 
+h# 606 value volume
+: set-volume  ( db -- )
+   dup 0>  if  drop 0  then
+   negate  1+ 2* 3 /  dup bwjoin  to volume
+;
+
 : open-out  ( -- )
    amplifier-on
    disable-playback
+   h# 010 h# 76 codec!            \ Route mixer out to headphones, unlock sample rate
    sample-rate d# 1000 / to s/ms
-   sample-rate  dup h# 2c codec!  dup h# 2e codec!  h# 30 codec!
-   0 set-master-volume
-\   0 set-mono-volume
-   h# 0f0f set-headphone-volume
-   h# 606 set-pcm-gain		\ enable line-out
-   h# 606 h# 38 codec!		\ enable surround out (headphones)
-   h# 010 h# 76 codec!  	\ Route mixer out to headphones, unlock sample rate
+   sample-rate h# 2e codec!       \ Only need to set surround DAC for OLPC
+   h# 606 set-pcm-gain            \ Basic PCM Gain - -9 dB, just below clipping
+   volume h# 38 codec!            \ headphone/surround output pin gain
 ;
 : close-out  ( -- )
-   h# 8808 set-pcm-gain			\ mute
-   h# 8000 set-master-volume
-   h# 8000 set-mono-volume
+   h# 8808 set-pcm-gain		\ mute
    amplifier-off
 ;
 
@@ -343,7 +344,7 @@
    get-device-id
    fatal-error?  if  false exit  then
    default
-   1  h# 2a codec-set   \ Enable variable rate
+   h# 2801  h# 2a codec-set   \ Enable variable rate, power down LFE and center DACs
    parse-args  0=  if  unmap-regs false exit  then
    true
 ;

Modified: dev/geode/ac97/selftest.fth
===================================================================
--- dev/geode/ac97/selftest.fth	2007-05-20 22:59:57 UTC (rev 409)
+++ dev/geode/ac97/selftest.fth	2007-05-21 07:20:51 UTC (rev 410)
@@ -23,20 +23,8 @@
    record-base  record-len  audio-in drop
 ;
 
-h# 606 value plevel   \ -9 dB, highest gain without digital clipping
-: set-plevel  ( db -- )
-   dup 0>  if  drop 0  then
-   negate  1+ 2* 3 /  dup bwjoin  to plevel
-;
-
-h# 0 value glevel
-: set-glevel  ( db -- )
-   dup 0>  if  drop 0  then
-   negate  1+ 2* 3 /  dup bwjoin  to glevel
-;
-
 : play  ( -- )
-   open-out  plevel set-pcm-gain  glevel h# 38 codec!
+   open-out
    record-base  record-len  audio-out drop  write-done
 ;
 
@@ -78,7 +66,7 @@
 : tone  ( freq -- )
    record-len la1+  alloc-mem to record-base
    make-tone
-   d# -9 set-glevel  play
+   d# -9 set-volume  play
    record-base record-len la1+  free-mem
 ;
 
@@ -125,14 +113,14 @@
 : sweep-test  ( -- )
    ." Playing sweep" cr
    make-sweep
-   d# -9 set-glevel  play
+   d# -9 set-volume  play
 ;
 
 : mic-test  ( -- )
    ." Recording ..." cr
    record
    ." Playing ..." cr
-   d# -3 set-glevel  play
+   d# -3 set-volume  play
 ;
 
 : selftest  ( -- error? )




More information about the OpenBIOS mailing list