| using namespace std; | |
| inline double elapsed_ms( | |
| std::chrono::time_point<std::chrono::high_resolution_clock> start, | |
| std::chrono::time_point<std::chrono::high_resolution_clock> end) { | |
| return std::chrono::duration<double, std::milli>(end - start).count(); | |
| } | |
| int main(int argc, char** argv) { | |
| if (argc < 2) { | |
| cerr << "Usage: " << argv[0] << " input.wav" << endl; | |
| return 1; | |
| } | |
| std::string inputFile = argv[1]; | |
| std::string outputFile = "output.wav"; | |
| AudioFile audio(inputFile); | |
| // Read input file timing | |
| auto startRead = std::chrono::high_resolution_clock::now(); | |
| if (!audio.read(inputFile)) { | |
| return 1; | |
| } | |
| auto endRead = std::chrono::high_resolution_clock::now(); | |
| double readTime = elapsed_ms(startRead, endRead); | |
| auto startBP = std::chrono::high_resolution_clock::now(); | |
| audio::filter::bandpassFilter( | |
| audio.data(), audio.size(), audio.getChannels(), audio.getSampleRate()); | |
| auto endBP = std::chrono::high_resolution_clock::now(); | |
| double bandPassTime = elapsed_ms(startBP, endBP); | |
| auto startNotch = std::chrono::high_resolution_clock::now(); | |
| audio::filter::notchFilter( | |
| audio.data(), audio.size(), audio.getChannels(), audio.getSampleRate()); | |
| auto endNotch = std::chrono::high_resolution_clock::now(); | |
| double notchTime = elapsed_ms(startNotch, endNotch); | |
| // IIR filter | |
| auto startIIR = std::chrono::high_resolution_clock::now(); | |
| audio::filter::iirFilter(audio.data(), audio.size(), audio.getChannels()); | |
| auto endIIR = std::chrono::high_resolution_clock::now(); | |
| double iirTime = elapsed_ms(startIIR, endIIR); | |
| // FIR filter | |
| auto startFIR = std::chrono::high_resolution_clock::now(); | |
| audio::filter::firFilter(audio.data(), audio.size(), audio.getChannels()); | |
| auto endFIR = std::chrono::high_resolution_clock::now(); | |
| double firTime = elapsed_ms(startFIR, endFIR); | |
| // Write output file | |
| auto startWrite = std::chrono::high_resolution_clock::now(); | |
| if (!audio.save(outputFile)) { | |
| return 1; | |
| } | |
| auto endWrite = std::chrono::high_resolution_clock::now(); | |
| double writeTime = elapsed_ms(startWrite, endWrite); | |
| double totalExecutionTime = | |
| readTime + bandPassTime + notchTime + iirTime + firTime + writeTime; | |
| // Print timings | |
| std::cout << "Serial Execution Times:" << std::endl; | |
| std::cout << "Read: " << readTime << " ms" << std::endl; | |
| std::cout << "Band-pass Filter: " << bandPassTime << " ms" << std::endl; | |
| std::cout << "Notch Filter: " << notchTime << " ms" << std::endl; | |
| std::cout << "IIR Filter: " << iirTime << " ms" << std::endl; | |
| std::cout << "FIR Filter: " << firTime << " ms" << std::endl; | |
| std::cout << "Write: " << writeTime << " ms" << std::endl; | |
| std::cout << "Total Execution: " << totalExecutionTime << " ms" << std::endl; | |
| return 0; | |
| } |
Xet Storage Details
- Size:
- 2.99 kB
- Xet hash:
- d1f1ef37bcf675aea09f390919aa500668146a189035e60c96a20d180430751e
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.