コード例 #1
0
ファイル: timer.c プロジェクト: ashang/xpenology-3.x
irqreturn_t px_timer_isr(unsigned int pid,
                         unsigned int tid,
                         unsigned int pc,
                         unsigned long long ts)
{
	bool buffer_full = false;
	PXD32_Hotspot_Sample_V2 sample_rec;

	if (tbs_running)
	{
		/* write sample record to sample buffer */
		sample_rec.pc	   = pc;
		sample_rec.pid	   = pid;
		sample_rec.tid	   = tid;
		sample_rec.registerId = COUNTER_PJ1_OS_TIMER;

		memcpy(sample_rec.timestamp, &ts, sizeof(sample_rec.timestamp));

		buffer_full = write_sample(0, &sample_rec);

		if (buffer_full)
		{
			tbs_running = false;
		}
		else
		{
			tbs_running = true;
		}
	}

	return 0;
}
コード例 #2
0
static irqreturn_t px_timer_isr(unsigned int pid,
                                unsigned int tid,
                                struct pt_regs * const regs,
                                unsigned int cpu,
                                unsigned long long ts)
{
	bool buffer_full = false;
	
	if (tbs_running)
	{
		PXD32_Hotspot_Sample_V2 sample_rec;

		/* write sample record to sample buffer */
		sample_rec.pc	   = regs->ARM_pc;
		sample_rec.pid	   = pid;
		sample_rec.tid	   = tid;
		sample_rec.registerId = COUNTER_PJ4B_OS_TIMER;

		memcpy(sample_rec.timestamp, &ts, sizeof(sample_rec.timestamp));

		buffer_full = write_sample(cpu, &sample_rec);

		if (buffer_full)
		{
			tbs_running = false;
		}
		else
		{
			tbs_running = true;
		}
	}

	return IRQ_HANDLED;
}
コード例 #3
0
ファイル: soundtest.c プロジェクト: golightlyb/cfw
static void write_callback(struct SoundIoOutStream *outstream, int frame_count_min, int frame_count_max) {
    UNUSED(frame_count_min);
    double float_sample_rate = outstream->sample_rate;
    double seconds_per_frame = 1.0 / float_sample_rate;
    struct SoundIoChannelArea *areas;
    int err;

    int frames_left = frame_count_max;

    for (;;) {
        int frame_count = frames_left;
        if ((err = soundio_outstream_begin_write(outstream, &areas, &frame_count))) {
            fprintf(stderr, "unrecoverable stream error: %s\n", soundio_strerror(err));
            exit(1);
        }

        if (!frame_count)
            break;

        const struct SoundIoChannelLayout *layout = &outstream->layout;

        double pitch = 440.0;
        double radians_per_second = pitch * 2.0 * PI;
        for (int frame = 0; frame < frame_count; frame += 1) {
            double sample = (float) sin((seconds_offset + frame * seconds_per_frame) * radians_per_second);
            for (int channel = 0; channel < layout->channel_count; channel += 1) {
                write_sample(areas[channel].ptr, sample);
                areas[channel].ptr += areas[channel].step;
            }
        }
        seconds_offset += seconds_per_frame * frame_count;

        if ((err = soundio_outstream_end_write(outstream))) {
            if (err == SoundIoErrorUnderflow)
                return;
            fprintf(stderr, "unrecoverable stream error: %s\n", soundio_strerror(err));
            exit(1);
        }

        frames_left -= frame_count;
        if (frames_left <= 0)
            break;
    }

    soundio_outstream_pause(outstream, want_pause);
}
コード例 #4
0
ファイル: lab.c プロジェクト: skoelden/TSEA81
void do_work(int *samples)
{
  int i;

  //  A busy loop. (In a real system this would do something
  //  more interesting such as an FFT or a particle filter,
  //  etc...)
  volatile int dummy; // A compiler warning is ok here
  for(i=0; i < 20000000;i++){
    dummy=i;
  }

  // Write out the samples.
  for(i=0; i < PROCESSING_INTERVAL; i++){
    write_sample(0,samples[i]);
  }

}
コード例 #5
0
ファイル: timer.c プロジェクト: ashang/xpenology-3.x
irqreturn_t px_timer_isr(unsigned int pid,
                         unsigned int tid,
                         unsigned int pc,
                         unsigned long long ts)
{
	bool buffer_full = false;
	PXD32_Hotspot_Sample_V2 sample_rec;

	// disable the interrupt
	TMR_IERn(timer_group, timer_no) = 0;

	// clear the interrupt flag
	TMR_ICRn(timer_group, timer_no) = 1;

	// set next match
	TMR_Tn_Mm(timer_group, timer_no, 0) = g_tbs_settings.interval * get_timer_freq() / 1000;
	//TMR_Tn_Mm(timer_group, timer_no, 0) += g_tbs_settings.interval * get_timer_freq() / 1000;

	if (tbs_running)
	{
		/* write sample record to sample buffer */
		sample_rec.pc	   = pc;
		sample_rec.pid	   = pid;
		sample_rec.tid	   = tid;
		sample_rec.registerId = COUNTER_PJ1_OS_TIMER;

		memcpy(sample_rec.timestamp, &ts, sizeof(sample_rec.timestamp));

		buffer_full = write_sample(0, &sample_rec);

		if (buffer_full)
		{
			tbs_running = false;
		}
		else
		{
			tbs_running = true;
		}
	}

	// enable the interrupt
	TMR_IERn(timer_group, timer_no) = 1;
	return IRQ_HANDLED;
}
コード例 #6
0
static irqreturn_t px_timer_isr(unsigned int pid,
                                unsigned int tid,
                                unsigned int pc,
                                unsigned int ts)
{
	bool buffer_full = false;

	if (OSSR & OSSR_PX_INTERRUPT)
	{
		PXD32_Hotspot_Sample sample_rec;
		
		/* disable the counter */
		OMCR5 &= ~0x7;
			
		/* clear the interrupt flag */
		OSSR = OSSR_PX_INTERRUPT;

		/* write sample record to sample buffer */
		sample_rec.pc  = pc;
		sample_rec.pid = pid;
		sample_rec.tid = tid;
		sample_rec.registerId = COUNTER_PXA2_OS_TIMER;
		memcpy(sample_rec.timestamp, &ts, 3);

		buffer_full = write_sample(&sample_rec);

		if (buffer_full)
		{
			/* if sample buffer is full, pause sampling */
			OMCR5 &= ~0x7;
		}
		else
		{
			/* enable the counter */
			OMCR5 |= OMCR_FREQ_32K;
		}

		return IRQ_HANDLED;
	}

	return IRQ_NONE;
}
コード例 #7
0
ファイル: main.c プロジェクト: John-He-928/fdkaac
static
int encode(aacenc_param_ex_t *params, pcm_reader_t *reader,
           HANDLE_AACENCODER encoder, uint32_t frame_length, 
           m4af_ctx_t *m4af)
{
    int16_t *ibuf = 0, *ip;
    aacenc_frame_t obuf[2] = {{ 0 }}, *obp;
    unsigned flip = 0;
    int nread = 1;
    int rc = -1;
    int remaining, consumed;
    int frames_written = 0, encoded = 0;
    aacenc_progress_t progress = { 0 };
    const pcm_sample_description_t *fmt = pcm_get_format(reader);

    ibuf = malloc(frame_length * fmt->bytes_per_frame);
    aacenc_progress_init(&progress, pcm_get_length(reader), fmt->sample_rate);

    for (;;) {
        /*
         * Since we delay the write, we cannot just exit loop when interrupted.
         * Instead, we regard it as EOF.
         */
        if (g_interrupted)
            nread = 0;
        if (nread > 0) {
            if ((nread = pcm_read_frames(reader, ibuf, frame_length)) < 0) {
                fprintf(stderr, "ERROR: read failed\n");
                goto END;
            }
            if (!params->silent)
                aacenc_progress_update(&progress, pcm_get_position(reader),
                                       fmt->sample_rate * 2);
        }
        ip = ibuf;
        remaining = nread;
        do {
            obp = &obuf[flip];
            consumed = aac_encode_frame(encoder, fmt, ip, remaining, obp);
            if (consumed < 0) goto END;
            if (consumed == 0 && obp->size == 0) goto DONE;
            if (obp->size == 0) break;

            remaining -= consumed;
            ip += consumed * fmt->channels_per_frame;
            flip ^= 1;
            /*
             * As we pad 1 frame at beginning and ending by our extrapolator,
             * we want to drop them.
             * We delay output by 1 frame by double buffering, and discard
             * second frame and final frame from the encoder.
             * Since sbr_header is included in the first frame (in case of
             * SBR), we cannot discard first frame. So we pick second instead.
             */
            ++encoded;
            if (encoded == 1 || encoded == 3)
                continue;
            obp = &obuf[flip];
            if (write_sample(params->output_fp, m4af, obp) < 0)
                goto END;
            ++frames_written;
        } while (remaining > 0);
    }
DONE:
    if (!params->silent)
        aacenc_progress_finish(&progress, pcm_get_position(reader));
    rc = frames_written;
END:
    if (ibuf) free(ibuf);
    if (obuf[0].data) free(obuf[0].data);
    if (obuf[1].data) free(obuf[1].data);
    return rc;
}
コード例 #8
0
ファイル: wav2smp.c プロジェクト: eriser/Soundpipe
int main(int argc, char *argv[]) 
{
    if(argc <= 1) {
        printf("Usage: [options] wav2smp in1.wav in1_name in2.wav in2_name...\n\n");
        printf("Flags:\n");
        printf("\t-w\tWAV file to write to (default: out.wav)\n");
        printf("\t-o\tINI file to write to (default: out.ini)\n");
        printf("\t-r\tSet samplerate. (default: 96000)\n");
        return 0;
    }


    int argpos = 1;
    int i;
    int sr = 96000;
    char wavfile[30] = "out.wav";
    char inifile[30] = "out.ini";
    float buf[4096];

    argv++;

    while(argv[0][0] == '-') {
        switch(argv[0][1]) {
            case 'w': 
                strncpy(wavfile, argv[1], 30);
                argv++; 
                argpos++;
                break;

            case 'o': 
                strncpy(inifile, argv[1], 30);
                argv++; 
                argpos++;
                break;

            case 'r': 
                sr = atoi(argv[1]);
                argv++; 
                argpos++;
                break;
                
            default: 
                fprintf(stderr, "Uknown option '%c'\n", argv[0][1]);
                break;

        }
        argv++;
        argpos++;
    }

    SF_INFO info;
    info.samplerate = sr; 
    info.channels = 1;
    info.format = SF_FORMAT_WAV | SF_FORMAT_FLOAT;
    SNDFILE *snd = sf_open(wavfile, SFM_WRITE, &info);
    FILE *fp = fopen(inifile, "w");
    uint32_t pos = 0; 


    for(i = argpos; i < argc; ) {
        write_sample(snd, fp, argv[0], argv[1], buf, 4096, &pos, sr); 
        argv += 2;
        i += 2;
    }

    fclose(fp); 
    sf_close(snd);
    return 0;
}
コード例 #9
0
ファイル: scope_files.c プロジェクト: LinuxCNC/linuxcnc
void write_log_file (char *filename)
{
	scope_data_t *dptr, *start;
	scope_horiz_t *horiz;
	int sample_len, chan_num, sample_period_ns, samples, n;
	char *label[16];
    //scope_disp_t *disp;
	scope_log_t *log;
    scope_chan_t *chan;
    hal_type_t type[16];
    FILE *fp;
	


    fp = fopen(filename, "w");
    if ( fp == NULL ) {
	fprintf(stderr, "ERROR: log file '%s' could not be created\n", filename );
	return;
    }

	/* fill in local variables */
	for (chan_num=0; chan_num<16; chan_num++) {
		chan = &(ctrl_usr->chan[chan_num]);
	    label[chan_num] = chan->name;
	 	type[chan_num] = chan->data_type;
	}    
	/* sample_len is really the number of channels, don't let it fool you */
	sample_len = ctrl_shm->sample_len;
    //disp = &(ctrl_usr->disp);
	n=0;
	samples = ctrl_usr->samples*sample_len ;
	//fprintf(stderr, "maxsamples = %p \n", maxsamples);
	log = &(ctrl_usr->log);
	horiz = &(ctrl_usr->horiz);
	sample_period_ns = horiz->thread_period_ns * ctrl_shm->mult;

	//for testing, this will be a check box or something eventually
	log->order=INTERLACED;

    /* write data */
    fprintf(fp, "Sampling period is %i nSec \n", sample_period_ns );

	/* point to the first sample in the display buffer */
	start = ctrl_usr->disp_buf ;

	switch (log->order) {
		case INTERLACED:
				while (n <= samples) {
				
					for (chan_num=0; chan_num<sample_len; chan_num++) {	
						dptr=start+n;	
						if ((n%sample_len)==0){
						fprintf( fp, "\n");
						}
						write_sample( fp, label[chan_num], dptr, type[chan_num]);
						/* point to next sample */
						n++;
					}
   				 }
				break;
		case NOT_INTERLACED:
				for (chan_num=0; chan_num<sample_len; chan_num++) {
					n=chan_num;
					while (n <= samples) {
						dptr=start+n;
						write_sample( fp, label[chan_num], dptr, type[chan_num]);
						fprintf( fp, "\n");
						/* point to next sample */
						n += sample_len;
					}
   				 }
				break;
	}
    
    fclose(fp);
    fprintf(stderr, "Log file '%s' written.\n", filename );
}
コード例 #10
0
ファイル: epidemics.c プロジェクト: rforge/epidemics
/* Function to be called from R */
void R_epidemics(int *seqLength, double *mutRate, int *npop, int *nHostPerPop, double *beta, int *nStart, int *t1, int *t2, int *Nsample, int *Tsample, int *duration, int *nbnb, int *listnb, double *pdisp){
	int i, nstep, counter_sample = 0, tabidx;

	/* Initialize random number generator */
	int j;
	time_t t;
	t = time(NULL); // time in seconds, used to change the seed of the random generator
	gsl_rng * rng;
	const gsl_rng_type *typ;
	gsl_rng_env_setup();
	typ=gsl_rng_default;
	rng=gsl_rng_alloc(typ);
	gsl_rng_set(rng,t); // changes the seed of the random generator


	/* transfer simulation parameters */
	struct param * par;
	par = (struct param *) malloc(sizeof(struct param));
	par->L = *seqLength;
	par->mu = *mutRate;
	par->muL = par->mu * par->L;
	par->rng = rng;
	par->npop = *npop;
	par->popsizes = nHostPerPop;
	par->beta = *beta;
	par->nstart = *nStart;
	par->t1 = *t1;
	par->t2 = *t2;
	par->t_sample = Tsample;
	par->n_sample = *Nsample;
	par->duration = *duration;
	par->cn_nb_nb = nbnb;
	par->cn_list_nb = listnb;
	par->cn_weights = pdisp;

	/* check/print parameters */
	check_param(par);
	print_param(par);

	/* dispersal matrix */
	struct network *cn = create_network(par);
	/* print_network(cn, TRUE); */

	/* group sizes */
	struct ts_groupsizes * grpsizes = create_ts_groupsizes(par);

	/* initiate population */
	struct metapopulation * metapop;
	metapop = create_metapopulation(par);

	/* get sampling schemes (timestep+effectives) */
	translate_dates(par);
	struct table_int *tabdates = get_table_int(par->t_sample, par->n_sample);
	printf("\n\nsampling at timesteps:");
	print_table_int(tabdates);

	/* create sample */
	struct sample ** samplist = (struct sample **) malloc(tabdates->n * sizeof(struct sample *));
	struct sample *samp;


	/* MAKE METAPOPULATION EVOLVE */
	nstep = 0;
	while(get_total_nsus(metapop)>0 && (get_total_ninf(metapop)+get_total_nexp(metapop))>0 && nstep<par->duration){
		nstep++;

		/* age metapopulation */
		age_metapopulation(metapop, par);

		/* process infections */
		for(j=0;j<get_npop(metapop);j++){
			process_infections(get_populations(metapop)[j], metapop, cn, par);
		}

		/* draw samples */
		if((tabidx = int_in_vec(nstep, tabdates->items, tabdates->n)) > -1){ /* TRUE if step must be sampled */
			samplist[counter_sample++] = draw_sample(metapop, tabdates->times[tabidx], par);
		}

		fill_ts_groupsizes(grpsizes, metapop, nstep);

	}

	/* we stopped after 'nstep' steps */
	if(nstep < par->duration){
		printf("\nEpidemics ended at time %d, before last sampling time (%d).\n", nstep, par->duration);
	} else {

		/* printf("\n\n-- FINAL METAPOPULATION --"); */
		/* print_metapopulation(metapop, FALSE); */

		/* merge samples */
		samp = merge_samples(samplist, tabdates->n, par);

		/* write sample to file */
		printf("\n\nWriting sample to file 'out-sample.txt'\n");
		write_sample(samp);

		/* free memory */
		free_sample(samp);

	}

	/* write group sizes to file */
	printf("\n\nPrinting group sizes to file 'out-popsize.txt'\n");
	write_ts_groupsizes(grpsizes);


	/* free memory */
	free_metapopulation(metapop);
	free_param(par);
	for(i=0;i<counter_sample;i++) free_sample(samplist[i]);
	free(samplist);
	free_table_int(tabdates);
	free_network(cn);
	free_ts_groupsizes(grpsizes);
}
コード例 #11
0
static irqreturn_t px_pmu_isr(unsigned int pid,
                              unsigned int tid,
                              unsigned int pc,
                              unsigned int timestamp)
{
	u32 pmnc_value;
	u32 flag_value;
	unsigned int i;
	bool buffer_full = false;

	PXD32_Hotspot_Sample sample_rec;

	/* disable the counters */
	pmnc_value = PJ4_Read_PMNC();
	pmnc_value &= ~0x1;
	PJ4_Write_PMNC(pmnc_value);

	/* clear the overflow flag */
	flag_value = PJ4_Read_FLAG();
	PJ4_Write_FLAG(0x8000000f);

	sample_rec.pc = pc;
	sample_rec.pid = pid;
	sample_rec.tid = tid;
	memcpy(sample_rec.timestamp, &timestamp, 3);

	if ((flag_value & 0x80000000) && es[COUNTER_PJ4_PMU_CCNT].enabled)
	{
		sample_rec.registerId = COUNTER_PJ4_PMU_CCNT;

		/* ccnt overflow */
		if (es[sample_rec.registerId].calibration == false)
		{
			/* write sample record in non-calibration mode */
			buffer_full |= write_sample(&sample_rec);
		}
		else
		{
			/* calculate the overflow count in calibration mode */
			es[sample_rec.registerId].overflow++;
		}

		PJ4_WritePMUCounter(sample_rec.registerId, es[sample_rec.registerId].reset_value); 
	}

	for (i=0; i<4; i++)
	{
		if (flag_value & (0x1 << i))
		{
			switch (i)
			{
			case 0:	sample_rec.registerId = COUNTER_PJ4_PMU_PMN0; break;
			case 1:	sample_rec.registerId = COUNTER_PJ4_PMU_PMN1; break;
			case 2:	sample_rec.registerId = COUNTER_PJ4_PMU_PMN2; break;
			case 3:	sample_rec.registerId = COUNTER_PJ4_PMU_PMN3; break;
			default: break;
			}

			if (es[sample_rec.registerId].calibration == false)
			{
				/* write sample record in non-calibration mode */
				buffer_full |= write_sample(&sample_rec);
			}
			else
			{
				/* calculate the overflow count in calibration mode */
				es[sample_rec.registerId].overflow++;
			}

			PJ4_WritePMUCounter(sample_rec.registerId, es[sample_rec.registerId].reset_value); 
		}

	}

	if (!buffer_full)
	{
		/* enable the counters */
		pmnc_value |= 0x1;
		PJ4_Write_PMNC(pmnc_value);
	}

	return IRQ_HANDLED;
}
コード例 #12
0
static irqreturn_t px_pmu_isr(unsigned int pid,
                              unsigned int tid,
                              unsigned int pc,
                              unsigned int timestamp)
{
	int i;
	int reg = 0;
	unsigned long flag_value;
	unsigned long pmnc_value;
	PXD32_Hotspot_Sample sample_rec;
	bool buffer_full = false;

	/* disable the timer interrupt */
	//disable_irq(PX_IRQ_PXA2_TIMER);

	/* disable the counters */
	pmnc_value = ReadPMUReg(PXA2_PMU_PMNC);
	WritePMUReg(PXA2_PMU_PMNC, pmnc_value & ~PMNC_ENABLE_BIT);
	
	/* clear the overflow flag */
	flag_value = ReadPMUReg(PXA2_PMU_FLAG);
	WritePMUReg(PXA2_PMU_FLAG, FLAG_OVERFLOW_BITS);

	/* write sample record to sample buffer */
	sample_rec.pc	   = pc;
	sample_rec.pid	   = pid;
	sample_rec.tid	   = tid;
	memcpy(sample_rec.timestamp, &timestamp, 3);

	if (flag_value & CCNT_OVERFLAG_BIT && es[COUNTER_PXA2_PMU_CCNT].enabled)
	{
		sample_rec.registerId = COUNTER_PXA2_PMU_CCNT;
		if (es[COUNTER_PXA2_PMU_CCNT].calibration == false)
		{
			/* write sample record in non-calibration mode */
			buffer_full |= write_sample(&sample_rec);
		}
		else
		{
			/* calculate the overflow count in calibration mode */
			es[sample_rec.registerId].overflow++;
		}

		/* reset the counter value */
		WritePMUReg(PXA2_PMU_CCNT, es[COUNTER_PXA2_PMU_CCNT].reset_value);
	}
	
	for (i=0; i<4; i++)
	{
		if (flag_value & (PMN0_OVERFLAG_BIT << i))
		{
			switch (i)
			{
			case 0: sample_rec.registerId = COUNTER_PXA2_PMU_PMN0; reg = PXA2_PMU_PMN0; break;
			case 1: sample_rec.registerId = COUNTER_PXA2_PMU_PMN1; reg = PXA2_PMU_PMN1; break;
			case 2: sample_rec.registerId = COUNTER_PXA2_PMU_PMN2; reg = PXA2_PMU_PMN2; break;
			case 3: sample_rec.registerId = COUNTER_PXA2_PMU_PMN3; reg = PXA2_PMU_PMN3; break;
			default: break;
			}
			
			if (es[sample_rec.registerId].calibration == false)
			{
				/* write sample record in non-calibration mode */
				buffer_full |= write_sample(&sample_rec);
			}
			else
			{
				/* calculate the overflow count in calibration mode */
				es[sample_rec.registerId].overflow++;
			}

			/* reset the counter value */
			WritePMUReg(reg, es[sample_rec.registerId].reset_value);
		}
	}
	
	if (!buffer_full)
	{
		/* enable the counters if buffer is not full */
		WritePMUReg(PXA2_PMU_PMNC, pmnc_value | PMNC_ENABLE_BIT);
	}

	/* enable the timer interrupt */
	//enable_irq(PX_IRQ_PXA2_TIMER);
	return IRQ_HANDLED;
}
コード例 #13
0
static irqreturn_t px_pmu_isr(unsigned int pid,
                              unsigned int tid,
                              struct pt_regs * const regs,
                              unsigned int cpu,
                              unsigned long long ts)
{
	u32 pmcr_value;
	u32 flag_value;
	unsigned int i;
	bool buffer_full = false;
	bool found = false;

	PXD32_Hotspot_Sample_V2 sample_rec;

	/* disable the counters */
	pmcr_value = A9_Read_PMCR();
	pmcr_value &= ~0x1;
	//pmcr_value |= 0x6;
	A9_Write_PMCR(pmcr_value);

	/* clear the overflow flag */
	flag_value = A9_Read_OVSR();
	A9_Write_OVSR(0xffffffff);

	/* add for PXA988 platform, Need to init CTI irq line */
	#ifdef PX_SOC_PXA988
	pxa988_ack_ctiint_func = (pxa988_ack_ctiint_t)kallsyms_lookup_name_func("pxa988_ack_ctiint");
	pxa988_ack_ctiint_func();
	//printk(KERN_EMERG "%s:%d,  kallsyms_lookup_name_func is : 0x%x, pxa988_ack_ctiint_func is : 0x%x\n", __FILE__, __LINE__, (unsigned long)kallsyms_lookup_name_func, (unsigned long)pxa988_ack_ctiint_func);
	#endif

	if (flag_value == 0)
	{
		return IRQ_NONE;
	}

	sample_rec.pc = regs->ARM_pc;
	sample_rec.pid = pid;
	sample_rec.tid = tid;
	memcpy(sample_rec.timestamp, &ts, sizeof(sample_rec.timestamp));

	if ((flag_value & 0x80000000) && es[COUNTER_A9_PMU_CCNT].enabled)
	{
		found = true;
		sample_rec.registerId = COUNTER_A9_PMU_CCNT;

		/* ccnt overflow */
		if (es[sample_rec.registerId].calibration == false)
		{
			/* write sample record in non-calibration mode */
			buffer_full |= write_sample(cpu, &sample_rec);
		}
		else
		{
			/* calculate the overflow count in calibration mode */
			es[sample_rec.registerId].overflow++;
		}

		A9_WritePMUCounter(sample_rec.registerId, es[sample_rec.registerId].reset_value);
	}

	for (i=0; i<A9_PMN_NUM; i++)
	{
		if (flag_value & (0x1 << i))
		{
			found = true;

			switch (i)
			{
			case 0:	sample_rec.registerId = COUNTER_A9_PMU_PMN0; break;
			case 1:	sample_rec.registerId = COUNTER_A9_PMU_PMN1; break;
			case 2:	sample_rec.registerId = COUNTER_A9_PMU_PMN2; break;
			case 3:	sample_rec.registerId = COUNTER_A9_PMU_PMN3; break;
			case 4:	sample_rec.registerId = COUNTER_A9_PMU_PMN4; break;
			case 5:	sample_rec.registerId = COUNTER_A9_PMU_PMN5; break;
			default: break;
			}

			if (es[sample_rec.registerId].calibration == false)
			{
				/* write sample record in non-calibration mode */
				buffer_full |= write_sample(cpu, &sample_rec);
			}
			else
			{
				/* calculate the overflow count in calibration mode */
				es[sample_rec.registerId].overflow++;
			}

			A9_WritePMUCounter(sample_rec.registerId, es[sample_rec.registerId].reset_value);
		}

	}

	if (!buffer_full)
	{
		/* enable the counters */
		pmcr_value |= 0x1;
		pmcr_value &= ~0x6;
		A9_Write_PMCR(pmcr_value);
	}

	return IRQ_HANDLED;
}
コード例 #14
0
static
int encode_sndfile(SNDFILE* snd, SF_INFO* info, pcm_sample_description_t* format,
           HANDLE_AACENCODER encoder,
           uint32_t frame_length, FILE *ofp, m4af_ctx_t *m4af,
           int show_progress)
{
#ifdef USE_LIBSAMPLERATE
    //short *resamplebuf = 0;
    SRC_STATE* srcstate = NULL;
    SRC_DATA srcdata;
    int srcerror = 0;
    float *ibuf = 0;
#else
    short *ibuf = 0;
#endif

    int16_t *pcmbuf = 0;
    uint32_t pcmsize = 0;
    uint8_t *obuf = 0;
    uint32_t olen;
    uint32_t osize = 0;
    int nread = 1;
    int consumed, written;
    int rc = -1;
    int frames_written = 0;
    aacenc_progress_t progress = { 0 };

    ibuf = malloc(frame_length * format->bytes_per_frame);
#ifdef USE_LIBSAMPLERATE
    if(format->sample_rate != info->samplerate) {
        /* set up resampler */
        srcstate = src_new(SRC_SINC_MEDIUM_QUALITY, info->channels, &srcerror);
        srcdata.src_ratio = format->sample_rate; srcdata.src_ratio /= info->samplerate;
        srcdata.data_in = ibuf;
        srcdata.data_out = malloc(frame_length * format->bytes_per_frame * srcdata.src_ratio);
        srcdata.end_of_input = 0;
    }

#endif
    aacenc_progress_init(&progress, info->frames, info->samplerate);
    do {
        if (g_interrupted)
            nread = 0;
        else if (nread) {
#ifdef USE_LIBSAMPLERATE
            if ((nread = sf_readf_float(snd, ibuf, frame_length)) < 0) {
#else
            if ((nread = sf_readf_short(snd, ibuf, frame_length)) < 0) {
#endif
                fprintf(stderr, "ERROR: read failed\n");
                goto END;
            } else if (nread > 0) {
                float* in_buf = ibuf;
#ifdef USE_LIBSAMPLERATE
                if(srcstate) {
                    /* run converstion */
                    srcdata.input_frames = nread;
                    srcdata.output_frames = frame_length;
                    if(srcerror = src_process(srcstate, &srcdata)) {
                        fprintf(stderr, "resample error: %s\n", src_strerror(srcerror));
                        goto END;
                    }
                    //printf("resampled %d samples to %d samples\n", srcdata.input_frames_used, srcdata.output_frames_gen);
                    in_buf = srcdata.data_out;
                    nread = srcdata.output_frames_gen;
                }
#endif
                if (pcm_convert_to_native_sint16(format, in_buf, nread,
                                                 &pcmbuf, &pcmsize) < 0) {
                    fprintf(stderr, "ERROR: unsupported sample format\n");
                    goto END;
                }
            }
            if (show_progress)
                aacenc_progress_update(&progress, sf_seek(snd, 0, SEEK_CUR),
                                       info->samplerate * 2);
        }
        written = nread;
        do {
            if ((consumed = aac_encode_frame(encoder, format, pcmbuf + (nread-written)*info->channels, written,
                                             &obuf, &olen, &osize)) < 0)
                goto END;
            //printf("nread: %d consumed: %d olen: %d\n", nread, consumed, olen);
            written -= (consumed / info->channels);
            if (olen > 0) {
                if (write_sample(ofp, m4af, obuf, olen, frame_length) < 0)
                    goto END;
                ++frames_written;
                //printf("wrote frame %d\n", frames_written);
            }
        } while (written > 0);
    } while (nread > 0 || olen > 0);

    if (show_progress)
        aacenc_progress_finish(&progress, sf_seek(snd, 0, SEEK_CUR));
    rc = frames_written;
END:
    if (ibuf) free(ibuf);
    if (pcmbuf) free(pcmbuf);
    if (obuf) free(obuf);
#ifdef USE_SAMPLERATE
    if (srcstate) {
        free(srcdata.data_out);
        src_delete(srcstate);
    }
#endif
    return rc;
}
#endif


static
int encode(wav_reader_t *wavf, HANDLE_AACENCODER encoder,
           uint32_t frame_length, FILE *ofp, m4af_ctx_t *m4af,
           int show_progress)
{
    uint8_t *ibuf = 0;
    int16_t *pcmbuf = 0;
    uint32_t pcmsize = 0;
    uint8_t *obuf = 0;
    uint32_t olen;
    uint32_t osize = 0;
    int nread = 1;
    int consumed;
    int rc = -1;
    int frames_written = 0;
    aacenc_progress_t progress = { 0 };
    const pcm_sample_description_t *format = wav_get_format(wavf);

    ibuf = malloc(frame_length * format->bytes_per_frame);
    aacenc_progress_init(&progress, wav_get_length(wavf), format->sample_rate);
    do {
        if (g_interrupted)
            nread = 0;
        else if (nread) {
            if ((nread = wav_read_frames(wavf, ibuf, frame_length)) < 0) {
                fprintf(stderr, "ERROR: read failed\n");
                goto END;
            } else if (nread > 0) {
                if (pcm_convert_to_native_sint16(format, ibuf, nread,
                                                 &pcmbuf, &pcmsize) < 0) {
                    fprintf(stderr, "ERROR: unsupported sample format\n");
                    goto END;
                }
            }
            if (show_progress)
                aacenc_progress_update(&progress, wav_get_position(wavf),
                                       format->sample_rate * 2);
        }
        if ((consumed = aac_encode_frame(encoder, format, pcmbuf, nread,
                                         &obuf, &olen, &osize)) < 0)
            goto END;
        if (olen > 0) {
            if (write_sample(ofp, m4af, obuf, olen, frame_length) < 0)
                goto END;
            ++frames_written;
        }
    } while (nread > 0 || olen > 0);

    if (show_progress)
        aacenc_progress_finish(&progress, wav_get_position(wavf));
    rc = frames_written;
END:
    if (ibuf) free(ibuf);
    if (pcmbuf) free(pcmbuf);
    if (obuf) free(obuf);
    return rc;
}