Date: Sat, 15 Sep 2001 11:41:16 +0400 From: Maxim Sobolev <sobomax@mail.ru> To: cg@FreeBSD.org Cc: multimedia@FreeBSD.org, current@FreeBSD.org Subject: Making DMA buffer resizeable depending on audio speed/format Message-ID: <E15iA4g-0007aK-00@smtp6.port.ru>
next in thread | raw e-mail | index | archive | help
This is a multi-part message in MIME format. --192.168.1.100.0.526.1000539647.245.19907 Content-Type: text/plain Hi there, I want to get your comments on the attached patch, which makes sound driver resizing its DMA buffer according to the currently selected audio speed/format. This is necessary because most audio hardware supports wide range of speeds/formats, which makes it hard to define one buffer size that will satisfy all supported formats and providing minimal latency for the formats with low datarates, while good skip protection for formats with high datarates. For example 4096 bytes used now in most drivers doesn't protect data playing on 44kHz from skipping when there is some kernel activity going on (for example output on console or switching between consoles), while at the same time this size means 0.5s latency for games that use 8kHz/8 bit audio formats, which is a quite noticeable delay. Attached patch fixes some maximal buffer size, which is necessary for proper registering with the DMA subsystem, while scales this buffer down when format with lower datarate is selected. I'm running this patch for a month on my -current system with OPL3-SA hardware and so far it works like a charm - mpg123 no longer skips when I'm scrolling in the editor running on console, while audio delay in digger (22kHz, 8 bit, mono) is absolutely unnoticeable. This patch only improves mss driver, but it should be relatively easy to modify other drivers as well (I do not have a hardware to test changes on). Thank you in advance! -Maxim --192.168.1.100.0.526.1000539647.245.19907 Content-Type: application/octet-stream; name="pcm.diff" Content-Transfer-Encoding: base64 PyBpc2EvbXNzLmMsdgo/IHBjbS9idWZmZXIuYyx2Cj8gcGNtL3NvdW5kLmMsdgpJbmRleDogaXNh L21zcy5jCj09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09 PT09PT09PT09PT09PT09PT0KUkNTIGZpbGU6IC9ob21lL25jdnMvc3JjL3N5cy9kZXYvc291bmQv aXNhL21zcy5jLHYKcmV0cmlldmluZyByZXZpc2lvbiAxLjcxCmRpZmYgLWQgLXUgLXIxLjcxIG1z cy5jCi0tLSBpc2EvbXNzLmMJMjA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09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09 PT09PT09PT09PT09PT09PT09ClJDUyBmaWxlOiAvaG9tZS9uY3ZzL3NyYy9zeXMvZGV2L3NvdW5k L3BjbS9idWZmZXIuaCx2CnJldHJpZXZpbmcgcmV2aXNpb24gMS4zCmRpZmYgLWQgLXUgLXIxLjMg YnVmZmVyLmgKLS0tIHBjbS9idWZmZXIuaAkyMDAxLzA1LzI3IDE0OjM5OjM0CTEuMworKysgcGNt L2J1ZmZlci5oCTIwMDEvMDkvMTUgMDQ6MzA6MzkKQEAgLTkzLDQgKzkzLDQgQEAKIGludCBzbmRi dWZfaXNhZG1hcHRyKHN0cnVjdCBzbmRfZGJ1ZiAqYik7CiB2b2lkIHNuZGJ1Zl9pc2FkbWFib3Vu Y2Uoc3RydWN0IHNuZF9kYnVmICpiKTsKIAotCitpbnQgc25kYnVmX2RhdGFyYXRlKGludCwgdV9p bnQzMl90KTsK --192.168.1.100.0.526.1000539647.245.19907-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?E15iA4g-0007aK-00>