aboutsummaryrefslogtreecommitdiffstats
path: root/src/audio_format.h
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2008-09-23 23:59:54 +0200
committerMax Kellermann <max@duempel.org>2008-09-23 23:59:54 +0200
commit128d8c7c15c0713cfccc42dfeea9b0cd9ed11d14 (patch)
tree92bb882c28b4f2621e3cccfbf1e1aa740f76a55c /src/audio_format.h
parente4f5d6bdf47c96dc9c0b5fe287598bc10b168a71 (diff)
downloadmpd-128d8c7c15c0713cfccc42dfeea9b0cd9ed11d14.tar.gz
mpd-128d8c7c15c0713cfccc42dfeea9b0cd9ed11d14.tar.xz
mpd-128d8c7c15c0713cfccc42dfeea9b0cd9ed11d14.zip
audio_format: added audio_format_sample_size()
The inline function audio_format_sample_size() calculates how many bytes each sample consumes. This function already takes into account that 24 bit samples are 4 bytes long, not 3.
Diffstat (limited to '')
-rw-r--r--src/audio_format.h17
1 files changed, 15 insertions, 2 deletions
diff --git a/src/audio_format.h b/src/audio_format.h
index d2461a338..e45d79cd5 100644
--- a/src/audio_format.h
+++ b/src/audio_format.h
@@ -47,14 +47,27 @@ static inline int audio_format_equals(const struct audio_format *a,
a->channels == b->channels;
}
+/**
+ * Returns the size of each (mono) sample in bytes.
+ */
+static inline unsigned audio_format_sample_size(const struct audio_format *af)
+{
+ if (af->bits <= 8)
+ return 1;
+ else if (af->bits <= 16)
+ return 2;
+ else
+ return 4;
+}
+
static inline double audio_format_time_to_size(const struct audio_format *af)
{
- return af->sampleRate * af->bits * af->channels / 8.0;
+ return af->sampleRate * af->channels * audio_format_sample_size(af);
}
static inline double audioFormatSizeToTime(const struct audio_format *af)
{
- return 8.0 / af->bits / af->channels / af->sampleRate;
+ return 1.0 / audio_format_time_to_size(af);
}
#endif