?? cbuf.cpp
字號(hào):
} return (count);} // end cbuf_long::peek/* * CBUF_FLOAT::PEEK - Read up to howmany elements from the circular buffer and place * them in where. Return number of elements actually read. * Same as read but the reader pointer is NOT updated. */long cbuf_float::peek( float *where, // where to put it long howmany, // how many to read BOOLEAN ckeod // if True, don't read past eod marker){ long count, rdr = reader, lastw; if (ckeod && eod >= 0) lastw = eod; else lastw = writer; for (count = 0; count < howmany; rdr++) { if (rdr >= size) rdr -= size; // wrap around if (rdr == lastw) break; where[count++] = buffer[rdr]; // move one element } return (count);} // end cbuf_float::peek/* * CBUF::CHECKEODREAD - Return True if the eod pointer will prevent reading the * requested number of samples. */BOOLEAN cbuf::checkeodread( long count // requested count){ long available; if (eod < 0) return (False); // eod pointer is not set available = eod - reader; if (available < 0) available += size; // wrap around if (available < count) return (True); else return (False);} // end cbuf::checkeodread/* * CBU_CHAR::READALL - Read all available data between the keeper pointer and the eod * pointer up to howmany and place the elements in where. Return * actual number of elements read. The pointers are left unchanged. */long cbuf_char::readall( char *where, // where to put it long howmany // how many to read){ long next, // next element start, // first element available last, // last element available count; if (keeper < 0) start = reader; // keeper not set else start = keeper; if (eod >= 0) last = eod; // set last available else if ((last = writer - 1) < 0) last += size; // wrap around for (next = start, count = 0; count < howmany && next <= last; next = (next + 1) % size, count++) where[count] = buffer[next]; return (count);} // end cbuf_char::readall/* * CBUF_SHORT::READALL - Read all available data between the keeper pointer and the eod * pointer up to howmany and place the elements in where. Return * actual number of elements read. The pointers are left unchanged. */long cbuf_short::readall( short *where, // where to put it long howmany // how many to read){ long next, // next element start, // first element available last, // last element available count; if (keeper < 0) start = reader; // keeper not set else start = keeper; if (eod >= 0) last = eod; // set last available else if ((last = writer - 1) < 0) last += size; // wrap around for (next = start, count = 0; count < howmany && next <= last; next = (next + 1) % size, count++) where[count] = buffer[next]; return (count);} // end cbuf_short::readall/* * CBUF_LONG::READALL - Read all available data between the keeper pointer and the eod * pointer up to howmany and place the elements in where. Return * actual number of elements read. The pointers are left unchanged. */long cbuf_long::readall( long *where, // where to put it long howmany // how many to read){ long next, // next element start, // first element available last, // last element available count; if (keeper < 0) start = reader; // keeper not set else start = keeper; if (eod >= 0) last = eod; // set last available else if ((last = writer - 1) < 0) last += size; // wrap around for (next = start, count = 0; count < howmany && next <= last; next = (next + 1) % size, count++) where[count] = buffer[next]; return (count);} // end cbuf_long::readall/* * CBUF_FLOAT::READALL - Read all available data between the keeper pointer and the eod * pointer up to howmany and place the elements in where. Return * actual number of elements read. The pointers are left unchanged. */long cbuf_float::readall( float *where, // where to put it long howmany // how many to read){ long next, // next element start, // first element available last, // last element available count; if (keeper < 0) start = reader; // keeper not set else start = keeper; if (eod >= 0) last = eod; // set last available else if ((last = writer - 1) < 0) last += size; // wrap around for (next = start, count = 0; count < howmany && next <= last; next = (next + 1) % size, count++) where[count] = buffer[next]; return (count);} // end cbuf_float::readall/* * CBUF_CHAR::WRITE - Write up to howmany elements from where and place them in * the circular buffer. Return number of elements actually * written. The writer pointer is updated. */long cbuf_char::write( char *where, // where to read it long howmany // how many to write){ long last, // last element available count; if (keeper >= 0) last = keeper - 1; else last = reader - 1; if (last < 0) last += size; // wrap around for (count = 0; count < howmany && writer != last; count++, writer = (writer + 1) % size) buffer[writer] = where[count]; // move one element if (count != howmany) overflow = True; return (count);} // end cbuf_char::write/* * CBUF_SHORT::WRITE - Write up to howmany elements from where and place them in * the circular buffer. Return number of elements actually * written. The writer pointer is updated. */long cbuf_short::write( short *where, // where to read it long howmany // how many to write){ long last, // last element available count; if (keeper >= 0) last = keeper - 1; else last = reader - 1; if (last < 0) last += size; // wrap around for (count = 0; count < howmany && writer != last; count++, writer = (writer + 1) % size) buffer[writer] = where[count]; // move one element if (count != howmany) overflow = True; return (count);} // end cbuf_short::write/* * CBUF_LONG::WRITE - Write up to howmany elements from where and place them in * the circular buffer. Return number of elements actually * written. The writer pointer is updated. */long cbuf_long::write( long *where, // where to read it long howmany // how many to write){ long last, // last element available count; if (keeper >= 0) last = keeper - 1; else last = reader - 1; if (last < 0) last += size; // wrap around for (count = 0; count < howmany && writer != last; count++, writer = (writer + 1) % size) buffer[writer] = where[count]; // move one element if (count != howmany) overflow = True; return (count);} // end cbuf_long::write/* * CBUF_FLOAT::WRITE - Write up to howmany elements from where and place them in * the circular buffer. Return number of elements actually * written. The writer pointer is updated. */long cbuf_float::write( float *where, // where to read it long howmany // how many to write){ long last, // last element available count; if (keeper >= 0) last = keeper - 1; else last = reader - 1; if (last < 0) last += size; // wrap around for (count = 0; count < howmany && writer != last; count++, writer = (writer + 1) % size) buffer[writer] = where[count]; // move one element if (count != howmany) overflow = True; return (count);} // end cbuf_float::writelong cbuf_char::readalltofile( char *file // file to create){ long next, // next element start, // first element available last, // last element available count; FILE *fd; if ((fd = fopen (file, "w")) == NULL) return (-1); if (keeper < 0) start = reader; // keeper not set else start = keeper; if (eod >= 0) last = eod; // set last available else if ((last = writer - 1) < 0) last += size; // wrap around for (next = start, count = 1; ; next = (next + 1) % size, count++) { fwrite (buffer + next, sizeof (char), 1, fd); if (next == last) break; // end of available } fclose (fd); return (count);} // end cbuf_char::readalltofilelong cbuf_short::readalltofile( char *file // file to create){ long next, // next element start, // first element available last, // last element available count; FILE *fd; if ((fd = fopen (file, "w")) == NULL) return (-1); if (keeper < 0) start = reader; // keeper not set else start = keeper; if (eod >= 0) last = eod; // set last available else if ((last = writer - 1) < 0) last += size; // wrap around for (next = start, count = 1; ; next = (next + 1) % size, count++) { fwrite (buffer + next, sizeof (short), 1, fd); if (next == last) break; // end of available } fclose (fd); return (count);} // end cbuf_short::readalltofilelong cbuf_long::readalltofile( char *file // file to create){ long next, // next element start, // first element available last, // last element available count; FILE *fd; if ((fd = fopen (file, "w")) == NULL) return (-1); if (keeper < 0) start = reader; // keeper not set else start = keeper; if (eod >= 0) last = eod; // set last available else if ((last = writer - 1) < 0) last += size; // wrap around for (next = start, count = 1; ; next = (next + 1) % size, count++) { fwrite (buffer + next, sizeof (long), 1, fd); if (next == last) break; // end of available } fclose (fd); return (count);} // end cbuf_long::readalltofilelong cbuf_float::readalltofile( char *file // file to create){ long next, // next element start, // first element available last, // last element available count; FILE *fd; if ((fd = fopen (file, "w")) == NULL) return (-1); if (keeper < 0) start = reader; // keeper not set else start = keeper; if (eod >= 0) last = eod; // set last available else if ((last = writer - 1) < 0) last += size; // wrap around for (next = start, count = 1; ; next = (next + 1) % size, count++) { fwrite (buffer + next, sizeof (float), 1, fd); if (next == last) break; // end of available } fclose (fd); return (count);} // end cbuf_float::readalltofile
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -