Note taking,
This commit is contained in:
@@ -1,6 +1,61 @@
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
#include <set>
|
||||
#include <string>
|
||||
|
||||
#include "sound.h"
|
||||
|
||||
namespace ReMixer {
|
||||
|
||||
/// 1. Abstraction Layer:
|
||||
/// Define abstract base classes or interfaces that capture the common
|
||||
/// functionalities across all supported audio APIs.
|
||||
/// 2. Platform Specific Implementations:
|
||||
/// Create conrete classes for each platform (PulseDevice, WasapiDevice)
|
||||
/// that inherit from the abstract interfaces and implement the API-specific calls.
|
||||
/// 3. Factory Pattern:
|
||||
/// Use a factory function or class to create the correct platform-specific
|
||||
/// implementation at runtime, based on the operating system.
|
||||
/// 4. Resource Management:
|
||||
/// Employ RAII for managing audio device handles, streams, and buffers. Utilize Smart Pointers?
|
||||
/// 5. Callbacks for asynchronous operations:
|
||||
/// Most low-level audio APIs use callbacks for delivering audio data (playback/capture)
|
||||
/// or notifying of device state changes. Your wrapper classes should expose this through
|
||||
/// C++ lambdas or std::function (or josh/Event)
|
||||
/// 6. Error Handling:
|
||||
/// A consistent error reporting mechanism is crucial
|
||||
/// 7. Data Formats:
|
||||
/// Handle common audio formats (PCM float, int16, int32) and sample rates. Provide conversion utilities if necessary.
|
||||
/// 8. Device Enumeration:
|
||||
/// Allow users to discover available audio input and output devices.
|
||||
///
|
||||
|
||||
enum class SampleFormat {
|
||||
Unknown,
|
||||
Float16,
|
||||
Float32,
|
||||
Int16,
|
||||
Int32,
|
||||
};
|
||||
|
||||
unsigned operator ""_Hz(unsigned long long int frequency);
|
||||
unsigned operator ""_kHz(long double frequency);
|
||||
unsigned operator ""_kHz(unsigned long long int frequency);
|
||||
|
||||
struct AudioFormat {
|
||||
uint32_t sample_rate;
|
||||
uint16_t channels;
|
||||
SampleFormat format;
|
||||
|
||||
static AudioFormat StereoFloat(uint32_t rate) {
|
||||
return {rate, 2, SampleFormat::Float16};
|
||||
}
|
||||
|
||||
static AudioFormat StereoFloat48kHz() {
|
||||
return StereoFloat(48_kHz);
|
||||
}
|
||||
};
|
||||
|
||||
enum class StreamDirection {
|
||||
PLAYBACK,
|
||||
RECORD,
|
||||
@@ -13,16 +68,51 @@ namespace ReMixer {
|
||||
STEREO = true
|
||||
};
|
||||
|
||||
unsigned operator ""_Hz(unsigned long long int frequency);
|
||||
unsigned operator ""_kHz(long double frequency);
|
||||
enum class DeviceType {
|
||||
Unknown, Output, Input, Duplex
|
||||
};
|
||||
|
||||
struct AudioDeviceInfo {
|
||||
std::string id;
|
||||
std::string name;
|
||||
DeviceType type;
|
||||
bool is_default;
|
||||
std::set<AudioFormat> supported_formats;
|
||||
};
|
||||
|
||||
class Stream;
|
||||
class SoundSubsystem;
|
||||
class PulseAudioSubsystem;
|
||||
class PulseStream;
|
||||
|
||||
class SoundHandle {
|
||||
public:
|
||||
protected:
|
||||
SoundHandle(const Sound& sound);
|
||||
private:
|
||||
};
|
||||
|
||||
class IAudioDevice {
|
||||
public:
|
||||
virtual ~IAudioDevice() = default;
|
||||
|
||||
virtual bool Initialize(const AudioFormat& requestedFormat, uint32_t bufferSizeFrames) = 0;
|
||||
virtual void Shutdown() = 0;
|
||||
virtual bool Start() = 0;
|
||||
virtual bool Stop() = 0;
|
||||
virtual bool IsRunning() const = 0;
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
void Init();
|
||||
void Cleanup();
|
||||
|
||||
/// Simple high-level API for sound playback.
|
||||
/// @note Assumes you want the default device, and ideal parameters to properly play the sound.
|
||||
/// @return SoundHandle instance for managing the state of playback. (i.e. pause, seek, resume, playback speed, events.)
|
||||
SoundHandle* PlaySoundAsync(Sound& Sound);
|
||||
|
||||
}
|
||||
|
||||
|
9
main.cpp
9
main.cpp
@@ -19,6 +19,9 @@
|
||||
#include <ReMixer/PulseSubsystem.h>
|
||||
#include <ReMixer/ReMixer.h>
|
||||
|
||||
|
||||
|
||||
|
||||
[[noreturn]] int main() {
|
||||
|
||||
using namespace ReMixer;
|
||||
@@ -56,7 +59,7 @@
|
||||
server.Play(second_stream, test_sound);
|
||||
}};
|
||||
|
||||
th.join();
|
||||
th.detach();
|
||||
server.Play(test_stream, wav_sound);
|
||||
|
||||
server.Play(test_stream, sine_sound);
|
||||
@@ -69,10 +72,6 @@
|
||||
server.Play(test_stream, wav_sound);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
while (true) {
|
||||
std::this_thread::sleep_for(25ms);
|
||||
}
|
||||
|
@@ -8,3 +8,7 @@ unsigned ReMixer::operator ""_Hz(unsigned long long int frequency) {
|
||||
unsigned ReMixer::operator ""_kHz(long double frequency) {
|
||||
return frequency * 1000;
|
||||
}
|
||||
|
||||
unsigned ReMixer::operator ""_kHz(unsigned long long int frequency) {
|
||||
return operator ""_kHz((long double)frequency);
|
||||
}
|
||||
|
Reference in New Issue
Block a user