mirror of
https://github.com/mauiaaron/apple2.git
synced 2025-01-01 07:30:45 +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_CTRLPOSITIONNOTIFY 0x00000100
|
||||
|
||||
|
||||
typedef struct {
|
||||
uint16_t wFormatTag;
|
||||
uint16_t nChannels;
|
||||
typedef struct AudioParams_s {
|
||||
uint16_t nChannels;
|
||||
unsigned long nSamplesPerSec;
|
||||
unsigned long nAvgBytesPerSec;
|
||||
uint16_t nBlockAlign;
|
||||
uint16_t wBitsPerSample;
|
||||
uint16_t cbSize;
|
||||
} WAVEFORMATEX, *LPWAVEFORMATEX;
|
||||
|
||||
typedef struct DSBUFFERDESC {
|
||||
unsigned long dwSize;
|
||||
unsigned long dwFlags;
|
||||
uint16_t nBlockAlign;
|
||||
uint16_t wBitsPerSample;
|
||||
unsigned long dwBufferBytes;
|
||||
unsigned long dwReserved;
|
||||
LPWAVEFORMATEX lpwfxFormat;
|
||||
} DSBUFFERDESC;
|
||||
} AudioParams_s;
|
||||
|
||||
typedef struct IDirectSound {
|
||||
|
||||
void *implementation_specific;
|
||||
|
||||
#define LPUNKNOWN void*
|
||||
int (*CreateSoundBuffer)(DSBUFFERDESC *pcDSBufferDesc, LPDIRECTSOUNDBUFFER * ppDSBuffer, LPUNKNOWN pUnkOuter);
|
||||
int (*CreateSoundBuffer)(AudioParams_s *pcDSBufferDesc, LPDIRECTSOUNDBUFFER * ppDSBuffer, LPUNKNOWN pUnkOuter);
|
||||
int (*DestroySoundBuffer)(LPDIRECTSOUNDBUFFER * ppDSBuffer);
|
||||
|
||||
} IDirectSound, *LPDIRECTSOUND;
|
||||
|
@ -18,7 +18,7 @@
|
||||
#include "audio/soundcore-openal.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);
|
||||
|
||||
typedef struct ALVoices {
|
||||
@ -138,7 +138,7 @@ long SoundSystemCreate(const char *sound_device, SoundSystemStruct **sound_struc
|
||||
}
|
||||
|
||||
(*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;
|
||||
|
||||
return 0;
|
||||
@ -257,7 +257,7 @@ static void DeleteVoice(ALVoice *voice)
|
||||
/* Creates a new voice object, and allocates the needed OpenAL source and
|
||||
* buffer objects. Error checking is simplified for the purposes of this
|
||||
* example, and will cause an abort if needed. */
|
||||
static ALVoice *NewVoice(ALBufferParamsStruct *params)
|
||||
static ALVoice *NewVoice(AudioParams_s *params)
|
||||
{
|
||||
ALVoice *voice = NULL;
|
||||
|
||||
@ -328,10 +328,10 @@ static ALVoice *NewVoice(ALBufferParamsStruct *params)
|
||||
voice->avail_buffers = node;
|
||||
}
|
||||
|
||||
voice->rate = (ALuint)params->lpwfxFormat->nSamplesPerSec;
|
||||
voice->rate = (ALuint)params->nSamplesPerSec;
|
||||
|
||||
// Emulator supports only mono and stereo
|
||||
if (params->lpwfxFormat->nChannels == 2)
|
||||
if (params->nChannels == 2)
|
||||
{
|
||||
voice->format = AL_FORMAT_STEREO16;
|
||||
}
|
||||
@ -687,7 +687,7 @@ static long ALGetStatus(void *_this, unsigned long *status)
|
||||
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 ...");
|
||||
assert(*soundbuf_struct == NULL);
|
||||
|
@ -31,8 +31,6 @@
|
||||
|
||||
typedef struct IDirectSoundBuffer ALSoundBufferStruct;
|
||||
|
||||
typedef struct DSBUFFERDESC ALBufferParamsStruct;
|
||||
|
||||
struct ALPlayBuf;
|
||||
typedef struct ALPlayBuf {
|
||||
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)
|
||||
{
|
||||
WAVEFORMATEX wavfmt;
|
||||
DSBUFFERDESC dsbdesc;
|
||||
AudioParams_s params = { 0 };
|
||||
|
||||
wavfmt.wFormatTag = WAVE_FORMAT_PCM;
|
||||
wavfmt.nChannels = nChannels;
|
||||
wavfmt.nSamplesPerSec = nSampleRate;
|
||||
wavfmt.wBitsPerSample = 16;
|
||||
wavfmt.nBlockAlign = wavfmt.nChannels==1 ? 2 : 4;
|
||||
wavfmt.nAvgBytesPerSec = wavfmt.nBlockAlign * wavfmt.nSamplesPerSec;
|
||||
|
||||
memset (&dsbdesc, 0, sizeof (dsbdesc));
|
||||
dsbdesc.dwSize = sizeof (dsbdesc);
|
||||
dsbdesc.dwBufferBytes = dwBufferSize;
|
||||
dsbdesc.lpwfxFormat = &wavfmt;
|
||||
dsbdesc.dwFlags = dwFlags | DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_STICKYFOCUS;
|
||||
params.nChannels = nChannels;
|
||||
params.nSamplesPerSec = nSampleRate;
|
||||
params.wBitsPerSample = 16;
|
||||
params.nBlockAlign = (params.nChannels == 1) ? 2 : 4;
|
||||
params.nAvgBytesPerSec = params.nBlockAlign * params.nSamplesPerSec;
|
||||
params.dwBufferBytes = dwBufferSize;
|
||||
|
||||
// Are buffers released when g_lpDS OR pVoice->lpDSBvoice is released?
|
||||
// . From DirectX doc:
|
||||
@ -126,7 +119,7 @@ int DSGetSoundBuffer(VOICE* pVoice, unsigned long dwFlags, unsigned long dwBuffe
|
||||
g_lpDS->DestroySoundBuffer(&pVoice->lpDSBvoice);
|
||||
//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))
|
||||
return hr;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user