Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Stream.cpp
Go to the documentation of this file.
1 //
2 // C++ Implementation: Audio::Stream
3 //
4 
5 #include "Stream.h"
6 #include "config.h"
7 
8 #include <utility>
9 #include <cstring>
10 
11 //using namespace std;
12 
13 namespace Audio {
14 
15  using std::min;
16 
17  Stream::Stream(const std::string& path) throw(Exception)
18  {
19  }
20 
22  {
23  }
24 
25  double Stream::getLength() throw(Exception)
26  {
27  return getLengthImpl();
28  }
29 
30  double Stream::getPosition() const throw()
31  {
32  return getPositionImpl();
33  }
34 
35  void Stream::seek(double position) throw(Exception)
36  {
37  seekImpl(position);
38  }
39 
40  unsigned int Stream::read(void *buffer, unsigned int bufferSize) throw(Exception)
41  {
42  void *rbuffer;
43  void *rbufferEnd;
44  unsigned int rbufferSize;
45  unsigned int rode = 0;
46 
47  try {
48  getBufferImpl(rbuffer, rbufferSize);
49  } catch (NoBufferException) {
50  nextBufferImpl();
51  getBufferImpl(rbuffer, rbufferSize);
52  curBufferPos = rbuffer;
53  }
54  rbufferEnd = ((char*)rbuffer) + rbufferSize;
55 
56  while (bufferSize > 0) {
57  if (!((curBufferPos >= rbuffer) && (curBufferPos < rbufferEnd))) {
58  nextBufferImpl();
59  getBufferImpl(rbuffer, rbufferSize);
60  curBufferPos = rbuffer;
61  rbufferEnd = ((char*)rbuffer) + rbufferSize;
62  }
63 
64  size_t remaining = min( bufferSize, (unsigned int)((char*)rbufferEnd - (char*)curBufferPos) ); //is there no std::ptrdiff?
65  memcpy(buffer, curBufferPos, remaining);
66  buffer = (void*)((char*)buffer + remaining);
67  curBufferPos = (void*)((char*)curBufferPos + remaining);
68  bufferSize -= remaining;
69  rode += remaining;
70  }
71 
72  return rode;
73  }
74 
75 };