* I misunderstood what means 24 bits B_AUDIO_INT (more than 2 years ago!): as audio data is left justified in a 32 bits container, we don't care much and convert as usual

32 bits data
* Echo audio driver doesn't support 24 bits in a 32 bits container as proposed by the media kit. We just manage 24 bits as 32 bits samples.
* The main benefit of this change is that the hda driver is now working with 24 bits samples (and 192khz).


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27362 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Jérôme Duval 2008-09-07 16:36:10 +00:00
parent c991159a1b
commit f0a85f978d
5 changed files with 10 additions and 146 deletions

View File

@ -204,6 +204,9 @@ echo_stream_set_audioparms(echo_stream *stream, uint8 channels,
PRINT((" status: %s \n", pStatusStrs[status])); PRINT((" status: %s \n", pStatusStrs[status]));
return B_ERROR; return B_ERROR;
} }
if (bitsPerSample == 24)
bitsPerSample = 32;
if ((stream->channels == channels) && if ((stream->channels == channels) &&
(stream->bitsPerSample == bitsPerSample) && (stream->bitsPerSample == bitsPerSample) &&

View File

@ -263,8 +263,7 @@ MixerCore::ApplyOutputFormat()
fResampler = new Resampler * [fMixBufferChannelCount]; fResampler = new Resampler * [fMixBufferChannelCount];
for (int i = 0; i < fMixBufferChannelCount; i++) for (int i = 0; i < fMixBufferChannelCount; i++)
fResampler[i] = new Resampler(media_raw_audio_format::B_AUDIO_FLOAT, fResampler[i] = new Resampler(media_raw_audio_format::B_AUDIO_FLOAT,
format.format, format.format);
format.valid_bits);
TRACE("MixerCore::OutputFormatChanged:\n"); TRACE("MixerCore::OutputFormatChanged:\n");
TRACE(" fMixBufferFrameRate %ld\n", fMixBufferFrameRate); TRACE(" fMixBufferFrameRate %ld\n", fMixBufferFrameRate);

View File

@ -67,7 +67,7 @@ MixerInput::MixerInput(MixerCore *core, const media_input &input, float mixFrame
// create resamplers // create resamplers
fResampler = new Resampler * [fInputChannelCount]; fResampler = new Resampler * [fInputChannelCount];
for (int i = 0; i < fInputChannelCount; i++) for (int i = 0; i < fInputChannelCount; i++)
fResampler[i] = new Resampler(fInput.format.u.raw_audio.format, media_raw_audio_format::B_AUDIO_FLOAT, 0); fResampler[i] = new Resampler(fInput.format.u.raw_audio.format, media_raw_audio_format::B_AUDIO_FLOAT);
// fMixerChannelInfo and fMixerChannelCount will be initialized by UpdateInputChannelDestinations() // fMixerChannelInfo and fMixerChannelCount will be initialized by UpdateInputChannelDestinations()
SetMixBufferFormat((int32)mixFrameRate, mixFrameCount); SetMixBufferFormat((int32)mixFrameRate, mixFrameCount);

View File

@ -13,7 +13,7 @@
#include "Resampler.h" #include "Resampler.h"
#include "MixerDebug.h" #include "MixerDebug.h"
Resampler::Resampler(uint32 src_format, uint32 dst_format, int16 dst_valid_bits) Resampler::Resampler(uint32 src_format, uint32 dst_format)
: fFunc(0) : fFunc(0)
{ {
if (dst_format == media_raw_audio_format::B_AUDIO_FLOAT) { if (dst_format == media_raw_audio_format::B_AUDIO_FLOAT) {
@ -43,11 +43,7 @@ Resampler::Resampler(uint32 src_format, uint32 dst_format, int16 dst_valid_bits)
switch (dst_format) { switch (dst_format) {
// float=>float already handled above // float=>float already handled above
case media_raw_audio_format::B_AUDIO_INT: case media_raw_audio_format::B_AUDIO_INT:
fFunc = &Resampler::float_to_int32_32; fFunc = &Resampler::float_to_int32;
if (dst_valid_bits == 24)
fFunc = &Resampler::float_to_int32_24;
else if (dst_valid_bits == 20)
fFunc = &Resampler::float_to_int32_20;
return; return;
case media_raw_audio_format::B_AUDIO_SHORT: case media_raw_audio_format::B_AUDIO_SHORT:
fFunc = &Resampler::float_to_int16; fFunc = &Resampler::float_to_int16;
@ -308,7 +304,7 @@ Resampler::uint8_to_float(const void *_src, int32 src_sample_offset, int32 src_s
} }
void void
Resampler::float_to_int32_32(const void *_src, int32 src_sample_offset, int32 src_sample_count, Resampler::float_to_int32(const void *_src, int32 src_sample_offset, int32 src_sample_count,
void *_dst, int32 dst_sample_offset, int32 dst_sample_count, float _gain) void *_dst, int32 dst_sample_offset, int32 dst_sample_count, float _gain)
{ {
register const char * src = (const char *) _src; register const char * src = (const char *) _src;
@ -372,136 +368,6 @@ Resampler::float_to_int32_32(const void *_src, int32 src_sample_offset, int32 sr
} }
void
Resampler::float_to_int32_24(const void *_src, int32 src_sample_offset, int32 src_sample_count,
void *_dst, int32 dst_sample_offset, int32 dst_sample_count, float _gain)
{
register const char * src = (const char *) _src;
register char * dst = (char *) _dst;
register int32 count = dst_sample_count;
register float gain = _gain * 8388607.0;
if (src_sample_count == dst_sample_count) {
// optimized case for no resampling
while (count--) {
register float sample = *(const float *)src * gain;
if (sample > 8388607.0f)
*(int32 *)dst = 8388607L;
else if (sample < -8388607.0f)
*(int32 *)dst = -8388607L;
else
*(int32 *)dst = (int32)sample;
src += src_sample_offset;
dst += dst_sample_offset;
}
return;
}
register float delta = float(src_sample_count) / float(dst_sample_count);
register float current = 0.0f;
if (delta < 1.0) {
// upsample
while (count--) {
register float sample = *(const float *)src * gain;
if (sample > 8388607.0f)
*(int32 *)dst = 8388607L;
else if (sample < -8388607.0f)
*(int32 *)dst = -8388607L;
else
*(int32 *)dst = (int32)sample;
dst += dst_sample_offset;
current += delta;
if (current >= 1.0f) {
current -= 1.0f;
src += src_sample_offset;
}
}
} else {
// downsample
while (count--) {
register float sample = *(const float *)src * gain;
if (sample > 8388607.0f)
*(int32 *)dst = 8388607L;
else if (sample < -8388607.0f)
*(int32 *)dst = -8388607L;
else
*(int32 *)dst = (int32)sample;
dst += dst_sample_offset;
current += delta;
register int32 skipcount = (int32)current;
current -= skipcount;
src += skipcount * src_sample_offset;
}
}
}
void
Resampler::float_to_int32_20(const void *_src, int32 src_sample_offset, int32 src_sample_count,
void *_dst, int32 dst_sample_offset, int32 dst_sample_count, float _gain)
{
register const char * src = (const char *) _src;
register char * dst = (char *) _dst;
register int32 count = dst_sample_count;
register float gain = _gain * 524287.0;
if (src_sample_count == dst_sample_count) {
// optimized case for no resampling
while (count--) {
register float sample = *(const float *)src * gain;
if (sample > 524287.0f)
*(int32 *)dst = 524287L;
else if (sample < -524287.0f)
*(int32 *)dst = -524287L;
else
*(int32 *)dst = (int32)sample;
src += src_sample_offset;
dst += dst_sample_offset;
}
return;
}
register float delta = float(src_sample_count) / float(dst_sample_count);
register float current = 0.0f;
if (delta < 1.0) {
// upsample
while (count--) {
register float sample = *(const float *)src * gain;
if (sample > 524287.0f)
*(int32 *)dst = 524287L;
else if (sample < -524287.0f)
*(int32 *)dst = -524287L;
else
*(int32 *)dst = (int32)sample;
dst += dst_sample_offset;
current += delta;
if (current >= 1.0f) {
current -= 1.0f;
src += src_sample_offset;
}
}
} else {
// downsample
while (count--) {
register float sample = *(const float *)src * gain;
if (sample > 524287.0f)
*(int32 *)dst = 524287L;
else if (sample < -524287.0f)
*(int32 *)dst = -524287L;
else
*(int32 *)dst = (int32)sample;
dst += dst_sample_offset;
current += delta;
register int32 skipcount = (int32)current;
current -= skipcount;
src += skipcount * src_sample_offset;
}
}
}
void void
Resampler::float_to_int16(const void *_src, int32 src_sample_offset, int32 src_sample_count, Resampler::float_to_int16(const void *_src, int32 src_sample_offset, int32 src_sample_count,
void *_dst, int32 dst_sample_offset, int32 dst_sample_count, float _gain) void *_dst, int32 dst_sample_offset, int32 dst_sample_count, float _gain)

View File

@ -14,7 +14,7 @@
class Resampler class Resampler
{ {
public: public:
Resampler(uint32 sourceformat, uint32 destformat, int16 dst_valid_bits); Resampler(uint32 sourceformat, uint32 destformat);
virtual ~Resampler(); virtual ~Resampler();
status_t InitCheck(); status_t InitCheck();
@ -33,11 +33,7 @@ protected:
void *dst, int32 dst_sample_offset, int32 dst_sample_count, float gain); void *dst, int32 dst_sample_offset, int32 dst_sample_count, float gain);
virtual void uint8_to_float (const void *src, int32 src_sample_offset, int32 src_sample_count, virtual void uint8_to_float (const void *src, int32 src_sample_offset, int32 src_sample_count,
void *dst, int32 dst_sample_offset, int32 dst_sample_count, float gain); void *dst, int32 dst_sample_offset, int32 dst_sample_count, float gain);
virtual void float_to_int32_32 (const void *src, int32 src_sample_offset, int32 src_sample_count, virtual void float_to_int32 (const void *src, int32 src_sample_offset, int32 src_sample_count,
void *dst, int32 dst_sample_offset, int32 dst_sample_count, float gain);
virtual void float_to_int32_24 (const void *src, int32 src_sample_offset, int32 src_sample_count,
void *dst, int32 dst_sample_offset, int32 dst_sample_count, float gain);
virtual void float_to_int32_20 (const void *src, int32 src_sample_offset, int32 src_sample_count,
void *dst, int32 dst_sample_offset, int32 dst_sample_count, float gain); void *dst, int32 dst_sample_offset, int32 dst_sample_count, float gain);
virtual void float_to_int16 (const void *src, int32 src_sample_offset, int32 src_sample_count, virtual void float_to_int16 (const void *src, int32 src_sample_offset, int32 src_sample_count,
void *dst, int32 dst_sample_offset, int32 dst_sample_count, float gain); void *dst, int32 dst_sample_offset, int32 dst_sample_count, float gain);