Fricked up the branch by forgetting commits, solving errors.

This commit is contained in:
2025-07-15 22:58:27 -05:00
parent 3f2d68617f
commit f588dac424
7 changed files with 97 additions and 9 deletions

View File

@@ -41,6 +41,7 @@ include_directories("include")
add_library(ReMixer ${SOURCES}
src/linux/PulseSubsystem.cpp
src/linux/SoundSubsystem.cpp)
add_executable(ReMixer-Test main.cpp)
set_target_properties(ReMixer PROPERTIES LINKER_LANGUAGE CXX)

View File

@@ -3,7 +3,7 @@
#include <set>
#include <string>
#include "sound.h"
#include "Sound.hpp"
namespace ReMixer {
@@ -30,12 +30,44 @@ 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 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;
@@ -43,7 +75,60 @@ namespace ReMixer {
class PulseAudioSubsystem;
class PulseStream;
enum class PlaybackStatus { Stopped, Playing, Paused, Finished, Error };
class SoundHandle {
friend void Init();
friend SoundHandle* PlaySoundAsync(Sound& sound);
public:
Event<> Finished;
Event<> Paused;
Event<std::string> ErrorEncountered;
void Pause();
void Resume();
void Stop();
PlaybackStatus Status() const;
bool IsPlaying() const;
bool IsPaused() const;
bool IsStopped();
float GetPlaybackPositionMs() const;
float GetPlaybackPositionPercent() const;
/// Playback speed control (e.g., 0.5 for half speed, 2.0 for double speed)
/// @note Requires sample rate conversion or similar at lower level.
void SetPlaybackSpeed(float rate);
float GetPlaybackSpeed() const;
void SetPlaybackPositionMs(float ms);
void SetPlaybackPositionPercent(float percent);
void Seek(float ms);
void SeekPercent(float percent);
/// Volume control (0.0 to 1.0)
void SetVolume(float volume);
float GetVolume() const;
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();

View File

@@ -138,6 +138,9 @@ namespace ReMixer {
/// Returns the number of separate channels this sound resource contains.
uint Channels() const;
/// Get the audio format of the loaded sound.
const AudioFormat& GetFormat() const;
/// Returns the time length, in seconds, of this sound resource.
float PlaybackLength();

View File

@@ -15,7 +15,7 @@
#include <pulse/stream.h>
#include <pulse/thread-mainloop.h>
#include <iostream>
#include <ReMixer/sound.h>
#include <ReMixer/Sound.hpp>
#include <ReMixer/SoundSubsystem.h>
namespace ReMixer {

View File

@@ -15,7 +15,7 @@
#include <fstream>
#include <thread>
#include <ReMixer/stream.h>
#include <ReMixer/sound.h>
#include <ReMixer/Sound.hpp>
#include <ReMixer/PulseSubsystem.h>
#include <ReMixer/ReMixer.h>
@@ -51,7 +51,6 @@
Sound square_sound = Sound::FromSquareWave(5.f, 0.025f, 2000, 0);
Sound noise_sound = Sound::FromNoise(5.f, 0.01);
std::thread th { [&]() {
server.Play(second_stream, test_sound);
}};

View File

@@ -1,4 +1,4 @@
#include <ReMixer/sound.h>
#include <ReMixer/Sound.hpp>
#include <vorbis/codec.h>
#include <vorbis/vorbisfile.h>
#include <fstream>

View File

@@ -1,5 +1,5 @@
#include <ReMixer/stream.h>
#include <ReMixer/sound.h>
#include <ReMixer/Sound.hpp>
#include <uuid/uuid.h>
#include <iostream>