basic_source.cpp

Go to the documentation of this file.
00001 #include "basic_source.h"
00002 #include "debug.h"
00003 #include "utility.h"
00004 
00005 
00006 namespace audiere {
00007 
00008   BasicSource::BasicSource() {
00009     m_repeat = false;
00010   }
00011 
00012   int
00013   BasicSource::read(int frame_count, void* buffer) {
00014     if (m_repeat) {
00015       const int frame_size = GetFrameSize(this);
00016 
00017       // the main read loop:
00018       u8* out = (u8*)buffer;
00019       int frames_left = frame_count;
00020       while (frames_left > 0) {
00021 
00022         // read some frames.  if we can't read anything, reset the stream
00023         // and try again.
00024         int frames_read = doRead(frames_left, out);
00025         if (frames_read == 0) {
00026           reset();
00027           frames_read = doRead(frames_left, out);
00028 
00029           // if we still can't read anything, we're done
00030           if (frames_read == 0) {
00031             ADR_LOG("Can't read any samples even after reset");
00032             break;
00033           }
00034         }
00035 
00036         frames_left -= frames_read;
00037         out += frames_read * frame_size;
00038       }
00039 
00040       return frame_count - frames_left;
00041 
00042     } else {
00043 
00044       return doRead(frame_count, buffer);
00045 
00046     }
00047   }
00048 
00049 }

Generated on Mon Feb 13 23:07:45 2006 for audiere by  doxygen 1.4.6