added a resampling class

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@3415 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
beveloper 2003-06-03 22:51:00 +00:00
parent b63f90a895
commit 575526ff34
3 changed files with 188 additions and 0 deletions

View File

@ -6,6 +6,7 @@ Addon mixer.media_addon : media :
AudioMixer.cpp
MixerAddOn.cpp
FillMixBuffer.cpp
Resampler.cpp
;
LinkSharedOSLibs mixer.media_addon : be media ;

View File

@ -0,0 +1,128 @@
/* Copyright (C) 2003 Marcus Overhagen
* Released under terms of the MIT license.
*
* A simple resampling class for the audio mixer.
* You pick the conversation function on object creation,
* and then call the Resample() function, specifying data pointer,
* offset (in bytes) to the next sample, and count of samples for
* both source and destination.
*
*/
#include "Resampler.h"
#include "debug.h"
Resampler::Resampler(uint32 src_format, uint32 dst_format)
: fFunc(0)
{
if (dst_format == media_raw_audio_format::B_AUDIO_FLOAT) {
switch (src_format) {
case media_raw_audio_format::B_AUDIO_FLOAT:
fFunc = &Resampler::float_to_float;
return;
case media_raw_audio_format::B_AUDIO_INT:
fFunc = &Resampler::int32_to_float;
return;
case media_raw_audio_format::B_AUDIO_SHORT:
fFunc = &Resampler::int16_to_float;
return;
case media_raw_audio_format::B_AUDIO_CHAR:
fFunc = &Resampler::int8_to_float;
return;
case media_raw_audio_format::B_AUDIO_UCHAR:
fFunc = &Resampler::uint8_to_float;
return;
default:
FATAL("Resampler::Resampler: unknown source format 0x%x\n", src_format);
return;
}
}
if (src_format == media_raw_audio_format::B_AUDIO_FLOAT) {
switch (dst_format) {
// float=>float already handled above
case media_raw_audio_format::B_AUDIO_INT:
fFunc = &Resampler::float_to_int32;
return;
case media_raw_audio_format::B_AUDIO_SHORT:
fFunc = &Resampler::float_to_int16;
return;
case media_raw_audio_format::B_AUDIO_CHAR:
fFunc = &Resampler::float_to_int8;
return;
case media_raw_audio_format::B_AUDIO_UCHAR:
fFunc = &Resampler::float_to_uint8;
return;
default:
FATAL("Resampler::Resampler: unknown destination format 0x%x\n", dst_format);
return;
}
}
FATAL("Resampler::Resampler: source or destination format must be B_AUDIO_FLOAT\n");
}
Resampler::~Resampler()
{
}
status_t
Resampler::InitCheck()
{
return (fFunc != 0) ? B_OK : B_ERROR;
}
void
Resampler::float_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
Resampler::int32_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
Resampler::int16_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
Resampler::int8_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
Resampler::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
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
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
Resampler::float_to_int8(const void *src, int32 src_sample_offset, int32 src_sample_count,
void *dst, int32 dst_sample_offset, int32 dst_sample_count, float gain)
{
}
void
Resampler::float_to_uint8(const void *src, int32 src_sample_offset, int32 src_sample_count,
void *dst, int32 dst_sample_offset, int32 dst_sample_count, float gain)
{
}

View File

@ -0,0 +1,59 @@
#ifndef _RESAMPLER_H
#define _RESAMPLER_H
/* Copyright (C) 2003 Marcus Overhagen
* Released under terms of the MIT license.
*
* A simple resampling class for the audio mixer.
* You pick the conversation function on object creation,
* and then call the Resample() function, specifying data pointer,
* offset (in bytes) to the next sample, and count of samples for
* both source and destination.
*
*/
#include <MediaDefs.h>
class Resampler
{
public:
Resampler(uint32 sourceformat, uint32 destformat);
virtual ~Resampler();
status_t InitCheck();
void Resample(const void *src, int32 src_sample_offset, int32 src_sample_count,
void *dst, int32 dst_sample_offset, int32 dst_sample_count, float gain);
protected:
virtual void float_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 int32_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 int16_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 int8_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 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,
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);
virtual void float_to_int8 (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_uint8 (const void *src, int32 src_sample_offset, int32 src_sample_count,
void *dst, int32 dst_sample_offset, int32 dst_sample_count, float gain);
private:
void (Resampler::*fFunc) (const void *, int32, int32, void *, int32, int32, float);
};
inline void
Resampler::Resample(const void *src, int32 src_sample_offset, int32 src_sample_count,
void *dst, int32 dst_sample_offset, int32 dst_sample_count, float gain)
{
(this->*fFunc)(src, src_sample_offset, src_sample_count, dst, dst_sample_offset, dst_sample_count, gain);
}
#endif