1
0
forked from Redacted/ReMixer

Work In Progress pacat_advanced program

This commit is contained in:
2024-08-21 22:04:27 -04:00
parent 5355c8f5ea
commit adb4277630
3 changed files with 134 additions and 10 deletions

View File

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

111
pacat_advanced.cpp Normal file
View File

@@ -0,0 +1,111 @@
#include <pulse/mainloop.h>
#include <pulse/mainloop-api.h>
#include <iostream>
#include <pulse/error.h>
#include <pulse/volume.h>
#include <pulse/stream.h>
#include <format>
// https://github.com/pulseaudio/pulseaudio/blob/master/src/pulse/simple.c
static void context_state_callback(pa_context *c, void *userdata)
{
switch(pa_context_get_state(c)) {
case PA_CONTEXT_READY:
case PA_CONTEXT_TERMINATED:
case PA_CONTEXT_FAILED:
case PA_CONTEXT_UNCONNECTED:
case PA_CONTEXT_CONNECTING:
case PA_CONTEXT_AUTHORIZING:
case PA_CONTEXT_SETTING_NAME:
default:
std::cerr << "The fuck?" << std::endl;
break;
}
}
int main(int argc, char* argv[]) {
if (argc == 1 || argv[1] == "-h" || argv[1] == "help") {
std::cout << "pacat - Tests playback of raw audio data via PulseAudio API." << std::endl;
std::cout << "usage: pacat <file> (presumably output.raw)\n" << std::endl;
}
static const pa_sample_spec ss = {
.format = PA_SAMPLE_S16LE,
.rate = 44100,
.channels = 2
};
int errno;
pa_mainloop *maneloop;
pa_context *ctx;
pa_stream *stream;
const pa_channel_map* map = NULL;
const pa_buffer_attr* attr = NULL;
const char* server = NULL;
const char* name = "This Dick";
pa_stream_direction_t dir = PA_STREAM_PLAYBACK;
const char* dev = NULL;
const char* stream_name = "playback";
if (!(maneloop = pa_mainloop_new()))
throw std::runtime_error("Failed to create a PulseAudio mainloop");
#pragma region Context Creation
if (!(ctx = pa_context_new(
pa_mainloop_get_api(maneloop),
"Sound Channel?")))
throw std::runtime_error("Failed to create a context");
pa_context_flags flags = pa_context_flags::PA_CONTEXT_NOAUTOSPAWN;
if (pa_context_connect(ctx, server, flags, NULL) < 0)
{
errno = pa_context_errno(ctx);
throw std::runtime_error(std::format("Failed to connect a context: {}", errno));
}
pa_context_set_state_callback(ctx, context_state_callback, NULL);
for (;;)
{
pa_context_state_t state;
state = pa_context_get_state(ctx);
if (state == PA_CONTEXT_READY)
break;
if (!PA_CONTEXT_IS_GOOD(state)) {
errno = pa_context_errno(ctx);
throw std::runtime_error(std::format("Context was not good! {}", errno));
}
// Wait until the context is ready
//pa_mainloop_wait(maneloop);
}
#pragma endregion
auto state = pa_context_get_state(ctx);
if (state != PA_CONTEXT_READY) {
}
if (!(stream = pa_stream_new(ctx, "This Dick", &ss, map)))
{
errno = pa_context_errno(ctx);
throw std::runtime_error(std::format("Failed to create a stream. Error code {}", errno));
}
//pa_stream_set_state_callback(stream, stream_state)
return 0;
}

View File

@@ -1,22 +1,32 @@
/// ReMixer
/// A Public Domain C++ Audio Playback Library
/// By william @ RedactedSoftware. Thanks to Dawsh & Maxine.
/// (c) 2024 Redacted Software
/// This work is explicitly dedicated to the public domain, for the hopeful betterment of the software industry.
/// @file pacat_simple.cpp
/// @desc A CLI program that plays back raw PCM data (given as a file) over the PulseAudio service.
/// @edit 2024-08-19
#include <iostream>
extern "C"
{
#include <stdio.h>
#include <cstdio>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <cstring>
#include <cerrno>
#include <fcntl.h>
#include <pulse/simple.h>
#include <pulse/error.h>
#include <pulse/volume.h>
#include <pulse/thread-mainloop.h>
#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");
std::cout << "pacat - Tests playback of raw audio data via PulseAudio API." << std::endl;
std::cout << "usage: pacat <file> (presumably output.raw)\n" << std::endl;
}
static const pa_sample_spec ss = {
@@ -94,4 +104,3 @@ int main(int argc, char* argv[])
return ret;
}
}