Frequency Literal Operators

This commit is contained in:
2025-07-15 21:48:47 -05:00
parent 09ee0360dc
commit 3f2d68617f
8 changed files with 138 additions and 72 deletions

View File

@@ -0,0 +1,28 @@
#pragma once
#include <cstdint>
namespace ReMixer {
enum class SampleFormat {
Unknown,
Float16,
Float32,
Int16,
Int32,
};
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);
}
};
}

View File

@@ -0,0 +1,17 @@
#pragma once
namespace ReMixer {
namespace FrequencyLiterals {
unsigned operator ""_Hz(long double frequency);
unsigned operator ""_Hz(unsigned long long int frequency);
unsigned operator ""_kHz(long double frequency);
unsigned operator ""_kHz(unsigned long long int frequency);
unsigned operator ""_MHz(long double frequency);
unsigned operator ""_MHz(unsigned long long int frequency);
unsigned operator ""_GHz(long double frequency);
unsigned operator ""_GHz(unsigned long long int frequency);
}
using namespace FrequencyLiterals;
}

View File

@@ -0,0 +1,30 @@
#pragma once
#include "ReMixer.h"
namespace ReMixer {
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 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;
};
}

View File

@@ -30,80 +30,20 @@ namespace ReMixer {
/// Allow users to discover available audio input and output devices. /// 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,
};
/// We do not plan to support specifications such as 7.1 Surround.
/// 3D Positional Audio will be implemented later in software.
enum class StreamMode : bool {
MONO = false,
STEREO = true
};
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 Sound;
class Stream; class Stream;
class SoundSubsystem; class SoundSubsystem;
class PulseAudioSubsystem; class PulseAudioSubsystem;
class PulseStream; 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 Init();

View File

@@ -0,0 +1,13 @@
#pragma once
#include "sound.h"
namespace ReMixer {
class SoundHandle {
public:
protected:
SoundHandle(const Sound& sound);
private:
};
}

View File

@@ -17,9 +17,21 @@
#include <iostream> #include <iostream>
#include <ReMixer/sound.h> #include <ReMixer/sound.h>
#include <ReMixer/SoundSubsystem.h> #include <ReMixer/SoundSubsystem.h>
#include <ReMixer/ReMixer.h>
namespace ReMixer { namespace ReMixer {
enum class StreamDirection {
PLAYBACK,
RECORD,
};
/// We do not plan to support specifications such as 7.1 Surround.
/// 3D Positional Audio will be implemented later in software.
enum class StreamMode : bool {
MONO = false,
STEREO = true
};
/// The stream class is an abstract class that represents distinct output / input channels on an audio system. /// 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. /// Each audio system implements their concept of streams as a derivation of this class.
class Stream { class Stream {

View File

@@ -1,14 +1,4 @@
#include <ReMixer/ReMixer.h> #include <ReMixer/ReMixer.h>
unsigned ReMixer::operator ""_Hz(unsigned long long int frequency) {
return 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);
}

36
src/shared/Frequency.cpp Normal file
View File

@@ -0,0 +1,36 @@
#include <ReMixer/Frequency.hpp>
namespace ReMixer::FrequencyLiterals {
unsigned operator ""_Hz(long double frequency) {
return frequency;
}
unsigned operator ""_MHz(long double frequency) {
return frequency * 1000 * 1000;
}
unsigned operator ""_MHz(unsigned long long int frequency) {
return frequency * 1000 * 1000;
}
unsigned operator ""_GHz(long double frequency) {
return frequency * 1000 * 1000 * 1000;
}
unsigned operator ""_GHz(unsigned long long int frequency) {
return frequency * 1000 * 1000 * 1000;
}
}
unsigned ReMixer::FrequencyLiterals::operator ""_Hz(unsigned long long int frequency) {
return frequency;
}
unsigned ReMixer::FrequencyLiterals::operator ""_kHz(long double frequency) {
return frequency * 1000;
}
unsigned ReMixer::FrequencyLiterals::operator ""_kHz(unsigned long long int frequency) {
return operator ""_kHz((long double)frequency);
}