]> code.delx.au - pulseaudio/commitdiff
add new function pa_usec_to_bytes() as inverse of pa_bytes_to_usec()
authorLennart Poettering <lennart@poettering.net>
Sun, 21 May 2006 14:06:33 +0000 (14:06 +0000)
committerLennart Poettering <lennart@poettering.net>
Sun, 21 May 2006 14:06:33 +0000 (14:06 +0000)
git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@942 fefdeb5f-60dc-0310-8127-8f9354f1896f

src/polyp/sample.c
src/polyp/sample.h

index 668a485edf5243a68ccad212ff7d9e5f1b6a6355..320e31a054425e34fee697ddc8c7d00fc74eebba 100644 (file)
@@ -66,6 +66,12 @@ pa_usec_t pa_bytes_to_usec(uint64_t length, const pa_sample_spec *spec) {
     return (pa_usec_t) (((double) length/pa_frame_size(spec)*1000000)/spec->rate);
 }
 
+size_t pa_usec_to_bytes(pa_usec_t t, const pa_sample_spec *spec) {
+    assert(spec);
+
+    return ((double) t * spec->rate / 1000000)*pa_frame_size(spec); 
+}
+
 int pa_sample_spec_valid(const pa_sample_spec *spec) {
     assert(spec);
 
index 09b12fd7944a123d19e0a9b75ca3194eaaeb8a7d..2a9a72fefc0ed1eb60e624513b7fcf85b9aa7899 100644 (file)
@@ -160,6 +160,9 @@ size_t pa_sample_size(const pa_sample_spec *spec);
 /** Calculate the time the specified bytes take to play with the specified sample type */
 pa_usec_t pa_bytes_to_usec(uint64_t length, const pa_sample_spec *spec);
 
+/** Calculates the number of bytes that are required for the specified time. \since 0.9 */
+size_t pa_usec_to_bytes(pa_usec_t t, const pa_sample_spec *spec);
+
 /** Return non-zero when the sample type specification is valid */
 int pa_sample_spec_valid(const pa_sample_spec *spec);