1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
|
/* SPDX-License-Identifier: Apache-2.0 */
/*
** Copyright 2008, The Android Open-Source Project
**
*/
#ifndef ANDROID_RESAMPLER_H
#define ANDROID_RESAMPLER_H
#include <stdint.h>
#include <sys/time.h>
__BEGIN_DECLS
#define RESAMPLER_QUALITY_MAX 10
#define RESAMPLER_QUALITY_MIN 0
#define RESAMPLER_QUALITY_DEFAULT 4
#define RESAMPLER_QUALITY_VOIP 3
#define RESAMPLER_QUALITY_DESKTOP 5
struct resampler_buffer {
union {
void* raw;
short* i16;
int8_t* i8;
};
size_t frame_count;
};
/* call back interface used by the resampler to get new data */
struct resampler_buffer_provider
{
/**
* get a new buffer of data:
* as input: buffer->frame_count is the number of frames requested
* as output: buffer->frame_count is the number of frames returned
* buffer->raw points to data returned
*/
int (*get_next_buffer)(struct resampler_buffer_provider *provider,
struct resampler_buffer *buffer);
/**
* release a consumed buffer of data:
* as input: buffer->frame_count is the number of frames released
* buffer->raw points to data released
*/
void (*release_buffer)(struct resampler_buffer_provider *provider,
struct resampler_buffer *buffer);
};
/* resampler interface */
struct resampler_itfe {
/**
* reset resampler state
*/
void (*reset)(struct resampler_itfe *resampler);
/**
* resample input from buffer provider and output at most *outFrameCount to out buffer.
* *outFrameCount is updated with the actual number of frames produced.
*/
int (*resample_from_provider)(struct resampler_itfe *resampler,
int16_t *out,
size_t *outFrameCount);
/**
* resample at most *inFrameCount frames from in buffer and output at most
* *outFrameCount to out buffer. *inFrameCount and *outFrameCount are updated respectively
* with the number of frames remaining in input and written to output.
*/
int (*resample_from_input)(struct resampler_itfe *resampler,
int16_t *in,
size_t *inFrameCount,
int16_t *out,
size_t *outFrameCount);
/**
* return the latency introduced by the resampler in ns.
*/
int32_t (*delay_ns)(struct resampler_itfe *resampler);
};
/**
* create a resampler according to input parameters passed.
* If resampler_buffer_provider is not NULL only resample_from_provider() can be called.
* If resampler_buffer_provider is NULL only resample_from_input() can be called.
*/
int create_resampler(uint32_t inSampleRate,
uint32_t outSampleRate,
uint32_t channelCount,
uint32_t quality,
struct resampler_buffer_provider *provider,
struct resampler_itfe **);
/**
* release resampler resources.
*/
void release_resampler(struct resampler_itfe *);
__END_DECLS
#endif // ANDROID_RESAMPLER_H
|