Exemple #1
0
off_t
outrepos(int samps, int fno)
{
        int seeking,amt;

        if(!status[fno]) {
                fprintf(stderr,"file %d is write protected!\n",fno);
                perror("write");
                closesf();
                }

        amt = samps * sfchans(&sfdesc[fno]) + pointer[fno];

        if ( (amt >= 0) && (amt < bufsize[fno]) ) {
                pointer[fno] = amt;     /* inside current buffer        */
                return(pointer[fno]);
                }
        
        if(wipe_is_off[fno]) _backup(fno);
        if(!peakoff[fno]) _chkpeak(fno);
        _writeit(fno);          /* write out current buffer */
        seeking = (amt - bufsize[fno]) * sfclass(&sfdesc[fno]);

        if ( (filepointer[fno] = lseek(sfd[fno],seeking,1)) == -1 ) {
                fprintf(stderr,"CMIX: bad outrepos lseek, file: %d\n",fno);
                closesf();
                }
        
        if(wipe_is_off[fno]) _readit(fno);
        pointer[fno] = 0;
        return(filepointer[fno]);
}
Exemple #2
0
double
sfcopy(float p[], int n_args)
{
	int maxread,n,input,output,bytes,jj;

	if(!n_args) fprintf(stderr,"(sfcopy(input_fno,output_fno,input_skip,output_skip,dur)\n");
	input = (int)p[0];
	output = (int)p[1];
	if((sfclass(&sfdesc[input]) != sfclass(&sfdesc[output])) ||
	   (sfchans(&sfdesc[input]) != sfchans(&sfdesc[output]))) {
		fprintf(stderr,
		 "Input and output specifications do not match. Canot copy.\n");
		closesf();
	}
	bytes = setnote(p[2],p[4],input) * 
		 sfchans(&sfdesc[input]) * sfclass(&sfdesc[input]);

	setnote(p[3],p[4],output);
	_backup(input);
	_backup(output);

	fprintf(stderr,"Copy %d bytes\n",bytes);

	while(bytes) {
		maxread = (bytes > nbytes) ? nbytes : bytes;
		if((n = read(sfd[input],sndbuf[input],maxread)) <= 0) {
			fprintf(stderr,"Apparent eof on input\n");
			return -1.0;
		}
		if((jj = write(sfd[output],sndbuf[input],n)) <= 0) {
			fprintf(stderr,"Trouble writing output file\n");
			closesf();
		}
		bytes -= n;
		filepointer[input] += n;
		filepointer[output] += n;
	}
	if(fsync(sfd[output]) < 0 ) {
		fprintf(stderr,"trouble fsyncing file");
		closesf();
	}
	fprintf(stderr,"Copy completed\n");

	return 0.0;
}
Exemple #3
0
int
getsetnote(float start, float dur, int filenum)
{
	int nsamples = setnote(start,dur,filenum);
	_backup(filenum);
	if(sfclass(&sfdesc[filenum]) == SF_FLOAT) getsample = getfsample;
	else          	                          getsample = getisample;
	return(nsamples);

}
Exemple #4
0
void
blayout(float *out, int *chlist, int fno, int size)
{
	register int i,j;
	register short *ibuf;
	register float *fbuf;
	register int todo;
	register int nchans;
	int len = bufsize[fno]; 

	nchans = sfchans(&sfdesc[fno]);

refill:	todo = ((pointer[fno] + size) > len) 
				? len - pointer[fno] : size;
	if(sfclass(&sfdesc[fno]) == SF_SHORT) {
	  for(i=0,ibuf = (short *)sndbuf[fno] + pointer[fno];i<todo;i += nchans) {
	    for(j=0; j<nchans; j++,ibuf++,out++) {
	      if(chlist[j]) {
		*ibuf = (short) *out;	
	      }
	    }
	  }
	}
	else {
	  for(i=0,fbuf = (float *)sndbuf[fno] + pointer[fno];i<todo;i += nchans) {
	    for(j=0; j<nchans; j++,fbuf++,out++) {
	      if(chlist[j]) {
		*fbuf = *out;
	      }
	    }
	  }
	}
	pointer[fno] += todo;

	if(pointer[fno] == len) {
		_backup(fno);
		if(!peakoff[fno])
			_chkpeak(fno);
		_writeit(fno);
		_readit(fno);
		pointer[fno] = 0;
	}

	if(size -= todo) goto refill;
}
Exemple #5
0
static int
_faddout(float *out, int fno)
{
	register int i;
	register int ipoint = pointer[fno];
	register int incr = sfchans(&sfdesc[fno]);
	register float *fbuf;

	for(i=0,fbuf = (float *)sndbuf[fno] + ipoint; i<incr; i++) {
	  *(fbuf + i) +=  *(out+i);
	}
	if((pointer[fno] += i) >= bufsize[fno] ) {
	  _backup(fno);
	  if(!peakoff[fno]) _chkpeak(fno);
	  _writeit(fno);
	  _readit(fno);
	  pointer[fno] = 0;
	}
	return 0;
}
Exemple #6
0
static int
_ilayout(float *out, int *chlist, int fno)
{
	register int i;
	register int ipoint = pointer[fno];
	register int incr = sfchans(&sfdesc[fno]);
	register short *ibuf;

	for(i=0,ibuf = (short *)sndbuf[fno] + ipoint; i<incr; i++) {
	  if(chlist[i]) {
	      *(ibuf + i) = *(out+i); 
	  }
	}
	if((pointer[fno] += i) >= bufsize[fno] ) {
		_backup(fno);
		if(!peakoff[fno]) _chkpeak(fno);
		_writeit(fno);
		_readit(fno);
		pointer[fno] = 0;
	}
	return 0;
}
Exemple #7
0
void
bwipeout(float *out, int fno, int size)
{
	register int i;
	register short *ibuf;
	register float *fbuf;
	register int todo;
	int len = bufsize[fno]; 

	
refill:	todo = ((pointer[fno] + size) > len) 
				? len - pointer[fno] : size;

	if(sfclass(&sfdesc[fno]) == SHORT) {
	  for(i=0,ibuf = (short *)sndbuf[fno] + pointer[fno];i<todo;i++) {
	    *(ibuf++) = (short)*(out++);
	  }
	}
	else {
	  for(i=0,fbuf = (float *)sndbuf[fno] + pointer[fno];i<todo;i++) {
	    *(fbuf++) = *(out++);
	  }
	}

	pointer[fno] += todo;

	if(pointer[fno] == len) {
		if(wipe_is_off[fno]) {   
			_backup(fno);
			wipe_is_off[fno] = 0;
			}
		if(!peakoff[fno])
			_chkpeak(fno);
		_writeit(fno);
		pointer[fno] = 0;
	}
	if(size -= todo) goto refill;
}
Exemple #8
0
static int
_fwipeout(float *out, int fno)   /* to force destructive writes */ 
{
	register int i;
	register int ipoint = pointer[fno];
	register int incr = sfchans(&sfdesc[fno]);
	register float *fbuf;

	for(i=0,fbuf = (float *)sndbuf[fno] + ipoint; i<incr; i++) {
	  *(fbuf + i) =  *(out+i);
	}
	if((pointer[fno] += i) >= bufsize[fno] ) {
		if(wipe_is_off[fno]) {   /*setnot positions after first read*/
			_backup(fno);
			wipe_is_off[fno] = 0;
			}
		if(!peakoff[fno])
			_chkpeak(fno);
		_writeit(fno);
		pointer[fno] = 0;
	}
	return 0;
}
Exemple #9
0
int
endnote(int xno)
{
	struct timeval tp;	
	struct timezone tzp;	
	int i,j,final_bytes,fno;
	float notepeak,*pk;
	double total;
	long *pkloc;
	struct tms timbuf;
	float peakval;
	struct stat st;
	short tisamp,*tibuf;
	float tfsamp,*tfbuf;

	fno = ABS(xno);  /* if fno is negative it means don't write
					final buffer,just pretend to */
	if(wipe_is_off[fno]) 
		_backup(fno); 
	/* else _flushbuf(fno); */
	if(!peakoff[fno]) _chkpeak(fno);
	final_bytes =  pointer[fno]  * sfclass(&sfdesc[fno]);
	
	/* This was DS's and PL's version of real time */
	/* Not used in this version */
#ifdef OLDRT

	/*  SHOULD NOT PLAY HERE -- LAST BUFFERS ALREADY PLAYED */
	if ((sfclass(&sfdesc[fno]) == SF_SHORT) && play_is_on)
		playbuf(sndbuf[fno],final_bytes/SF_SHORT);
	else if ((sfclass(&sfdesc[fno]) == SF_FLOAT) && play_is_on) {
		peakval = getpeakval(peakflag,fno);
		playfbuf(sndbuf[fno],peakval,swap[fno],nbytes/SF_FLOAT);
	}
#endif

	/* write out only fractional part of last record, god bless unix!*/
	if(pointer[fno] && (play_is_on < 2)) {
		if(xno >= 0) {
			/* Swap bytes if necessary */
			if(final_bytes && swap_bytes[fno]) {
				/* SHORT file */
				if(sfclass(&sfdesc[fno]) == SF_SHORT) {
					tibuf = (short *)sndbuf[fno]; 
					for (i=0;i<final_bytes/SF_SHORT;i++) {
						tisamp = *(tibuf+i);
						*(tibuf+i) = reverse_int2(&tisamp);
					}
				}
				/* FLOAT file */
				if(sfclass(&sfdesc[fno]) == SF_FLOAT) {
					tfbuf = (float *)sndbuf[fno]; 
					for (i=0;i<final_bytes/SF_FLOAT;i++) {
						/* 	byte_reverse4(tfbuf+i); */
						/* 	tfsamp = *(tfbuf+i); */
						/* 	*(tfbuf+i) = (float)reverse_int4(&tfsamp); */
					  	tfsamp = *(tfbuf+i);
						byte_reverse4(&tfsamp);
					  	*(tfbuf+i) = tfsamp;
					}
				}
   			}
   			if((i = write(sfd[fno],sndbuf[fno],final_bytes)) 
											!= final_bytes) {
				rtcmix_warn("CMIX", "Bad UNIX write, file %d, nbytes = %d\n",
					fno,i);
				perror("write");
				closesf();
   			}
   		}
   		if((filepointer[fno] += final_bytes) > originalsize[fno]) 
   		if(xno >0)  originalsize[fno] = filepointer[fno];
	}
	/* DT: 	if(play_is_on) flush_buffers(); */
	
	pk = (float *)peak[fno];
	pkloc = (long *)peakloc[fno];
	total = ((double)filepointer[fno]-headersize[fno])
					/((double)sfclass(&sfdesc[fno]))
					/(double)sfchans(&sfdesc[fno])/SR();
	
	/* _writeit(fno);  write out final record */

	for(i = 0,notepeak=0; i<sfchans(&sfdesc[fno]); i++) { 
		if(*(pk+i) > sfmaxamp(&sfm[fno],i)) {
			sfmaxamp(&sfm[fno],i) = *(pk+i);
			sfmaxamploc(&sfm[fno],i) = *(pkloc+i);
		}
		if(*(pk+i) > notepeak) notepeak = *(pk+i);
	}
	
	gettimeofday(&tp,&tzp);
	sfmaxamptime(&sfm[fno]) = tp.tv_sec;
		
	if((filepointer[fno] = lseek(sfd[fno],0L,0)) < 0) {
		rtcmix_warn("CMIX", "Bad lseek to beginning of file\n");
		perror("lseek");
		closesf();
	}


	times(&timbuf);

#ifndef MAXMSP // this really isn't used...
	printf("\n(%6.2f)",(float)(
					(timbuf.tms_stime-clockin[fno].tms_stime)+
					(timbuf.tms_utime-clockin[fno].tms_utime))/60.);
	printf(" %9.4f .. %9.4f MM ",starttime[fno],total);
	
	if(!peakoff[fno]) {
		for(j=0;j<sfchans(&sfdesc[fno]);j++)
			printf(" c%d=%e",j,*(pk+j));
		printf("\n");
		if(punch[fno]) {
			printf("alter(%e,%e,%e/%e",
						(double)starttime[fno],(double)(total-starttime[fno]),
						punch[fno],notepeak);
			for(i=0; i<sfchans(&sfdesc[fno]); i++)
				printf(",1 ");
			printf(")\n");
			printf("mix(%g,%g,%g,%g/%g",
							(double)starttime[fno],(double)starttime[fno],-(double)(total-starttime[fno]),punch[fno],notepeak);
			for(i=0; i<sfchans(&sfdesc[fno]); i++)
				printf(",%d ",i);
			printf(")\n");
		}
	}
#endif // MAXMSP

	/* Copy the updated peak stats into the SFHEADER struct for this
	   output file. (No swapping necessary.)
	*/
	memcpy(&(sfmaxampstruct(&sfdesc[fno])), &sfm[fno], sizeof(SFMAXAMP));

	/* Write header to file. */
	if (wheader(sfd[fno], &sfdesc[fno])) {
		rtcmix_warn("endnote", "bad header write\n");
		perror("write");
		closesf();
	}
	return 0;
}
Exemple #10
0
void HoldemPoker::makeAction(int action_id)
{
    _backup();
    /* if it's random player turn, action_id = dealt card id
     * otherwise it's the bet of a player. First player bids 1. */
    /* random player, action_id = card id */
    if (cur_player == RANDOM_PLAYER_NR)
    {
        int seeing_player = randomActionPlayer();
        int card_id = action_id;
        /* remove the card from the deck */
        deck.erase(std::remove(deck.begin(), deck.end(), card_id), deck.end());

        /* card for both players */
        if (seeing_player == ALL_PLAYERS)
        {
            for (int p = 0; p < 2; p++)
                player_cards[p].push_back(card_id);
        }
        /* card for single player */
        else
            player_cards[seeing_player].push_back(card_id);

        cards_dealt ++;
        /* We've dealt all the cards for this phase */
        if (cards_dealt == RANDOM_PHASE_CARDS_NUMBER[random_phase])
        {
            random_phase ++;
            cards_dealt = 0;
            _startOfBiddingPhase();
        }
    }
    else
    {
        bids_number ++;
        int bet = action_id;
        if (bet > MAX_STAKE)
        {
            fprintf(stderr, "ERROR: Betting %d: more than MAX_STAKE=%d\n", bet, MAX_STAKE);
            throw 1;
        }
        /* player looses */
        else if (bet < cur_stake)
        {
            _endGame(other(cur_player));
        }
        else if (bet == cur_stake)
        {
            agreed_stake = cur_stake;
            /* Second player agrees */
            if (bids_number >= 2)
                _endOfBiddingPhase();
            else
                cur_player = other(cur_player);
        }
        if (bet > cur_stake)
        {
            if (bids_number > MAX_BIDS_NUMBER)
            {
                fprintf(stderr, "ERROR: Raising the stake not allowed after 2 bets, there were %d bets\n", bids_number);
                throw 2;
            }
            else
            {
                agreed_stake = cur_stake;
                cur_stake = bet;
                cur_player = other(cur_player);
            }
        }
    }
}