2 * Copyright (C) 2010-2013 Team XBMC
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with XBMC; see the file COPYING. If not, see
17 * <http://www.gnu.org/licenses/>.
21 #include "Interfaces/AESound.h"
23 #include "AEFactory.h"
24 #include "Utils/AEAudioFormat.h"
26 #include "ActiveAESound.h"
27 #include "utils/log.h"
28 #include "DllAvUtil.h"
30 using namespace ActiveAE;
31 using namespace XFILE;
33 /* typecast AE to CActiveAE */
34 #define AE (*((CActiveAE*)CAEFactory::GetEngine()))
36 CActiveAESound::CActiveAESound(const std::string &filename) :
38 m_filename (filename),
46 CActiveAESound::~CActiveAESound()
53 void CActiveAESound::Play()
58 void CActiveAESound::Stop()
63 bool CActiveAESound::IsPlaying()
69 uint8_t** CActiveAESound::InitSound(bool orig, SampleConfig config, int nb_samples)
78 *info = new CSoundPacket(config, nb_samples);
80 (*info)->nb_samples = 0;
81 m_isConverted = false;
85 bool CActiveAESound::StoreSound(bool orig, uint8_t **buffer, int samples, int linesize)
93 if ((*info)->nb_samples + samples > (*info)->max_nb_samples)
95 CLog::Log(LOGERROR, "CActiveAESound::StoreSound - exceeded max samples");
99 int bytes_to_copy = samples * (*info)->bytes_per_sample * (*info)->config.channels;
100 bytes_to_copy /= (*info)->planes;
101 int start = (*info)->nb_samples * (*info)->bytes_per_sample * (*info)->config.channels;
102 start /= (*info)->planes;
104 for (int i=0; i<(*info)->planes; i++)
106 memcpy((*info)->data[i]+start, buffer[i], bytes_to_copy);
108 (*info)->nb_samples += samples;
113 CSoundPacket *CActiveAESound::GetSound(bool orig)
121 bool CActiveAESound::Prepare()
123 unsigned int flags = READ_TRUNCATED | READ_CHUNKED;
124 m_pFile = new CFile();
126 if (!m_pFile->Open(m_filename, flags))
132 m_isSeekPosible = m_pFile->IoControl(IOCTRL_SEEK_POSSIBLE, NULL) != 0;
133 m_fileSize = m_pFile->GetLength();
137 void CActiveAESound::Finish()
143 int CActiveAESound::GetChunkSize()
145 return m_pFile->GetChunkSize();
148 int CActiveAESound::Read(void *h, uint8_t* buf, int size)
150 CFile *pFile = static_cast<CActiveAESound*>(h)->m_pFile;
151 return pFile->Read(buf, size);
154 offset_t CActiveAESound::Seek(void *h, offset_t pos, int whence)
156 CFile* pFile = static_cast<CActiveAESound*>(h)->m_pFile;
157 if(whence == AVSEEK_SIZE)
158 return pFile->GetLength();
160 return pFile->Seek(pos, whence & ~AVSEEK_FORCE);