Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

repeatable.cpp

Go to the documentation of this file.
00001 #include "repeatable.h"
00002 #include "utility.h"
00003 
00004 
00005 namespace audiere {
00006 
00007   RepeatableStream::RepeatableStream(SampleSource* source) {
00008     m_repeat = false;
00009     m_source = source;
00010 
00011     // grab the sample size in bytes
00012     int channel_count, sample_rate;
00013     SampleFormat sample_format;
00014     m_source->getFormat(channel_count, sample_rate, sample_format);
00015     m_frame_size = channel_count * GetSampleSize(sample_format);
00016   }
00017 
00018 
00019   void
00020   RepeatableStream::setRepeat(bool repeat) {
00021     m_repeat = repeat;
00022   }
00023 
00024 
00025   bool
00026   RepeatableStream::getRepeat() {
00027     return m_repeat;
00028   }
00029 
00030 
00031   void
00032   RepeatableStream::getFormat(
00033     int& channel_count,
00034     int& sample_rate,
00035     SampleFormat& sample_format)
00036   {
00037     m_source->getFormat(channel_count, sample_rate, sample_format);
00038   }
00039 
00040 
00041   int
00042   RepeatableStream::read(int frame_count, void* buffer) {
00043     if (m_repeat) {
00044 
00045       unsigned char* out = (unsigned char*)buffer;
00046       int samples_left = frame_count;
00047       while (samples_left > 0) {
00048 
00049         // read some samples
00050         int samples_read = m_source->read(samples_left, out);
00051 
00052         // if we couldn't read anything, reset the stream and try again
00053         if (samples_read == 0) {
00054           m_source->reset();
00055           samples_read = m_source->read(samples_left, buffer);
00056         }
00057 
00058         // if we still can't read anything, we're done
00059         if (samples_read == 0) {
00060           break;
00061         }
00062 
00063         samples_left -= samples_read;
00064         out += samples_read * m_frame_size;
00065       }
00066 
00067       return frame_count - samples_left;
00068 
00069     } else {
00070 
00071       return m_source->read(frame_count, buffer);
00072 
00073     }
00074   }
00075 
00076 
00077   void
00078   RepeatableStream::reset() {
00079     m_source->reset();
00080   }
00081 
00082 
00083   bool
00084   RepeatableStream::isSeekable() {
00085     return m_source->isSeekable();
00086   }
00087 
00088 
00089   int
00090   RepeatableStream::getLength() {
00091     return m_source->getLength();
00092   }
00093 
00094 
00095   void
00096   RepeatableStream::setPosition(int position) {
00097     m_source->setPosition(position);
00098   }
00099 
00100   
00101   int
00102   RepeatableStream::getPosition() {
00103     return m_source->getPosition();
00104   }
00105 
00106 }

Generated on Sat Oct 12 01:43:03 2002 for audiere by doxygen1.2.17