mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2024-11-14 21:37:52 -07:00
Linux: Add libao to DSL_NULL plugin so I get audio in linux
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@89 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
parent
3114c27143
commit
9d312559cf
126
Source/Plugins/Plugin_DSP_NULL/Src/PCHW/AOSoundStream.cpp
Normal file
126
Source/Plugins/Plugin_DSP_NULL/Src/PCHW/AOSoundStream.cpp
Normal file
@ -0,0 +1,126 @@
|
|||||||
|
#include <ao/ao.h>
|
||||||
|
#include <pthread.h>
|
||||||
|
#include "AOSoundStream.h"
|
||||||
|
|
||||||
|
namespace AOSound
|
||||||
|
{
|
||||||
|
pthread_t thread;
|
||||||
|
StreamCallback callback;
|
||||||
|
|
||||||
|
char *buffer;
|
||||||
|
int buf_size;
|
||||||
|
|
||||||
|
ao_device *device;
|
||||||
|
ao_sample_format format;
|
||||||
|
int default_driver;
|
||||||
|
|
||||||
|
int bufferSize;
|
||||||
|
int totalRenderedBytes;
|
||||||
|
int sampleRate;
|
||||||
|
volatile int threadData;
|
||||||
|
int currentPos;
|
||||||
|
int lastPos;
|
||||||
|
short realtimeBuffer[1024 * 1024];
|
||||||
|
int AOSound_GetSampleRate()
|
||||||
|
{
|
||||||
|
return sampleRate;
|
||||||
|
}
|
||||||
|
bool WriteDataToBuffer(int dwOffset,char* soundData, int dwSoundBytes)
|
||||||
|
{
|
||||||
|
//void* ptr1, * ptr2;
|
||||||
|
//DWORD numBytes1, numBytes2;
|
||||||
|
// Obtain memory address of write block. This will be in two parts if the block wraps around.
|
||||||
|
//HRESULT hr = dsBuffer->Lock(dwOffset, dwSoundBytes, &ptr1, &numBytes1, &ptr2, &numBytes2, 0);
|
||||||
|
|
||||||
|
// If the buffer was lost, restore and retry lock.
|
||||||
|
/*if (DSERR_BUFFERLOST == hr)
|
||||||
|
{
|
||||||
|
dsBuffer->Restore();
|
||||||
|
hr = dsBuffer->Lock(dwOffset, dwSoundBytes, &ptr1, &numBytes1, &ptr2, &numBytes2, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (SUCCEEDED(hr))
|
||||||
|
{
|
||||||
|
memcpy(ptr1, soundData, numBytes1);
|
||||||
|
|
||||||
|
if (ptr2 != 0)
|
||||||
|
{
|
||||||
|
memcpy(ptr2, soundData + numBytes1, numBytes2);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Release the data back to DirectSound.
|
||||||
|
dsBuffer->Unlock(ptr1, numBytes1, ptr2, numBytes2);
|
||||||
|
return(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
return(false);*/
|
||||||
|
ao_play(device, soundData, dwSoundBytes);
|
||||||
|
return true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void* soundThread(void*)
|
||||||
|
{
|
||||||
|
currentPos = 0;
|
||||||
|
lastPos = 0;
|
||||||
|
|
||||||
|
// Prefill buffer?
|
||||||
|
//writeDataToBuffer(0,realtimeBuffer,bufferSize);
|
||||||
|
// dsBuffer->Lock(0, bufferSize, (void **)&p1, &num1, (void **)&p2, &num2, 0);
|
||||||
|
//dsBuffer->Play(0, 0, DSBPLAY_LOOPING);
|
||||||
|
|
||||||
|
while (!threadData)
|
||||||
|
{
|
||||||
|
// No blocking inside the csection
|
||||||
|
//dsBuffer->GetCurrentPosition((DWORD*)¤tPos, 0);
|
||||||
|
int numBytesToRender = 256;
|
||||||
|
|
||||||
|
if (numBytesToRender >= 256)
|
||||||
|
{
|
||||||
|
(*callback)(realtimeBuffer, numBytesToRender >> 2, 16, 44100, 2);
|
||||||
|
|
||||||
|
WriteDataToBuffer(0, (char*)realtimeBuffer, numBytesToRender);
|
||||||
|
//currentPos = ModBufferSize(lastPos + numBytesToRender);
|
||||||
|
//totalRenderedBytes += numBytesToRender;
|
||||||
|
|
||||||
|
//lastPos = currentPos;
|
||||||
|
}
|
||||||
|
|
||||||
|
//WaitForSingleObject(soundSyncEvent, MAXWAIT);
|
||||||
|
}
|
||||||
|
|
||||||
|
//dsBuffer->Stop();
|
||||||
|
return(0); //hurra!
|
||||||
|
}
|
||||||
|
bool AOSound_StartSound(int _sampleRate, StreamCallback _callback)
|
||||||
|
{
|
||||||
|
callback = _callback;
|
||||||
|
threadData = 0;
|
||||||
|
sampleRate = _sampleRate;
|
||||||
|
|
||||||
|
//no security attributes, automatic resetting, init state nonset, untitled
|
||||||
|
//soundSyncEvent = CreateEvent(0, false, false, 0);
|
||||||
|
ao_initialize();
|
||||||
|
default_driver = ao_default_driver_id();
|
||||||
|
format.bits = 16;
|
||||||
|
format.channels = 2;
|
||||||
|
format.rate = sampleRate;
|
||||||
|
format.byte_format = AO_FMT_LITTLE;
|
||||||
|
|
||||||
|
//vi vill ha access till DSOUND så...
|
||||||
|
device = ao_open_live(default_driver, &format, NULL /* no options */);
|
||||||
|
if (device == NULL) {
|
||||||
|
fprintf(stderr, "Error opening device.\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
buf_size = format.bits/8 * format.channels * format.rate;
|
||||||
|
buffer = (char*)calloc(buf_size, sizeof(char));
|
||||||
|
pthread_create(&thread, NULL, soundThread, (void *)NULL);
|
||||||
|
return(true);
|
||||||
|
}
|
||||||
|
void AOSound_StopSound()
|
||||||
|
{
|
||||||
|
ao_close(device);
|
||||||
|
ao_shutdown();
|
||||||
|
}
|
||||||
|
}
|
35
Source/Plugins/Plugin_DSP_NULL/Src/PCHW/AOSoundStream.h
Normal file
35
Source/Plugins/Plugin_DSP_NULL/Src/PCHW/AOSoundStream.h
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
// Copyright (C) 2003-2008 Dolphin Project.
|
||||||
|
|
||||||
|
// This program is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, version 2.0.
|
||||||
|
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License 2.0 for more details.
|
||||||
|
|
||||||
|
// A copy of the GPL 2.0 should have been included with the program.
|
||||||
|
// If not, see http://www.gnu.org/licenses/
|
||||||
|
|
||||||
|
// Official SVN repository and contact information can be found at
|
||||||
|
// http://code.google.com/p/dolphin-emu/
|
||||||
|
|
||||||
|
#ifndef __AOSOUNDSTREAM_H__
|
||||||
|
#define __AOSOUNDSTREAM_H__
|
||||||
|
|
||||||
|
namespace AOSound
|
||||||
|
{
|
||||||
|
typedef void (*StreamCallback)(short* buffer, int numSamples, int bits, int rate, int channels);
|
||||||
|
|
||||||
|
bool AOSound_StartSound(int sampleRate, StreamCallback _callback);
|
||||||
|
void AOSound_UpdateSound();
|
||||||
|
void AOSound_StopSound();
|
||||||
|
|
||||||
|
float AOSound_GetTimer();
|
||||||
|
int AOSound_GetCurSample();
|
||||||
|
int AOSound_GetSampleRate();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif //__AOSOUNDSTREAM_H__
|
@ -5,6 +5,7 @@ files = ["DSPHandler.cpp",
|
|||||||
"main.cpp",
|
"main.cpp",
|
||||||
"Config.cpp",
|
"Config.cpp",
|
||||||
"Globals.cpp",
|
"Globals.cpp",
|
||||||
|
"PCHW/AOSoundStream.cpp",
|
||||||
"PCHW/Mixer.cpp",
|
"PCHW/Mixer.cpp",
|
||||||
"UCodes/UCode_AX.cpp",
|
"UCodes/UCode_AX.cpp",
|
||||||
"UCodes/UCode_CARD.cpp",
|
"UCodes/UCode_CARD.cpp",
|
||||||
@ -14,4 +15,5 @@ files = ["DSPHandler.cpp",
|
|||||||
"UCodes/UCodes.cpp",
|
"UCodes/UCodes.cpp",
|
||||||
"UCodes/UCode_Zelda.cpp",
|
"UCodes/UCode_Zelda.cpp",
|
||||||
]
|
]
|
||||||
env.SharedLibrary("../../../../Binary/linux/Plugins/dsphle.so", files, LIBS = ["common"])
|
dspenv=env.Copy(LINKFLAGS = "`pkg-config --libs ao` ")
|
||||||
|
dspenv.SharedLibrary("../../../../Binary/linux/Plugins/dsphle.so", files, LIBS = ["common"])
|
||||||
|
@ -24,7 +24,7 @@
|
|||||||
#include "AboutDlg.h"
|
#include "AboutDlg.h"
|
||||||
#include "ConfigDlg.h"
|
#include "ConfigDlg.h"
|
||||||
#else
|
#else
|
||||||
// TODO
|
#include "PCHW/AOSoundStream.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "PCHW/Mixer.h"
|
#include "PCHW/Mixer.h"
|
||||||
@ -110,6 +110,8 @@ void DSP_Initialize(DSPInitialize _dspInitialize)
|
|||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
DSound::DSound_StartSound((HWND)g_dspInitialize.hWnd, g_Config.m_SampleRate, Mixer);
|
DSound::DSound_StartSound((HWND)g_dspInitialize.hWnd, g_Config.m_SampleRate, Mixer);
|
||||||
|
#else
|
||||||
|
AOSound::AOSound_StartSound(g_Config.m_SampleRate, Mixer);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -119,6 +121,8 @@ void DSP_Shutdown()
|
|||||||
// delete the UCodes
|
// delete the UCodes
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
DSound::DSound_StopSound();
|
DSound::DSound_StopSound();
|
||||||
|
#else
|
||||||
|
AOSound::AOSound_StopSound();
|
||||||
#endif
|
#endif
|
||||||
CDSPHandler::Destroy();
|
CDSPHandler::Destroy();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user