Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F96922
XMAudioSource.cpp
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
XMAudioSource.cpp
View Options
#include
<echo/Resource/XMAudioSource.h>
#include
<echo/Audio/AudioBuffer.h>
#include
<iostream>
namespace
Echo
{
XMAudioSource
::
XMAudioSource
(
File
xmFile
)
:
mModFile
(
0
),
mModFileMem
(
0
),
mSampleData
(
0
),
mSampleDataSize
(
0
)
{
mLastNotAppeneded
=
0
;
if
(
xmFile
.
IsOpen
())
{
u32
size
=
xmFile
.
GetSize
();
mModFileMem
=
new
u8
[
size
];
xmFile
.
Read
(
mModFileMem
,
1
,
size
);
mSampleDataSize
=
(
44100
*
2
*
2
)
*
5
;
//44100 samples a second, 2 channels, 16 bits a sample * seconds.
mSampleData
=
new
u16
[
mSampleDataSize
];
mModFile
=
ModPlug_Load
(
mModFileMem
,
size
);
}
else
{
std
::
cout
<<
"XM track "
<<
xmFile
.
GetActualFileName
()
<<
" is not open"
<<
std
::
endl
;
}
}
XMAudioSource
::~
XMAudioSource
()
{
ModPlug_Unload
(
mModFile
);
delete
[]
mModFileMem
;
delete
[]
mSampleData
;
}
void
XMAudioSource
::
Restart
()
{
if
(
mModFile
)
{
ModPlug_Seek
(
mModFile
,
0
);
}
}
u32
XMAudioSource
::
GetSampleRate
()
{
if
(
mModFile
)
{
ModPlug_Settings
settings
;
ModPlug_GetSettings
(
&
settings
);
return
settings
.
mFrequency
;
}
return
0
;
}
u32
XMAudioSource
::
GetBitDepth
()
{
if
(
mModFile
)
{
ModPlug_Settings
settings
;
ModPlug_GetSettings
(
&
settings
);
return
settings
.
mBits
;
}
return
0
;
}
Seconds
XMAudioSource
::
GetLength
()
{
f32
l
=
0
;
if
(
mModFile
)
{
//Get the length of the mod, in milliseconds
l
=
static_cast
<
f32
>
(
ModPlug_GetLength
(
mModFile
));
//Convert the length to seconds.
l
/=
1000.0f
;
}
return
Seconds
(
l
);
}
u32
XMAudioSource
::
GetNumChannels
()
{
if
(
mModFile
)
{
ModPlug_Settings
settings
;
ModPlug_GetSettings
(
&
settings
);
return
settings
.
mChannels
;
}
return
1
;
}
u32
XMAudioSource
::
UpdateBuffer
(
AudioBuffer
&
buffer
,
u32
numBytesToRead
)
{
if
(
mModFile
)
{
u32
readSize
=
std
::
min
(
numBytesToRead
,
mSampleDataSize
);
//Normal stream operation.
ModPlug_Read
(
mModFile
,
&
(
mSampleData
[
mLastNotAppeneded
]),
readSize
-
mLastNotAppeneded
);
u32
bytesRead
=
buffer
.
Append
(
mSampleData
,
readSize
);
//The number of bytes not appended is the requested amount minus the amount read.
mLastNotAppeneded
=
numBytesToRead
-
bytesRead
;
return
bytesRead
;
}
return
0
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-c++
Expires
Thu, Dec 5, 2:02 AM (7 h, 33 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
62522
Default Alt Text
XMAudioSource.cpp (2 KB)
Attached To
Mode
rEE Echo 3
Attached
Detach File
Event Timeline
Log In to Comment