Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Donald Haase
Cockatrice
Commits
0c1c0fcb
Commit
0c1c0fcb
authored
May 21, 2011
by
Max-Wilhelm Bruker
Browse files
added sound engine files
parent
a4097659
Changes
2
Show whitespace changes
Inline
Side-by-side
cockatrice/src/soundengine.cpp
0 → 100644
View file @
0c1c0fcb
#include
"soundengine.h"
#include
"settingscache.h"
#include
<QAudioOutput>
#include
<QAudioFormat>
#include
<QFile>
#include
<QBuffer>
SoundEngine
::
SoundEngine
(
QObject
*
parent
)
:
QObject
(
parent
)
{
inputBuffer
=
new
QBuffer
;
QAudioFormat
format
;
format
.
setFrequency
(
44100
);
format
.
setChannels
(
1
);
format
.
setSampleSize
(
16
);
format
.
setCodec
(
"audio/pcm"
);
format
.
setByteOrder
(
QAudioFormat
::
LittleEndian
);
format
.
setSampleType
(
QAudioFormat
::
SignedInt
);
audio
=
new
QAudioOutput
(
format
,
this
);
connect
(
settingsCache
,
SIGNAL
(
soundPathChanged
()),
this
,
SLOT
(
cacheData
()));
cacheData
();
}
void
SoundEngine
::
cacheData
()
{
static
const
QStringList
fileNames
=
QStringList
()
<<
"notification"
<<
"draw"
<<
"playcard"
<<
"shuffle"
<<
"tap"
<<
"untap"
;
for
(
int
i
=
0
;
i
<
fileNames
.
size
();
++
i
)
{
QFile
file
(
settingsCache
->
getSoundPath
()
+
"/"
+
fileNames
[
i
]
+
".raw"
);
file
.
open
(
QIODevice
::
ReadOnly
);
audioData
.
insert
(
fileNames
[
i
],
file
.
readAll
());
file
.
close
();
}
}
void
SoundEngine
::
playSound
(
const
QString
&
fileName
)
{
if
(
!
settingsCache
->
getSoundEnabled
())
return
;
audio
->
stop
();
inputBuffer
->
close
();
inputBuffer
->
setData
(
audioData
[
fileName
]);
inputBuffer
->
open
(
QIODevice
::
ReadOnly
);
audio
->
start
(
inputBuffer
);
}
void
SoundEngine
::
notification
()
{
playSound
(
"notification"
);
}
void
SoundEngine
::
draw
()
{
playSound
(
"draw"
);
}
void
SoundEngine
::
playCard
()
{
playSound
(
"playcard"
);
}
void
SoundEngine
::
shuffle
()
{
playSound
(
"shuffle"
);
}
void
SoundEngine
::
tap
()
{
playSound
(
"tap"
);
}
void
SoundEngine
::
untap
()
{
playSound
(
"untap"
);
}
cockatrice/src/soundengine.h
0 → 100644
View file @
0c1c0fcb
#ifndef SOUNDENGINE_H
#define SOUNDENGINE_H
#include
<QObject>
#include
<QMap>
class
QAudioOutput
;
class
QBuffer
;
class
SoundEngine
:
public
QObject
{
Q_OBJECT
private:
void
playSound
(
const
QString
&
fileName
);
QMap
<
QString
,
QByteArray
>
audioData
;
QBuffer
*
inputBuffer
;
QAudioOutput
*
audio
;
private
slots
:
void
cacheData
();
public:
SoundEngine
(
QObject
*
parent
=
0
);
public
slots
:
void
notification
();
void
draw
();
void
playCard
();
void
shuffle
();
void
tap
();
void
untap
();
};
extern
SoundEngine
*
soundEngine
;
#endif
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment