Frequency Literal Operators
This commit is contained in:
28
include/ReMixer/AudioFormat.hpp
Normal file
28
include/ReMixer/AudioFormat.hpp
Normal 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);
|
||||
}
|
||||
};
|
||||
}
|
17
include/ReMixer/Frequency.hpp
Normal file
17
include/ReMixer/Frequency.hpp
Normal 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;
|
||||
}
|
30
include/ReMixer/IAudioDevice.hpp
Normal file
30
include/ReMixer/IAudioDevice.hpp
Normal 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;
|
||||
|
||||
|
||||
};
|
||||
}
|
@@ -30,80 +30,20 @@ namespace ReMixer {
|
||||
/// 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 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();
|
||||
|
13
include/ReMixer/SoundHandle.hpp
Normal file
13
include/ReMixer/SoundHandle.hpp
Normal file
@@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
#include "sound.h"
|
||||
|
||||
namespace ReMixer {
|
||||
class SoundHandle {
|
||||
public:
|
||||
protected:
|
||||
SoundHandle(const Sound& sound);
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
}
|
@@ -17,9 +17,21 @@
|
||||
#include <iostream>
|
||||
#include <ReMixer/sound.h>
|
||||
#include <ReMixer/SoundSubsystem.h>
|
||||
#include <ReMixer/ReMixer.h>
|
||||
|
||||
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.
|
||||
/// Each audio system implements their concept of streams as a derivation of this class.
|
||||
class Stream {
|
||||
|
@@ -1,14 +1,4 @@
|
||||
#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
36
src/shared/Frequency.cpp
Normal 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);
|
||||
}
|
Reference in New Issue
Block a user