Vegastrike 0.5.1 rc1
1.0
Original sources for Vegastrike Evolved
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
SimpleSound.cpp
Go to the documentation of this file.
1
//
2
// C++ Implementation: Audio::SimpleSound
3
//
4
5
#include "
SimpleSound.h
"
6
#include "config.h"
7
8
#include "
CodecRegistry.h
"
9
#include "
Stream.h
"
10
11
namespace
Audio {
12
13
SimpleSound::SimpleSound
(
const
std::string& name,
VSFileSystem::VSFileType
_type,
bool
streaming)
14
throw
()
15
:
Sound
(name, streaming),
16
type(_type)
17
{
18
}
19
20
SimpleSound::~SimpleSound
()
21
{
22
}
23
24
void
SimpleSound::loadStream
()
25
throw(
Exception
)
26
{
27
if
(
isStreamLoaded
())
28
throw
(
ResourceAlreadyLoadedException
());
29
30
// Open stream and initialize shared pointer
31
stream.reset(
32
CodecRegistry::getSingleton
()->open(
33
getName
(),
34
getType
()
35
)
36
);
37
38
// Copy format
39
getFormat
() =
getStream
()->getFormat();
40
}
41
42
void
SimpleSound::closeStream
()
43
throw(
ResourceNotLoadedException
)
44
{
45
if
(!
isStreamLoaded
())
46
throw
(ResourceNotLoadedException());
47
stream.reset();
48
}
49
50
SharedPtr<Stream>
SimpleSound::getStream
()
const
51
throw(
ResourceNotLoadedException
)
52
{
53
if
(!
isStreamLoaded
())
54
throw
(ResourceNotLoadedException());
55
return
stream;
56
}
57
58
void
SimpleSound::readBuffer
(
SoundBuffer
&
buffer
)
59
throw
(
Exception
)
60
{
61
if
(
buffer
.getFormat() == getFormat()) {
62
// Same formats, so all we have to do is read bytes ;)
63
buffer
.setUsedBytes(
64
getStream()->read(
buffer
.getBuffer(),
buffer
.getByteCapacity() )
65
);
66
}
else
{
67
// Save the buffer format, we'll have to reformat to this format
68
Format
targetFormat =
buffer
.getFormat();
69
70
// Set buffer format to stream format
71
buffer
.setFormat(getFormat());
72
73
// Now read bytes from the stream
74
buffer
.setUsedBytes(
75
getStream()->read(
buffer
.getBuffer(),
buffer
.getByteCapacity() )
76
);
77
78
// Finally we have to reformat the buffer back to the original format
79
buffer
.reformat(targetFormat);
80
}
81
}
82
83
void
SimpleSound::abortLoad
()
84
throw()
85
{
86
// Intentionally blank
87
}
88
89
};
src
audio
SimpleSound.cpp
Generated on Fri May 29 2015 23:07:06 for Vegastrike 0.5.1 rc1 by
1.8.4