1 /*************************************************************************** 2 \file audioencoder.cpp 3 4 copyright : (C) 2002-6 by mean/gruntster/Mihail 5 email : fixounet@free.fr 6 ***************************************************************************/ 7 8 /*************************************************************************** 9 * * 10 * This program is free software; you can redistribute it and/or modify * 11 * it under the terms of the GNU General Public License as published by * 12 * the Free Software Foundation; either version 2 of the License, or * 13 * (at your option) any later version. * 14 * * 15 ***************************************************************************/ 16 17 #ifndef AUDIO_ENCODER_H 18 #define AUDIO_ENCODER_H 19 20 #include "ADM_coreAudioEncoder6_export.h" 21 #include "ADM_coreAudio.h" 22 #include "ADM_audioCodecEnum.h" 23 #include "ADM_audioFilter.h" 24 #include "ADM_confCouple.h" 25 #include "ADM_byteBuffer.h" 26 #define AUDIOENC_COPY 0 27 28 29 typedef int AUDIOENCODER; 30 typedef enum 31 { 32 AudioEncoderRunning, 33 AudioEncoderNoInput, 34 AudioEncoderStopped 35 }AudioEncoderState; 36 /** 37 \class AUDMEncoder 38 \brief audio encoder base class. Combined with the audioaccess class it makes the exact opposite 39 of the bridge class, i.e. convert audioFilter to ADM_access then ADM_stream. 40 41 */ 42 #define ADM_AUDIO_ENCODER_BUFFER_SIZE (6*32*1024) 43 class ADM_COREAUDIOENCODER6_EXPORT ADM_AudioEncoder 44 { 45 protected: 46 47 AudioEncoderState _state; // True if cannot encode anymore 48 // 49 uint8_t *_extraData; 50 uint32_t _extraSize; 51 AUDMAudioFilter *_incoming; 52 53 54 ADM_floatBuffer tmpbuffer; // incoming samples are stored here before encoding 55 uint32_t tmphead,tmptail; 56 57 bool refillBuffer(int minimum); // Mininum is in float 58 59 bool reorder(float *sample_in,float *sample_out,int samplePerChannel,CHANNEL_TYPE *mapIn,CHANNEL_TYPE *mapOut); 60 bool reorderToPlanar(float *sample_in,float *sample_out,int samplePerChannel,CHANNEL_TYPE *mapIn,CHANNEL_TYPE *mapOut); 61 bool reorderToPlanar2(float *sample_in,float **sample_out,int samplePerChannel,CHANNEL_TYPE *mapIn,CHANNEL_TYPE *mapOut); 62 // The encoder can remap the audio channel (or not). If so, let's store the the configuration here 63 CHANNEL_TYPE outputChannelMapping[MAX_CHANNELS]; 64 WAVHeader wavheader; /// To be filled by the encoder, especially byterate and codec Id. 65 public: 66 // 67 ADM_AudioEncoder(AUDMAudioFilter *in, CONFcouple *setup); 68 virtual ~ADM_AudioEncoder(); 69 extraData(uint32_t * l,uint8_t ** d)70 virtual uint8_t extraData(uint32_t *l,uint8_t **d) {*l=_extraSize;*d=_extraData;return 1;} getInfo(void)71 WAVHeader *getInfo(void) {return &wavheader;} isVBR(void)72 virtual bool isVBR(void) {return true;} 73 virtual bool initialize(void)=0; /// Returns true if init ok, false if encoding is impossible 74 virtual bool encode(uint8_t *dest, uint32_t *len, uint32_t *samples)=0; /// returns false if eof met provideAccurateSample(void)75 virtual bool provideAccurateSample(void) {return true;} /// Some encoder does not provide samples, in that case 76 /// Return false, but the matching parser must exist! 77 const std::string &getLanguage(void); 78 }; 79 #endif 80