Bela
Real-time, ultra-low-latency audio and sensor processing system for BeagleBone Black
 All Classes Files Functions Variables Typedefs Macros Groups
WriteFile.h
1 /*
2  * WriteFile.h
3  *
4  * Created on: 5 Oct 2015
5  * Author: giulio
6  */
7 
8 #ifndef WRITEFILE_H_
9 #define WRITEFILE_H_
10 #include <Bela.h>
11 #include <vector>
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <string.h>
15 #include <unistd.h>
16 
17 typedef enum {
18  kBinary,
19  kText
20 } WriteFileType;
21 
22 class WriteFile {
23 private:
24  static AuxiliaryTask writeAllFilesTask;
25  bool echo;
26  int echoedLines;
27  int echoPeriod;
28  char *header;
29  char *footer;
30  char *stringBuffer;
31  int stringBufferLength;
32  std::vector<float> buffer;
33  int textReadPointer;
34  int binaryReadPointer;
35  int writePointer;
36  bool variableOpen;
37  char* format;
38  int lineLength;
39  WriteFileType fileType;
40  static int sleepTimeMs;
41  FILE *file;
42  char* _filename;
43  void writeLine();
44  void writeHeader();
45  void writeFooter();
46  void allocateAndCopyString(const char* source, char** destination);
47  void print(const char* string);
48  void printBinary(const char* string);
49  void setLineLength(int newLineLength);
50  int getOffsetFromPointer(int aPointer);
51  std::vector<char *> formatTokens;
52  static void sanitizeString(char* string);
53  static void sanitizeString(char* string, int numberOfArguments);
54  static bool isThreadRunning();
55  static bool auxiliaryTaskRunning;
56  static bool threadShouldExit();
57  static bool threadIsExiting;
58  static bool threadRunning;
59  static bool staticConstructed;
60  static void staticConstructor();
61  static std::vector<WriteFile *> objAddrs;
62  void writeOutput(bool flush);
63 public:
64  WriteFile();
71  void setFileType(WriteFileType newFileType);
72 
77  void setEcho(bool newEcho);
78 
83  void setEchoInterval(int newPeriod);
84 
92  void setBufferSize(unsigned int newSize);
93 
100  void setFormat(const char* newFormat);
106  void setHeader(const char* newHeader);
112  void setFooter(const char* newFooter);
113 
117  void log(float value);
121  void log(const float* array, int length);
122 
129  void init(const char* filename, bool overwrite = false);
130 
135  int getOffset();
136 
143  float getBufferStatus();
144  ~WriteFile();
145  static int getNumInstances();
146  static void writeAllHeaders();
147  static void writeAllFooters();
148  static void writeAllOutputs(bool flush);
149  static void startThread();
150  static void stopThread();
151  static void run(void*);
159  static char* generateUniqueFilename(const char* original);
160 };
161 
162 #endif /* WRITEFILE_H_ */
void init(const char *filename, bool overwrite=false)
void setEchoInterval(int newPeriod)
void setEcho(bool newEcho)
float getBufferStatus()
int getOffset()
void setFooter(const char *newFooter)
void log(float value)
void setFileType(WriteFileType newFileType)
void setBufferSize(unsigned int newSize)
static char * generateUniqueFilename(const char *original)
Definition: WriteFile.h:22
Main Bela public API.
void * AuxiliaryTask
Definition: Bela.h:445
void setFormat(const char *newFormat)
void setHeader(const char *newHeader)