add audio.get_input_info()

This commit is contained in:
MihailRis
2025-10-24 01:19:07 +03:00
parent 001c1b430b
commit 6c558eb3d5
4 changed files with 49 additions and 4 deletions
+19 -3
View File
@@ -68,9 +68,17 @@ std::unique_ptr<Speaker> ALSound::newInstance(int priority, int channel) const {
}
ALInputDevice::ALInputDevice(
ALAudio* al, ALCdevice* device, uint channels, uint bitsPerSample
ALAudio* al,
ALCdevice* device,
uint channels,
uint bitsPerSample,
uint sampleRate
)
: al(al), device(device), channels(channels), bitsPerSample(bitsPerSample) {
: al(al),
device(device),
channels(channels),
bitsPerSample(bitsPerSample),
sampleRate(sampleRate) {
}
ALInputDevice::~ALInputDevice() {
@@ -92,6 +100,14 @@ uint ALInputDevice::getChannels() const {
return channels;
}
uint ALInputDevice::getSampleRate() const {
return sampleRate;
}
uint ALInputDevice::getBitsPerSample() const {
return bitsPerSample;
}
size_t ALInputDevice::read(char* buffer, size_t bufferSize) {
ALCint samplesCount = 0;
alcGetIntegerv(device, ALC_CAPTURE_SAMPLES, sizeof(samplesCount), &samplesCount);
@@ -546,7 +562,7 @@ std::unique_ptr<InputDevice> ALAudio::openInputDevice(
return nullptr;
return std::make_unique<ALInputDevice>(
this, device, channels, bitsPerSample
this, device, channels, bitsPerSample, sampleRate
);
}
+8 -1
View File
@@ -85,7 +85,11 @@ namespace audio {
class ALInputDevice : public InputDevice {
public:
ALInputDevice(
ALAudio* al, ALCdevice* device, uint channels, uint bitsPerSample
ALAudio* al,
ALCdevice* device,
uint channels,
uint bitsPerSample,
uint sampleRate
);
~ALInputDevice() override;
@@ -93,6 +97,8 @@ namespace audio {
void stopCapture() override;
uint getChannels() const override;
uint getSampleRate() const override;
uint getBitsPerSample() const override;
size_t read(char* buffer, size_t bufferSize) override;
private:
@@ -100,6 +106,7 @@ namespace audio {
ALCdevice* device;
uint channels;
uint bitsPerSample;
uint sampleRate;
};
/// @brief AL source adapter
+6
View File
@@ -120,6 +120,12 @@ namespace audio {
/// @brief Get number of audio channels
/// @return 1 if mono, 2 if stereo
virtual uint getChannels() const = 0;
/// @brief Get audio sampling frequency
/// @return number of mono samples per second
virtual uint getSampleRate() const = 0;
/// @brief Get number of bits per mono sample
/// @return 8 or 16
virtual uint getBitsPerSample() const = 0;
virtual size_t read(char* buffer, size_t bufferSize) = 0;
};