vorbis_decode and pacat tools packaged with ReMixer. Proper integration coming next

This commit is contained in:
2024-08-14 17:19:39 -04:00
parent 45e3ea1a5e
commit 5355c8f5ea
4 changed files with 77 additions and 47 deletions

View File

@@ -49,5 +49,8 @@ endif()
target_link_libraries(ReMixer-Test PUBLIC ReMixer)
add_executable(pacatsimple pacat_simple.cpp)
target_link_libraries(pacatsimple pulse-simple pulse)
add_executable(pacat pacat_simple.cpp)
target_link_libraries(pacat pulse-simple pulse)
add_executable(vorbis_decode vorbis_decode.cpp)
target_link_libraries(vorbis_decode vorbisfile vorbis)

View File

@@ -17,52 +17,7 @@
#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);
}
[[noreturn]] int main() {
const char* inputFile = "song.ogg";
const char* outputFile = "output.raw";
decodeVorbis(inputFile, outputFile);
std::cout << "Decoding complete. Raw audio data saved to " << outputFile << std::endl;
Stream stream("ReMixer-Test", "Main", SampleRate::STANDARD, StreamMode::STEREO);
FILE* rawData = fopen("output.raw", "rb");

View File

@@ -1,3 +1,5 @@
#include <iostream>
extern "C"
{
@@ -11,6 +13,12 @@ extern "C"
#define BUFSIZE 1024
int main(int argc, char* argv[])
{
if (argc == 1 || argv[1] == "-h" || argv[1] == "help")
{
printf("pacat - Tests playback of raw audio data via PulseAudio API.\n");
printf("usage: pacat <file> (presumably output.raw)\n");
}
static const pa_sample_spec ss = {
.format = PA_SAMPLE_S16LE,
.rate = 44100,

64
vorbis_decode.cpp Normal file
View File

@@ -0,0 +1,64 @@
#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());
}