perf.cc (2132B)
1 #include <cstdlib> 2 #include <iostream> 3 #include <fstream> 4 5 const char *SAMPLE_FILE = SAMPLES_DIR "/perf.wav"; 6 const int SAMPLE_RATE = 44100; 7 const int SAMPLE_DURATION = 8 * 60; // 8 minutes 8 const int SAMPLES = SAMPLE_RATE * SAMPLE_DURATION; // per channel 9 10 // Some of the tests will use a sample .wav file which is auto-generated if it doesn't exists. 11 static void create_samples() 12 { 13 if (std::ifstream(SAMPLE_FILE).good()) { 14 return; 15 } 16 17 std::ofstream file(SAMPLE_FILE, std::ofstream::binary); 18 const int data_size = SAMPLES * 2 * 2; // samples * channels * bytes per sample 19 uint16_t u16; 20 uint32_t u32; 21 file.write("RIFF", 4); 22 file.write(reinterpret_cast<const char*>(&(u32 = 36 + data_size)), 4); // size 23 file.write("WAVE", 4); 24 file.write("fmt ", 4); 25 file.write(reinterpret_cast<const char*>(&(u32 = 16)), 4); // subchunk size 26 file.write(reinterpret_cast<const char*>(&(u16 = 1)), 2); // 1 = PCM 27 file.write(reinterpret_cast<const char*>(&(u16 = 2)), 2); // 2 = stereo 28 file.write(reinterpret_cast<const char*>(&(u32 = SAMPLE_RATE)), 4); 29 file.write(reinterpret_cast<const char*>(&(u32 = SAMPLE_RATE * 2 * 2)), 4); // byte rate 30 file.write(reinterpret_cast<const char*>(&(u16 = 2 * 2)), 2); // block align 31 file.write(reinterpret_cast<const char*>(&(u16 = 16)), 2); // bits per sample 32 file.write("data", 4); 33 file.write(reinterpret_cast<const char*>(&(u32 = data_size)), 4); 34 35 // Fill in both channels with pseudo-random values. 36 srand(93); 37 for (int i = 0; i < SAMPLES * 2; ++i) { 38 file.write(reinterpret_cast<const char*>(&(u16 = rand())), 2); 39 } 40 } 41 42 // Reading and decoding an audio file. 43 static void perf_decoder() 44 { 45 } 46 47 // Running FFTs and processing the results. 48 static void perf_worker() 49 { 50 } 51 52 // Managing worker and decoder threads (in isolation from the actual decoder and worker). 53 static void perf_pipeline() 54 { 55 } 56 57 // Testing it all together. 58 static void perf_all() 59 { 60 } 61 62 // Performance regression tests. 63 int main() 64 { 65 create_samples(); 66 67 perf_decoder(); 68 perf_worker(); 69 perf_pipeline(); 70 perf_all(); 71 72 return 0; 73 }