openAudioDevice method
Open an audio device.
If device
is null
, then the default device will be opened,.
If isCapture
is null
, then device.isCapture
will be used.
Implementation
OpenAudioDevice openAudioDevice({
final AudioDevice? device,
final bool? isCapture,
final AudioSpec? settings,
}) {
var capture = isCapture;
Pointer<Char> namePointer;
if (device != null) {
if (capture == null) {
capture = device.isCapture;
namePointer = device.name.toCharPointer();
} else {
throw SdlError(
-1,
'You must specify either `device` or `isCapture`, but not both.',
);
}
} else {
if (capture == null) {
throw SdlError(
-1,
'When `device == null`, `isCapture` must be specified.',
);
} else {
namePointer = nullptr;
}
}
if (settings != null) {
_audioSpecDesiredPointer.ref
..channels = settings.channels
..format = settings.audioFormat
..freq = settings.freq
..samples = settings.samples
..silence = settings.silence
..size = settings.size;
}
final id = checkReturnValue(
sdl.SDL_OpenAudioDevice(
namePointer,
boolToValue(capture),
_audioSpecDesiredPointer,
_audioSpecObtainedPointer,
0,
),
);
if (id <= 0) {
throw SdlError(id, getError());
}
final spec = AudioSpec.fromPointer(_audioSpecObtainedPointer);
malloc.free(namePointer);
return OpenAudioDevice(this, device, id, spec);
}