Skip to content

Commit fbae5d4

Browse files
committed
feat: add period and buffer time/size min, max, and get/set methods to HwParams
1 parent b4a4a31 commit fbae5d4

File tree

1 file changed

+154
-0
lines changed

1 file changed

+154
-0
lines changed

src/pcm.rs

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,6 +1216,30 @@ impl<'a> HwParams<'a> {
12161216
.map(|_| ())
12171217
}
12181218

1219+
pub fn set_period_size_min(&self, v: Frames, dir: ValueOr) -> Result<Frames> {
1220+
let mut d = dir as c_int;
1221+
let mut r = v as alsa::snd_pcm_uframes_t;
1222+
acheck!(snd_pcm_hw_params_set_period_size_min(
1223+
(self.1).0,
1224+
self.0,
1225+
&mut r,
1226+
&mut d
1227+
))
1228+
.map(|_| r as Frames)
1229+
}
1230+
1231+
pub fn set_period_size_max(&self, v: Frames, dir: ValueOr) -> Result<Frames> {
1232+
let mut d = dir as c_int;
1233+
let mut r = v as alsa::snd_pcm_uframes_t;
1234+
acheck!(snd_pcm_hw_params_set_period_size_max(
1235+
(self.1).0,
1236+
self.0,
1237+
&mut r,
1238+
&mut d
1239+
))
1240+
.map(|_| r as Frames)
1241+
}
1242+
12191243
pub fn set_period_time_near(&self, v: u32, dir: ValueOr) -> Result<u32> {
12201244
let mut d = dir as c_int;
12211245
let mut r = v as c_uint;
@@ -1228,6 +1252,61 @@ impl<'a> HwParams<'a> {
12281252
.map(|_| r as u32)
12291253
}
12301254

1255+
pub fn set_period_time(&self, v: u32, dir: ValueOr) -> Result<()> {
1256+
acheck!(snd_pcm_hw_params_set_period_time(
1257+
(self.1).0,
1258+
self.0,
1259+
v as c_uint,
1260+
dir as c_int
1261+
))
1262+
.map(|_| ())
1263+
}
1264+
1265+
pub fn set_period_time_min(&self, v: u32, dir: ValueOr) -> Result<u32> {
1266+
let mut d = dir as c_int;
1267+
let mut r = v as c_uint;
1268+
acheck!(snd_pcm_hw_params_set_period_time_min(
1269+
(self.1).0,
1270+
self.0,
1271+
&mut r,
1272+
&mut d
1273+
))
1274+
.map(|_| r as u32)
1275+
}
1276+
1277+
pub fn set_period_time_max(&self, v: u32, dir: ValueOr) -> Result<u32> {
1278+
let mut d = dir as c_int;
1279+
let mut r = v as c_uint;
1280+
acheck!(snd_pcm_hw_params_set_period_time_max(
1281+
(self.1).0,
1282+
self.0,
1283+
&mut r,
1284+
&mut d
1285+
))
1286+
.map(|_| r as u32)
1287+
}
1288+
1289+
pub fn get_period_time(&self) -> Result<u32> {
1290+
let (mut v, mut d) = (0, 0);
1291+
acheck!(snd_pcm_hw_params_get_period_time(self.0, &mut v, &mut d)).map(|_| v as u32)
1292+
}
1293+
1294+
pub fn get_period_time_min(&self) -> Result<u32> {
1295+
let (mut v, mut d) = (0, 0);
1296+
acheck!(snd_pcm_hw_params_get_period_time_min(
1297+
self.0, &mut v, &mut d
1298+
))
1299+
.map(|_| v as u32)
1300+
}
1301+
1302+
pub fn get_period_time_max(&self) -> Result<u32> {
1303+
let (mut v, mut d) = (0, 0);
1304+
acheck!(snd_pcm_hw_params_get_period_time_max(
1305+
self.0, &mut v, &mut d
1306+
))
1307+
.map(|_| v as u32)
1308+
}
1309+
12311310
pub fn get_period_size(&self) -> Result<Frames> {
12321311
let (mut v, mut d) = (0, 0);
12331312
acheck!(snd_pcm_hw_params_get_period_size(self.0, &mut v, &mut d)).map(|_| v as Frames)
@@ -1249,6 +1328,18 @@ impl<'a> HwParams<'a> {
12491328
.map(|_| v as Frames)
12501329
}
12511330

1331+
pub fn set_periods_near(&self, v: u32, dir: ValueOr) -> Result<u32> {
1332+
let mut d = dir as c_int;
1333+
let mut r = v as c_uint;
1334+
acheck!(snd_pcm_hw_params_set_periods_near(
1335+
(self.1).0,
1336+
self.0,
1337+
&mut r,
1338+
&mut d
1339+
))
1340+
.map(|_| r as u32)
1341+
}
1342+
12521343
pub fn set_periods(&self, v: u32, dir: ValueOr) -> Result<()> {
12531344
acheck!(snd_pcm_hw_params_set_periods(
12541345
(self.1).0,
@@ -1259,6 +1350,30 @@ impl<'a> HwParams<'a> {
12591350
.map(|_| ())
12601351
}
12611352

1353+
pub fn set_periods_min(&self, v: u32, dir: ValueOr) -> Result<u32> {
1354+
let mut d = dir as c_int;
1355+
let mut r = v as c_uint;
1356+
acheck!(snd_pcm_hw_params_set_periods_min(
1357+
(self.1).0,
1358+
self.0,
1359+
&mut r,
1360+
&mut d
1361+
))
1362+
.map(|_| r as u32)
1363+
}
1364+
1365+
pub fn set_periods_max(&self, v: u32, dir: ValueOr) -> Result<u32> {
1366+
let mut d = dir as c_int;
1367+
let mut r = v as c_uint;
1368+
acheck!(snd_pcm_hw_params_set_periods_max(
1369+
(self.1).0,
1370+
self.0,
1371+
&mut r,
1372+
&mut d
1373+
))
1374+
.map(|_| r as u32)
1375+
}
1376+
12621377
pub fn get_periods(&self) -> Result<u32> {
12631378
let (mut v, mut d) = (0, 0);
12641379
acheck!(snd_pcm_hw_params_get_periods(self.0, &mut v, &mut d)).map(|_| v as u32)
@@ -1325,6 +1440,40 @@ impl<'a> HwParams<'a> {
13251440
.map(|_| r as u32)
13261441
}
13271442

1443+
pub fn set_buffer_time(&self, v: u32, dir: ValueOr) -> Result<()> {
1444+
acheck!(snd_pcm_hw_params_set_buffer_time(
1445+
(self.1).0,
1446+
self.0,
1447+
v as c_uint,
1448+
dir as c_int
1449+
))
1450+
.map(|_| ())
1451+
}
1452+
1453+
pub fn set_buffer_time_min(&self, v: u32, dir: ValueOr) -> Result<u32> {
1454+
let mut d = dir as c_int;
1455+
let mut r = v as c_uint;
1456+
acheck!(snd_pcm_hw_params_set_buffer_time_min(
1457+
(self.1).0,
1458+
self.0,
1459+
&mut r,
1460+
&mut d
1461+
))
1462+
.map(|_| r as u32)
1463+
}
1464+
1465+
pub fn set_buffer_time_max(&self, v: u32, dir: ValueOr) -> Result<u32> {
1466+
let mut d = dir as c_int;
1467+
let mut r = v as c_uint;
1468+
acheck!(snd_pcm_hw_params_set_buffer_time_max(
1469+
(self.1).0,
1470+
self.0,
1471+
&mut r,
1472+
&mut d
1473+
))
1474+
.map(|_| r as u32)
1475+
}
1476+
13281477
pub fn get_buffer_size(&self) -> Result<Frames> {
13291478
let mut v = 0;
13301479
acheck!(snd_pcm_hw_params_get_buffer_size(self.0, &mut v)).map(|_| v as Frames)
@@ -1340,6 +1489,11 @@ impl<'a> HwParams<'a> {
13401489
acheck!(snd_pcm_hw_params_get_buffer_size_max(self.0, &mut v)).map(|_| v as Frames)
13411490
}
13421491

1492+
pub fn get_buffer_time(&self) -> Result<u32> {
1493+
let (mut v, mut d) = (0, 0);
1494+
acheck!(snd_pcm_hw_params_get_buffer_time(self.0, &mut v, &mut d)).map(|_| v as u32)
1495+
}
1496+
13431497
pub fn get_buffer_time_min(&self) -> Result<u32> {
13441498
let (mut v, mut d) = (0, 0);
13451499
acheck!(snd_pcm_hw_params_get_buffer_time_min(

0 commit comments

Comments
 (0)