aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2018-02-21 11:50:28 +0100
committerMatthias P. Braendli <matthias.braendli@mpb.li>2018-02-21 11:50:28 +0100
commit3a5da13910ec0eccf439d8b3a9f6728d127dc1b8 (patch)
tree3442b428d7eb8bb21f057eb08b945a91950d25f4
parent60140af509d33cd2179c56388b16746e9d67071a (diff)
downloadODR-AudioEnc-3a5da13910ec0eccf439d8b3a9f6728d127dc1b8.tar.gz
ODR-AudioEnc-3a5da13910ec0eccf439d8b3a9f6728d127dc1b8.tar.bz2
ODR-AudioEnc-3a5da13910ec0eccf439d8b3a9f6728d127dc1b8.zip
Correct wav header write
-rw-r--r--src/AACDecoder.cpp4
-rw-r--r--src/wavfile.cpp8
-rw-r--r--src/wavfile.h4
3 files changed, 8 insertions, 8 deletions
diff --git a/src/AACDecoder.cpp b/src/AACDecoder.cpp
index 238a801..861bdaf 100644
--- a/src/AACDecoder.cpp
+++ b/src/AACDecoder.cpp
@@ -104,13 +104,13 @@ void AACDecoder::decode_frame(uint8_t *data, size_t len)
std::to_string(init_result));
}
- m_channels = aac_channel_mode || ps_flag ? 2 : 1;
+ m_channels = (aac_channel_mode or ps_flag) ? 2 : 1;
size_t output_frame_len = 960 * 2 * m_channels * (sbr_flag ? 2 : 1);
m_output_frame.resize(output_frame_len);
fprintf(stderr, " Setting decoder output frame len %zu\n", output_frame_len);
const int sample_rate = dac_rate ? 48000 : 32000;
- m_wav_writer.initialise_header(sample_rate);
+ m_wav_writer.initialise_header(sample_rate, m_channels);
m_decoder_set_up = true;
fprintf(stderr, " Set up decoder with %d Hz, %s%swith %d channels\n",
diff --git a/src/wavfile.cpp b/src/wavfile.cpp
index 7de4ffc..4bd4bd6 100644
--- a/src/wavfile.cpp
+++ b/src/wavfile.cpp
@@ -219,7 +219,7 @@ WavWriter::WavWriter(const char *filename)
}
}
-void WavWriter::initialise_header(int rate)
+void WavWriter::initialise_header(int rate, int channels)
{
struct wavfile_header header;
@@ -234,10 +234,10 @@ void WavWriter::initialise_header(int rate)
header.riff_length = 0;
header.fmt_length = 16;
header.audio_format = 1;
- header.num_channels = 2;
+ header.num_channels = channels;
header.sample_rate = samples_per_second;
- header.byte_rate = samples_per_second*(bits_per_sample/8);
- header.block_align = bits_per_sample/8;
+ header.byte_rate = samples_per_second*(bits_per_sample/8)*channels;
+ header.block_align = channels*bits_per_sample/8;
header.bits_per_sample = bits_per_sample;
header.data_length = 0;
diff --git a/src/wavfile.h b/src/wavfile.h
index a8cd4d9..6d68053 100644
--- a/src/wavfile.h
+++ b/src/wavfile.h
@@ -1,6 +1,6 @@
/* ------------------------------------------------------------------
* Copyright (C) 2009 Martin Storsjo
- * Copyright (C) 2017 Matthias P. Braendli
+ * Copyright (C) 2018 Matthias P. Braendli
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -35,7 +35,7 @@ class WavWriter {
WavWriter(const WavWriter& other) = delete;
WavWriter& operator=(const WavWriter& other) = delete;
- void initialise_header(int rate);
+ void initialise_header(int rate, int channels);
void write_data(const uint8_t *data, int length);