3 * Copyright (C) 2011-2012 Team XBMC
6 * This Program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2, or (at your option)
11 * This Program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with XBMC; see the file COPYING. If not, see
18 * <http://www.gnu.org/licenses/>.
22 #include <samplerate.h>
25 #include "CoreAudioRingBuffer.h"
26 #include "ICoreAudioSource.h"
27 #include "cores/AudioEngine/AEAudioFormat.h"
28 #include "cores/AudioEngine/Interfaces/AEStream.h"
29 #include "cores/AudioEngine/Utils/AEConvert.h"
30 #include "cores/AudioEngine/Utils/AERemap.h"
32 #if defined(TARGET_DARWIN_IOS)
33 # include "CoreAudioAEHALIOS.h"
35 # include "CoreAudioAEHALOSX.h"
38 class CoreAudioRingBuffer;
40 class CCoreAudioAEStream : public IAEStream, public ICoreAudioSource
43 friend class CCoreAudioAE;
44 CCoreAudioAEStream(enum AEDataFormat format, unsigned int sampleRate, unsigned int encodedSamplerate, CAEChannelInfo channelLayout, unsigned int options);
45 virtual ~CCoreAudioAEStream();
47 CAUOutputDevice *m_outputUnit;
50 void ReinitConverter();
51 void CloseConverter();
55 void InitializeRemap();
56 virtual void Destroy();
58 virtual const unsigned int GetFrameSize() const;
59 virtual unsigned int GetSpace();
60 virtual unsigned int AddData(void *data, unsigned int size);
61 unsigned int GetFrames(uint8_t *buffer, unsigned int size);
62 virtual double GetDelay();
63 virtual bool IsBuffering();
64 virtual double GetCacheTime();
65 virtual double GetCacheTotal();
68 virtual bool IsDraining();
69 virtual bool IsDrained();
74 virtual void Resume();
78 virtual float GetVolume();
79 virtual float GetReplayGain();
80 virtual void SetVolume(float volume);
81 virtual void SetReplayGain(float factor);
83 virtual const unsigned int GetChannelCount() const;
84 virtual const unsigned int GetSampleRate() const;
85 virtual const unsigned int GetEncodedSampleRate() const;
86 virtual const enum AEDataFormat GetDataFormat() const;
87 virtual const bool IsRaw() const;
89 /* for dynamic sample rate changes (smoothvideo) */
90 virtual double GetResampleRatio();
91 virtual bool SetResampleRatio(double ratio);
93 virtual void RegisterAudioCallback(IAudioCallback* pCallback);
94 virtual void UnRegisterAudioCallback();
96 virtual void FadeVolume(float from, float to, unsigned int time);
97 virtual bool IsFading();
98 virtual void RegisterSlave(IAEStream *stream);
100 OSStatus Render(AudioUnitRenderActionFlags* actionFlags,
101 const AudioTimeStamp* pTimeStamp,
104 AudioBufferList* pBufList);
107 void InternalFlush();
109 OSStatus OnRender(AudioUnitRenderActionFlags *ioActionFlags,
110 const AudioTimeStamp *inTimeStamp,
112 UInt32 inNumberFrames,
113 AudioBufferList *ioData);
115 AEDataFormat m_rawDataFormat;
117 AEAudioFormat m_OutputFormat;
118 unsigned int m_chLayoutCountOutput;
119 AEAudioFormat m_StreamFormat;
120 unsigned int m_chLayoutCountStream;
121 unsigned int m_StreamBytesPerSample;
122 unsigned int m_OutputBytesPerSample;
124 //bool m_forceResample; /* true if we are to force resample even when the rates match */
125 //bool m_resample; /* true if the audio needs to be resampled */
126 bool m_convert; /* true if the bitspersample needs converting */
127 bool m_valid; /* true if the stream is valid */
128 bool m_delete; /* true if CCoreAudioAE is to free this object */
129 CAERemap m_remap; /* the remapper */
130 float m_volume; /* the volume level */
131 float m_rgain; /* replay gain level */
132 IAEStream *m_slave; /* slave aestream */
134 CAEConvert::AEConvertToFn m_convertFn;
136 CoreAudioRingBuffer *m_Buffer;
137 float *m_convertBuffer; /* buffer for converted data */
138 int m_convertBufferSize;
139 //float *m_resampleBuffer; /* buffer for resample data */
140 //int m_resampleBufferSize;
141 uint8_t *m_upmixBuffer; /* buffer for remap data */
142 int m_upmixBufferSize;
143 uint8_t *m_remapBuffer; /* buffer for remap data */
144 int m_remapBufferSize;
145 uint8_t *m_vizRemapBuffer; /* buffer for remap data */
146 int m_vizRemapBufferSize;
152 unsigned int m_AvgBytesPerSec;
154 /* vizualization internals */
156 IAudioCallback *m_audioCallback;
163 unsigned int m_fadeTime;
165 unsigned int m_frameSize;
167 void Upmix(void *input, unsigned int channelsInput, void *output, unsigned int channelsOutput, unsigned int frames, AEDataFormat dataFormat);