#include #include #include void decodeVorbis(const char* inputFile, const char* outputFile) { OggVorbis_File vf; FILE* inFile = fopen(inputFile, "rb"); if (!inFile) { std::cerr << "Error opening input file." << std::endl; return; } if (ov_open(inFile, &vf, NULL, 0) < 0) { std::cerr << "Error opening Ogg Vorbis file." << std::endl; fclose(inFile); return; } std::cout << vf.pcmlengths << " pcmlengths" << std::endl; std::cout << vf.pcm_offset << " pcm_offset" << std::endl; vorbis_info* vi = ov_info(&vf, -1); std::cout << vi->channels << " channels" << std::endl; std::cout << vi->version << " version" << std::endl; std::cout << vi->rate << " rate" << std::endl; std::cout << vi->bitrate_lower << " bitrate_lower" << std::endl; std::cout << vi->bitrate_nominal << " bitrate_nominal" << std::endl; std::cout << vi->bitrate_upper << " bitrate_upper" << std::endl; std::ofstream outFile(outputFile, std::ios::binary); if (!outFile.is_open()) { std::cerr << "Error opening output file." << std::endl; ov_clear(&vf); fclose(inFile); return; } char pcmout[4096]; int current_section; long bytes; // Data is read as 2-byte signed words, but we store into a char buffer? while ((bytes = ov_read(&vf, pcmout, sizeof(pcmout), 0, 2, 1, ¤t_section)) > 0) { outFile.write(pcmout, bytes); } outFile.close(); ov_clear(&vf); //fclose(inFile); std::cout << "Decoding complete. Raw audio data saved to " << outputFile << std::endl; } int main(int argc, char* argv[]) { if (argc == 1 || argv[1] == "-h" || argv[1] == "help") { std::cout << "vorbis_decode is an in-house tool that is used to convert OGG Vorbisfiles to raw PCM audio data." << std::endl; std::cout << "usage: vorbis_decode " << std::endl; return 0; } if (argc < 3) { std::cout << "Error: Invalid arguments!" << std::endl; return -1; } std::string input_file_name = argv[1]; std::string output_file_name = argv[2]; decodeVorbis(input_file_name.c_str(), output_file_name.c_str()); }