Commit ce63254c authored by Stefan Westerfeld's avatar Stefan Westerfeld

Fix floating point wav input format.

Signed-off-by: Stefan Westerfeld's avatarStefan Westerfeld <stefan@space.twc.de>
parent 597fc3fc
...@@ -67,13 +67,18 @@ SFInputStream::open (const string& filename) ...@@ -67,13 +67,18 @@ SFInputStream::open (const string& filename)
m_bit_depth = 24; m_bit_depth = 24;
break; break;
case SF_FORMAT_FLOAT:
case SF_FORMAT_PCM_32: case SF_FORMAT_PCM_32:
m_bit_depth = 32; m_bit_depth = 32;
break; break;
case SF_FORMAT_FLOAT:
m_bit_depth = 32;
m_read_float_data = true;
break;
case SF_FORMAT_DOUBLE: case SF_FORMAT_DOUBLE:
m_bit_depth = 64; m_bit_depth = 64;
m_read_float_data = true;
break; break;
default: default:
...@@ -101,7 +106,21 @@ SFInputStream::read_frames (vector<float>& samples, size_t count) ...@@ -101,7 +106,21 @@ SFInputStream::read_frames (vector<float>& samples, size_t count)
{ {
assert (m_state == State::OPEN); assert (m_state == State::OPEN);
if (m_read_float_data) /* float or double input */
{
samples.resize (count * m_n_channels);
sf_count_t r_count = sf_readf_float (m_sndfile, &samples[0], count);
if (sf_error (m_sndfile))
return Error (sf_strerror (m_sndfile));
samples.resize (r_count * m_n_channels);
}
else /* integer input */
{
vector<int> isamples (count * m_n_channels); vector<int> isamples (count * m_n_channels);
sf_count_t r_count = sf_readf_int (m_sndfile, &isamples[0], count); sf_count_t r_count = sf_readf_int (m_sndfile, &isamples[0], count);
if (sf_error (m_sndfile)) if (sf_error (m_sndfile))
...@@ -119,6 +138,7 @@ SFInputStream::read_frames (vector<float>& samples, size_t count) ...@@ -119,6 +138,7 @@ SFInputStream::read_frames (vector<float>& samples, size_t count)
const double norm = 1.0 / 0x80000000LL; const double norm = 1.0 / 0x80000000LL;
for (size_t i = 0; i < samples.size(); i++) for (size_t i = 0; i < samples.size(); i++)
samples[i] = isamples[i] * norm; samples[i] = isamples[i] * norm;
}
return Error::Code::NONE; return Error::Code::NONE;
} }
......
...@@ -31,6 +31,7 @@ class SFInputStream : public AudioInputStream ...@@ -31,6 +31,7 @@ class SFInputStream : public AudioInputStream
int m_n_values = 0; int m_n_values = 0;
int m_bit_depth = 0; int m_bit_depth = 0;
int m_sample_rate = 0; int m_sample_rate = 0;
bool m_read_float_data = false;
enum class State { enum class State {
NEW, NEW,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment