/*************************************************************************** * __________ __ ___. * Open \______ \ ____ ____ | | _\_ |__ _______ ___ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ * \/ \/ \/ \/ \/ * * Copyright (C) 2007 by Rostilav Checkan * $Id$ * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY * KIND, either express or implied. * ****************************************************************************/ #include #include #include "dummies.h" #include "proxy.h" struct user_settings global_settings; struct wps_state wps_state; struct gui_wps gui_wps[NB_SCREENS]; struct wps_data wps_datas[NB_SCREENS]; struct cuesheet *curr_cue; struct system_status global_status; struct gui_syncstatusbar statusbars; struct playlist_info current_playlist; struct font sysfont; int battery_percent = 100; struct mp3entry current_song, next_song; int _audio_status; charger_input_state_type charger_input_state; #if CONFIG_CHARGING >= CHARGING_MONITOR charge_state_type charge_state; #endif #if defined(CPU_PP) && defined(BOOTLOADER) /* We don't enable interrupts in the iPod bootloader, so we need to fake the current_tick variable */ #define current_tick (signed)(USEC_TIMER/10000) #else volatile long current_tick; #endif void dummies_init(){ sysfont.height = 9; sysfont.maxwidth = 6; global_settings.statusbar=true; } int playlist_amount_ex(const struct playlist_info* playlist); void sound_set_volume(int value) { DEBUGF3("sound_set_volume(int value=%d)",value); global_settings.volume = value; } int sound_get_pitch(void) { return 0; } int sound_min(int setting) { DEBUGF3("sound_min(int setting=%d)",setting); return -78; //audiohw_settings[setting].minval; } void sleep(int hz) { } void audio_init(void){} void audio_wait_for_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) { return _audio_status; } #if CONFIG_CODEC == SWCODEC int audio_track_count(void){return 0;} /* SWCODEC only */ long audio_filebufused(void){return 0;} /* 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){} #ifdef HAVE_ALBUMART int audio_current_aa_hid(void){return -1;} #endif struct mp3entry* audio_current_track(void){return 0;} struct mp3entry* audio_next_track(void){return 0;} bool audio_has_changed_track(void) { return false; } int get_sleep_timer(void){return 0;} int battery_level(void){return battery_percent;} /* percent */ int battery_time(void){return 0;} /* minutes */ unsigned int battery_adc_voltage(void){return 0;} /* voltage from ADC in millivolts */ unsigned int battery_voltage(void){return 0;} /* filtered batt. voltage in millivolts */ int get_radio_status(void){return 0;} /* returns full path of playlist (minus extension) */ char *playlist_name(const struct playlist_info* playlist, char *buf, int buf_size) { char *sep; if (!playlist) return "no"; snprintf(buf, buf_size, "%s", playlist->filename+playlist->dirlen); if (!buf[0]) return NULL; /* Remove extension */ sep = strrchr(buf, '.'); if(sep) *sep = 0; return buf; } int playlist_get_display_index(void) { return 1; } void gui_syncsplash(int ticks, const unsigned char *fmt, ...) { } void splash(int ticks, const unsigned char *fmt, ...) { } void gui_statusbar_draw(struct gui_statusbar * bar, bool force_redraw){ DEBUGF3("gui_statusbar_draw"); } void yield(void){} /* returns true if cuesheet support is initialised */ bool cuesheet_is_enabled(void){return false;} /* allocates the cuesheet buffer */ void cuesheet_init(void){} /* looks if there is a cuesheet file that has a name matching "trackpath" */ bool look_for_cuesheet_file(const char *trackpath, char *found_cue_path){return false;} /* parse cuesheet "file" and store the information in "cue" */ bool parse_cuesheet(char *file, struct cuesheet *cue){return false;} /* reads a cuesheet to find the audio track associated to it */ bool get_trackname_from_cuesheet(char *filename, char *buf){return false;} /* display a cuesheet struct */ void browse_cuesheet(struct cuesheet *cue){} /* display a cuesheet file after parsing and loading it to the plugin buffer */ bool display_cuesheet_content(char* filename){return false;} /* finds the index of the current track played within a cuesheet */ int cue_find_current_track(struct cuesheet *cue, unsigned long curpos){return 0;} /* update the id3 info to that of the currently playing track in the cuesheet */ void cue_spoof_id3(struct cuesheet *cue, struct mp3entry *id3){} /* skip to next track in the cuesheet towards "direction" (which is 1 or -1) */ bool curr_cuesheet_skip(int direction, unsigned long curr_pos){return false;} #ifdef HAVE_LCD_BITMAP /* draw track markers on the progressbar */ void cue_draw_markers(struct screen *screen, unsigned long tracklen, int x, int y, int w, int h){} #endif #ifdef HAVE_ALBUMART void draw_album_art(struct gui_wps *gwps, int handle_id, bool clear) { if (!gwps || !gwps->data || !gwps->display || handle_id < 0) return; struct wps_data *data = gwps->data; #ifdef HAVE_REMOTE_LCD /* No album art on RWPS */ if (data->remote_wps) return; #endif struct bitmap *bmp; /* if (bufgetdata(handle_id, 0, (void *)&bmp) <= 0) return;*/ short x = data->albumart_x; short y = data->albumart_y; short width = bmp->width; short height = bmp->height; if (data->albumart_max_width > 0) { /* Crop if the bitmap is too wide */ width = MIN(bmp->width, data->albumart_max_width); /* Align */ if (data->albumart_xalign & WPS_ALBUMART_ALIGN_RIGHT) x += data->albumart_max_width - width; else if (data->albumart_xalign & WPS_ALBUMART_ALIGN_CENTER) x += (data->albumart_max_width - width) / 2; } if (data->albumart_max_height > 0) { /* Crop if the bitmap is too high */ height = MIN(bmp->height, data->albumart_max_height); /* Align */ if (data->albumart_yalign & WPS_ALBUMART_ALIGN_BOTTOM) y += data->albumart_max_height - height; else if (data->albumart_yalign & WPS_ALBUMART_ALIGN_CENTER) y += (data->albumart_max_height - height) / 2; } if (!clear) { /* Draw the bitmap */ gwps->display->set_drawmode(DRMODE_FG); gwps->display->bitmap_part((fb_data*)bmp->data, 0, 0, bmp->width, x, y, width, height); gwps->display->set_drawmode(DRMODE_SOLID); } else { /* Clear the bitmap */ gwps->display->set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID); gwps->display->fillrect(x, y, width, height); gwps->display->set_drawmode(DRMODE_SOLID); } } #endif /* Update the "data" pointer to make the handle's data available to the caller. Return the length of the available linear data or < 0 for failure (handle not found). The caller is blocked until the requested amount of data is available. size is the amount of linear data requested. it can be 0 to get as much as possible. The guard buffer may be used to provide the requested size. This means it's unsafe to request more than the size of the guard buffer. */ size_t bufgetdata(int handle_id, size_t size, void **data) { return size; } void gui_syncstatusbar_draw(struct gui_syncstatusbar * bars, bool force_redraw) { #ifdef HAVE_LCD_BITMAP if(!global_settings.statusbar) return; #endif /* HAVE_LCD_BITMAP */ int i; FOR_NB_SCREENS(i) { gui_statusbar_draw( &(bars->statusbars[i]), force_redraw ); } } void unload_wps_backdrop(void) { } void unload_remote_wps_backdrop(void) { } #if CONFIG_CODEC == SWCODEC int get_replaygain_mode(bool have_track_gain, bool have_album_gain) { int type; bool track = ((global_settings.replaygain_type == REPLAYGAIN_TRACK) || ((global_settings.replaygain_type == REPLAYGAIN_SHUFFLE) && global_settings.playlist_shuffle)); type = (!track && have_album_gain) ? REPLAYGAIN_ALBUM : have_track_gain ? REPLAYGAIN_TRACK : -1; return type; } #endif /* Common functions for all targets */ void rtc_init(void){} int rtc_read_datetime(unsigned char* buf){return 0;} int rtc_write_datetime(unsigned char* buf){return 0;} void backlight_on(void){} void backlight_off(void){} void remote_backlight_on(void){} void remote_backlight_off(void){} void debugf(const char *fmt, ...) {} void panicf( const char *fmt, ...) { } off_t filesize(int fd){return 0;} int playlist_amount(void) { return playlist_amount_ex(NULL); } int playlist_amount_ex(const struct playlist_info* playlist) { if (!playlist) playlist = ¤t_playlist; return playlist->amount; } int get_action(int context, int timeout) { return 0; } void lcd_mono_bitmap(const unsigned char *src, int x, int y, int width, int height){} void pcm_calculate_rec_peaks(int *left, int *right) { } void pcm_calculate_peaks(int *left, int *right) { } bool led_read(int delayticks) /* read by status bar update */ { return false; } #ifndef HAS_BUTTON_HOLD bool is_keys_locked(void) { return false; } #endif long default_event_handler_ex(long event, void (*callback)(void *), void *parameter) { return 0; } long default_event_handler(long event) { return default_event_handler_ex(event, NULL, NULL); } void ab_draw_markers(struct screen * screen, int capacity, int x, int y, int w, int h) { } void pcmbuf_beep(unsigned int frequency, size_t duration, int amplitude){} 22' href='#n222'>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
/*
** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
**  
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
** 
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
** 
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software 
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**
** Any non-GPL usage of this software or parts of this software is strictly
** forbidden.
**
** Commercial non-GPL licensing of this software is possible.
** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
**
** $Id$
**/

#include "common.h"
#include "structs.h"

#include <stdlib.h>

#include "bits.h"
#include "mp4.h"
#include "syntax.h"

/* defines if an object type can be decoded by this library or not */
static uint8_t ObjectTypesTable[32] = {
    0, /*  0 NULL */
#ifdef MAIN_DEC
    1, /*  1 AAC Main */
#else
    0, /*  1 AAC Main */
#endif
    1, /*  2 AAC LC */
#ifdef SSR_DEC
    1, /*  3 AAC SSR */
#else
    0, /*  3 AAC SSR */
#endif
#ifdef LTP_DEC
    1, /*  4 AAC LTP */
#else
    0, /*  4 AAC LTP */
#endif
#ifdef SBR_DEC
    1, /*  5 SBR */
#else
    0, /*  5 SBR */
#endif
#ifdef SCALABLE_DEC
    1, /*  6 AAC Scalable */
#else
    0, /*  6 AAC Scalable */
#endif
    0, /*  7 TwinVQ */
    0, /*  8 CELP */
    0, /*  9 HVXC */
    0, /* 10 Reserved */
    0, /* 11 Reserved */
    0, /* 12 TTSI */
    0, /* 13 Main synthetic */
    0, /* 14 Wavetable synthesis */
    0, /* 15 General MIDI */
    0, /* 16 Algorithmic Synthesis and Audio FX */

    /* MPEG-4 Version 2 */
#ifdef ERROR_RESILIENCE
    1, /* 17 ER AAC LC */
    0, /* 18 (Reserved) */
#ifdef LTP_DEC
    1, /* 19 ER AAC LTP */
#else
    0, /* 19 ER AAC LTP */
#endif
#ifdef SCALABLE_DEC
    1, /* 20 ER AAC scalable */
#else
    0, /* 20 ER AAC scalable */
#endif
    0, /* 21 ER TwinVQ */
    0, /* 22 ER BSAC */
#ifdef LD_DEC
    1, /* 23 ER AAC LD */
#else
    0, /* 23 ER AAC LD */
#endif
    0, /* 24 ER CELP */
    0, /* 25 ER HVXC */
    0, /* 26 ER HILN */
    0, /* 27 ER Parametric */
#else /* No ER defined */
    0, /* 17 ER AAC LC */
    0, /* 18 (Reserved) */
    0, /* 19 ER AAC LTP */
    0, /* 20 ER AAC scalable */
    0, /* 21 ER TwinVQ */
    0, /* 22 ER BSAC */
    0, /* 23 ER AAC LD */
    0, /* 24 ER CELP */
    0, /* 25 ER HVXC */
    0, /* 26 ER HILN */
    0, /* 27 ER Parametric */
#endif
    0, /* 28 (Reserved) */
    0, /* 29 (Reserved) */
    0, /* 30 (Reserved) */
    0  /* 31 (Reserved) */
};

/* Table 1.6.1 */
int8_t NEAACDECAPI NeAACDecAudioSpecificConfig(uint8_t *pBuffer,
                                               uint32_t buffer_size,
                                               mp4AudioSpecificConfig *mp4ASC)
{
    return AudioSpecificConfig2(pBuffer, buffer_size, mp4ASC, NULL);
}

int8_t AudioSpecificConfig2(uint8_t *pBuffer,
                            uint32_t buffer_size,
                            mp4AudioSpecificConfig *mp4ASC,
                            program_config *pce)
{
    bitfile ld;
    int8_t result = 0;
#ifdef SBR_DEC
    int8_t bits_to_decode = 0;
#endif

    if (pBuffer == NULL)
        return -7;
    if (mp4ASC == NULL)
        return -8;

    memset(mp4ASC, 0, sizeof(mp4AudioSpecificConfig));

    faad_initbits(&ld, pBuffer, buffer_size);
    faad_byte_align(&ld);

    mp4ASC->objectTypeIndex = (uint8_t)faad_getbits(&ld, 5
        DEBUGVAR(1,1,"parse_audio_decoder_specific_info(): ObjectTypeIndex"));

    mp4ASC->samplingFrequencyIndex = (uint8_t)faad_getbits(&ld, 4
        DEBUGVAR(1,2,"parse_audio_decoder_specific_info(): SamplingFrequencyIndex"));

    mp4ASC->channelsConfiguration = (uint8_t)faad_getbits(&ld, 4
        DEBUGVAR(1,3,"parse_audio_decoder_specific_info(): ChannelsConfiguration"));

    mp4ASC->samplingFrequency = get_sample_rate(mp4ASC->samplingFrequencyIndex);

    if (ObjectTypesTable[mp4ASC->objectTypeIndex] != 1)
    {
        faad_endbits(&ld);
        return -1;
    }

    if (mp4ASC->samplingFrequency == 0)
    {
        faad_endbits(&ld);
        return -2;
    }

    if (mp4ASC->channelsConfiguration > 7)
    {
        faad_endbits(&ld);
        return -3;
    }

#if (defined(PS_DEC) || defined(DRM_PS))
    /* check if we have a mono file */
    if (mp4ASC->channelsConfiguration == 1)
    {
        /* upMatrix to 2 channels for implicit signalling of PS */
        mp4ASC->channelsConfiguration = 2;
    }
#endif

#ifdef SBR_DEC
    mp4ASC->sbr_present_flag = -1;
    if (mp4ASC->objectTypeIndex == 5)
    {
        uint8_t tmp;

        mp4ASC->sbr_present_flag = 1;
        tmp = (uint8_t)faad_getbits(&ld, 4
            DEBUGVAR(1,5,"parse_audio_decoder_specific_info(): extensionSamplingFrequencyIndex"));
        /* check for downsampled SBR */
        if (tmp == mp4ASC->samplingFrequencyIndex)
            mp4ASC->downSampledSBR = 1;
        mp4ASC->samplingFrequencyIndex = tmp;
        if (mp4ASC->samplingFrequencyIndex == 15)
        {
            mp4ASC->samplingFrequency = (uint32_t)faad_getbits(&ld, 24
                DEBUGVAR(1,6,"parse_audio_decoder_specific_info(): extensionSamplingFrequencyIndex"));
        } else {
            mp4ASC->samplingFrequency = get_sample_rate(mp4ASC->samplingFrequencyIndex);
        }
        mp4ASC->objectTypeIndex = (uint8_t)faad_getbits(&ld, 5
            DEBUGVAR(1,7,"parse_audio_decoder_specific_info(): ObjectTypeIndex"));
    }
#endif

    /* get GASpecificConfig */
    if (mp4ASC->objectTypeIndex == 1 || mp4ASC->objectTypeIndex == 2 ||
        mp4ASC->objectTypeIndex == 3 || mp4ASC->objectTypeIndex == 4 ||
        mp4ASC->objectTypeIndex == 6 || mp4ASC->objectTypeIndex == 7)
    {
        result = GASpecificConfig(&ld, mp4ASC, pce);

#ifdef ERROR_RESILIENCE
    } else if (mp4ASC->objectTypeIndex >= ER_OBJECT_START) { /* ER */
        result = GASpecificConfig(&ld, mp4ASC, pce);
        mp4ASC->epConfig = (uint8_t)faad_getbits(&ld, 2
            DEBUGVAR(1,143,"parse_audio_decoder_specific_info(): epConfig"));

        if (mp4ASC->epConfig != 0)
            result = -5;
#endif

    } else {
        result = -4;
    }

#ifdef SSR_DEC
    /* shorter frames not allowed for SSR */
    if ((mp4ASC->objectTypeIndex == 4) && mp4ASC->frameLengthFlag)
        return -6;
#endif


#ifdef SBR_DEC
    bits_to_decode = (int8_t)(buffer_size*8 - faad_get_processed_bits(&ld));

    if ((mp4ASC->objectTypeIndex != 5) && (bits_to_decode >= 16))
    {
        int16_t syncExtensionType = (int16_t)faad_getbits(&ld, 11
            DEBUGVAR(1,9,"parse_audio_decoder_specific_info(): syncExtensionType"));

        if (syncExtensionType == 0x2b7)
        {
            mp4ASC->objectTypeIndex = (uint8_t)faad_getbits(&ld, 5
                DEBUGVAR(1,10,"parse_audio_decoder_specific_info(): extensionAudioObjectType"));

            if (mp4ASC->objectTypeIndex == 5)
            {
                mp4ASC->sbr_present_flag = (uint8_t)faad_get1bit(&ld
                    DEBUGVAR(1,11,"parse_audio_decoder_specific_info(): sbr_present_flag"));

                if (mp4ASC->sbr_present_flag)
                {
                    uint8_t tmp;
                    tmp = (uint8_t)faad_getbits(&ld, 4
                        DEBUGVAR(1,12,"parse_audio_decoder_specific_info(): extensionSamplingFrequencyIndex"));

                    /* check for downsampled SBR */
                    if (tmp == mp4ASC->samplingFrequencyIndex)
                        mp4ASC->downSampledSBR = 1;
                    mp4ASC->samplingFrequencyIndex = tmp;

                    if (mp4ASC->samplingFrequencyIndex == 15)
                    {
                        mp4ASC->samplingFrequency = (uint32_t)faad_getbits(&ld, 24
                            DEBUGVAR(1,13,"parse_audio_decoder_specific_info(): extensionSamplingFrequencyIndex"));
                    } else {
                        mp4ASC->samplingFrequency = get_sample_rate(mp4ASC->samplingFrequencyIndex);
                    }
                }
            }
        }
    }

    /* no SBR signalled, this could mean either implicit signalling or no SBR in this file */
    /* MPEG specification states: assume SBR on files with samplerate <= 24000 Hz */
    if (mp4ASC->sbr_present_flag == -1)
    {
        if (mp4ASC->samplingFrequency <= 24000)
        {
            mp4ASC->samplingFrequency *= 2;
            mp4ASC->forceUpSampling = 1;
        } else /* > 24000*/ {
            mp4ASC->downSampledSBR = 1;
        }
    }
#endif

    faad_endbits(&ld);

    return result;
}