7 typedef unsigned long long bufsize_type;
8 const int FLOATSIZE = sizeof(float);
12 Buffer(bufsize_type size, int sp, int nSamples, int cvlen, const char* tmpF) {
15 buffer = new float[size];
16 ftmpOut.open(tmpF, std::ios::binary);
19 this->nSamples = nSamples;
25 if (fr < to) flushToTempFile();
31 void write(float *vec) {
32 if (size - cpos < bufsize_type(cvlen)) flushToTempFile();
33 memcpy(buffer + cpos, vec, FLOATSIZE * cvlen);
39 bufsize_type size, cpos; // cpos : current position
42 std::ofstream ftmpOut;
44 int fr, to; // each flush, sample fr .. to - 1
47 void flushToTempFile() {
48 std::streampos gap1 = std::streampos(fr) * FLOATSIZE;
49 std::streampos gap2 = std::streampos(nSamples - to) * FLOATSIZE;
52 ftmpOut.seekp(0, std::ios::beg);
53 for (int i = 0; i < cvlen; i++) {
55 ftmpOut.seekp(gap1, std::ios::cur);
56 for (int j = fr; j < to; j++) {
57 ftmpOut.write((char*)p, FLOATSIZE);
60 ftmpOut.seekp(gap2, std::ios::cur);
68 #endif /* BUFFER_H_ */