mirror of
https://github.com/mauiaaron/apple2.git
synced 2024-09-29 23:54:53 +00:00
Refactor : rename and coalesce audio buffer initialization structs
This commit is contained in:
parent
49d2fe6e09
commit
3767f55846
@ -147,31 +147,21 @@ static inline bool SUCCEEDED(int x) { return x == DS_OK; }
|
|||||||
#define DSBCAPS_CTRLVOLUME 0x00000080
|
#define DSBCAPS_CTRLVOLUME 0x00000080
|
||||||
#define DSBCAPS_CTRLPOSITIONNOTIFY 0x00000100
|
#define DSBCAPS_CTRLPOSITIONNOTIFY 0x00000100
|
||||||
|
|
||||||
|
typedef struct AudioParams_s {
|
||||||
typedef struct {
|
uint16_t nChannels;
|
||||||
uint16_t wFormatTag;
|
|
||||||
uint16_t nChannels;
|
|
||||||
unsigned long nSamplesPerSec;
|
unsigned long nSamplesPerSec;
|
||||||
unsigned long nAvgBytesPerSec;
|
unsigned long nAvgBytesPerSec;
|
||||||
uint16_t nBlockAlign;
|
uint16_t nBlockAlign;
|
||||||
uint16_t wBitsPerSample;
|
uint16_t wBitsPerSample;
|
||||||
uint16_t cbSize;
|
|
||||||
} WAVEFORMATEX, *LPWAVEFORMATEX;
|
|
||||||
|
|
||||||
typedef struct DSBUFFERDESC {
|
|
||||||
unsigned long dwSize;
|
|
||||||
unsigned long dwFlags;
|
|
||||||
unsigned long dwBufferBytes;
|
unsigned long dwBufferBytes;
|
||||||
unsigned long dwReserved;
|
} AudioParams_s;
|
||||||
LPWAVEFORMATEX lpwfxFormat;
|
|
||||||
} DSBUFFERDESC;
|
|
||||||
|
|
||||||
typedef struct IDirectSound {
|
typedef struct IDirectSound {
|
||||||
|
|
||||||
void *implementation_specific;
|
void *implementation_specific;
|
||||||
|
|
||||||
#define LPUNKNOWN void*
|
#define LPUNKNOWN void*
|
||||||
int (*CreateSoundBuffer)(DSBUFFERDESC *pcDSBufferDesc, LPDIRECTSOUNDBUFFER * ppDSBuffer, LPUNKNOWN pUnkOuter);
|
int (*CreateSoundBuffer)(AudioParams_s *pcDSBufferDesc, LPDIRECTSOUNDBUFFER * ppDSBuffer, LPUNKNOWN pUnkOuter);
|
||||||
int (*DestroySoundBuffer)(LPDIRECTSOUNDBUFFER * ppDSBuffer);
|
int (*DestroySoundBuffer)(LPDIRECTSOUNDBUFFER * ppDSBuffer);
|
||||||
|
|
||||||
} IDirectSound, *LPDIRECTSOUND;
|
} IDirectSound, *LPDIRECTSOUND;
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
#include "audio/soundcore-openal.h"
|
#include "audio/soundcore-openal.h"
|
||||||
#include "audio/alhelpers.h"
|
#include "audio/alhelpers.h"
|
||||||
|
|
||||||
static long OpenALCreateSoundBuffer(ALBufferParamsStruct *params, ALSoundBufferStruct **soundbuf_struct, void *extra_data);
|
static long OpenALCreateSoundBuffer(AudioParams_s *params, ALSoundBufferStruct **soundbuf_struct, void *extra_data);
|
||||||
static long OpenALDestroySoundBuffer(ALSoundBufferStruct **soundbuf_struct);
|
static long OpenALDestroySoundBuffer(ALSoundBufferStruct **soundbuf_struct);
|
||||||
|
|
||||||
typedef struct ALVoices {
|
typedef struct ALVoices {
|
||||||
@ -138,7 +138,7 @@ long SoundSystemCreate(const char *sound_device, SoundSystemStruct **sound_struc
|
|||||||
}
|
}
|
||||||
|
|
||||||
(*sound_struct)->implementation_specific = ctx;
|
(*sound_struct)->implementation_specific = ctx;
|
||||||
(*sound_struct)->CreateSoundBuffer = (int (*)(DSBUFFERDESC *, LPDIRECTSOUNDBUFFER *, void *))OpenALCreateSoundBuffer;
|
(*sound_struct)->CreateSoundBuffer = (int (*)(AudioParams_s *, LPDIRECTSOUNDBUFFER *, void *))OpenALCreateSoundBuffer;
|
||||||
(*sound_struct)->DestroySoundBuffer = (int (*)(LPDIRECTSOUNDBUFFER *))OpenALDestroySoundBuffer;
|
(*sound_struct)->DestroySoundBuffer = (int (*)(LPDIRECTSOUNDBUFFER *))OpenALDestroySoundBuffer;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -257,7 +257,7 @@ static void DeleteVoice(ALVoice *voice)
|
|||||||
/* Creates a new voice object, and allocates the needed OpenAL source and
|
/* Creates a new voice object, and allocates the needed OpenAL source and
|
||||||
* buffer objects. Error checking is simplified for the purposes of this
|
* buffer objects. Error checking is simplified for the purposes of this
|
||||||
* example, and will cause an abort if needed. */
|
* example, and will cause an abort if needed. */
|
||||||
static ALVoice *NewVoice(ALBufferParamsStruct *params)
|
static ALVoice *NewVoice(AudioParams_s *params)
|
||||||
{
|
{
|
||||||
ALVoice *voice = NULL;
|
ALVoice *voice = NULL;
|
||||||
|
|
||||||
@ -328,10 +328,10 @@ static ALVoice *NewVoice(ALBufferParamsStruct *params)
|
|||||||
voice->avail_buffers = node;
|
voice->avail_buffers = node;
|
||||||
}
|
}
|
||||||
|
|
||||||
voice->rate = (ALuint)params->lpwfxFormat->nSamplesPerSec;
|
voice->rate = (ALuint)params->nSamplesPerSec;
|
||||||
|
|
||||||
// Emulator supports only mono and stereo
|
// Emulator supports only mono and stereo
|
||||||
if (params->lpwfxFormat->nChannels == 2)
|
if (params->nChannels == 2)
|
||||||
{
|
{
|
||||||
voice->format = AL_FORMAT_STEREO16;
|
voice->format = AL_FORMAT_STEREO16;
|
||||||
}
|
}
|
||||||
@ -687,7 +687,7 @@ static long ALGetStatus(void *_this, unsigned long *status)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static long OpenALCreateSoundBuffer(ALBufferParamsStruct *params, ALSoundBufferStruct **soundbuf_struct, void *extra_data)
|
static long OpenALCreateSoundBuffer(AudioParams_s *params, ALSoundBufferStruct **soundbuf_struct, void *extra_data)
|
||||||
{
|
{
|
||||||
LOG("OpenALCreateSoundBuffer ...");
|
LOG("OpenALCreateSoundBuffer ...");
|
||||||
assert(*soundbuf_struct == NULL);
|
assert(*soundbuf_struct == NULL);
|
||||||
|
@ -31,8 +31,6 @@
|
|||||||
|
|
||||||
typedef struct IDirectSoundBuffer ALSoundBufferStruct;
|
typedef struct IDirectSoundBuffer ALSoundBufferStruct;
|
||||||
|
|
||||||
typedef struct DSBUFFERDESC ALBufferParamsStruct;
|
|
||||||
|
|
||||||
struct ALPlayBuf;
|
struct ALPlayBuf;
|
||||||
typedef struct ALPlayBuf {
|
typedef struct ALPlayBuf {
|
||||||
const ALuint bufid; // the hash id
|
const ALuint bufid; // the hash id
|
||||||
|
@ -101,21 +101,14 @@ bool DSGetLock(LPDIRECTSOUNDBUFFER pVoice, unsigned long dwOffset, unsigned long
|
|||||||
|
|
||||||
int DSGetSoundBuffer(VOICE* pVoice, unsigned long dwFlags, unsigned long dwBufferSize, unsigned long nSampleRate, int nChannels)
|
int DSGetSoundBuffer(VOICE* pVoice, unsigned long dwFlags, unsigned long dwBufferSize, unsigned long nSampleRate, int nChannels)
|
||||||
{
|
{
|
||||||
WAVEFORMATEX wavfmt;
|
AudioParams_s params = { 0 };
|
||||||
DSBUFFERDESC dsbdesc;
|
|
||||||
|
|
||||||
wavfmt.wFormatTag = WAVE_FORMAT_PCM;
|
params.nChannels = nChannels;
|
||||||
wavfmt.nChannels = nChannels;
|
params.nSamplesPerSec = nSampleRate;
|
||||||
wavfmt.nSamplesPerSec = nSampleRate;
|
params.wBitsPerSample = 16;
|
||||||
wavfmt.wBitsPerSample = 16;
|
params.nBlockAlign = (params.nChannels == 1) ? 2 : 4;
|
||||||
wavfmt.nBlockAlign = wavfmt.nChannels==1 ? 2 : 4;
|
params.nAvgBytesPerSec = params.nBlockAlign * params.nSamplesPerSec;
|
||||||
wavfmt.nAvgBytesPerSec = wavfmt.nBlockAlign * wavfmt.nSamplesPerSec;
|
params.dwBufferBytes = dwBufferSize;
|
||||||
|
|
||||||
memset (&dsbdesc, 0, sizeof (dsbdesc));
|
|
||||||
dsbdesc.dwSize = sizeof (dsbdesc);
|
|
||||||
dsbdesc.dwBufferBytes = dwBufferSize;
|
|
||||||
dsbdesc.lpwfxFormat = &wavfmt;
|
|
||||||
dsbdesc.dwFlags = dwFlags | DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_STICKYFOCUS;
|
|
||||||
|
|
||||||
// Are buffers released when g_lpDS OR pVoice->lpDSBvoice is released?
|
// Are buffers released when g_lpDS OR pVoice->lpDSBvoice is released?
|
||||||
// . From DirectX doc:
|
// . From DirectX doc:
|
||||||
@ -126,7 +119,7 @@ int DSGetSoundBuffer(VOICE* pVoice, unsigned long dwFlags, unsigned long dwBuffe
|
|||||||
g_lpDS->DestroySoundBuffer(&pVoice->lpDSBvoice);
|
g_lpDS->DestroySoundBuffer(&pVoice->lpDSBvoice);
|
||||||
//DSReleaseSoundBuffer(pVoice);
|
//DSReleaseSoundBuffer(pVoice);
|
||||||
}
|
}
|
||||||
int hr = g_lpDS->CreateSoundBuffer(&dsbdesc, &pVoice->lpDSBvoice, g_lpDS);
|
int hr = g_lpDS->CreateSoundBuffer(¶ms, &pVoice->lpDSBvoice, g_lpDS);
|
||||||
if(FAILED(hr))
|
if(FAILED(hr))
|
||||||
return hr;
|
return hr;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user