Skip to content

Commit 61e90e8

Browse files
committed
Expose internal device properties negotiated by the audio backend
After initialization, miniaudio's ma_device struct contains both the requested and the actual (internal) format, channel count, and sample rate for capture and playback. The internal values reflect what the audio backend actually negotiated, which can differ from what the application requested. A common case is ALSA's dsnoop plugin, which locks the hardware at a fixed sample rate and silently resamples. The existing SampleRate() method returns the requested rate, hiding the mismatch. The new CaptureInternalSampleRate() and PlaybackInternalSampleRate() methods let callers detect this. New methods: - CaptureInternalSampleRate / PlaybackInternalSampleRate - CaptureInternalFormat / PlaybackInternalFormat - CaptureInternalChannels / PlaybackInternalChannels
1 parent 856f609 commit 61e90e8

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

device.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,46 @@ func (dev *Device) SampleRate() uint32 {
101101
return uint32(dev.cptr().sampleRate)
102102
}
103103

104+
// CaptureInternalSampleRate returns the sample rate negotiated with the audio
105+
// backend for capture. This may differ from SampleRate() when the backend
106+
// cannot honor the requested rate, for example when ALSA's dsnoop plugin locks
107+
// the hardware at a fixed rate and resamples in software.
108+
func (dev *Device) CaptureInternalSampleRate() uint32 {
109+
return uint32(dev.cptr().capture.internalSampleRate)
110+
}
111+
112+
// PlaybackInternalSampleRate returns the sample rate negotiated with the audio
113+
// backend for playback.
114+
func (dev *Device) PlaybackInternalSampleRate() uint32 {
115+
return uint32(dev.cptr().playback.internalSampleRate)
116+
}
117+
118+
// CaptureInternalFormat returns the sample format negotiated with the audio
119+
// backend for capture. This may differ from CaptureFormat() when the backend
120+
// performs format conversion internally.
121+
func (dev *Device) CaptureInternalFormat() FormatType {
122+
return FormatType(dev.cptr().capture.internalFormat)
123+
}
124+
125+
// PlaybackInternalFormat returns the sample format negotiated with the audio
126+
// backend for playback.
127+
func (dev *Device) PlaybackInternalFormat() FormatType {
128+
return FormatType(dev.cptr().playback.internalFormat)
129+
}
130+
131+
// CaptureInternalChannels returns the channel count negotiated with the audio
132+
// backend for capture. This may differ from CaptureChannels() when the backend
133+
// performs channel conversion internally.
134+
func (dev *Device) CaptureInternalChannels() uint32 {
135+
return uint32(dev.cptr().capture.internalChannels)
136+
}
137+
138+
// PlaybackInternalChannels returns the channel count negotiated with the audio
139+
// backend for playback.
140+
func (dev *Device) PlaybackInternalChannels() uint32 {
141+
return uint32(dev.cptr().playback.internalChannels)
142+
}
143+
104144
// Start activates the device.
105145
// For playback devices this begins playback. For capture devices it begins recording.
106146
//

0 commit comments

Comments
 (0)