static PaError InitializeDeviceInfo(PaMacCoreDeviceInfo *macCoreDeviceInfo,  AudioDeviceID macCoreDeviceId, PaHostApiIndex hostApiIndex )
{
    PaDeviceInfo *deviceInfo = &macCoreDeviceInfo->inheritedDeviceInfo;
    deviceInfo->structVersion = 2;
    deviceInfo->hostApi = hostApiIndex;
    
    PaError err = paNoError;
    UInt32 propSize;

    err = conv_err(AudioDeviceGetPropertyInfo(macCoreDeviceId, 0, 0, kAudioDevicePropertyDeviceName, &propSize, NULL));
    // FIXME: this allocation should be part of the allocations group
    char *name = PaUtil_AllocateMemory(propSize);
    err = conv_err(AudioDeviceGetProperty(macCoreDeviceId, 0, 0, kAudioDevicePropertyDeviceName, &propSize, name));
    if (!err) {
        deviceInfo->name = name;
    }
    
    Float64 sampleRate;
    propSize = sizeof(Float64);
    err = conv_err(AudioDeviceGetProperty(macCoreDeviceId, 0, 0, kAudioDevicePropertyNominalSampleRate, &propSize, &sampleRate));
    if (!err) {
        deviceInfo->defaultSampleRate = sampleRate;
    }


    // Get channel info
    err = GetChannelInfo(deviceInfo, macCoreDeviceId, 1);
    err = GetChannelInfo(deviceInfo, macCoreDeviceId, 0);

    return err;
}
Exemple #2
0
//-------------------------------------------------------------------------------
//
//	DoIt
//
//	Finally something interesting. You have been selected from your menu entry
//	or via the actions system to do your thing. Dump everything you can about
//	Photoshop by asking Photoshop. The output file is "Getter.log".
//
//-------------------------------------------------------------------------------
SPErr DoIt(PSActionsPlugInMessage * /*message*/)
{
	SPErr	error = 0;

	char logfilename[MAX_PATH];
	char* filename = (char*)"Getter.log";
	
	error = GetFullPathToDesktop(logfilename, MAX_PATH);
	if (error)
	{
		logfilename[0] = '\0';
		error = 0;
	}
	
	strncat(logfilename, filename, MAX_PATH-1);
	logfilename[MAX_PATH-1] = '\0';

	GetApplicationInfo(logfilename);
	GetLayerInfo(logfilename);
	GetActionInfo(logfilename);
	GetDocumentInfo(logfilename);
	GetChannelInfo(logfilename);
	GetBackgroundInfo(logfilename);

	// the above routines can do their job by indexing into the open objects
	// path info and history info are only available to the target document
	// 1. remember who is the current target
	// 2. target the other documents by indexing
	// 3. switch back to the original target 
	//    (use the ID it is the most reliable way to switch back)
	int32 currentDocumentID = 0;
	int32 numDocuments = 0;
	int32 docCounter = 0;

	// we are ignoring errors so this will not give an invalid error
	// message when there are no documents open
	(void) PIUGetInfo(classDocument, keyDocumentID, &currentDocumentID, NULL);

	(void) PIUGetInfo(classApplication, keyNumberOfDocuments, &numDocuments, NULL);

	if (numDocuments > 0)
	{
		for (docCounter = 1; docCounter <= numDocuments; docCounter++)
		{
			// this routine will error if we select the document
			// that is already selected, we don't care about this
			// as an error, keep chugging
			(void) PIUSelectByIndex(classDocument, docCounter);
			GetPathInfo(logfilename);
			GetHistoryInfo(logfilename);
		}
		// this routine will error if we select the document
		// that is already selected, we don't care about this
		// as an error, keep chugging
		(void) PIUSelectByID(classDocument, currentDocumentID);
	}

	return (error);
}
bool CalculateVelocityHandler::GetObsPara(int &eventid, QList<ObsPara> &list)
{
    QList<PickInfo> epick;

    for (int i = 0; i < pickinfo_list_.count(); i++)
    {
        if (pickinfo_list_.at(i).event_id == eventid)
        {
            epick.append(pickinfo_list_.at(i));
        }
    }
    for (int i = 0; i < epick.count(); i++)
    {
        PickInfo pinfo = epick.at(i);

        ChannelInfo cinfo;
        if (!GetChannelInfo(pinfo.channel_id, cinfo))
        {
            return false;
        }

        ObsPara para;
        para.station_id = pinfo.channel_id;
        para.channl_id = pinfo.channel_id;
        para.year = pinfo.trigger_time.year;
        para.month = pinfo.trigger_time.month;
        para.day = pinfo.trigger_time.day;
        para.hour = pinfo.trigger_time.hour;
        para.minute = pinfo.trigger_time.minute;
        para.second = pinfo.trigger_time.second;
        para.mili_sec = pinfo.trigger_time.tenth_ms;

        if (pinfo.p_pick_index == UN_INVALID_INT)
        {
            para.p_index = -1;
        }
        else
        {
            para.p_index = pinfo.p_pick_index;
        }

        if (pinfo.s_pick_index == UN_INVALID_INT)
        {
            para.s_index = -1;
        }
        else
        {
            para.s_index = pinfo.s_pick_index;
        }

        para.sample_rate = cinfo.sample_rate;

        list.append(para);
    }

    return true;
}
// Подключение к каналу виртуального пользователя.
void OnVirtualUserChannelConnect(BYTE *InBuffer) {
	String name, channel_name;

	try {
		// virtual user.
		GetStreamString (&InBuffer, &name);
		// channel.
		GetStreamString(&InBuffer, &channel_name);
		// topic.
		GetStreamString(&InBuffer, NULL);
		// greeting.
		GetStreamString(&InBuffer, NULL);

		LogicalConnections::iterator connection = FindConnectionByUser(name);
		OnlineUsersList::iterator user = GetConnectionUser(connection);
		ChannelsList::iterator channel = FindChannelByName(channel_name);
		StringList channel_users;
		if (!IsChannelMonitored(channel_name)) {
			AddChannelWatcher(name, channel_name);
			Channel channel_info = GetChannelInfo(channel_name);
			channel_users = GetChannelUsersList(name, channel_name);
			channel_info.online_users = channel_users.size();
			UpdateChannel(channel, GetChannelInfo(channel_name));
			for (unsigned int i = 0; i < channel_info.online_users; i++) {
				AddUserChannel(name, channel_name);
			}
		} else {
			AddUserChannel(name, channel_name);
			channel_users = GetChannelUsers(channel_name);
        }

		MapList params;
		params.insert(pair<String, String>("channel", channel_name));
		params.insert(pair<String, String>("topic", channel->topic));
		params.insert(pair<String, String>("greeting", channel->greeting));
		params.insert(pair<String, String>("users", "[" + implode(channel_users) + "]"));

		String json_object = SetParametersObject(params, true);
		SendNotification("virtual_user_channel_connect", json_object, connection, false);
	} catch (Exception *E) {
		throw(Format(e_virtual_user_channel_connect, ARRAYOFCONST((E->Message))));
	}
}
Bool PaintUndoTile::Init(PaintLayerBmp *pBitmap, Int x, Int y)
{
	m_pDestBitmap->SetLink(pBitmap);
	if (!pBitmap)
	{
		return false;
	}

	m_xTile = (int)(x * PAINTTILEINV);
	m_yTile = (int)(y * PAINTTILEINV);

	m_x = m_xTile * PAINTTILESIZE;
	m_y = m_yTile * PAINTTILESIZE;

	int bitdepth, numChannels;
	if (!GetChannelInfo(pBitmap, bitdepth, numChannels))
		return false;

	if (m_pData)
	{
		DeleteMem(m_pData);
		m_dataSize = 0;
	}

	COLORMODE colorMode = (COLORMODE)pBitmap->GetColorMode();
	Int32 bitsPerPixel = (bitdepth / 8) * numChannels;
	m_dataSize = PAINTTILESIZE * PAINTTILESIZE * bitsPerPixel;
	m_pData = NewMem(UChar, m_dataSize);

	if (!m_pData)
		return false;

	//Copy the data across;
	UChar *pos = m_pData;
	for (Int32 yy = 0; yy < PAINTTILESIZE; yy++)
	{
		pBitmap->GetPixelCnt((Int32)m_x, (Int32)m_y + yy, (Int32)PAINTTILESIZE, &pos[yy*PAINTTILESIZE*bitsPerPixel], colorMode, PIXELCNT_0);
	}

	return true;
}
void CalculateVelocityHandler::GetStationPSVel(QList<StationVelPara> &para)
{
    QList<LocData> list = station_adjust_result_.at(0).list;

    for (int i = 0; i < list.count(); i++)
    {
        LocData data = list.at(i);

        StationVelPara svel_para;

        ChannelInfo cinfo;
        GetChannelInfo(data.chanel_id, cinfo);
        StationInfo sinfo;
        GetStationInfo(cinfo.station_id, sinfo);

        svel_para.station_id = sinfo.id;
        svel_para.station_name = sinfo.name;

        switch (cinfo.component)
        {
        case 0:
            svel_para.component = "X";
            break;
        case 1:
            svel_para.component = "Y";
            break;
        case 2:
            svel_para.component = "Z";
            break;
        default:
            svel_para.component = "-";
        }

        svel_para.p_vel = station_adjust_result_.at(0).p_vel;
        svel_para.s_vel = station_adjust_result_.at(0).s_vel;

        para.append(svel_para);
    }
}
Exemple #7
0
bool CNtlLogSystem::IsChannelOn(DWORD dwSource, BYTE byChannel)
{
	::EnterCriticalSection(&m_lock);

	sSOURCE_INFO* pSourceInfo = GetSourceInfo(dwSource);
	if (NULL == pSourceInfo)
	{
		::LeaveCriticalSection(&m_lock);
		return false;
	}

	sCHANNEL_INFO* pChannelInfo = GetChannelInfo(pSourceInfo, byChannel);
	if (NULL == pChannelInfo)
	{
		::LeaveCriticalSection(&m_lock);
		return false;
	}

	bool bIsOn = pChannelInfo->bIsOn;

	::LeaveCriticalSection(&m_lock);
	return bIsOn;
}
void PaintUndoTile::Apply()
{
	PaintLayerBmp *pBitmap = GetBitmap();
	if (!pBitmap)
	{
		return;
	}

	int bitdepth, numChannels;
	if (!GetChannelInfo(pBitmap, bitdepth, numChannels))
		return;

	COLORMODE colorMode = (COLORMODE)pBitmap->GetColorMode();
	Int32 bitsPerPixel = (bitdepth / 8) * numChannels;

	//Copy the data across;
	UChar *pos = m_pData;
	for (Int32 y = 0; y < PAINTTILESIZE; y++)
	{
		pBitmap->SetPixelCnt((Int32)m_x, (Int32)m_y + y, PAINTTILESIZE, &pos[y*PAINTTILESIZE*bitsPerPixel], bitsPerPixel, colorMode , PIXELCNT_0);
	}

	pBitmap->UpdateRefresh((Int32)m_x, (Int32)m_y, (Int32)m_x+PAINTTILESIZE, (Int32)m_y+PAINTTILESIZE, UPDATE_STD);
}
bool CalculateVelocityHandler::GetTimeGridPara(TimeGridPara &para, int channel_id)
{
    AppSettings setting = ConfigManager::GetInstance()->AppSetting();

    para.grid.origin_x = setting.mine_area().min_x;
    para.grid.origin_y = setting.mine_area().min_y;
    para.grid.origin_z = setting.mine_area().min_z;

    if (setting.cell_step() == 0)
    {
        return false;
    }

    para.grid.step_x = setting.cell_step();
    para.grid.step_y = setting.cell_step();
    para.grid.step_z = setting.cell_step();

    para.grid.grid_num_x = (setting.mine_area().max_x - setting.mine_area().min_x) / para.grid.step_x;
    para.grid.grid_num_y = (setting.mine_area().max_y - setting.mine_area().min_y) / para.grid.step_y;
    para.grid.grid_num_z = (setting.mine_area().max_z - setting.mine_area().min_z) / para.grid.step_z;

    para.layer_list = setting.layer_info();

    QList<ChannelInfo> list = channel_map_.values();

    for (int i = 0; i < list.count(); i++)
    {
        ChannelInfo info = list.at(i);

        if (channel_id != 0)
        {
            if (info.id != channel_id)
            {
                continue;
            }
        }

        ChannelInfo cinfo;

        if (!GetChannelInfo(info.id, cinfo))
        {
            return false;
        }

        StationInfo sinfo;

        if (!GetStationInfo(cinfo.station_id, sinfo))
        {
            return false;
        }

        SCInfo scinfo;
        scinfo.name = sinfo.name + "_" + QString().sprintf("%d", cinfo.component);
        scinfo.channel_id = cinfo.id;
        scinfo.east = sinfo.point.east;
        scinfo.north = sinfo.point.north;
        scinfo.deep = sinfo.point.deep;

        para.scinfo_list.append(scinfo);
    }

    return true;
}
Exemple #10
0
const char * NczPlayer::GetIPAddress()
{
	return GetChannelInfo()->GetAddress();
}
Exemple #11
0
static void VmbusGetChannelInfo(struct hv_device *DeviceObject,
				struct hv_device_info *DeviceInfo)
{
	GetChannelInfo(DeviceObject, DeviceInfo);
}
Exemple #12
0
int FAACAPI faacEncEncode(faacEncHandle hEncoder,
                          int32_t *inputBuffer,
                          unsigned int samplesInput,
                          unsigned char *outputBuffer,
                          unsigned int bufferSize
                          )
{
    unsigned int channel, i;
    int sb, frameBytes;
    unsigned int offset;
    BitStream *bitStream; /* bitstream used for writing the frame to */
    TnsInfo *tnsInfo_for_LTP;
    TnsInfo *tnsDecInfo;
#ifdef DRM
    int desbits, diff;
    double fix;
#endif

    /* local copy's of parameters */
    ChannelInfo *channelInfo = hEncoder->channelInfo;
    CoderInfo *coderInfo = hEncoder->coderInfo;
    unsigned int numChannels = hEncoder->numChannels;
    unsigned int sampleRate = hEncoder->sampleRate;
    unsigned int aacObjectType = hEncoder->config.aacObjectType;
    unsigned int mpegVersion = hEncoder->config.mpegVersion;
    unsigned int useLfe = hEncoder->config.useLfe;
    unsigned int useTns = hEncoder->config.useTns;
    unsigned int allowMidside = hEncoder->config.allowMidside;
    unsigned int bandWidth = hEncoder->config.bandWidth;
    unsigned int shortctl = hEncoder->config.shortctl;

    /* Increase frame number */
    hEncoder->frameNum++;

    if (samplesInput == 0)
        hEncoder->flushFrame++;

    /* After 4 flush frames all samples have been encoded,
       return 0 bytes written */
    if (hEncoder->flushFrame > 4)
        return 0;

    /* Determine the channel configuration */
    GetChannelInfo(channelInfo, numChannels, useLfe);

    /* Update current sample buffers */
    for (channel = 0; channel < numChannels; channel++) 
	{
		double *tmp;

        if (hEncoder->sampleBuff[channel]) {
            for(i = 0; i < FRAME_LEN; i++) {
                hEncoder->ltpTimeBuff[channel][i] = hEncoder->sampleBuff[channel][i];
            }
        }
        if (hEncoder->nextSampleBuff[channel]) {
            for(i = 0; i < FRAME_LEN; i++) {
                hEncoder->ltpTimeBuff[channel][FRAME_LEN + i] =
						hEncoder->nextSampleBuff[channel][i];
            }
        }

		if (!hEncoder->sampleBuff[channel])
			hEncoder->sampleBuff[channel] = (double*)AllocMemory(FRAME_LEN*sizeof(double));
		
		tmp = hEncoder->sampleBuff[channel];

        hEncoder->sampleBuff[channel]		= hEncoder->nextSampleBuff[channel];
        hEncoder->nextSampleBuff[channel]	= hEncoder->next2SampleBuff[channel];
        hEncoder->next2SampleBuff[channel]	= hEncoder->next3SampleBuff[channel];
		hEncoder->next3SampleBuff[channel]	= tmp;

        if (samplesInput == 0)
        {
            /* start flushing*/
            for (i = 0; i < FRAME_LEN; i++)
                hEncoder->next3SampleBuff[channel][i] = 0.0;
        }
        else
        {
			int samples_per_channel = samplesInput/numChannels;

            /* handle the various input formats and channel remapping */
            switch( hEncoder->config.inputFormat )
			{
                case FAAC_INPUT_16BIT:
					{
						short *input_channel = (short*)inputBuffer + hEncoder->config.channel_map[channel];

						for (i = 0; i < samples_per_channel; i++)
						{
							hEncoder->next3SampleBuff[channel][i] = (double)*input_channel;
							input_channel += numChannels;
						}
					}
                    break;

                case FAAC_INPUT_32BIT:
					{
						int32_t *input_channel = (int32_t*)inputBuffer + hEncoder->config.channel_map[channel];
						
						for (i = 0; i < samples_per_channel; i++)
						{
							hEncoder->next3SampleBuff[channel][i] = (1.0/256) * (double)*input_channel;
							input_channel += numChannels;
						}
					}
                    break;

                case FAAC_INPUT_FLOAT:
					{
						float *input_channel = (float*)inputBuffer + hEncoder->config.channel_map[channel];

						for (i = 0; i < samples_per_channel; i++)
						{
							hEncoder->next3SampleBuff[channel][i] = (double)*input_channel;
							input_channel += numChannels;
						}
					}
                    break;

                default:
                    return -1; /* invalid input format */
                    break;
            }

            for (i = (int)(samplesInput/numChannels); i < FRAME_LEN; i++)
                hEncoder->next3SampleBuff[channel][i] = 0.0;
		}

		/* Psychoacoustics */
		/* Update buffers and run FFT on new samples */
		/* LFE psychoacoustic can run without it */
		if (!channelInfo[channel].lfe || channelInfo[channel].cpe)
		{
			hEncoder->psymodel->PsyBufferUpdate( 
					&hEncoder->fft_tables, 
					&hEncoder->gpsyInfo, 
					&hEncoder->psyInfo[channel],
					hEncoder->next3SampleBuff[channel], 
					bandWidth,
					hEncoder->srInfo->cb_width_short,
					hEncoder->srInfo->num_cb_short);
		}
    }

    if (hEncoder->frameNum <= 3) /* Still filling up the buffers */
        return 0;

    /* Psychoacoustics */
    hEncoder->psymodel->PsyCalculate(channelInfo, &hEncoder->gpsyInfo, hEncoder->psyInfo,
        hEncoder->srInfo->cb_width_long, hEncoder->srInfo->num_cb_long,
        hEncoder->srInfo->cb_width_short,
        hEncoder->srInfo->num_cb_short, numChannels);

    hEncoder->psymodel->BlockSwitch(coderInfo, hEncoder->psyInfo, numChannels);

    /* force block type */
    if (shortctl == SHORTCTL_NOSHORT)
    {
		for (channel = 0; channel < numChannels; channel++)
		{
			coderInfo[channel].block_type = ONLY_LONG_WINDOW;
		}
    }
    if (shortctl == SHORTCTL_NOLONG)
    {
		for (channel = 0; channel < numChannels; channel++)
		{
			coderInfo[channel].block_type = ONLY_SHORT_WINDOW;
		}
    }

    /* AAC Filterbank, MDCT with overlap and add */
    for (channel = 0; channel < numChannels; channel++) {
        int k;

        FilterBank(hEncoder,
            &coderInfo[channel],
            hEncoder->sampleBuff[channel],
            hEncoder->freqBuff[channel],
            hEncoder->overlapBuff[channel],
            MOVERLAPPED);

        if (coderInfo[channel].block_type == ONLY_SHORT_WINDOW) {
            for (k = 0; k < 8; k++) {
                specFilter(hEncoder->freqBuff[channel]+k*BLOCK_LEN_SHORT,
						sampleRate, bandWidth, BLOCK_LEN_SHORT);
            }
        } else {
            specFilter(hEncoder->freqBuff[channel], sampleRate,
					bandWidth, BLOCK_LEN_LONG);
        }
    }

    /* TMP: Build sfb offset table and other stuff */
    for (channel = 0; channel < numChannels; channel++) {
        channelInfo[channel].msInfo.is_present = 0;

        if (coderInfo[channel].block_type == ONLY_SHORT_WINDOW) {
			coderInfo[channel].max_sfb = hEncoder->srInfo->num_cb_short;
            coderInfo[channel].nr_of_sfb = hEncoder->srInfo->num_cb_short;

            coderInfo[channel].num_window_groups = 1;
            coderInfo[channel].window_group_length[0] = 8;
            coderInfo[channel].window_group_length[1] = 0;
            coderInfo[channel].window_group_length[2] = 0;
            coderInfo[channel].window_group_length[3] = 0;
            coderInfo[channel].window_group_length[4] = 0;
            coderInfo[channel].window_group_length[5] = 0;
            coderInfo[channel].window_group_length[6] = 0;
            coderInfo[channel].window_group_length[7] = 0;

            offset = 0;
            for (sb = 0; sb < coderInfo[channel].nr_of_sfb; sb++) {
                coderInfo[channel].sfb_offset[sb] = offset;
                offset += hEncoder->srInfo->cb_width_short[sb];
            }
            coderInfo[channel].sfb_offset[coderInfo[channel].nr_of_sfb] = offset;
        } else {
            coderInfo[channel].max_sfb = hEncoder->srInfo->num_cb_long;
            coderInfo[channel].nr_of_sfb = hEncoder->srInfo->num_cb_long;

            coderInfo[channel].num_window_groups = 1;
            coderInfo[channel].window_group_length[0] = 1;

            offset = 0;
            for (sb = 0; sb < coderInfo[channel].nr_of_sfb; sb++) {
                coderInfo[channel].sfb_offset[sb] = offset;
                offset += hEncoder->srInfo->cb_width_long[sb];
            }
            coderInfo[channel].sfb_offset[coderInfo[channel].nr_of_sfb] = offset;
        }
    }

    /* Perform TNS analysis and filtering */
    for (channel = 0; channel < numChannels; channel++) {
        if ((!channelInfo[channel].lfe) && (useTns)) {
            TnsEncode(&(coderInfo[channel].tnsInfo),
					coderInfo[channel].max_sfb,
					coderInfo[channel].max_sfb,
					coderInfo[channel].block_type,
					coderInfo[channel].sfb_offset,
					hEncoder->freqBuff[channel]);
        } else {
            coderInfo[channel].tnsInfo.tnsDataPresent = 0;      /* TNS not used for LFE */
        }
    }

    for(channel = 0; channel < numChannels; channel++)
    {
        if((coderInfo[channel].tnsInfo.tnsDataPresent != 0) && (useTns))
            tnsInfo_for_LTP = &(coderInfo[channel].tnsInfo);
        else
            tnsInfo_for_LTP = NULL;

        if(channelInfo[channel].present && (!channelInfo[channel].lfe) &&
            (coderInfo[channel].block_type != ONLY_SHORT_WINDOW) &&
            (mpegVersion == MPEG4) && (aacObjectType == LTP))
        {
            LtpEncode(hEncoder,
					&coderInfo[channel],
					&(coderInfo[channel].ltpInfo),
					tnsInfo_for_LTP,
					hEncoder->freqBuff[channel],
					hEncoder->ltpTimeBuff[channel]);
        } else {
            coderInfo[channel].ltpInfo.global_pred_flag = 0;
        }
    }

    for(channel = 0; channel < numChannels; channel++)
    {
        if ((aacObjectType == MAIN) && (!channelInfo[channel].lfe)) {
            int numPredBands = min(coderInfo[channel].max_pred_sfb, coderInfo[channel].nr_of_sfb);
            PredCalcPrediction(hEncoder->freqBuff[channel],
					coderInfo[channel].requantFreq,
					coderInfo[channel].block_type,
					numPredBands,
					(coderInfo[channel].block_type==ONLY_SHORT_WINDOW)?
					hEncoder->srInfo->cb_width_short:hEncoder->srInfo->cb_width_long,
					coderInfo,
					channelInfo,
					channel);
        } else {
            coderInfo[channel].pred_global_flag = 0;
        }
    }

    for (channel = 0; channel < numChannels; channel++) {
		if (coderInfo[channel].block_type == ONLY_SHORT_WINDOW) {
			SortForGrouping(&coderInfo[channel],
					&hEncoder->psyInfo[channel],
					&channelInfo[channel],
					hEncoder->srInfo->cb_width_short,
					hEncoder->freqBuff[channel]);
		}
		CalcAvgEnrg(&coderInfo[channel], hEncoder->freqBuff[channel]);

      // reduce LFE bandwidth
		if (!channelInfo[channel].cpe && channelInfo[channel].lfe)
		{
			coderInfo[channel].nr_of_sfb = coderInfo[channel].max_sfb = 3;
		}
	}

    MSEncode(coderInfo, channelInfo, hEncoder->freqBuff, numChannels, allowMidside);

    for (channel = 0; channel < numChannels; channel++)
    {
        CalcAvgEnrg(&coderInfo[channel], hEncoder->freqBuff[channel]);
    }

#ifdef DRM
    /* loop the quantization until the desired bit-rate is reached */
    diff = 1; /* to enter while loop */
    hEncoder->aacquantCfg.quality = 120; /* init quality setting */
    while (diff > 0) { /* if too many bits, do it again */
#endif
    /* Quantize and code the signal */
    for (channel = 0; channel < numChannels; channel++) {
        if (coderInfo[channel].block_type == ONLY_SHORT_WINDOW) {
            AACQuantize(&coderInfo[channel], &hEncoder->psyInfo[channel],
					&channelInfo[channel], hEncoder->srInfo->cb_width_short,
					hEncoder->srInfo->num_cb_short, hEncoder->freqBuff[channel],
					&(hEncoder->aacquantCfg));
        } else {
            AACQuantize(&coderInfo[channel], &hEncoder->psyInfo[channel],
					&channelInfo[channel], hEncoder->srInfo->cb_width_long,
					hEncoder->srInfo->num_cb_long, hEncoder->freqBuff[channel],
					&(hEncoder->aacquantCfg));
        }
    }

#ifdef DRM
    /* Write the AAC bitstream */
    bitStream = OpenBitStream(bufferSize, outputBuffer);
    WriteBitstream(hEncoder, coderInfo, channelInfo, bitStream, numChannels);

    /* Close the bitstream and return the number of bytes written */
    frameBytes = CloseBitStream(bitStream);

    /* now calculate desired bits and compare with actual encoded bits */
    desbits = (int) ((double) numChannels * (hEncoder->config.bitRate * FRAME_LEN)
            / hEncoder->sampleRate);

    diff = ((frameBytes - 1 /* CRC */) * 8) - desbits;

    /* do linear correction according to relative difference */
    fix = (double) desbits / ((frameBytes - 1 /* CRC */) * 8);

    /* speed up convergence. A value of 0.92 gives approx up to 10 iterations */
    if (fix > 0.92)
        fix = 0.92;

    hEncoder->aacquantCfg.quality *= fix;

    /* quality should not go lower than 1, set diff to exit loop */
    if (hEncoder->aacquantCfg.quality <= 1)
        diff = -1;
    }
#endif

    // fix max_sfb in CPE mode
    for (channel = 0; channel < numChannels; channel++)
    {
		if (channelInfo[channel].present
				&& (channelInfo[channel].cpe)
				&& (channelInfo[channel].ch_is_left))
		{
			CoderInfo *cil, *cir;

			cil = &coderInfo[channel];
			cir = &coderInfo[channelInfo[channel].paired_ch];

			cil->max_sfb = cir->max_sfb = max(cil->max_sfb, cir->max_sfb);
			cil->nr_of_sfb = cir->nr_of_sfb = cil->max_sfb;
		}
    }

    MSReconstruct(coderInfo, channelInfo, numChannels);

    for (channel = 0; channel < numChannels; channel++)
    {
        /* If short window, reconstruction not needed for prediction */
        if ((coderInfo[channel].block_type == ONLY_SHORT_WINDOW)) {
            int sind;
            for (sind = 0; sind < BLOCK_LEN_LONG; sind++) {
				coderInfo[channel].requantFreq[sind] = 0.0;
            }
        } else {

            if((coderInfo[channel].tnsInfo.tnsDataPresent != 0) && (useTns))
                tnsDecInfo = &(coderInfo[channel].tnsInfo);
            else
                tnsDecInfo = NULL;

            if ((!channelInfo[channel].lfe) && (aacObjectType == LTP)) {  /* no reconstruction needed for LFE channel*/

                LtpReconstruct(&coderInfo[channel], &(coderInfo[channel].ltpInfo),
						coderInfo[channel].requantFreq);

                if(tnsDecInfo != NULL)
                    TnsDecodeFilterOnly(&(coderInfo[channel].tnsInfo), coderInfo[channel].nr_of_sfb,
							coderInfo[channel].max_sfb, coderInfo[channel].block_type,
							coderInfo[channel].sfb_offset, coderInfo[channel].requantFreq);

                IFilterBank(hEncoder, &coderInfo[channel],
						coderInfo[channel].requantFreq,
						coderInfo[channel].ltpInfo.time_buffer,
						coderInfo[channel].ltpInfo.ltp_overlap_buffer,
						MOVERLAPPED);

                LtpUpdate(&(coderInfo[channel].ltpInfo),
						coderInfo[channel].ltpInfo.time_buffer,
						coderInfo[channel].ltpInfo.ltp_overlap_buffer,
						BLOCK_LEN_LONG);
            }
        }
    }

#ifndef DRM
    /* Write the AAC bitstream */
    bitStream = OpenBitStream(bufferSize, outputBuffer);

    WriteBitstream(hEncoder, coderInfo, channelInfo, bitStream, numChannels);

    /* Close the bitstream and return the number of bytes written */
    frameBytes = CloseBitStream(bitStream);

    /* Adjust quality to get correct average bitrate */
    if (hEncoder->config.bitRate)
	{
		double fix;
		int desbits = numChannels * (hEncoder->config.bitRate * FRAME_LEN)
				/ hEncoder->sampleRate;
		int diff = (frameBytes * 8) - desbits;

		hEncoder->bitDiff += diff;
		fix = (double)hEncoder->bitDiff / desbits;
		fix *= 0.01;
		fix = max(fix, -0.2);
		fix = min(fix, 0.2);

		if (((diff > 0) && (fix > 0.0)) || ((diff < 0) && (fix < 0.0)))
		{
			hEncoder->aacquantCfg.quality *= (1.0 - fix);
			if (hEncoder->aacquantCfg.quality > 300)
				hEncoder->aacquantCfg.quality = 300;
            if (hEncoder->aacquantCfg.quality < 50)
                hEncoder->aacquantCfg.quality = 50;
		}
    }
#endif

    return frameBytes;
}
Exemple #13
0
bool CNtlLogSystem::AddLogAlternative(DWORD dwSource, BYTE byChannel, char* pszFormatString, va_list args)
{
	if (NULL == pszFormatString)
	{
		return false;
	}

	::EnterCriticalSection(&m_lock);

	if (false == m_bIsEnabled)
	{
		::LeaveCriticalSection(&m_lock);
		return true;
	}

	sSOURCE_INFO* pSourceInfo = GetSourceInfo(dwSource);
	if (NULL == pSourceInfo)
	{
		::LeaveCriticalSection(&m_lock);
		return false;
	}

	sCHANNEL_INFO* pChannelInfo = GetChannelInfo(pSourceInfo, byChannel);
	if (NULL == pChannelInfo)
	{
		::LeaveCriticalSection(&m_lock);
		return false;
	}

	if (false == pChannelInfo->bIsOn)
	{
		::LeaveCriticalSection(&m_lock);
		return true;
	}

	sLOG_FILE_KEY key(dwSource, byChannel);

	std::map<sLOG_FILE_KEY, sLOG_FILE_INFO*>::iterator iter;
	iter = m_mapLogFileRef.find(key);

	if (m_mapLogFileRef.end() == iter)
	{
		::LeaveCriticalSection(&m_lock);
		return false;
	}

	sLOG_FILE_INFO* pLogFileInfo = iter->second;

	::LeaveCriticalSection(&m_lock);

	::EnterCriticalSection(&(pLogFileInfo->lock));

	SYSTEMTIME localTime;
	GetLocalTime(&localTime);

	if (pLogFileInfo->wLastLogYear != localTime.wYear ||
		pLogFileInfo->wLastLogMonth != localTime.wMonth ||
		pLogFileInfo->wLastLogDay != localTime.wDay)
	{
		CloseLogFile(pLogFileInfo);
		OpenLogFile(pLogFileInfo);
	}

	fprintf( pLogFileInfo->fileStream.GetFilePtr(), "[%s],", pChannelInfo->szChannelName);
	vfprintf( pLogFileInfo->fileStream.GetFilePtr(), pszFormatString, args);
	fprintf( pLogFileInfo->fileStream.GetFilePtr(), "\n");
	fflush( pLogFileInfo->fileStream.GetFilePtr() );

	::LeaveCriticalSection(&(pLogFileInfo->lock));
	return true;
}
Exemple #14
0
bool CNtlLogSystem::RegisterChannel(
						DWORD dwSource, BYTE byChannel, char* pszChannelName,
						char* pszLogFileNamePrefix, char* pszLogFileNameSuffix, char* pszLogFileExtName, bool bIsOn)
{
	if (NULL == pszChannelName || NULL == pszLogFileNamePrefix || NULL == pszLogFileNameSuffix || NULL == pszLogFileExtName)
	{
		return false;
	}

	::EnterCriticalSection(&m_lock);

	sSOURCE_INFO* pSourceInfo = GetSourceInfo(dwSource);
	if (NULL == pSourceInfo)
	{
		::LeaveCriticalSection(&m_lock);
		return false;
	}

	sCHANNEL_INFO* pChannelInfo = GetChannelInfo(pSourceInfo, byChannel);
	if (NULL != pChannelInfo)
	{
		::LeaveCriticalSection(&m_lock);
		return false;
	}

	// Creates channel info.
	{
		pChannelInfo = new sCHANNEL_INFO(bIsOn);
		if (NULL == pChannelInfo)
		{
			::LeaveCriticalSection(&m_lock);
			return false;
		}

		NTL_SAFE_STRCPY(pChannelInfo->szChannelName, pszChannelName);

		if (false == (pSourceInfo->mapChannel).insert(std::pair<BYTE, sCHANNEL_INFO*>(byChannel, pChannelInfo)).second)
		{
			SAFE_DELETE(pChannelInfo);

			::LeaveCriticalSection(&m_lock);
			return false;
		}
	}

	sLOG_FILE_INFO* pLogFileInfo = NULL;

	// Creates log file info.
	{
		CNtlString strLogFileKey;
		strLogFileKey.Format("%s_%s", pszLogFileNamePrefix, pszLogFileNameSuffix);

		std::map<CNtlString, sLOG_FILE_INFO*>::iterator iterLogFile;
		iterLogFile = (pSourceInfo->mapLoggingFileInfo).find(strLogFileKey);

		if ((pSourceInfo->mapLoggingFileInfo).end() == iterLogFile)
		{
			pLogFileInfo = new sLOG_FILE_INFO;
			if (NULL == pLogFileInfo)
			{
				(pSourceInfo->mapChannel).erase(byChannel);
				SAFE_DELETE(pChannelInfo);

				::LeaveCriticalSection(&m_lock);
				return false;
			}

			NTL_SAFE_STRCPY(pLogFileInfo->szLogFileNamePrefix, pszLogFileNamePrefix);
			NTL_SAFE_STRCPY(pLogFileInfo->szLogFileNameSuffix, pszLogFileNameSuffix);
			NTL_SAFE_STRCPY(pLogFileInfo->szLogFileExtName, pszLogFileExtName);

			if (false == (pSourceInfo->mapLoggingFileInfo).insert(std::pair<CNtlString, sLOG_FILE_INFO*>(strLogFileKey, pLogFileInfo)).second)
			{
				SAFE_DELETE(pLogFileInfo);

				(pSourceInfo->mapChannel).erase(byChannel);
				SAFE_DELETE(pChannelInfo);

				::LeaveCriticalSection(&m_lock);
				return false;
			}

			if (false == OpenLogFile(pLogFileInfo))
			{
				(pSourceInfo->mapLoggingFileInfo).erase(strLogFileKey);
				SAFE_DELETE(pLogFileInfo);

				(pSourceInfo->mapChannel).erase(byChannel);
				SAFE_DELETE(pChannelInfo);

				::LeaveCriticalSection(&m_lock);
				return false;
			}

			::EnterCriticalSection(&(pLogFileInfo->lock));

			pLogFileInfo->dwRefCount = 1;
		}
		else
		{
			pLogFileInfo = iterLogFile->second;

			::EnterCriticalSection(&(pLogFileInfo->lock));

			(pLogFileInfo->dwRefCount)++;
		}

		sLOG_FILE_KEY logKey(dwSource, byChannel);

		if (false == m_mapLogFileRef.insert(std::pair<sLOG_FILE_KEY, sLOG_FILE_INFO*>(logKey, pLogFileInfo)).second)
		{
			(pLogFileInfo->dwRefCount)--;

			if (0 == pLogFileInfo->dwRefCount)
			{
				::LeaveCriticalSection(&(pLogFileInfo->lock));

				(pSourceInfo->mapLoggingFileInfo).erase(strLogFileKey);
				SAFE_DELETE(pLogFileInfo);
			}
			else
			{
				::LeaveCriticalSection(&(pLogFileInfo->lock));
			}

			(pSourceInfo->mapChannel).erase(byChannel);
			SAFE_DELETE(pChannelInfo);

			::LeaveCriticalSection(&m_lock);
			return false;
		}
		else
		{
			::LeaveCriticalSection(&(pLogFileInfo->lock));
		}
	}

	::LeaveCriticalSection(&m_lock);
	return true;
}
Exemple #15
0
int PutWaveformData ( FILE *ptr , DBlist tree , int cm6 )
{
    char id	[ 5 ] ,
	time	[ 24 ] ,
	station	[ 6 ] ,
	channel	[ 4 ] ,
	auxid	[ 5 ] ,
	datatype[ 4 ] ,
	samps	[ 9 ] ,
	samprat	[ 12 ] ,
	calib	[ 11 ] ,
	calper	[ 9 ] ;
    char instype[ ] = "      ",
	hang	[ 6 ] ,
	vang	[ 5 ] ;

    double dHang , dVang ;

    int Ntraces = 0 ;

    int dots = 0 ;
    int jdx ;
    int column ;
    int MaxColumns = 15 ;

    struct CSStree *Tree = (struct CSStree *) tree ;
    struct wfdiscList *wfL ;

    printf ( "Converting waveforms " ) ;
    for ( wfL = Tree->wfHead ; wfL ; wfL = wfL->next , Ntraces++ ) {
	int *iData ;
	struct sitechanList *sc = Tree->scHead ;

	/* display dots for the users sake */
	putchar('.');
	dots++;
	if(dots == 80){
	    putchar('\n');
	    dots = 0;
	}
	fflush(stdout);

	/* data_type record */
	fprintf(ptr,"DATA_TYPE WAVEFORM\n");

	/* BEGIN WID2 RECORD */

	/* id */
	strcpy ( id , "WID2" ) ;

	/* date and time */
	if(isValidFloat( dbl_LIST_WFDISC, dbl_WFDIS_TIME, wfL->element->time )){
	    sprintf ( time , "%-23.23s" , tmListEpochTime ( wfL->element->time , 14 ) ) ;
	    time[ 10 ] = ' ' ;
	}
	else
	    strcpy ( time , "                       " ) ;	/* 23 spaces */
	    
	/* station */
	if ( isValidString ( dbl_LIST_WFDISC, dbl_WFDIS_STA , wfL->element->sta ) &&
             strcmp( wfL->element->sta , "-    " ) ) 
	    sprintf ( station , "%-5.5s" , wfL->element->sta ) ;
	else
	    strcpy ( station , "     " ) ;	/* 5 spaces */

	/* channel */
	if ( isValidString ( dbl_LIST_WFDISC, dbl_WFDIS_CHAN , wfL->element->chan ) &&
             strcmp( wfL->element->chan , "-  " )  )
	    sprintf ( channel , "%-3.3s" , wfL->element->chan ) ;
	else
	    strcpy ( channel , "   " ) ;	/* 3 spaces */

	/* auxid */
	strcpy ( auxid , "    " ) ;		/* 4 spaces */

	/* datatype */
        if( cm6 )
	    strcpy ( datatype , "CM6" ) ;       /* 3 spaces */
        else
	    strcpy ( datatype , "INT" ) ;       /* 3 spaces */

	/* samps */
	if ( isValidInt ( dbl_LIST_WFDISC, dbl_WFDIS_NSAMP , wfL->element->nsamp ) )
	    sprintf ( samps , "%8d" , wfL->element->nsamp ) ;
	else {
	    printf ( "Warning:  file %d had no value for samps\n" , Ntraces + 1 ) ;
	    continue ;
	}

	/* samprat */
	if ( isValidFloat ( dbl_LIST_WFDISC, dbl_WFDIS_SAMPRATE , wfL->element->samprate ) )
	    sprintf ( samprat , "%11.6f" , wfL->element->samprate ) ;
	else
	    strcpy ( samprat , "           " ) ;/* 11 spaces */

	/* calib */
	if ( isValidFloat ( dbl_LIST_WFDISC, dbl_WFDIS_CALIB , wfL->element->calib ) )
	    sprintf ( calib , "%10.2e" , wfL->element->calib ) ;
	else
	    strcpy ( calib , "          " ) ;	/* 10 spaces */

	/* calper */
        if ( isValidFloat ( dbl_LIST_WFDISC, dbl_WFDIS_CALPER , wfL->element->calper ) )
            sprintf ( calper , "%7.3f" , wfL->element->calper ) ;
        else
            sprintf ( calper , "%s", "        " ) ;   /* 8 spaces */

	/* instype */
	if ( isValidString ( dbl_LIST_WFDISC, dbl_WFDIS_INSTYPE , wfL->element->instype ) &&
             strcmp( wfL->element->instype , "-     " )  )
	    sprintf ( instype , "%-6.6s" , wfL->element->instype ) ;
	else
	    strcpy ( instype , "      " ) ;	/* 6 spaces */

	/* hang and vang */
	GetChannelInfo(sc, station, channel, &dHang, &dVang);
	if ( isValidFloat ( dbl_LIST_SITECHAN, dbl_SITEC_HANG , dHang ) )
	    sprintf ( hang , "%5.1f" , dHang ) ;
	else
	    strcpy ( hang , "     " ) ;		/* 5 spaces */

	if ( isValidFloat ( dbl_LIST_SITECHAN, dbl_SITEC_VANG , dVang ) )
            sprintf ( vang , "%4.1f" , dVang ) ;
        else
            strcpy ( vang , "    " ) ;         /* 4 spaces */

	fprintf(ptr, "%s %s %s %s %s %s %s %s %s %s %s %s %s\n", id, time, station,
	  channel, auxid, datatype, samps, samprat, calib, calper, instype, hang, vang);
	/* END WID2 RECORD */


	/* dat2 record */
	fprintf(ptr,"DAT2\n");

	column = 0 ;

	if( !wfL->seis ) {
	    printf ( "ERROR: Data not found!\n " ) ;
	    return ( -1 ) ;
	}

	/* waveform */
	iData = (int *) malloc ( wfL->element->nsamp * sizeof( int ) ) ;
	if ( !iData ) {
	    printf ( "Error:  insufficient memory, PutWavefomrData\n" ) ;
	    return 0 ;
	}
	for ( jdx = 0 ; jdx < wfL->element->nsamp ; jdx++ ) {
	    double point = wfL->seis->i[ jdx ] ;

	    point = point >= 0 ? point + 0.5 : point - 0.5 ;
	    iData[ jdx ] = (int) point ;

            if( !cm6 ){    /* INT format, one point at a time. */
	        fprintf ( ptr , "%d " , (int) point ) ;
	        if ( ++column == MaxColumns ) {
		    fprintf ( ptr , "\n" ) ;
		    column = 0 ;
	        }
            }
	}
        if( cm6 ){
	    char *cOut ;  /* data compressed into CM6 format. */

            takeDiff( iData , wfL->element->nsamp ) ;

	    /* call cmprs6 to get string of chars */
	    if( cmprs6( wfL->element->nsamp , iData , &cOut ) ) {
                printf ( "Error:  insufficient memory, PutWavefomrData\n" ) ;
                free( cOut );
                return 0 ;
            }

	    /* write it out (it already has newlines every 80 chars.) */
	    fprintf ( ptr , "%s", cOut ) ;
            fprintf ( ptr , "\n" ) ;

            free( cOut ) ;

            remdif1( iData , wfL->element->nsamp ) ;
            remdif1( iData , wfL->element->nsamp ) ;
        }
	else
	    if ( column ) fprintf ( ptr , "\n" ) ;

	fprintf(ptr,"CHK2  %d\n\n", CheckSumFromIntArray(iData, wfL->element->nsamp) );
	free ( iData ) ;

    } /* end for */

    printf ( "\n" ) ;

    return Ntraces ;
} /* end PutWaveformData */