* mixer media addon builds on beos, fixed includes missing
* added 24 bits B_AUDIO_INT support (20 bits still missing) Marcus please review and fix if needed git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16253 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
SubDir HAIKU_TOP src add-ons media media-add-ons mixer ;
|
||||
|
||||
SetSubDirSupportedPlatformsBeOSCompatible ;
|
||||
|
||||
UsePrivateHeaders media ;
|
||||
|
||||
Addon mixer.media_addon : media :
|
||||
|
||||
@@ -257,7 +257,7 @@ MixerCore::ApplyOutputFormat()
|
||||
// create new resamplers
|
||||
fResampler = new Resampler * [fMixBufferChannelCount];
|
||||
for (int i = 0; i < fMixBufferChannelCount; i++)
|
||||
fResampler[i] = new Resampler(media_raw_audio_format::B_AUDIO_FLOAT, format.format);
|
||||
fResampler[i] = new Resampler(media_raw_audio_format::B_AUDIO_FLOAT, format.format, format.valid_bits);
|
||||
|
||||
TRACE("MixerCore::OutputFormatChanged:\n");
|
||||
TRACE(" fMixBufferFrameRate %ld\n", fMixBufferFrameRate);
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
#ifndef _MIXER_CORE_H
|
||||
#define _MIXER_CORE_H
|
||||
|
||||
#include <Buffer.h>
|
||||
#include <Locker.h>
|
||||
#include <TimeSource.h>
|
||||
#include "MixerSettings.h"
|
||||
|
||||
class AudioMixer;
|
||||
|
||||
@@ -60,7 +60,7 @@ MixerInput::MixerInput(MixerCore *core, const media_input &input, float mixFrame
|
||||
// create resamplers
|
||||
fResampler = new Resampler * [fInputChannelCount];
|
||||
for (int i = 0; i < fInputChannelCount; i++)
|
||||
fResampler[i] = new Resampler(fInput.format.u.raw_audio.format, media_raw_audio_format::B_AUDIO_FLOAT);
|
||||
fResampler[i] = new Resampler(fInput.format.u.raw_audio.format, media_raw_audio_format::B_AUDIO_FLOAT, 0);
|
||||
|
||||
// fMixerChannelInfo and fMixerChannelCount will be initialized by UpdateInputChannelDestinations()
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define _MIXER_SETTINGS_H
|
||||
|
||||
#include <Message.h>
|
||||
#include <Path.h>
|
||||
|
||||
class MixerInput;
|
||||
class MixerOutput;
|
||||
|
||||
@@ -7,8 +7,10 @@
|
||||
#define PRINT_CHANNEL_MASK(fmt) ((void)0)
|
||||
#endif
|
||||
|
||||
#ifndef __SGI_STL_INTERNAL_ALGOBASE_H
|
||||
template<class t> const t & max(const t &t1, const t &t2) { return (t1 > t2) ? t1 : t2; }
|
||||
template<class t> const t & min(const t &t1, const t &t2) { return (t1 < t2) ? t1 : t2; }
|
||||
#endif
|
||||
template<class t> const t abs(const t t1) { return (t1 < 0) ? - t1 : t1; }
|
||||
|
||||
void fix_multiaudio_format(media_multi_audio_format *format);
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
#include "Resampler.h"
|
||||
#include "debug.h"
|
||||
|
||||
Resampler::Resampler(uint32 src_format, uint32 dst_format)
|
||||
Resampler::Resampler(uint32 src_format, uint32 dst_format, int16 dst_valid_bits)
|
||||
: fFunc(0)
|
||||
{
|
||||
if (dst_format == media_raw_audio_format::B_AUDIO_FLOAT) {
|
||||
@@ -43,7 +43,11 @@ Resampler::Resampler(uint32 src_format, uint32 dst_format)
|
||||
switch (dst_format) {
|
||||
// float=>float already handled above
|
||||
case media_raw_audio_format::B_AUDIO_INT:
|
||||
fFunc = &Resampler::float_to_int32;
|
||||
fFunc = &Resampler::float_to_int32_32;
|
||||
if (dst_valid_bits == 24)
|
||||
fFunc = &Resampler::float_to_int32_24;
|
||||
//if (dst_valid_bits == 20)
|
||||
// fFunc = &Resampler::float_to_int32_20;
|
||||
return;
|
||||
case media_raw_audio_format::B_AUDIO_SHORT:
|
||||
fFunc = &Resampler::float_to_int16;
|
||||
@@ -304,7 +308,7 @@ Resampler::uint8_to_float(const void *_src, int32 src_sample_offset, int32 src_s
|
||||
}
|
||||
|
||||
void
|
||||
Resampler::float_to_int32(const void *_src, int32 src_sample_offset, int32 src_sample_count,
|
||||
Resampler::float_to_int32_32(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;
|
||||
@@ -367,6 +371,72 @@ Resampler::float_to_int32(const void *_src, int32 src_sample_offset, int32 src_s
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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 < -2147483647.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_int16(const void *_src, int32 src_sample_offset, int32 src_sample_count,
|
||||
void *_dst, int32 dst_sample_offset, int32 dst_sample_count, float _gain)
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
class Resampler
|
||||
{
|
||||
public:
|
||||
Resampler(uint32 sourceformat, uint32 destformat);
|
||||
Resampler(uint32 sourceformat, uint32 destformat, int16 dst_valid_bits);
|
||||
virtual ~Resampler();
|
||||
|
||||
status_t InitCheck();
|
||||
@@ -33,7 +33,9 @@ protected:
|
||||
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,
|
||||
void *dst, int32 dst_sample_offset, int32 dst_sample_count, float gain);
|
||||
virtual void float_to_int32 (const void *src, int32 src_sample_offset, int32 src_sample_count,
|
||||
virtual void float_to_int32_32 (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_int16 (const void *src, int32 src_sample_offset, int32 src_sample_count,
|
||||
void *dst, int32 dst_sample_offset, int32 dst_sample_count, float gain);
|
||||
|
||||
Reference in New Issue
Block a user