aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/audio.c2
-rw-r--r--src/audioOutputs/audioOutput_alsa.c2
-rw-r--r--src/audioOutputs/audioOutput_osx.c5
-rw-r--r--src/audio_format.h8
-rw-r--r--src/timer.c2
5 files changed, 12 insertions, 7 deletions
diff --git a/src/audio.c b/src/audio.c
index a4d4e3ea4..353f8b8d2 100644
--- a/src/audio.c
+++ b/src/audio.c
@@ -315,7 +315,7 @@ static int flushAudioBuffer(void)
static size_t audio_buffer_size(const struct audio_format *af)
{
- return (af->bits >> 3) * af->channels * (af->sample_rate >> 5);
+ return audio_format_frame_size(af) * (af->sample_rate >> 5);
}
static void audio_buffer_resize(size_t size)
diff --git a/src/audioOutputs/audioOutput_alsa.c b/src/audioOutputs/audioOutput_alsa.c
index 30ad449f3..9d47ff244 100644
--- a/src/audioOutputs/audioOutput_alsa.c
+++ b/src/audioOutputs/audioOutput_alsa.c
@@ -288,7 +288,7 @@ configure_hw:
if (err < 0)
goto error;
- ad->sampleSize = audio_format_sample_size(audioFormat) * audioFormat->channels;
+ ad->sampleSize = audio_format_frame_size(audioFormat);
DEBUG("ALSA device \"%s\" will be playing %i bit, %u channel audio at "
"%u Hz\n", ad->device, audioFormat->bits,
diff --git a/src/audioOutputs/audioOutput_osx.c b/src/audioOutputs/audioOutput_osx.c
index 1fc0a5d9e..65060cc8c 100644
--- a/src/audioOutputs/audioOutput_osx.c
+++ b/src/audioOutputs/audioOutput_osx.c
@@ -266,8 +266,7 @@ static int osx_openDevice(struct audio_output *audioOutput,
streamDesc.mFormatFlags |= kLinearPCMFormatFlagIsBigEndian;
#endif
- streamDesc.mBytesPerPacket =
- audioFormat->channels * audio_format_sample_size(audioFormat);
+ streamDesc.mBytesPerPacket = audio_format_frame_size(audioFormat);
streamDesc.mFramesPerPacket = 1;
streamDesc.mBytesPerFrame = streamDesc.mBytesPerPacket;
streamDesc.mChannelsPerFrame = audioFormat->channels;
@@ -284,7 +283,7 @@ static int osx_openDevice(struct audio_output *audioOutput,
/* create a buffer of 1s */
od->bufferSize = (audioFormat->sample_rate) *
- (audioFormat->bits >> 3) * (audioFormat->channels);
+ audio_format_frame_size(audioFormat);
od->buffer = xrealloc(od->buffer, od->bufferSize);
od->pos = 0;
diff --git a/src/audio_format.h b/src/audio_format.h
index 2475aa77e..bbebc51b1 100644
--- a/src/audio_format.h
+++ b/src/audio_format.h
@@ -61,9 +61,15 @@ static inline unsigned audio_format_sample_size(const struct audio_format *af)
return 4;
}
+static inline unsigned
+audio_format_frame_size(const struct audio_format *af)
+{
+ return audio_format_sample_size(af) * af->channels;
+}
+
static inline double audio_format_time_to_size(const struct audio_format *af)
{
- return af->sample_rate * af->channels * audio_format_sample_size(af);
+ return af->sample_rate * audio_format_frame_size(af);
}
static inline double audioFormatSizeToTime(const struct audio_format *af)
diff --git a/src/timer.c b/src/timer.c
index 84c03fbe6..46e1cdd86 100644
--- a/src/timer.c
+++ b/src/timer.c
@@ -40,7 +40,7 @@ Timer *timer_new(const struct audio_format *af)
timer = xmalloc(sizeof(Timer));
timer->time = 0;
timer->started = 0;
- timer->rate = af->sample_rate * (af->bits / CHAR_BIT) * af->channels;
+ timer->rate = af->sample_rate * audio_format_frame_size(af);
return timer;
}