1 #ifndef AUDIOGRAPHER_UTILS_H
2 #define AUDIOGRAPHER_UTILS_H
16 static void free_resources();
18 /// Initialize zero buffer, if buffer is != 0, it will be used as the zero buffer
20 static void init_zeros (nframes_t frames, T const * buffer = 0)
23 throw Exception (Utils(), "init_zeros must be called with an argument greater than zero.");
25 unsigned long n_zeros = frames * sizeof (T);
26 if (n_zeros <= num_zeros) { return; }
29 zeros = reinterpret_cast<char const *>(buffer);
31 zeros = new char[n_zeros];
32 memset (const_cast<char *>(zeros), 0, n_zeros);
38 static T const * get_zeros (nframes_t frames)
40 if (frames * sizeof (T) > num_zeros) {
41 throw Exception (Utils(), "init_zeros has not been called with a large enough frame count");
43 return reinterpret_cast<T const *> (zeros);
47 static nframes_t get_zero_buffer_size ()
49 return num_zeros / sizeof (T);
53 static char const * zeros;
54 static unsigned long num_zeros;
59 #endif // AUDIOGRAPHER_ROUTINES_H