00001 #ifndef RESAMPLER_H 00002 #define RESAMPLER_H 00003 00004 00005 #include "audiere.h" 00006 #include "debug.h" 00007 #include "dumb_resample.h" 00008 #include "types.h" 00009 #include "utility.h" 00010 00011 00012 namespace audiere { 00013 00014 class Resampler : public RefImplementation<SampleSource> { 00015 public: 00016 Resampler(SampleSource* source, int rate); 00017 00018 // for now, resamplers always return (2, rate, 16-bit) 00019 void ADR_CALL getFormat( 00020 int& channel_count, 00021 int& sample_rate, 00022 SampleFormat& sample_format); 00023 00024 int ADR_CALL read(int frame_count, void* buffer); 00025 void ADR_CALL reset(); 00026 00027 bool ADR_CALL isSeekable(); 00028 int ADR_CALL getLength(); 00029 void ADR_CALL setPosition(int position); 00030 int ADR_CALL getPosition(); 00031 00032 bool ADR_CALL getRepeat(); 00033 void ADR_CALL setRepeat(bool repeat); 00034 00035 int ADR_CALL getTagCount(); 00036 const char* ADR_CALL getTagKey(int i); 00037 const char* ADR_CALL getTagValue(int i); 00038 const char* ADR_CALL getTagType(int i); 00039 00040 void setPitchShift(float shift); 00041 float getPitchShift(); 00042 00043 private: 00044 void fillBuffers(); 00045 void resetState(); 00046 00047 private: 00048 RefPtr<SampleSource> m_source; 00049 int m_rate; 00050 int m_native_channel_count; 00051 int m_native_sample_rate; 00052 SampleFormat m_native_sample_format; 00053 00054 enum { BUFFER_SIZE = 4096 }; 00055 sample_t m_native_buffer_l[BUFFER_SIZE]; 00056 sample_t m_native_buffer_r[BUFFER_SIZE]; 00057 DUMB_RESAMPLER m_resampler_l; 00058 DUMB_RESAMPLER m_resampler_r; 00059 int m_buffer_length; // number of samples read into each buffer 00060 00061 float m_shift; 00062 }; 00063 00064 } 00065 00066 #endif