Subj : Re: A really stupid Question - how to build a library To : borland.public.cpp.borlandcpp From : D Kat Date : Thu Oct 07 2004 01:42 pm "Bob Gonder" wrote in message news:6ob9m05r1ijn1ed5ojlu3uvov85ttf8qvm@4ax.com... >D Kat wrote: > >>each time an end of buffer is reached..... Then of course there are the >>counters (ticks for each call to the interrupt) and other variables that >>are >>needed by the main program. I seem to be going around in circles on this. > > Forget for a minute what the Main program needs..... > Put everything the Library code needs, in the Library. > Then, think about what the Main program needs to know. > Anything that the Main doesn't need to know, make static. > Probably readlength[] and playndx; > static int readlength[whatever]; > static int playndx; > > Everything the Main program needs to know, declare in a Header file as > extern. > extern int TIMERS; > extern int counter[]; > extern int timer[]; > >> int button,i; // button iterator >> unsigned char PA_buttons,PC_buttons; // temp holding register for current All sounds good (that is clear and easy to understand..) >> for (i=0;i > Are there more than 2 timers? > Is TIMERS a fixed value? > If so, then unroll the loop for much better speed (important for ISRs) The timer variable is an array whose size in history had varied because different programs used it in different ways. Each time the ISR is called this variable if it is greater than ZERO counts down (most often used for something such as a delay or wait function - we use an LCD display that has to have delays between commands written out to it for example and we have to have delays between trials). In addition there has to be an array of counters the count up (clocks). This would be used the keep track of where in time a button was pushed relative to when the first sample of an auditory file was played. A quick and dirty discription of a program we might have to write - A speech file is played. Associated with each speech file is a picture that must be presented when the second syllable of the speech file is reached (there would be an array of speech names and associated with that an array of display times). So on file1 when the counter is equal to Time1 a picture is shown. >> if (counter[0] == file_length)PLAYFLAG=0; > > Program defensively, check >= instead of == PLAYFLAG Should be a BOOL but I >> if (PLAYFLAG==1) >> { >> if (counter[1] == (readlength[playndx]-1)) > Program defensively, check >= instead of == that code would not work. Basically the flag to read in the next buffer and switch buffers played should ONLY be set when the counter is at end of buffer. >> {//if at end of buffer point to next buffer >> playndx++; >> if(playndx==NUMBUF)playndx=0;//next buffer at 0 if beyond last buffer > > Program defensively, check >= instead of == If the playndx is > than NUMBUF then there is a serious error >> if(readlength[playndx]<2) PLAYFLAG=0;//if buffer empty - stop play >> else{ //else setup to play next buffer and read next buffer >> da_point = &wavebuffer[playndx][0]; //point to next buffer to play >> counter[1]=0;//counter for this buffer set to beginning >> READ = 1; >> }// read flag: buffer is empty -> fill buffer >> } > > This loops the output if the buffer is empty? the outpw should occur first. If I put it after the test of buffers, I wrote it wrong. It should be /************************************* Initialization = buffers filled; pointer to buffers set to buffer[0][0]; Flags set to appropriate falues ( 0 for READBUFFER and 1 for PLAYBUFFER and GETBUTTONPUSH); When in ISR D/A OUT; Check place in buffer and if necessary set READBUFFERFLAG and switch pointer to other buffer ; then check if Buttonboard has been pushed; if counter == length of file set PLAYFLAG to 0; in Play routine while PLAYFLAG true - fill buffer if necessary and reset flag; when PLAYFLAG false wait a few seconds to collect BUTTONPUSH return to main (which will open file or files and call play) /*********************************************** > >> outpw(DA_0,*da_point); >> outpw(DA_1,*da_point++); >> } > .