29 #include <boost/scoped_array.hpp> 76 NeAACDecConfigurationPtr conf = NeAACDecGetCurrentConfiguration(
_handle);
77 conf->outputFormat = FAAD_FMT_16BIT;
79 NeAACDecSetConfiguration(
_handle, conf);
84 extraData.
read(extraDataBuf.get(), extraData.
size());
92 throw Common::Exception(
"Could not initialize AAC decoder: %s", NeAACDecGetErrorMessage(err));
104 size_t inBufferPos = 0;
105 size_t inBufferSize = stream.
size();
107 boost::scoped_array<byte> inBuffer(
new byte[inBufferSize]);
108 if (stream.
read(inBuffer.get(), inBufferSize) != inBufferSize)
114 while (inBufferPos < inBufferSize) {
115 NeAACDecFrameInfo frameInfo;
116 void *decodedSamples = NeAACDecDecode(
_handle, &frameInfo, inBuffer.get() + inBufferPos, inBufferSize - inBufferPos);
118 if (frameInfo.error != 0)
119 throw Common::Exception(
"Failed to decode AAC frame: %s", NeAACDecGetErrorMessage(frameInfo.error));
121 byte *buffer =
new byte[frameInfo.samples * 2];
122 std::memcpy(buffer, decodedSamples, frameInfo.samples * 2);
128 inBufferPos += frameInfo.bytesconsumed;
QueuingAudioStream * makeQueuingAudioStream(int rate, int channels)
Factory function for an QueuingAudioStream.
void finish()
Mark this stream as finished.
PacketizedAudioStream * makeAACStream(Common::SeekableReadStream &extraData)
Create a PacketizedAudioStream that decodes AAC sound.
virtual size_t seek(ptrdiff_t offset, Origin whence=kOriginBegin)=0
Sets the stream position indicator for the stream.
virtual void finish()=0
Mark this stream as finished.
Implementing the reading stream interfaces for plain memory blocks.
bool isFinished() const
Is the stream marked as finished?
RewindableAudioStream * makePCMStream(Common::SeekableReadStream *stream, int rate, byte flags, int channels, bool disposeAfterUse)
Creates an audio stream, which plays from the given stream.
Decoding PCM (Pulse Code Modulation).
A simple scoped smart pointer template.
bool endOfStream() const
End of stream reached? If this returns true, it means that all data in this stream is used up and no ...
virtual void queueAudioStream(AudioStream *audStream, bool disposeAfterUse=true)=0
Queue an audio stream for playback.
Basic exceptions to throw.
Common::ScopedPtr< QueuingAudioStream > _audStream
An AudioStream designed to work in terms of packets.
virtual size_t read(void *dataPtr, size_t dataSize)=0
Read data from the stream.
Simple memory based 'stream', which implements the ReadStream interface for a plain memory block...
AudioStream * decodeFrame(Common::SeekableReadStream &stream)
bool endOfData() const
End of data reached? If this returns true, it means that at this time there is no data available in t...
const Exception kReadError("Read error")
Exception when reading from a stream failed.
A scoped plain pointer, allowing pointer-y access and normal deletion.
virtual size_t size() const =0
Obtains the total size of the stream, measured in bytes.
void queuePacket(Common::SeekableReadStream *data)
Queue the next packet to be decoded.
sound is 16 bits wide (default: 8bit)
Generic audio input stream.
int getRate() const
Sample rate of the stream.
A smart pointer with a deletion flag.
samples are in native endianness
size_t readBuffer(int16 *buffer, const size_t numSamples)
Fill the given buffer with up to numSamples samples.
int getChannels() const
Return the number channels in this stream.
Interface for a seekable & readable data stream.
AACDecoder(Common::SeekableReadStream &stream)