/*************************************************************************** * __________ __ ___. * Open \______ \ ____ ____ | | _\_ |__ _______ ___ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ * \/ \/ \/ \/ \/ * $Id$ * * Copyright (C) 2005 by Linus Nielsen Feltzing * * All files in this archive are subject to the GNU General Public License. * See the file COPYING in the source tree root for full license agreement. * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * ****************************************************************************/ #ifndef AUDIO_H #define AUDIO_H #include #include /* These must always be included with audio.h for this to compile under cetain conditions. Do it here or else spread the complication around to many files. */ #if CONFIG_CODEC == SWCODEC #include "pcm_sampr.h" #include "pcm_playback.h" #ifdef HAVE_RECORDING #include "pcm_record.h" #include "id3.h" #include "enc_base.h" #endif /* HAVE_RECORDING */ #endif /* CONFIG_CODEC == SWCODEC */ #ifdef SIMULATOR #define audio_play(x) sim_audio_play(x) #endif #define AUDIO_STATUS_PLAY 0x0001 #define AUDIO_STATUS_PAUSE 0x0002 #define AUDIO_STATUS_RECORD 0x0004 #define AUDIO_STATUS_PRERECORD 0x0008 #define AUDIO_STATUS_ERROR 0x0010 #define AUDIO_STATUS_WARNING 0x0020 #define AUDIOERR_DISK_FULL 1 #define AUDIO_GAIN_LINEIN 0 #define AUDIO_GAIN_MIC 1 struct audio_debug { int audiobuflen; int audiobuf_write; int audiobuf_swapwrite; int audiobuf_read; int last_dma_chunk_size; bool dma_on; bool playing; bool play_pending; bool is_playing; bool filling; bool dma_underrun; int unplayed_space; int playable_space; int unswapped_space; int low_watermark_level; int lowest_watermark_level; }; void audio_init(void); void audio_play(long offset); void audio_stop(void); void audio_pause(void); void audio_resume(void); void audio_next(void); void audio_prev(void); int audio_status(void); #if CONFIG_CODEC == SWCODEC int audio_track_count(void); /* SWCODEC only */ long audio_filebufused(void); /* SWCODEC only */ void audio_pre_ff_rewind(void); /* SWCODEC only */ #endif /* CONFIG_CODEC == SWCODEC */ void audio_ff_rewind(long newtime); void audio_flush_and_reload_tracks(void); struct mp3entry* audio_current_track(void); struct mp3entry* audio_next_track(void); bool audio_has_changed_track(void); void audio_get_debugdata(struct audio_debug *dbgdata); void audio_set_crossfade(int type); void audio_set_buffer_margin(int seconds); unsigned int audio_error(void); void audio_error_clear(void); int audio_get_file_pos(void); void audio_beep(int duration); void audio_init_playback(void); /* Required call when audio buffer is require for some other purpose */ unsigned char *audio_get_buffer(bool talk_buf, size_t *buffer_size); #ifdef IRAM_STEAL /* Required call when codec IRAM is needed for some other purpose */ void audio_iram_steal(void); #endif /* channel modes */ enum rec_channel_modes { __CHN_MODE_START_INDEX = -1, CHN_MODE_STEREO, CHN_MODE_MONO, CHN_NUM_MODES }; #if CONFIG_CODEC == SWCODEC /* channel mode capability bits */ #define CHN_CAP_STEREO (1 << CHN_MODE_STEREO) #define CHN_CAP_MONO (1 << CHN_MODE_MONO) #define CHN_CAP_ALL (CHN_CAP_STEREO | CHN_CAP_MONO) #endif /* CONFIG_CODEC == SWCODEC */ enum audio_sources { AUDIO_SRC_PLAYBACK = -1, /* Virtual source */ HAVE_MIC_IN_(AUDIO_SRC_MIC,) HAVE_LINE_IN_(AUDIO_SRC_LINEIN,) HAVE_SPDIF_IN_(AUDIO_SRC_SPDIF,) HAVE_FMRADIO_IN_(AUDIO_SRC_FMRADIO,) AUDIO_NUM_SOURCES, AUDIO_SRC_MAX = AUDIO_NUM_SOURCES-1, AUDIO_SRC_DEFAULT = AUDIO_SRC_PLAYBACK }; extern int audio_channels; extern int audio_output_source; #ifdef HAVE_RECORDING /* Recordable source implies it has the input as well */ /* For now there's no restrictions on any targets with which inputs are recordable so define them as equivalent - if they do differ, special handling is needed right now. */ enum rec_sources { __REC_SRC_FIRST = -1, HAVE_MIC_REC_(REC_SRC_MIC,) HAVE_LINE_REC_(REC_SRC_LINEIN,) HAVE_SPDIF_REC_(REC_SRC_SPDIF,) HAVE_FMRADIO_REC_(REC_SRC_FMRADIO,) REC_NUM_SOURCES }; #endif /* HAVE_RECORDING */ #if CONFIG_CODEC == SWCODEC /* selects a source to monitor for recording or playback */ #define SRCF_PLAYBACK 0x0000 /* default */ #define SRCF_RECORDING 0x1000 #if CONFIG_TUNER /* for AUDIO_SRC_FMRADIO */ #define SRCF_FMRADIO_PLAYING 0x0000 /* default */ #define SRCF_FMRADIO_PAUSED 0x2000 #endif #endif #ifdef HAVE_RECORDING /* parameters for audio_set_recording_options */ struct audio_recording_options { int rec_source; int rec_frequency; int rec_channels; int rec_prerecord_time; #if CONFIG_CODEC == SWCODEC int rec_source_flags; /* for rec_set_source */ struct encoder_config enc_config; #else int rec_quality; bool rec_editable; #endif }; /* audio recording functions */ void audio_init_recording(unsigned int buffer_offset); void audio_close_recording(void); void audio_record(const char *filename); void audio_stop_recording(void); void audio_pause_recording(void); void audio_resume_recording(void); void audio_new_file(const char *filename); void audio_set_recording_options(struct audio_recording_options *options); void audio_set_recording_gain(int left, int right, int type); unsigned long audio_recorded_time(void); unsigned long audio_num_recorded_bytes(void); #if CONFIG_CODEC == SWCODEC /* SWCODEC recoring functions */ /* playback.c */ bool audio_load_encoder(int afmt); void audio_remove_encoder(void); unsigned char *audio_get_recording_buffer(size_t *buffer_size); #endif /* CONFIG_CODEC == SWCODEC */ #endif /* HAVE_RECORDING */ #if CONFIG_CODEC == SWCODEC /* SWCODEC misc. audio functions */ #if INPUT_SRC_CAPS != 0 /* audio.c */ void audio_set_input_source(int source, unsigned flags); /* audio_input_mux: target-specific implementation used by audio_set_source to set hardware inputs and audio paths */ void audio_input_mux(int source, unsigned flags); void audio_set_output_source(int source); #endif /* INPUT_SRC_CAPS */ #endif /* CONFIG_CODEC == SWCODEC */ #ifdef HAVE_SPDIF_IN /* returns index into rec_master_sampr_list */ int audio_get_spdif_sample_rate(void); /* > 0: monitor EBUin, 0: Monitor IISrecv, <0: reset only */ void audio_spdif_set_monitor(int monitor_spdif); #endif /* HAVE_SPDIF_IN */ unsigned long audio_prev_elapsed(void); /***********************************************************************/ /* audio event handling */ /* subscribe to one or more audio event(s) by OR'ing together the desired */ /* event IDs (defined below); a handler is called with a solitary event ID */ /* (so switch() is okay) and possibly some useful data (depending on the */ /* event); a handler must return one of the return codes defined below */ typedef int (*AUDIO_EVENT_HANDLER)(unsigned short event, unsigned long data); void audio_register_event_handler(AUDIO_EVENT_HANDLER handler, unsigned short mask); /***********************************************************************/ /* handler return codes */ #define AUDIO_EVENT_RC_IGNORED 200 /* indicates that no action was taken or the event was not recognized */ #define AUDIO_EVENT_RC_HANDLED 201 /* indicates that the event was handled and some action was taken which renders the original event invalid; USE WITH CARE!; this return code aborts all further processing of the given event */ /***********************************************************************/ /* audio event IDs */ #define AUDIO_EVENT_POS_REPORT (1<<0) /* sends a periodic song position report to handlers; a report is sent on each kernal tick; the number of ticks per second is defined by HZ; on each report the current song position is passed in 'data'; if a handler takes an action that changes the song or the song position it must return AUDIO_EVENT_RC_HANDLED which suppresses the event for any remaining handlers */ #define AUDIO_EVENT_END_OF_TRACK (1<<1) /* generated when the end of the currently playing track is reached; no data is passed; if the handler implements some alternate end-of-track processing it should return AUDIO_EVENT_RC_HANDLED which suppresses the event for any remaining handlers as well as the normal end-of-track processing */ #endif href='#n178'>178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347
<?
$svn = "http://svn.rockbox.org/viewvc.cgi/trunk/";
$wiki = "http://www.rockbox.org/wiki/";

function func_sort($a, $b)
{
    $a = preg_replace('/^((unsigned|const|struct|enum) [^ ]*|[a-z0-9 \*_]*) [\*]?/i', '', $a);
    $b = preg_replace('/^((unsigned|const|struct|enum) [^ ]*|[a-z0-9 \*_]*) [\*]?/i', '', $b);
    return strnatcasecmp($a, $b);
}

function get_newest()
{
    global $svn;
    
    $mypath = $_SERVER['SCRIPT_FILENAME'];
    $mypath = substr($mypath, 0, strrpos($mypath, "/"))."/";
    
    $text = file_get_contents($mypath."../../apps/plugin.h");

    $text = str_replace(array("\r\n", "\r"), "\n", $text);

    /* Located plugin_api struct */
    foreach(explode("\n", $text) as $line_nr => $line)
    {
        if(trim($line) == "struct plugin_api {")
        {
            $text = explode("\n", $text);
            $text = array_slice($text, $line_nr+1);
            break;
        }
    }

    foreach($text as $line_nr => $line)
    {
        if(trim($line) == "};")
        {
            $text = array_slice($text, 0, $line_nr-1);
            break;
        }
    }
    /* Locating done */

    /* Clean up stuff a bit .. */
    for($i=0; $i<count($text); $i++)
        $text[$i] = trim($text[$i]);


    /* Fake preprocesser */
    $ret = array();
    $_groups = array();
    $conditions = array();
    $strip_next = 0;
    $group = "";
    for($i=0; $i<count($text); $i++)
    {
        $tmp = trim($text[$i]);
        
        if(substr($tmp, 0, 1) == '#')
        {
            $tmp = trim(substr($tmp, 1));
            if(strtolower(substr($tmp, 0, 2)) == "if")
            {
                if(strtolower(substr($tmp, 2, 3)) == "def")
                    $conditions[] = "defined(".substr($tmp, 6).")";
                else if(strtolower(substr($tmp, 2, 4)) == "ndef")
                    $conditions[] = "!defined(".substr($tmp, 7).")";
                else
                {
                    while(substr($tmp, strlen($tmp)-1, 1) == "\\")
                    {
                       $i++;
                       $tmp = substr($tmp, 0, strlen($tmp)-1)." ".trim($text[$i]);
                    }

                    $conditions[] = substr($tmp, 3);
                }
            }
            else if(strtolower(substr($tmp, 0, 4)) == "elif")
            {
                while(substr($tmp, strlen($tmp)-1, 1) == "\\")
                {
                   $i++;
                   $tmp = substr($tmp, 0, strlen($tmp)-1)." ".trim($text[$i]);
                }
                $conditions[count($conditions)-1] = substr($tmp, 5);
            }
            else if(strtolower(substr($tmp, 0, 4)) == "else")
                $conditions[count($conditions)-1] = "!( ".$conditions[count($conditions)-1]." )";
            else if(strtolower(substr($tmp, 0, 5)) == "endif")
                array_pop($conditions);
        }
        else if(strlen($tmp) == 0)
            $group = "";
        else if(substr($tmp, 0, 2) == "/*")
        {
            while(strpos($tmp, "*/") === false)
            {
               $i++;
               $tmp .= " ".trim($text[$i]);
            }
            $group = explode("/*", trim($tmp));
            $group = explode("*/", $group[1]);
            $group = trim($group[0]);
        }
        else
        {
            while(strpos($tmp, ";") === false)
            {
               $i++;
               $tmp .= " ".trim($text[$i]);
            }

            /* Replace those (*func)(int args) with func(int args) */
            $tmp = preg_replace('/\(\*([^\)]*)\)/i', '\1', $tmp, 1);
            $tmp = substr($tmp, 0, strlen($tmp)-1);
            $ret[$tmp] = array("func" => $tmp, "cond" => "(".implode(") && (", $conditions).")", "group" => $group);
        }
    }

    uksort($ret, "func_sort");

    return $ret;
}

function parse_documentation($data)
{
    $data = explode("\n", $data);

    $ret = array();
    $cur_func = "";
    foreach($data as $line)
    {
        if(substr($line, 0, 1) == "#")
            continue;
        else if(substr($line, 0, 4) == "    ")
        {
            $tmp = trim($line);
            if(strpos($tmp, " ") !== false)
                $tmp = array(substr($tmp, 1, strpos($tmp, " ")-1), substr($tmp, strpos($tmp, " ")) );
            else
                $tmp = array(substr($tmp, 1), "");

            $ret[$cur_func][$tmp[0]][] = $tmp[1];
        }
        else if(strlen($line) == 0)
            continue;
        else
            $cur_func = substr($line, 0);
    }

    $_ret = array();
    foreach($ret as $func => $el)
    {
        if(isset($el["group"]))
            $group = trim($el["group"][0]);
        else
            $group = "misc";

        $_ret[$group][$func] = $el;
    }

    return $_ret;
}

function get_func($func)
{
    $func = preg_replace('/^((unsigned|const|struct|enum) [^ ]*|[a-z0-9 \*_]*) [\*]?/i', '', $func);
    if(strpos($func, "PREFIX") !== false)
        $func = substr($func, 0, strrpos($func, "("));
    else if(strpos($func, "(") !== false)
        $func = substr($func, 0, strpos($func, "("));

    return $func;
}

function get_args($func)
{
    /* Check if this _is_ a function */
    if(strpos($func, "(") === false)
        return array();

    /* Get rid of return value */
    $func = preg_replace('/^((unsigned|const|struct|enum) [^ ]*|[a-z0-9 \*_]*) [\*]?/i', '', $func);

    /* Get rid of function name */
    if(strpos($func, "(") !== false)
        $func = substr($func, strpos($func, "("));

    /* Get rid of ATTRIBUTE_PRINTF */
    if(strpos($func, "ATTRIBUTE_PRINTF") !== false)
        $func = substr($func, 0, strpos($func, "ATTRIBUTE_PRINTF"));

    $level = 0;
    $args = array();
    $buffer = "";
    for($i=0; $i<strlen($func); $i++)
    {
        switch($func{$i})
        {
            case "(":
                $level++;
                if($level > 1)
                    $buffer .= "(";
            break;
            case ")":
                $level--;
                if($level > 0)
                {
                    $buffer .= ")";
                    break;
                }
            case ",":
                if($level <= 1)
                {
                    if(strpos($buffer, "(,") !== false)
                    {
                        $tmp = array();
                        preg_match_all('/[^ ]*, [^)]*\)/', $buffer, $tmp);
                        $tmp = $tmp[0];
                        foreach($tmp as $el)
                        {
                            if(strlen($el) > 0)
                                $args[] = trim($el);
                        }
                        $tmp = preg_replace('/[^ ]*, [^)]*\)/', '', $buffer);
                        $args[] = trim($tmp);
                    }
                    else
                        $args[] = trim($buffer);
                    $buffer = "";
                }
                else
                    $buffer .= ",";
            break;
            default:
                $buffer .= $func{$i};
            break;
        }
    }

    /* Filter out void */
    for($i=0; $i<count($args); $i++)
    {
        if($args[$i] == "void")
            unset($args[$i]);
    }

    return $args;
}

function get_return($func)
{
    $ret = array();
    preg_match('/^((unsigned|const|struct|enum) [^ ]*|[a-z0-9 \*_]*) [\*]?/i', $func, $ret);

    if(trim($ret[0]) == "void")
        return false;
    else
        return trim($ret[0]);
}

function split_var($var)
{
    if(strpos($var, "(,") !== false)
    {
        $p1 = substr($var, 0, strrpos($var, " "));
        $p2 = substr($var, strrpos($var, " "));
        $p2 = substr($p2, 0, strlen($p2)-1);
    }
    else if(strpos($var, "(*") !== false)
    {
        $p2 = array();
        preg_match('/\(\*\w*\)/', $var, $p2);
        $p2 = $p2[0];

        $p1 = substr($var, strpos($var, $p2));
        $p2 = substr($p2, 2, strlen($p2)-3);
    }
    else
    {
        $p1 = substr($var, 0, strrpos($var, " "));
        $p2 = substr($var, strrpos($var, " "));
    }

    if(strpos($p2, "*") !== false)
    {
       for($i=0; $i<substr_count($p2, "*"); $i++)
           $p1 .= "*";
       $p2 = str_replace("*", "", $p2);
    }

    return array(trim($p1), trim($p2));
}

function _simplify($text)
{
    $text = ereg_replace('\(!\( (.*)[ ]?\)\)', '!\1', $text);
    $text = ereg_replace('\(\(([^ ])\)\)', '\1', $text);
    return $text;
}

function clean_func($func)
{
    $func = str_replace(array("   ", "  "), " ", $func);
    $func = str_replace("  ", " ", $func);
    return $func;
}

function do_see_markup($data)
{
    $ret = array();
    foreach($data as $el)
    {
        $el = trim($el);
        
        if(substr($el, 0, 1) != "[")
           $ret[] = do_markup("[F[".$el."]]");
        else
           $ret[] = do_markup($el);
    }

    return implode(" &amp; ", $ret);
}

function do_markup($data)
{
    global $svn, $wiki;

    $data = ereg_replace('=([^=]*)=', '<code>\1</code>', $data);
    $data = ereg_replace('\[W\[([^#\[]*)([^\[]*)\]\]', '<a href="'.$wiki.'\1\2">\1</a>', $data);
    $data = ereg_replace('\[S\[([^\[]*)\]\]', '<a href="'.$svn.'\1?content-type=text%2Fplain">\1</a>', $data);
    $data = ereg_replace('\[F\[([^\[]*)\]\]', '<a href="#\1">\1</a>', $data);
    $data = ereg_replace('\[\[([^#\[]*)([^\[]*)\]\]', '<a href="\1\2">\1</a>', $data);
    $data = str_replace("%BR%", "<br />", $data);
    $data = nl2br($data);

    return $data;
}

function get_tpl_part($search, $haystack)
{
    $tpl = array();
    ereg($search[0].".*".$search[1], $haystack, $tpl);
    return str_replace(array($search[0], $search[1]), "", $tpl[0]);
}
?>