Esempio n. 1
0
void Lm4867ShutDown(int sel)
{
	if(sel)
		SetMemory(REG_PDATD, 0x4, OR_OPCODE);
	else
		SetMemory(REG_PDATD, 0xfb, AND_OPCODE);
}
Esempio n. 2
0
static void ResetV9Chip()
{
	int x;

	x = ReadMemory(REG_PCOND);
	x &= 0xffcc;
	x |= 0x11;
	WriteMemory(REG_PCOND, x);		//GPD0, 2 set to output

	SetMemory(REG_PDATD, 0xfe, AND_OPCODE);
#ifndef NCSC
	Delay(100);
#endif
	SetMemory(REG_PDATD, 0x1, OR_OPCODE);
#ifndef NCSC
	Delay(10);
#endif
}
Esempio n. 3
0
static void ResetV5Chip()
{
	int x;

	x = ReadMemory(REG_PCONG);
	x &= 0x3fff;
	x |= 0x4000;
	WriteMemory(REG_PCONG, x);		//GPG7 set to output

	SetMemory(REG_PDATG, 0x7f, AND_OPCODE);
#ifndef NCSC
	Delay(100);
#endif
	SetMemory(REG_PDATG, 0x80, OR_OPCODE);
#ifndef NCSC
	Delay(10);
#endif
}
Esempio n. 4
0
/*-----------------------------------------------------------------------------
 Data Members
------------------------------------------------------------------------------*/
PROTECTED extern PacketMgrInputBufferInfo packetMgrInputBuffer;


//*****************************************************************************
//
// Exported Functions
//
//*****************************************************************************


//****************************************************************************/
PROTECTED Result PacketMgrParsePacket(pLIB_XML_Tag *Tag, uint32 *PacketId)
{
    Result result = PACKET_MGR_RESULT(SUCCESS);
    uint32 packetSizeBytes;
    uint32 pi;
    pLIB_XML_Tag tag;

    tag = *Tag;
    pi = packetMgrInputBuffer.FirstPacketIndex;

    if( packetMgrInputBuffer.PacketInfo[pi].StartIndex < packetMgrInputBuffer.PacketInfo[pi].EndIndex )
    {
        packetSizeBytes = packetMgrInputBuffer.PacketInfo[pi].EndIndex - packetMgrInputBuffer.PacketInfo[pi].StartIndex;
    }
    else
    {
        packetSizeBytes = PACKET_MGR_INPUT_BUFFER_SIZE - packetMgrInputBuffer.PacketInfo[pi].StartIndex + packetMgrInputBuffer.PacketInfo[pi].EndIndex;
    }


    if( (tag = (pLIB_XML_Tag) AllocMemory(sizeof(LIB_XML_Tag) + packetSizeBytes)) == NULL )
    {
        result = PACKET_MGR_RESULT(MEM_ALLOC_FAIL);
    }
    else
    {
        tag->Data = (uint8*)tag + sizeof(LIB_XML_Tag);
        tag->ChildCount = 1;
        *PacketId = packetMgrInputBuffer.PacketInfo[pi].Id;

        if( packetMgrInputBuffer.PacketInfo[pi].StartIndex < packetMgrInputBuffer.PacketInfo[pi].EndIndex )
        {
            CopyMemory(tag->Data, &packetMgrInputBuffer.Buffer[packetMgrInputBuffer.PacketInfo[pi].StartIndex], packetSizeBytes);
        }
        else
        {
            packetSizeBytes = PACKET_MGR_INPUT_BUFFER_SIZE - packetMgrInputBuffer.PacketInfo[pi].StartIndex;

            CopyMemory(tag->Data, &packetMgrInputBuffer.Buffer[packetMgrInputBuffer.PacketInfo[pi].StartIndex], packetSizeBytes);
            CopyMemory(&((uint8*)tag->Data)[packetSizeBytes], packetMgrInputBuffer.Buffer, packetMgrInputBuffer.PacketInfo[pi].EndIndex);
        }

        if( sscanf(tag->Data, "<%s>", tag->Tag) != 1 )
        {
            result = PACKET_MGR_RESULT(BAD_PACKET);
        }
    }

    SetMemory(&packetMgrInputBuffer.PacketInfo[pi], PACKET_NULL_INDEX, sizeof(PacketMgrPacketInfo));
    packetMgrInputBuffer.FirstPacketIndex = (packetMgrInputBuffer.FirstPacketIndex+1)/PACKET_MGR_INPUT_MAX_PACKETS;
    packetMgrInputBuffer.PacketsAvailable--;
    packetMgrInputBuffer.BytesUsed -= packetSizeBytes;

    return result;
}
Esempio n. 5
0
void InitialXexSetup( void )
{
	// Remove Microsoft's F*****g Breakpoints (tmp until lander can get the offset of the function)
	byte nopOpcode[4] = { 0x60, 0x00, 0x00, 0x00 };
	SetMemory((void*)0x81B0C8B0, (void*)&nopOpcode, sizeof(nopOpcode));

	// Remove Intro bik and Credits
	byte removeBIK[4] = { 0x2B, 0x09, 0x00, 0x01 };
	SetMemory((void*)0x82666110, (void*)&removeBIK, sizeof(removeBIK));

	// Unlock Everything
	byte unlockEverything[4] = { 0x39, 0x60, 0x00, 0x01 };
	SetMemory((void*)0x82548EF8, (void*)&unlockEverything, sizeof(unlockEverything));

	// Remove RSA Checks
	byte removeRSA[4] = { 0x38, 0x60, 0x00, 0x01 };
	SetMemory((void*)0x8233392C, (void*)&removeRSA, sizeof(removeRSA));

	// Unlock every Campaign Level
	byte unlockCampaignLevels[30];
	for (int i = 0; i < 30; i++)
		unlockCampaignLevels[i] = 0xff;
	SetMemory((void*)0xC274FAD0, (void*)&unlockCampaignLevels, sizeof(unlockCampaignLevels));

	// Remove Fall Damage
	float noFallDamage = 200;
	SetMemory((void*)0x82014864, (void*)&noFallDamage, sizeof(noFallDamage));
}
Esempio n. 6
0
void AdcTest(){

	uint8_t program[] = {
		//0x05, //junk byte since PC is incremented before reading instruction
		0x69, 0x16, // LDA #$16
		0x6D ,0x00 ,0x00 //LDA $00
		
	};

	auto tma =std::unique_ptr<TestMemoryAccesor>(new TestMemoryAccesor());
	for(int i = 0; i<sizeof(program); i++){
		tma->SetMemory(i,program[i]);
	}
	CPU cpu(std::move(tma));
	cpu.Step(); // A = 22
	cpu.Step(); // A = 22 + *(0) = 22 + 0x69 = 22 + 105 = 127

}
Esempio n. 7
0
// Writes ones to memory, then verifies results.
//
// Returns FALSE if fails and fills the MemError struct. Returns TRUE
// if successful.
BOOL TestWriteOnes32(uint32 *addr, int size, MemError *pError)
{
	volatile uint32 *ptr;
	uint32 *startPtr, *endPtr;
	uint32 value;

	startPtr = (uint32 *)addr;
	endPtr = (uint32 *)(addr + size/sizeof(*ptr));

	// Set memory to all ones
	SetMemory(addr, size, ~0);

	// Verify it's cleared
	for(ptr = startPtr; ptr < endPtr; ptr++) {
		value = *ptr & DATA_MASK;
		if(value != (~0 & DATA_MASK)) {
			FillError(pError, (uint32)ptr, value, ~0 & DATA_MASK, 4);
			return FALSE;
		}
	}	

	return TRUE;
}
Esempio n. 8
0
/*-----------------------------------------------------------------------------
 Data Members
------------------------------------------------------------------------------*/
PROTECTED PacketMgrInputBufferInfo packetMgrInputBuffer;
PROTECTED PacketMgrOutputBufferInfo packetMgrOutputBuffer;

PROTECTED pLIB_ARRAY_LIST_List packetMgrTagListenerList;


//*****************************************************************************
//
// Exported Functions
//
//*****************************************************************************


//****************************************************************************/
PUBLIC Result PACKET_MGR_Init( void )
{
    Result result = PACKET_MGR_RESULT(SUCCESS);

    LOG_Printf("Initializing Packet Mgr component\n");

    ZeroMemory(&packetMgrInputBuffer, sizeof(PacketMgrInputBufferInfo));
    ZeroMemory(&packetMgrOutputBuffer, sizeof(PacketMgrOutputBufferInfo));
    SetMemory(&packetMgrInputBuffer.PacketInfo, PACKET_NULL_INDEX, sizeof(PacketMgrPacketInfo)*PACKET_MGR_INPUT_MAX_PACKETS);

    packetMgrTagListenerList = NULL;


    if( RESULT_IS_ERROR(result, OS_CREATE_MUTEX(&packetMgrInputBuffer.Mutex)) )
    {
        LOG_Printf("Failed to create read buffer mutex\n");
    }
    else if( RESULT_IS_ERROR(result, OS_CREATE_MUTEX(&packetMgrOutputBuffer.Mutex)) )
    {
        LOG_Printf("Failed to create write buffer mutex\n");
    }
    else if( RESULT_IS_ERROR(result, COMPOSITE_USB_RegisterReadVirComCallback(VirComReadCallback)) )
    {
        LOG_Printf("Failed to register virtual com read callback\n");
    }
    else if( RESULT_IS_ERROR(result, PacketMgrCreateTask()) )
    {
        LOG_Printf("Failed to create the packet mgr task\n");
    }
    else if( (packetMgrTagListenerList = LIB_ARRAY_LIST_CreateList(sizeof(PacketMgrTagListenerInfo), 1)) == NULL )
    {
        result = PACKET_MGR_RESULT(CREATE_LIS_LIST_FAIL);
        LOG_Printf("Failed to create array list\n");
    }

    return result;
}
Esempio n. 9
0
static int huffspec(faacDecHandle hDecoder, Info *info, int nsect, byte *sect,
             int *factors, Float *coef)
{
    Hcb *hcb;
    Huffman *hcw;
    int i, j, k, table, step, stop, bottom, top;
    int *bands, *bandp;
    int *quant, *qp;
    int *tmp_spec;
    int *quantPtr;
    int *tmp_specPtr;

    quant = AllocMemory(LN2*sizeof(int));
    tmp_spec = AllocMemory(LN2*sizeof(int));

    quantPtr = quant;
    tmp_specPtr = tmp_spec;

#ifndef _WIN32
    SetMemory(quant, 0, LN2*sizeof(int));
#endif

    bands = info->bk_sfb_top;
    bottom = 0;
    k = 0;
    bandp = bands;
    for(i = nsect; i; i--) {
        table = sect[0];
        top = sect[1];
        sect += 2;
        if( (table == 0) || (table == NOISE_HCB) ||
            (table == INTENSITY_HCB) || (table == INTENSITY_HCB2) ) {
            bandp = bands+top;
            k = bandp[-1];
            bottom = top;
            continue;
        }
        if(table < BY4BOOKS+1) {
            step = 4;
        } else {
            step = 2;
        }
        hcb = &book[table];
        hcw = hcb->hcw;
        qp = quant+k;
        for(j = bottom; j < top; j++) {
            stop = *bandp++;
            while(k < stop) {
                decode_huff_cw(hDecoder, hcw, qp, hcb);

                if (!hcb->signed_cb)
                    get_sign_bits(hDecoder, qp, step);
                if(table == ESCBOOK){
                    qp[0] = getescape(hDecoder, qp[0]);
                    qp[1] = getescape(hDecoder, qp[1]);
                }
                qp += step;
                k += step;
            }
        }
        bottom = top;
    }

    /* pulse coding reconstruction */
    if ((info->islong) && (hDecoder->pulse_info.pulse_data_present))
        pulse_nc(hDecoder, quant, &hDecoder->pulse_info);

    if (!info->islong) {
        deinterleave (quant,tmp_spec,
            (short)info->num_groups,
            info->group_len,
            info->sfb_per_sbk,
            info->sfb_width_128);

        for (i = LN2/16 - 1; i >= 0; --i)
        {
            *quantPtr++ = *tmp_specPtr++; *quantPtr++ = *tmp_specPtr++;
            *quantPtr++ = *tmp_specPtr++; *quantPtr++ = *tmp_specPtr++;
            *quantPtr++ = *tmp_specPtr++; *quantPtr++ = *tmp_specPtr++;
            *quantPtr++ = *tmp_specPtr++; *quantPtr++ = *tmp_specPtr++;
            *quantPtr++ = *tmp_specPtr++; *quantPtr++ = *tmp_specPtr++;
            *quantPtr++ = *tmp_specPtr++; *quantPtr++ = *tmp_specPtr++;
            *quantPtr++ = *tmp_specPtr++; *quantPtr++ = *tmp_specPtr++;
            *quantPtr++ = *tmp_specPtr++; *quantPtr++ = *tmp_specPtr++;
        }
    }

    /* inverse quantization */
    for (i=0; i<info->bins_per_bk; i++) {
        coef[i] = esc_iquant(hDecoder, quant[i]);
    }

    /* rescaling */
    {
        int sbk, nsbk, sfb, nsfb, fac, top;
        Float *fp, scale;

        i = 0;
        fp = coef;
        nsbk = info->nsbk;
        for (sbk=0; sbk<nsbk; sbk++) {
            nsfb = info->sfb_per_sbk[sbk];
            k=0;
            for (sfb=0; sfb<nsfb; sfb++) {
                top = info->sbk_sfb_top[sbk][sfb];
                fac = factors[i++]-SF_OFFSET;

                if (fac >= 0 && fac < TEXP) {
                    scale = hDecoder->exptable[fac];
                }
                else {
                    if (fac == -SF_OFFSET) {
                        scale = 0;
                    }
                    else {
                        scale = (float)pow(2.0,  0.25*fac);
                    }
                }
                for ( ; k<top; k++) {
                    *fp++ *= scale;
                }
            }
        }
    }

    if (quant) FreeMemory(quant);
    if (tmp_spec) FreeMemory(tmp_spec);

    return 1;
}
Esempio n. 10
0
/*
 * get scale factors
 */
static int hufffac(faacDecHandle hDecoder, Info *info, byte *group, int nsect, byte *sect,
        int global_gain, int *factors)
{
    Huffscl *hcw;
    int i, b, bb, t, n, sfb, top, fac, is_pos;
    int factor_transmitted[MAXBANDS], *fac_trans;
    int noise_pcm_flag = 1;
    int noise_nrg;

    /* clear array for the case of max_sfb == 0 */
    SetMemory(factor_transmitted, 0, MAXBANDS*sizeof(int));
    SetMemory(factors, 0, MAXBANDS*sizeof(int));

    sfb = 0;
    fac_trans = factor_transmitted;
    for(i = 0; i < nsect; i++){
        top = sect[1];      /* top of section in sfb */
        t = sect[0];        /* codebook for this section */
        sect += 2;
        for(; sfb < top; sfb++) {
            fac_trans[sfb] = t;
        }
    }

    /* scale factors are dpcm relative to global gain
    * intensity positions are dpcm relative to zero
    */
    fac = global_gain;
    is_pos = 0;
    noise_nrg = global_gain - NOISE_OFFSET;

    /* get scale factors */
    hcw = bookscl;
    bb = 0;
    for(b = 0; b < info->nsbk; ){
        n = info->sfb_per_sbk[b];
        b = *group++;
        for(i = 0; i < n; i++){
            switch (fac_trans[i]) {
            case ZERO_HCB:      /* zero book */
                break;
            default:            /* spectral books */
                /* decode scale factor */
                t = decode_huff_cw_scl(hDecoder, hcw);
                fac += t - MIDFAC;    /* 1.5 dB */
                if(fac >= 2*TEXP || fac < 0)
                    return 0;
                factors[i] = fac;
                break;
            case BOOKSCL:       /* invalid books */
                return 0;
            case INTENSITY_HCB:     /* intensity books */
            case INTENSITY_HCB2:
                /* decode intensity position */
                t = decode_huff_cw_scl(hDecoder, hcw);
                is_pos += t - MIDFAC;
                factors[i] = is_pos;
                break;
            case NOISE_HCB:     /* noise books */
                /* decode noise energy */
                if (noise_pcm_flag) {
                    noise_pcm_flag = 0;
                    t = faad_getbits(&hDecoder->ld, NOISE_PCM_BITS) - NOISE_PCM_OFFSET;
                } else
                    t = decode_huff_cw_scl(hDecoder, hcw) - MIDFAC;
                noise_nrg += t;
                factors[i] = noise_nrg;
                break;
            }
        }

        /* expand short block grouping */
        if (!(info->islong)) {
            for(bb++; bb < b; bb++) {
                for (i=0; i<n; i++) {
                    factors[i+n] = factors[i];
                }
                factors += n;
            }
        }
        fac_trans += n;
        factors += n;
    }
    return 1;
}
Esempio n. 11
0
/*
 * read and decode the data for the next 1024 output samples
 * return -1 if there was an error
 */
int huffdecode(faacDecHandle hDecoder, int id, MC_Info *mip, byte *win,
               Wnd_Shape *wshape,
               byte **cb_map, int **factors,
               byte **group, byte *hasmask, byte **mask, byte *max_sfb,
               int **lpflag, int **prstflag,
               NOK_LT_PRED_STATUS **nok_ltp_status,
               TNS_frame_info **tns, Float **coef)
{
    int i, tag, common_window, ch, widx, first=0, last=0;

    int global_gain;  /* not used in this routine */
    Info info;

    tag = faad_getbits(&hDecoder->ld, LEN_TAG);

    switch(id) {
    case ID_SCE:
        common_window = 0;
        break;
    case ID_CPE:
        common_window = faad_get1bit(&hDecoder->ld); /* common_window */
        break;
    default:
        /* CommonWarning("Unknown id"); */
        return(-1);
    }

    if ((ch = chn_config(hDecoder, id, tag, common_window, mip)) < 0)
        return -1;

    switch(id) {
    case ID_SCE:
        widx = mip->ch_info[ch].widx;
        first = ch;
        last = ch;
        hasmask[widx] = 0;
        break;
    case ID_CPE:
        first = ch;
        last = mip->ch_info[ch].paired_ch;
        if (common_window) {
            widx = mip->ch_info[ch].widx;
            if (!get_ics_info(hDecoder, &win[widx], &wshape[widx].this_bk, group[widx],
                &max_sfb[widx], lpflag[widx], prstflag[widx],
                nok_ltp_status[widx],nok_ltp_status[mip->ch_info[ch].paired_ch], common_window))
                return -1;

            hasmask[widx] = getmask(hDecoder, hDecoder->winmap[win[widx]], group[widx],
                max_sfb[widx], mask[widx]);
        }
        else {
            hasmask[mip->ch_info[first].widx] = 0;
            hasmask[mip->ch_info[last].widx] = 0;
        }
        break;
    }

    for (i=first; i<=last; i++) {
        widx = mip->ch_info[i].widx;
        SetMemory(coef[i], 0, LN2*sizeof(Float));

        if(!getics(hDecoder, &info, common_window, &win[widx], &wshape[widx].this_bk,
            group[widx], &max_sfb[widx], lpflag[widx], prstflag[widx],
            cb_map[i], coef[i], &global_gain, factors[i], nok_ltp_status[widx],
            tns[i]))
            return -1;
    }

    return 0;
}
Esempio n. 12
0
int AACQuantize(CoderInfo *coderInfo,
                PsyInfo *psyInfo,
                ChannelInfo *channelInfo,
                int *cb_width,
                int num_cb,
                double *xr,
		AACQuantCfg *aacquantCfg)
{
    int sb, i, do_q = 0;
    int bits = 0, sign;
    double xr_pow[FRAME_LEN];
    double xmin[MAX_SCFAC_BANDS];
    int xi[FRAME_LEN];

    /* Use local copy's */
    int *scale_factor = coderInfo->scale_factor;

    /* Set all scalefactors to 0 */
    coderInfo->global_gain = 0;
    for (sb = 0; sb < coderInfo->nr_of_sfb; sb++)
        scale_factor[sb] = 0;

    /* Compute xr_pow */
    for (i = 0; i < FRAME_LEN; i++) {
        double temp = fabs(xr[i]);
        xr_pow[i] = sqrt(temp * sqrt(temp));
        do_q += (temp > 1E-20);
    }

    if (do_q) {
        CalcAllowedDist(coderInfo, psyInfo, xr, xmin, aacquantCfg->quality);
	coderInfo->global_gain = 0;
	FixNoise(coderInfo, xr, xr_pow, xi, xmin,
		 aacquantCfg->pow43, aacquantCfg->adj43);
	BalanceEnergy(coderInfo, xr, xi, aacquantCfg->pow43);
	UpdateRequant(coderInfo, xi, aacquantCfg->pow43);

        for ( i = 0; i < FRAME_LEN; i++ )  {
            sign = (xr[i] < 0) ? -1 : 1;
            xi[i] *= sign;
            coderInfo->requantFreq[i] *= sign;
        }
    } else {
        coderInfo->global_gain = 0;
        SetMemory(xi, 0, FRAME_LEN*sizeof(int));
    }

    BitSearch(coderInfo, xi);

    /* offset the difference of common_scalefac and scalefactors by SF_OFFSET  */
    for (i = 0; i < coderInfo->nr_of_sfb; i++) {
        if ((coderInfo->book_vector[i]!=INTENSITY_HCB)&&(coderInfo->book_vector[i]!=INTENSITY_HCB2)) {
            scale_factor[i] = coderInfo->global_gain - scale_factor[i] + SF_OFFSET;
        }
    }
    coderInfo->global_gain = scale_factor[0];
#if 0
	printf("global gain: %d\n", coderInfo->global_gain);
	for (i = 0; i < coderInfo->nr_of_sfb; i++)
	  printf("sf %d: %d\n", i, coderInfo->scale_factor[i]);
#endif

    /* place the codewords and their respective lengths in arrays data[] and len[] respectively */
    /* there are 'counter' elements in each array, and these are variable length arrays depending on the input */
#ifdef DRM
    coderInfo->iLenReordSpData = 0; /* init length of reordered spectral data */
    coderInfo->iLenLongestCW = 0; /* init length of longest codeword */
    coderInfo->cur_cw = 0; /* init codeword counter */
#endif
    coderInfo->spectral_count = 0;
    sb = 0;
    for(i = 0; i < coderInfo->nr_of_sfb; i++) {
        OutputBits(
            coderInfo,
#ifdef DRM
            &coderInfo->book_vector[i], /* needed for VCB11 */
#else
            coderInfo->book_vector[i],
#endif
            xi,
            coderInfo->sfb_offset[i],
            coderInfo->sfb_offset[i+1]-coderInfo->sfb_offset[i]);

        if (coderInfo->book_vector[i])
              sb = i;
    }

    // FIXME: Check those max_sfb/nr_of_sfb. Isn't it the same?
    coderInfo->max_sfb = coderInfo->nr_of_sfb = sb + 1;

    return bits;
}
Esempio n. 13
0
faacEncHandle FAACAPI faacEncOpen(unsigned long sampleRate,
                                  unsigned int numChannels,
                                  unsigned long *inputSamples,
                                  unsigned long *maxOutputBytes)
{
    unsigned int channel;
    faacEncHandle hEncoder;

    *inputSamples = FRAME_LEN*numChannels;
    *maxOutputBytes = (6144/8)*numChannels;

#ifdef DRM
    *maxOutputBytes += 1; /* for CRC */
#endif

    hEncoder = (faacEncStruct*)AllocMemory(sizeof(faacEncStruct));
    SetMemory(hEncoder, 0, sizeof(faacEncStruct));

    hEncoder->numChannels = numChannels;
    hEncoder->sampleRate = sampleRate;
    hEncoder->sampleRateIdx = GetSRIndex(sampleRate);

    /* Initialize variables to default values */
    hEncoder->frameNum = 0;
    hEncoder->flushFrame = 0;

    /* Default configuration */
    hEncoder->config.version = FAAC_CFG_VERSION;
    hEncoder->config.name = libfaacName;
    hEncoder->config.copyright = libCopyright;
    hEncoder->config.mpegVersion = MPEG4;
    hEncoder->config.aacObjectType = LTP;
    hEncoder->config.allowMidside = 1;
    hEncoder->config.useLfe = 1;
    hEncoder->config.useTns = 0;
    hEncoder->config.bitRate = 0; /* default bitrate / channel */
    hEncoder->config.bandWidth = bwfac * hEncoder->sampleRate;
    if (hEncoder->config.bandWidth > bwbase)
		hEncoder->config.bandWidth = bwbase;
    hEncoder->config.quantqual = 100;
    hEncoder->config.psymodellist = (psymodellist_t *)psymodellist;
    hEncoder->config.psymodelidx = 0;
    hEncoder->psymodel =
      hEncoder->config.psymodellist[hEncoder->config.psymodelidx].model;
    hEncoder->config.shortctl = SHORTCTL_NORMAL;

	/* default channel map is straight-through */
	for( channel = 0; channel < 64; channel++ )
		hEncoder->config.channel_map[channel] = channel;
	
    /*
        by default we have to be compatible with all previous software
        which assumes that we will generate ADTS
        /AV
    */
    hEncoder->config.outputFormat = 1;

    /*
        be compatible with software which assumes 24bit in 32bit PCM
    */
    hEncoder->config.inputFormat = FAAC_INPUT_32BIT;

    /* find correct sampling rate depending parameters */
    hEncoder->srInfo = &srInfo[hEncoder->sampleRateIdx];

    for (channel = 0; channel < numChannels; channel++) 
	{
        hEncoder->coderInfo[channel].prev_window_shape = SINE_WINDOW;
        hEncoder->coderInfo[channel].window_shape = SINE_WINDOW;
        hEncoder->coderInfo[channel].block_type = ONLY_LONG_WINDOW;
        hEncoder->coderInfo[channel].num_window_groups = 1;
        hEncoder->coderInfo[channel].window_group_length[0] = 1;

        /* FIXME: Use sr_idx here */
        hEncoder->coderInfo[channel].max_pred_sfb = GetMaxPredSfb(hEncoder->sampleRateIdx);

        hEncoder->sampleBuff[channel] = NULL;
        hEncoder->nextSampleBuff[channel] = NULL;
        hEncoder->next2SampleBuff[channel] = NULL;
        hEncoder->ltpTimeBuff[channel] = (double*)AllocMemory(2*BLOCK_LEN_LONG*sizeof(double));
        SetMemory(hEncoder->ltpTimeBuff[channel], 0, 2*BLOCK_LEN_LONG*sizeof(double));
    }

    /* Initialize coder functions */
	fft_initialize( &hEncoder->fft_tables );
    
	hEncoder->psymodel->PsyInit(&hEncoder->gpsyInfo, hEncoder->psyInfo, hEncoder->numChannels,
        hEncoder->sampleRate, hEncoder->srInfo->cb_width_long,
        hEncoder->srInfo->num_cb_long, hEncoder->srInfo->cb_width_short,
        hEncoder->srInfo->num_cb_short);

    FilterBankInit(hEncoder);

    TnsInit(hEncoder);

    LtpInit(hEncoder);

    PredInit(hEncoder);

    AACQuantizeInit(hEncoder->coderInfo, hEncoder->numChannels,
		    &(hEncoder->aacquantCfg));

	

    HuffmanInit(hEncoder->coderInfo, hEncoder->numChannels);

    /* Return handle */
    return hEncoder;
}
Esempio n. 14
0
PFREELDR_MEMORY_DESCRIPTOR
PcMemGetMemoryMap(ULONG *MemoryMapSize)
{
    ULONG i, EntryCount;
    ULONG ExtendedMemorySizeAtOneMB;
    ULONG ExtendedMemorySizeAtSixteenMB;
    ULONG EbdaBase, EbdaSize;
    TRACE("PcMemGetMemoryMap()\n");

    EntryCount = PcMemGetBiosMemoryMap(PcMemoryMap, MAX_BIOS_DESCRIPTORS);

    /* If the BIOS didn't provide a memory map, synthesize one */
    if (EntryCount == 0)
    {
        GetExtendedMemoryConfiguration(&ExtendedMemorySizeAtOneMB,
                                       &ExtendedMemorySizeAtSixteenMB);

        /* Conventional memory */
        AddMemoryDescriptor(PcMemoryMap,
                            MAX_BIOS_DESCRIPTORS,
                            0,
                            PcMemGetConventionalMemorySize() * 1024 / PAGE_SIZE,
                            LoaderFree);

        /* Extended memory */
        PcMapCount = AddMemoryDescriptor(PcMemoryMap,
                                         MAX_BIOS_DESCRIPTORS,
                                         1024 * 1024 / PAGE_SIZE,
                                         ExtendedMemorySizeAtOneMB * 1024 / PAGE_SIZE,
                                         LoaderFree);

        if (ExtendedMemorySizeAtSixteenMB != 0)
        {
            /* Extended memory at 16MB */
            PcMapCount = AddMemoryDescriptor(PcMemoryMap,
                                             MAX_BIOS_DESCRIPTORS,
                                             0x1000000 / PAGE_SIZE,
                                             ExtendedMemorySizeAtSixteenMB * 64 * 1024 / PAGE_SIZE,
                                             LoaderFree);
        }

        /* Check if we have an EBDA and get it's location */
        if (GetEbdaLocation(&EbdaBase, &EbdaSize))
        {
            /* Add the descriptor */
            PcMapCount = AddMemoryDescriptor(PcMemoryMap,
                                             MAX_BIOS_DESCRIPTORS,
                                             (EbdaBase / PAGE_SIZE),
                                             ADDRESS_AND_SIZE_TO_SPAN_PAGES(EbdaBase, EbdaSize),
                                             LoaderFirmwarePermanent);
        }
    }

    /* Setup some protected ranges */
    SetMemory(0x000000, 0x01000, LoaderFirmwarePermanent); // Realmode IVT / BDA
    SetMemory(0x0A0000, 0x50000, LoaderFirmwarePermanent); // Video memory
    SetMemory(0x0F0000, 0x10000, LoaderSpecialMemory); // ROM
    SetMemory(0xFFF000, 0x01000, LoaderSpecialMemory); // unusable memory (do we really need this?)

    /* Reserve some static ranges for freeldr */
    ReserveMemory(0x1000, STACKLOW - 0x1000, LoaderFirmwareTemporary, "BIOS area");
    ReserveMemory(STACKLOW, STACKADDR - STACKLOW, LoaderOsloaderStack, "FreeLdr stack");
    ReserveMemory(FREELDR_BASE, FrLdrImageSize, LoaderLoadedProgram, "FreeLdr image");

    /* Default to 1 page above freeldr for the disk read buffer */
    DiskReadBuffer = (PUCHAR)ALIGN_UP_BY(FREELDR_BASE + FrLdrImageSize, PAGE_SIZE);
    DiskReadBufferSize = PAGE_SIZE;

    /* Scan for free range above freeldr image */
    for (i = 0; i < PcMapCount; i++)
    {
        if ((PcMemoryMap[i].BasePage > (FREELDR_BASE / PAGE_SIZE)) &&
            (PcMemoryMap[i].MemoryType == LoaderFree))
        {
            /* Use this range for the disk read buffer */
            DiskReadBuffer = (PVOID)(PcMemoryMap[i].BasePage * PAGE_SIZE);
            DiskReadBufferSize = min(PcMemoryMap[i].PageCount * PAGE_SIZE,
                                     MAX_DISKREADBUFFER_SIZE);
            break;
        }
    }

    TRACE("DiskReadBuffer=%p, DiskReadBufferSize=%lx\n",
          DiskReadBuffer, DiskReadBufferSize);

    /* Now reserve the range for the disk read buffer */
    ReserveMemory((ULONG_PTR)DiskReadBuffer,
                  DiskReadBufferSize,
                  LoaderFirmwareTemporary,
                  "Disk read buffer");

    TRACE("Dumping resulting memory map:\n");
    for (i = 0; i < PcMapCount; i++)
    {
        TRACE("BasePage=0x%lx, PageCount=0x%lx, Type=%s\n",
              PcMemoryMap[i].BasePage,
              PcMemoryMap[i].PageCount,
              MmGetSystemMemoryMapTypeString(PcMemoryMap[i].MemoryType));
    }

    *MemoryMapSize = PcMapCount;
    return PcMemoryMap;
}
Esempio n. 15
0
int common_startdisk(long newrowsize, long newcolsize, int colors)
{
    int freemem;
    long memorysize;
    unsigned int *fwd_link = nullptr;
    long longtmp;
    unsigned int cache_size;
    BYTE *tempfar = nullptr;
    if (g_disk_flag)
    {
        enddisk();
    }
    if (driver_diskp()) // otherwise, real screen also in use, don't hit it
    {
        char buf[128];
        helptitle();
        driver_set_attr(1, 0, C_DVID_BKGRD, 24*80);  // init rest to background
        for (int i = 0; i < BOXDEPTH; ++i)
        {
            driver_set_attr(BOXROW+i, BOXCOL, C_DVID_LO, BOXWIDTH);  // init box
        }
        driver_put_string(BOXROW+2, BOXCOL+4, C_DVID_HI, "'Disk-Video' mode");
        sprintf(buf, "Screen resolution: %d x %d", sxdots, sydots);
        driver_put_string(BOXROW+4, BOXCOL+4, C_DVID_LO, buf);
        if (disktarga)
        {
            driver_put_string(-1, -1, C_DVID_LO, "  24 bit Targa");
        }
        else
        {
            driver_put_string(-1, -1, C_DVID_LO, "  Colors: ");
            sprintf(buf, "%d", colors);
            driver_put_string(-1, -1, C_DVID_LO, buf);
        }
        sprintf(buf, "Save name: %s", savename);
        driver_put_string(BOXROW+8, BOXCOL+4, C_DVID_LO, buf);
        driver_put_string(BOXROW+10, BOXCOL+4, C_DVID_LO, "Status:");
        dvid_status(0, "clearing the 'screen'");
    }
    high_offset = -1;
    seek_offset = high_offset;
    cur_offset = seek_offset;
    cur_row    = -1;
    if (disktarga)
    {
        pixelshift = 0;
    }
    else
    {
        pixelshift = 3;
        int i = 2;
        while (i < colors)
        {
            i *= i;
            --pixelshift;
        }
    }
    timetodisplay = bf_math != bf_math_type::NONE ? 10 : 1000;  // time-to-g_driver-status counter

    /* allocate cache: try for the max; leave FREEMEMk free if we can get
        that much or more; if we can't get that much leave 1/2 of whatever
        there is free; demand a certain minimum or nogo at all */
    freemem = FREEMEM;

    for (cache_size = CACHEMAX; cache_size >= CACHEMIN; --cache_size)
    {
        longtmp = ((int)cache_size < freemem) ?
                  (long)cache_size << 11 : (long)(cache_size+freemem) << 10;
        tempfar = static_cast<BYTE *>(malloc(longtmp));
        if (tempfar != nullptr)
        {
            free(tempfar);
            break;
        }
    }
    if (debugflag == debug_flags::force_disk_min_cache)
    {
        cache_size = CACHEMIN;
    }
    longtmp = (long)cache_size << 10;
    cache_start = (cache *)malloc(longtmp);
    if (cache_size == 64)
    {
        --longtmp; // safety for next line
    }
    cache_lru = cache_start;
    cache_end = cache_lru + longtmp/sizeof(*cache_start);
    membuf = (BYTE *)malloc((long)BLOCKLEN);
    if (cache_start == nullptr || membuf == nullptr)
    {
        stopmsg(STOPMSG_NONE,
            "*** insufficient free memory for cache buffers ***");
        return -1;
    }
    if (driver_diskp())
    {
        char buf[50];
        sprintf(buf, "Cache size: %dK", cache_size);
        driver_put_string(BOXROW+6, BOXCOL+4, C_DVID_LO, buf);
    }

    // preset cache to all invalid entries so we don't need free list logic
    for (int i = 0; i < HASHSIZE; ++i)
    {
        hash_ptr[i] = 0xffff; // 0xffff marks the end of a hash chain
    }
    longtmp = 100000000L;
    for (cache *ptr1 = cache_start; ptr1 < cache_end; ++ptr1)
    {
        ptr1->dirty = false;
        ptr1->lru = false;
        longtmp += BLOCKLEN;
        fwd_link = &hash_ptr[(((unsigned short)longtmp >> BLOCKSHIFT) & (HASHSIZE-1))];
        ptr1->offset = longtmp;
        ptr1->hashlink = *fwd_link;
        *fwd_link = (int)((char *)ptr1 - (char *)cache_start);
    }

    memorysize = (long)(newcolsize) * newrowsize + headerlength;
    int i = (short)memorysize & (BLOCKLEN-1);
    if (i != 0)
    {
        memorysize += BLOCKLEN - i;
    }
    memorysize >>= pixelshift;
    memorysize >>= BLOCKSHIFT;
    g_disk_flag = true;
    rowsize = (unsigned int) newrowsize;
    colsize = (unsigned int) newcolsize;

    if (disktarga)
    {
        // Retrieve the header information first
        BYTE *tmpptr;
        tmpptr = membuf;
        fseek(fp, 0L, SEEK_SET);
        for (int i = 0; i < headerlength; i++)
        {
            *tmpptr++ = (BYTE)fgetc(fp);
        }
        fclose(fp);
        dv_handle = MemoryAlloc((U16)BLOCKLEN, memorysize, DISK);
    }
    else
    {
        dv_handle = MemoryAlloc((U16)BLOCKLEN, memorysize, MEMORY);
    }
    if (dv_handle == 0)
    {
        stopmsg(STOPMSG_NONE, "*** insufficient free memory/disk space ***");
        g_good_mode = false;
        rowsize = 0;
        return -1;
    }

    if (driver_diskp())
    {
        driver_put_string(BOXROW+2, BOXCOL+23, C_DVID_LO,
                          (MemoryType(dv_handle) == DISK) ? "Using your Disk Drive" : "Using your memory");
    }

    membufptr = membuf;

    if (disktarga)
    {
        // Put header information in the file
        MoveToMemory(membuf, (U16)headerlength, 1L, 0, dv_handle);
    }
    else
    {
        for (long offset = 0; offset < memorysize; offset++)
        {
            SetMemory(0, (U16)BLOCKLEN, 1L, offset, dv_handle);
            if (driver_key_pressed())           // user interrupt
            {
                // esc to cancel, else continue
                if (stopmsg(STOPMSG_CANCEL, "Disk Video initialization interrupted:\n"))
                {
                    enddisk();
                    g_good_mode = false;
                    return -2;            // -1 == failed, -2 == cancel
                }
            }
        }
    }

    if (driver_diskp())
    {
        dvid_status(0, "");
    }
    return 0;
}