cAudio  2.3.0
3d Audio Engine
cFileSourceFactory.h
1 // Copyright (c) 2008-2011 Raynaldo (Wildicv) Rivera, Joshua (Dark_Kilauea) Jones, Murat (wolfmanfx) Sari
2 // This file is part of the "cAudio Engine"
3 // For conditions of distribution and use, see copyright notice in cAudio.h
4 
5 #pragma once
6 
7 #include "IDataSourceFactory.h"
8 
9 #if CAUDIO_COMPILE_WITH_FILE_SOURCE == 1
10 
11 #include "cFileSource.h"
12 #include "cMemorySource.h"
13 #include "cMutex.h"
14 
15 namespace cAudio
16 {
17  class cFileSourceFactory : public IDataSourceFactory
18  {
19  public:
20  cFileSourceFactory() { }
21  virtual ~cFileSourceFactory() { }
22 
23  virtual IDataSource* CreateDataSource(const char* filename, bool streamingRequested)
24  {
25  IDataSource* source = CAUDIO_NEW cFileSource(filename);
26 
27  if(!streamingRequested && source && source->isValid())
28  {
29  //A bit hackish, but if the user doesn't want streaming, make this a memory source
30  int length = source->getSize();
31  char* tempbuf = (char*)CAUDIO_MALLOC(length);
32  if(tempbuf)
33  {
34  source->read(tempbuf, length);
35  IDataSource* memSource = CAUDIO_NEW cMemorySource(tempbuf, length, true);
36  CAUDIO_FREE(tempbuf);
37 
38  if(memSource && memSource->isValid())
39  {
40  source->drop();
41  return memSource;
42  }
43 
44  if(memSource)
45  memSource->drop();
46  }
47  }
48  return source;
49  }
50  };
51 };
52 
53 #endif
cAudio
Main namespace for the entire cAudio library.
Definition: cAudioCapture.h:15