More boilerplate work
This commit is contained in:
@@ -16,6 +16,10 @@ namespace ReMixer {
|
||||
unsigned operator ""_Hz(unsigned long long int frequency);
|
||||
unsigned operator ""_kHz(long double frequency);
|
||||
|
||||
class Stream;
|
||||
class SoundSubsystem;
|
||||
class PulseAudioSubsystem;
|
||||
class PulseStream;
|
||||
|
||||
}
|
||||
|
||||
|
@@ -4,6 +4,8 @@
|
||||
|
||||
namespace ReMixer
|
||||
{
|
||||
class Stream;
|
||||
|
||||
/// A managed sound handler object.
|
||||
class NuSound
|
||||
{
|
||||
@@ -81,10 +83,7 @@ namespace ReMixer
|
||||
class SoundSubsystem
|
||||
{
|
||||
public:
|
||||
SoundSubsystem()
|
||||
{
|
||||
|
||||
}
|
||||
SoundSubsystem() {}
|
||||
|
||||
std::vector<AudioDevice> GetAudioDevices();
|
||||
std::vector<PlaybackDevice> GetPlaybackDevices();
|
||||
|
@@ -20,25 +20,36 @@
|
||||
#include <ReMixer/ReMixer.h>
|
||||
|
||||
namespace ReMixer {
|
||||
|
||||
|
||||
/// The stream class is an abstract class that represents distinct output / input channels on an audio system.
|
||||
/// Each audio system implements their concept of streams as a derivation of this class.
|
||||
class Stream {
|
||||
public:
|
||||
Stream() = default;
|
||||
//Stream(SoundSubsystem* parent_system);
|
||||
|
||||
uint SampleRate() const { return sample_rate;}
|
||||
uint ChannelCount() const { return channel_count;}
|
||||
std::string Name() const { return name;}
|
||||
|
||||
/// TODO: It may not be possible to actually change these parameters after creation of the stream object.
|
||||
void SetStreamDirection(const StreamDirection& direction);
|
||||
void SetName(const std::string& name);
|
||||
void SetSampleRate(uint sample_rate);
|
||||
void SetChannelCount(uint channel_count);
|
||||
|
||||
public:
|
||||
unsigned int sample_rate;
|
||||
size_t bufferSize;
|
||||
uint16_t handle;
|
||||
|
||||
private:
|
||||
std::string name;
|
||||
std::string parent_name;
|
||||
unsigned int channel_count;
|
||||
StreamDirection dir;
|
||||
std::vector<char> buffer;
|
||||
public:
|
||||
Stream() = default;
|
||||
Stream(SoundSubsystem* parent_system);
|
||||
|
||||
uint SampleRate() const { return sample_rate;}
|
||||
|
||||
unsigned int sample_rate;
|
||||
size_t bufferSize;
|
||||
uint16_t handle;
|
||||
//Stream(const std::string& application_name, const std::string& stream_name, SampleRate sample_rate, StreamMode mode);
|
||||
unsigned int stream_id;
|
||||
SoundSubsystem* parent_system;
|
||||
};
|
||||
|
||||
class PulseStream : public Stream
|
||||
@@ -54,6 +65,7 @@ namespace ReMixer {
|
||||
static void OnStreamRequest(pa_stream* s, size_t length, void* userdata);
|
||||
static void OnLatencyUpdate(pa_stream* s, void* userdata);
|
||||
protected:
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
|
@@ -2,6 +2,7 @@
|
||||
|
||||
void ReMixer::PulseAudioSubsystem::Play(const ReMixer::PulseStream &stream, const ReMixer::Sound &sound) {
|
||||
|
||||
// Check parameters and compatibility between stream and sound.
|
||||
if (stream.SampleRate() != sound.SampleRate())
|
||||
{
|
||||
std::cerr << "There is an incongruency in sample rate between the stream and the sound file. "
|
||||
@@ -19,7 +20,7 @@ void ReMixer::PulseAudioSubsystem::Play(const ReMixer::PulseStream &stream, cons
|
||||
{
|
||||
size_t l;
|
||||
int r;
|
||||
while(!(l = pa_stream_writable_size(stream.stream))) {
|
||||
while(!((l = pa_stream_writable_size(stream.stream)))) {
|
||||
pa_threaded_mainloop_wait(pa->mainloop);
|
||||
}
|
||||
|
||||
@@ -38,7 +39,7 @@ bool ReMixer::PulseAudioSubsystem::Connected() {
|
||||
return ctx_connected;
|
||||
}
|
||||
|
||||
ReMixer::PulseStream ReMixer::PulseAudioSubsystem::CreateStream(const std::string &stream_name) {
|
||||
ReMixer::PulseStream ReMixer::PulseAudioSubsystem::CreateStream(const std::string& stream_name) {
|
||||
// Assumed defaults
|
||||
// TODO: Expose to the API later
|
||||
static const pa_sample_spec ss = {
|
||||
@@ -47,12 +48,13 @@ ReMixer::PulseStream ReMixer::PulseAudioSubsystem::CreateStream(const std::strin
|
||||
.channels = 2
|
||||
};
|
||||
|
||||
const pa_cvolume* volume = NULL;
|
||||
pa_channel_map* map = NULL;
|
||||
const char* dev = NULL;
|
||||
pa_buffer_attr* attr = NULL;
|
||||
const pa_cvolume* volume = nullptr;
|
||||
pa_channel_map* map = nullptr;
|
||||
const char* dev = nullptr;
|
||||
pa_buffer_attr* attr = nullptr;
|
||||
|
||||
PulseStream new_stream = PulseStream();
|
||||
new_stream.SetName(stream_name);
|
||||
new_stream.sample_rate = 44.1_kHz;
|
||||
pa_threaded_mainloop_lock(pa->mainloop);
|
||||
|
||||
|
@@ -4,53 +4,18 @@
|
||||
#include <iostream>
|
||||
|
||||
|
||||
|
||||
|
||||
/*Stream::Stream(const std::string& name, const std::string& stream_name, SampleRate sample_rate, StreamMode mode) {
|
||||
this->application_name = name;
|
||||
this->stream_name = stream_name;
|
||||
this->sample_rate = sample_rate;
|
||||
this->mode = mode;
|
||||
handle = UUID::dice(0, 65535);
|
||||
|
||||
//50ms.
|
||||
bufferSize = (unsigned int) sample_rate * numChannels() * 2 / 20;
|
||||
|
||||
pa_sample_spec sample_spec = {.format = PA_SAMPLE_S16LE, .rate = (uint32_t) sample_rate, .channels = (uint8_t) numChannels()};
|
||||
|
||||
pa_buffer_attr buffer_attr = {buffer_attr.maxlength = (uint32_t) -1, buffer_attr.tlength = bufferSize, buffer_attr.prebuf = (uint32_t) -1,
|
||||
buffer_attr.minreq = (uint32_t) -1, buffer_attr.fragsize = (uint32_t) -1};
|
||||
|
||||
stream = pa_simple_new(nullptr, name.c_str(), PA_STREAM_PLAYBACK, nullptr, name.c_str(), &sample_spec, nullptr, &buffer_attr, nullptr);
|
||||
|
||||
if (stream == nullptr)
|
||||
{
|
||||
throw std::runtime_error("Could not connect to the PulseAudio server");
|
||||
}
|
||||
|
||||
streamList.push_back(new Stream(*this));
|
||||
}
|
||||
|
||||
void Stream::test_play(const void* data, size_t size, int* err)
|
||||
void ReMixer::Stream::SetName(const std::string& name)
|
||||
{
|
||||
int return_code = pa_simple_write(stream, data, size, err);
|
||||
|
||||
if (return_code != 0) // success
|
||||
std::cerr << "A problem occurred pushing sound data to the buffer. Err code: " << return_code << std::endl;
|
||||
this->name = name;
|
||||
}
|
||||
|
||||
unsigned int Stream::numChannels() {
|
||||
return (unsigned int) mode + 1;
|
||||
}
|
||||
void ReMixer::Stream::SetSampleRate(uint sample_rate)
|
||||
{ this->sample_rate = sample_rate;}
|
||||
|
||||
void ReMixer::Stream::SetChannelCount(uint channel_count)
|
||||
{ this->channel_count = channel_count;}
|
||||
|
||||
void Stream::erase() {
|
||||
pa_simple_free(stream);
|
||||
|
||||
for (int i = 0; i < streamList.size(); i++)
|
||||
if (this == streamList[i])
|
||||
streamList.erase(streamList.begin() + i);
|
||||
}
|
||||
*/
|
||||
void ReMixer::PulseStream::OnStreamStateChanged(pa_stream *s, void *userdata) {
|
||||
std::cout << "stream state callback: ";
|
||||
|
||||
|
Reference in New Issue
Block a user