mirror of
https://github.com/libretro/gambatte-libretro.git
synced 2024-11-23 07:49:48 +00:00
directsoundengine: add device selection.
directdrawblitter: only list devices if there are more than 2 devices (including primary) directdrawblitter: use private static member rather than global friend enumeration callback capitalization changes git-svn-id: https://gambatte.svn.sourceforge.net/svnroot/gambatte@139 9dfb2916-2d38-0410-aef4-c5fe6c9ffc24
This commit is contained in:
parent
115e2476ad
commit
39f05a45e2
@ -18,25 +18,70 @@
|
||||
***************************************************************************/
|
||||
#include "directsoundengine.h"
|
||||
|
||||
// #include <iostream>
|
||||
#include <cstring>
|
||||
#include <QWidget>
|
||||
#include <QCheckBox>
|
||||
#include <QComboBox>
|
||||
#include <QLabel>
|
||||
#include <QVBoxLayout>
|
||||
#include <QHBoxLayout>
|
||||
#include <QSettings>
|
||||
|
||||
DirectSoundEngine::DirectSoundEngine(HWND hwnd_in)
|
||||
: AudioEngine("DirectSound"), confWidget(new QWidget), globalBufBox(new QCheckBox("Global buffer")),
|
||||
lpDS(NULL), lpDSB(NULL), hwnd(hwnd_in), useGlobalBuf(false)
|
||||
Q_DECLARE_METATYPE(GUID*)
|
||||
|
||||
BOOL CALLBACK DirectSoundEngine::enumCallback(LPGUID lpGuid, const char *lpcstrDescription, const char */*lpcstrModule*/, LPVOID lpContext) {
|
||||
if (lpGuid) {
|
||||
DirectSoundEngine *const thisptr = static_cast<DirectSoundEngine*>(lpContext);
|
||||
thisptr->deviceList.append(*lpGuid);
|
||||
thisptr->deviceSelector->addItem(lpcstrDescription, QVariant::fromValue(&thisptr->deviceList.last()));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
DirectSoundEngine::DirectSoundEngine(HWND hwnd_in) :
|
||||
AudioEngine("DirectSound"),
|
||||
confWidget(new QWidget),
|
||||
globalBufBox(new QCheckBox("Global buffer")),
|
||||
deviceSelector(new QComboBox),
|
||||
lpDS(NULL),
|
||||
lpDSB(NULL),
|
||||
bufSize(0),
|
||||
deviceIndex(0),
|
||||
offset(0),
|
||||
hwnd(hwnd_in),
|
||||
useGlobalBuf(false)
|
||||
{
|
||||
confWidget->setLayout(new QVBoxLayout);
|
||||
confWidget->layout()->setMargin(0);
|
||||
confWidget->layout()->addWidget(globalBufBox);
|
||||
DirectSoundEnumerateA(enumCallback, this);
|
||||
|
||||
if (deviceSelector->count() < 1)
|
||||
deviceSelector->addItem(QString(), QVariant::fromValue<GUID*>(NULL));
|
||||
|
||||
{
|
||||
QVBoxLayout *const mainLayout = new QVBoxLayout;
|
||||
mainLayout->setMargin(0);
|
||||
|
||||
if (deviceSelector->count() > 1) {
|
||||
QHBoxLayout *const hlayout = new QHBoxLayout;
|
||||
|
||||
hlayout->addWidget(new QLabel(QString("DirectSound device:")));
|
||||
hlayout->addWidget(deviceSelector);
|
||||
|
||||
mainLayout->addLayout(hlayout);
|
||||
}
|
||||
|
||||
mainLayout->addWidget(globalBufBox);
|
||||
confWidget->setLayout(mainLayout);
|
||||
}
|
||||
|
||||
{
|
||||
QSettings settings;
|
||||
settings.beginGroup("directsoundengine");
|
||||
useGlobalBuf = settings.value("useGlobalBuf", useGlobalBuf).toBool();
|
||||
|
||||
if ((deviceIndex = settings.value("deviceIndex", deviceIndex).toUInt()) >= static_cast<unsigned>(deviceSelector->count()))
|
||||
deviceIndex = 0;
|
||||
|
||||
settings.endGroup();
|
||||
}
|
||||
|
||||
@ -49,15 +94,18 @@ DirectSoundEngine::~DirectSoundEngine() {
|
||||
QSettings settings;
|
||||
settings.beginGroup("directsoundengine");
|
||||
settings.setValue("useGlobalBuf", useGlobalBuf);
|
||||
settings.setValue("deviceIndex", deviceIndex);
|
||||
settings.endGroup();
|
||||
}
|
||||
|
||||
void DirectSoundEngine::acceptSettings() {
|
||||
useGlobalBuf = globalBufBox->isChecked();
|
||||
deviceIndex = deviceSelector->currentIndex();
|
||||
}
|
||||
|
||||
void DirectSoundEngine::rejectSettings() {
|
||||
globalBufBox->setChecked(useGlobalBuf);
|
||||
deviceSelector->setCurrentIndex(deviceIndex);
|
||||
}
|
||||
|
||||
static unsigned nearestPowerOf2(const unsigned in) {
|
||||
@ -77,7 +125,7 @@ static unsigned nearestPowerOf2(const unsigned in) {
|
||||
}
|
||||
|
||||
int DirectSoundEngine::init(const int rate, const unsigned latency) {
|
||||
if (DirectSoundCreate(NULL, &lpDS, NULL) != DS_OK) {
|
||||
if (DirectSoundCreate(deviceSelector->itemData(deviceIndex).value<GUID*>(), &lpDS, NULL) != DS_OK) {
|
||||
lpDS = NULL;
|
||||
goto fail;
|
||||
}
|
||||
|
@ -20,21 +20,28 @@
|
||||
#define DIRECTSOUNDENGINE_H
|
||||
|
||||
class QCheckBox;
|
||||
class QComboBox;
|
||||
|
||||
#include "../audioengine.h"
|
||||
#include <QList>
|
||||
#include <memory>
|
||||
#include <dsound.h>
|
||||
|
||||
class DirectSoundEngine : public AudioEngine {
|
||||
const std::auto_ptr<QWidget> confWidget;
|
||||
QCheckBox *const globalBufBox;
|
||||
QComboBox *const deviceSelector;
|
||||
LPDIRECTSOUND lpDS;
|
||||
LPDIRECTSOUNDBUFFER lpDSB;
|
||||
QList<GUID> deviceList;
|
||||
unsigned bufSize;
|
||||
unsigned deviceIndex;
|
||||
DWORD offset;
|
||||
HWND hwnd;
|
||||
bool useGlobalBuf;
|
||||
|
||||
static BOOL CALLBACK enumCallback(LPGUID, const char*, const char*, LPVOID);
|
||||
|
||||
public:
|
||||
DirectSoundEngine(HWND hwnd);
|
||||
~DirectSoundEngine();
|
||||
|
@ -29,7 +29,7 @@
|
||||
|
||||
Q_DECLARE_METATYPE(GUID*)
|
||||
|
||||
BOOL WINAPI enumCallback(GUID FAR *lpGUID, char *lpDriverDescription, char */*lpDriverName*/, LPVOID lpContext, HMONITOR) {
|
||||
BOOL WINAPI DirectDrawBlitter::enumCallback(GUID FAR *lpGUID, char *lpDriverDescription, char */*lpDriverName*/, LPVOID lpContext, HMONITOR) {
|
||||
DirectDrawBlitter *const thisptr = static_cast<DirectDrawBlitter*>(lpContext);
|
||||
GUID *guidptr = NULL;
|
||||
|
||||
@ -85,7 +85,7 @@ DirectDrawBlitter::DirectDrawBlitter(PixelBufferSetter setPixelBuffer, QWidget *
|
||||
QVBoxLayout *const mainLayout = new QVBoxLayout;
|
||||
mainLayout->setMargin(0);
|
||||
|
||||
if (deviceSelector->count() > 1) {
|
||||
if (deviceSelector->count() > 2) {
|
||||
QHBoxLayout *const hlayout = new QHBoxLayout;
|
||||
|
||||
hlayout->addWidget(new QLabel(QString(tr("DirectDraw device:"))));
|
||||
|
@ -28,8 +28,6 @@ class QCheckBox;
|
||||
class QComboBox;
|
||||
|
||||
class DirectDrawBlitter : public BlitterWidget {
|
||||
friend BOOL WINAPI enumCallback(GUID FAR *, char*, char*, LPVOID, HMONITOR);
|
||||
|
||||
const std::auto_ptr<QWidget> confWidget;
|
||||
QCheckBox *const vblankBox;
|
||||
QCheckBox *const flippingBox;
|
||||
@ -53,6 +51,7 @@ class DirectDrawBlitter : public BlitterWidget {
|
||||
bool exclusive;
|
||||
bool flipping;
|
||||
|
||||
static BOOL WINAPI enumCallback(GUID FAR *, char*, char*, LPVOID, HMONITOR);
|
||||
bool initPrimarySurface();
|
||||
bool initVideoSurface();
|
||||
bool restoreSurfaces();
|
||||
|
@ -33,7 +33,7 @@ int main(int argc, char *argv[]) {
|
||||
source.generateButtonLabels(),
|
||||
source.generateButtonDefaults(),
|
||||
source.generateVideoSourceInfos(),
|
||||
"Video Filter:",
|
||||
"Video filter:",
|
||||
QSize(160, 144),
|
||||
source.generateSampleRates());
|
||||
GambatteMenuHandler mh(mw, &source, argc, argv);
|
||||
|
@ -53,7 +53,7 @@ SoundDialog::SoundDialog(const std::vector<AudioEngine*> &engines, const std::ve
|
||||
|
||||
{
|
||||
QHBoxLayout *const hLayout = new QHBoxLayout;
|
||||
hLayout->addWidget(new QLabel(tr("Sound Engine:")));
|
||||
hLayout->addWidget(new QLabel(tr("Sound engine:")));
|
||||
|
||||
for (std::size_t i = 0; i < engines.size(); ++i)
|
||||
engineSelector->addItem(engines[i]->nameString);
|
||||
@ -64,7 +64,7 @@ SoundDialog::SoundDialog(const std::vector<AudioEngine*> &engines, const std::ve
|
||||
|
||||
{
|
||||
QHBoxLayout *const hLayout = new QHBoxLayout;
|
||||
hLayout->addWidget(new QLabel(tr("Sample Rate:")));
|
||||
hLayout->addWidget(new QLabel(tr("Sample rate:")));
|
||||
|
||||
for (unsigned i = 0; i < rates.size(); ++i)
|
||||
rateSelector->addItem(QString::number(rates[i]) + " Hz", rates[i]);
|
||||
@ -75,7 +75,7 @@ SoundDialog::SoundDialog(const std::vector<AudioEngine*> &engines, const std::ve
|
||||
|
||||
{
|
||||
QHBoxLayout *const hLayout = new QHBoxLayout;
|
||||
hLayout->addWidget(new QLabel(tr("Buffer Latency:")));
|
||||
hLayout->addWidget(new QLabel(tr("Buffer latency:")));
|
||||
latencySelector->setRange(4, 999);
|
||||
latencySelector->setSuffix(" ms");
|
||||
hLayout->addWidget(latencySelector);
|
||||
|
@ -87,7 +87,7 @@ sourceIndexStore(0)
|
||||
|
||||
for (unsigned i = 0; i < hzSelector.size(); ++i) {
|
||||
hLayout = new QHBoxLayout;
|
||||
hLayout->addWidget(new QLabel("Full Screen mode (screen " + QString::number(i) + "):"));
|
||||
hLayout->addWidget(new QLabel("Full screen mode (screen " + QString::number(i) + "):"));
|
||||
QHBoxLayout *hhLayout = new QHBoxLayout;
|
||||
hhLayout->addWidget((fullResSelector[i] = new QComboBox));
|
||||
hhLayout->addWidget((hzSelector[i] = new QComboBox));
|
||||
|
Loading…
Reference in New Issue
Block a user