Files
ReMixer/vorbis_decode.cpp

64 lines
1.6 KiB
C++

#include <vorbis/vorbisfile.h>
#include <iostream>
#include <fstream>
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;
}
vorbis_info* vi = ov_info(&vf, -1);
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;
while ((bytes = ov_read(&vf, pcmout, sizeof(pcmout), 0, 2, 1, &current_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 <input> <output>" << 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());
}