Пример #1
0
void AudioPlayer::stop()
{
	playing_ = false;

//	sem_post(&sem_);
	pthread_cond_signal(&cond_);

	pthread_join(thread_, NULL);

	alSourceStop(source_);

	freebuffers();
}
Пример #2
0
int dfww(int argc, char *argv[], int retc, char *retv[])
/*************/
{   int firstindex;
    int lastindex;
    int step;
    int ctrace;
    int do_ww;
    int local_color;
    int imag_on;
    int redoDscale;
    int color_traces;
    int index=1;
    int maxindex=nblocks * specperblock;
    double save_sc, save_wc, save_sc2, save_wc2;

    (void) retc;
    (void) retv;
    redoDscale = dscale_onscreen();
    Wturnoff_buttons();
    plot = (argv[0][0] == 'p');
    do_ww = (argv[0][2] == 'w');
    if (Bnmr && !plot)
        return(COMPLETE);
    revflag = 0;
    if(initfid(plot+1)) return(ERROR);
    dispcalib = (float) (mnumypnts-ymin) / (float) wc2max;
    if (init_vars2()) return(ERROR);
    clearMspec();

    checkinput(argc,argv,&firstindex,&lastindex,&step,&imag_on,&color_traces);
    if (!plot)
        setwindows(argv);
    if ((firstindex < 1) || (firstindex > maxindex))
    {
        Werrprintf("spectrum %d does not exist",firstindex);
        return(ERROR);
    }

    save_sc=sc;
    save_wc=wc;
    save_sc2=sc2;
    save_wc2=wc2;

    if (lastindex < firstindex)
        lastindex = firstindex;
    if (lastindex > maxindex)
        lastindex = maxindex;
    //setscwc(firstindex,lastindex,step);
    if(plot) setscwc(firstindex,lastindex,step);
    else setscwc_new(firstindex,lastindex,step);
    setspecmaxmin();
    disp_specIndex(firstindex);

    /*  Need to change this for multiple traces...  */

    get_fid_color(argc,argv,&local_color,imag_on);
    ctrace = index = firstindex;
    if (!plot && inRepaintMode && redoDscale)
        new_dscale(FALSE,TRUE);
    if (do_ww)
        if (init_whitewash(mnumxpnts))
            do_ww = FALSE;
    while ((ctrace <= lastindex) && !interuption)
    {
        if(plot) exp_factors(FALSE);
        else calcDisplayPars();
        if(color_traces)
            local_color=((index % (NUM_AV_COLORS-2)) + FIRST_AV_COLOR + 1);

        if (calc_fid(ctrace-1))
            return(ERROR);
        if (imag_on)
            imagdisp(local_color, do_ww);
        else
            fiddisp(local_color, do_ww);
        if(plot) {
            sc += ho;
            if (!horizontal)
                sc2 += vo;
        } else {
            dss_sc += ho;
            if (!horizontal)
                dss_sc2 += vo;
        }
        ctrace += step;
        index++;
    }
    if (!plot)
    {
        ResetLabels();
        DispField(FIELD1,PARAM_COLOR,"vf",vs,1);
        InitVal(FIELD2,HORIZ,SP_NAME, PARAM_COLOR,UNIT4,
                SP_NAME, PARAM_COLOR,SCALED,2);
        InitVal(FIELD3,HORIZ,WP_NAME, PARAM_COLOR,UNIT4,
                WP_NAME, PARAM_COLOR,SCALED,2);
        if (firstindex != lastindex)
        {
            DispField(FIELD4,PARAM_COLOR,"first",(double) firstindex,0);
            DispField(FIELD5,PARAM_COLOR,"last",(double) lastindex,0);
            DispField(FIELD6,PARAM_COLOR,"step",(double) step,0);
        }
    }
    if (plot)
        amove(0,0);
    else {
        exit_display();
        Wsetgraphicsdisplay("dfs");
    }
    endgraphics();

    sc=save_sc;
    wc=save_wc;
    sc2=save_sc2;
    wc2=save_wc2;
    P_setreal(CURRENT,"sc",sc,0);
    P_setreal(CURRENT,"wc",wc,0);
    P_setreal(CURRENT,"sc2",sc2,0);
    P_setreal(CURRENT,"wc2",wc2,0);

    if (do_ww)
        close_whitewash();
    if (freebuffers()) return(ERROR);
    appendvarlist("dss_sc,dss_wc,sc,wc,vo,ho");
    return(COMPLETE);
}
Пример #3
0
void AudioPlayer::tick_p()
{
	pthread_mutex_lock(&mutex_);

	if (playing_ == false)
	{
		pthread_mutex_unlock(&mutex_);
		return;
	}

	ALuint buffer;

	if (emptyqueue_)
	{
		ALint state;
		alGetSourcei(source_, AL_SOURCE_STATE, &state);

		if (state == AL_PLAYING)
		{
			pthread_mutex_unlock(&mutex_);
			return;
		}

		finished_ = true;

		playing_ = false;
		freebuffers();

		pthread_mutex_unlock(&mutex_);
		return;
	}

	ALint queued;
	alGetSourcei(source_, AL_BUFFERS_QUEUED, &queued);
	if (queued < NUM_BUFFERS)
	{
		alGenBuffers(1, &buffer);
//		printf("alGenBuffers: %d\n", buffer);
	}
	else
	{
		ALint processed;
		alGetSourcei(source_, AL_BUFFERS_PROCESSED, &processed);

		if (processed == 0)
		{
			pthread_mutex_unlock(&mutex_);
			return;
		}

		alSourceUnqueueBuffers(source_, 1, &buffer);
		//		printf("alSourceUnqueueBuffers\n");
		positions_.pop_front();
	}

	double pos = streamer_->tell();
//	printf("pos: %g\n", pos);
	size_t done = streamer_->read(buffer_, BUFFER_SIZE);
//	printf("done: %d\n", done);
	if (done != 0)
	{
		alBufferData(buffer, (audiosource_->channelCount() == 1) ? AL_FORMAT_MONO16 : AL_FORMAT_STEREO16, buffer_, done, audiosource_->rate());
		alSourceQueueBuffers(source_, 1, &buffer);
		//		printf("alSourceQueueBuffers\n");
		positions_.push_back(pos);

		ALint state;
		alGetSourcei(source_, AL_SOURCE_STATE, &state);
		if (state == AL_STOPPED)
			alSourcePlay(source_);
	}
	else
	{
		alDeleteBuffers(1, &buffer);
//		printf("alDeleteBuffers: %d\n", buffer);
		emptyqueue_ = true;
	}

	pthread_mutex_unlock(&mutex_);
	return;
}