Merge pull request #2030 from vgturtle127/beautification-12

Beautification 12 - Source/Project64-audio directory
This commit is contained in:
zilmar 2021-04-12 13:27:47 +09:30 committed by GitHub
commit fe6bd038f0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 161 additions and 142 deletions

View File

@ -7,6 +7,7 @@
// Copyright(C) 2003 JttL
// Copyright(C) 2002 Hacktarux
// GNU/GPLv2 licensed: https://gnu.org/licenses/gpl-2.0.html
#include <Common/Util.h>
#ifdef _WIN32
#include <Project64-audio/Driver/DirectSound.h>
@ -30,7 +31,7 @@ void SetTimerResolution ( void );
#define ENDIAN_SWAP_BYTE (~0 & 0x7 & 3)
#define BES(address) ((address) ^ ENDIAN_SWAP_BYTE)
/* Read header for type definition */
// Read header for type definition
AUDIO_INFO g_AudioInfo;
bool g_PluginInit = false;
@ -71,7 +72,7 @@ EXPORT void CALL AiDacrateChanged(int SystemType)
WriteTrace(TraceAudioInterface, TraceDebug, "Start (SystemType: %d)", SystemType);
if (!g_PluginInit)
{
WriteTrace(TraceAudioInterface, TraceNotice, "Plugin has not been initilized");
WriteTrace(TraceAudioInterface, TraceNotice, "Plugin has not been initialized");
WriteTrace(TraceAudioInterface, TraceDebug, "Done");
return;
}
@ -97,7 +98,7 @@ EXPORT void CALL AiDacrateChanged(int SystemType)
if (Frequency < 8000)
{
WriteTrace(TraceAudioDriver, TraceDebug, "Not Audio Data!");
WriteTrace(TraceAudioDriver, TraceDebug, "Not audio data!");
return;
}
@ -156,7 +157,7 @@ EXPORT void CALL AiUpdate(int32_t Wait)
}
else
{
pjutil::Sleep(1); // TODO: Fixme -- Ai Update appears to be problematic
pjutil::Sleep(1); // TODO: Fix this: Ai update appears to be problematic
}
WriteTrace(TraceAudioInterface, TraceDebug, "Done");
}
@ -200,9 +201,9 @@ EXPORT void CALL GetDllInfo(PLUGIN_INFO * PluginInfo)
PluginInfo->Version = 0x0101;
PluginInfo->Type = PLUGIN_TYPE_AUDIO;
#ifdef _DEBUG
sprintf(PluginInfo->Name, "Project64 Audio Plugin (Debug): %s", VER_FILE_VERSION_STR);
sprintf(PluginInfo->Name, "Project64 audio plugin (Debug): %s", VER_FILE_VERSION_STR);
#else
sprintf(PluginInfo->Name, "Project64 Audio Plugin: %s", VER_FILE_VERSION_STR);
sprintf(PluginInfo->Name, "Project64 audio plugin: %s", VER_FILE_VERSION_STR);
#endif
PluginInfo->MemoryBswaped = true;
PluginInfo->NormalMemory = false;

View File

@ -1,14 +1,12 @@
/**********************************************************************************
Common Audio plugin spec, version #1.1
**********************************************************************************
Notes:
------
// Common audio plugin spec, version 1.1
Setting the approprate bits in the MI_INTR_REG and calling CheckInterrupts which
/*
Notes:
Setting the appropriate bits in the MI_INTR_REG and calling CheckInterrupts which
are both passed to the DLL in InitiateAudio will generate an Interrupt from with in
the plugin.
*/
**********************************************************************************/
#pragma once
#include <Common/stdtypes.h>
@ -32,20 +30,21 @@ enum
enum
{
AI_STATUS_FIFO_FULL = 0x80000000, /* Bit 31: full */
AI_STATUS_DMA_BUSY = 0x40000000, /* Bit 30: busy */
AI_STATUS_FIFO_FULL = 0x80000000, // Bit 31: full
AI_STATUS_DMA_BUSY = 0x40000000, // Bit 30: busy
MI_INTR_AI = 0x04, /* Bit 2: AI intr */
MI_INTR_AI = 0x04, // Bit 2: AI INTR
AI_CONTROL_DMA_ON = 0x01,
AI_CONTROL_DMA_OFF = 0x00,
};
/***** Structures *****/
// Structures
typedef struct
{
uint16_t Version; /* Should be set to 0x0101 */
uint16_t Type; /* Set to PLUGIN_TYPE_AUDIO */
char Name[100]; /* Name of the DLL */
uint16_t Version; // Should be set to 0x0101
uint16_t Type; // Set to PLUGIN_TYPE_AUDIO
char Name[100]; // Name of the DLL
int32_t NormalMemory;
int32_t MemoryBswaped;
} PLUGIN_INFO;
@ -55,12 +54,10 @@ typedef struct
void * hwnd;
void * hinst;
int32_t MemoryBswaped; // If this is set to TRUE, then the memory has been pre
// bswap on a dword (32 bits) boundry
int32_t MemoryBswaped; // If this is set to TRUE, then the memory has been pre-bswap'd on a DWORD (32-bit) boundary
// eg. the first 8 bytes are stored like this:
// 4 3 2 1 8 7 6 5
uint8_t * HEADER; // This is the rom header (first 40h bytes of the rom
uint8_t * HEADER; // This is the ROM header (first 40h bytes of the ROM)
// This will be in the same memory format as the rest of the memory.
uint8_t * RDRAM;
uint8_t * DMEM;
@ -78,127 +75,139 @@ typedef struct
void(CALL *CheckInterrupts)(void);
} AUDIO_INFO;
/******************************************************************
/*
Function: AiDacrateChanged
Purpose: This function is called to notify the dll that the
Purpose: This function is called to notify the DLL that the
AiDacrate registers value has been changed.
input: The System type:
SYSTEM_NTSC 0
SYSTEM_PAL 1
SYSTEM_MPAL 2
output: none
*******************************************************************/
*/
EXPORT void CALL AiDacrateChanged(int32_t SystemType);
/******************************************************************
/*
Function: AiLenChanged
Purpose: This function is called to notify the dll that the
Purpose: This function is called to notify the DLL that the
AiLen registers value has been changed.
input: none
output: none
*******************************************************************/
*/
EXPORT void CALL AiLenChanged(void);
/******************************************************************
/*
Function: AiReadLength
Purpose: This function is called to allow the dll to return the
Purpose: This function is called to allow the DLL to return the
value that AI_LEN_REG should equal
input: none
output: The amount of bytes still left to play.
*******************************************************************/
*/
EXPORT uint32_t CALL AiReadLength(void);
/******************************************************************
/*
Function: AiUpdate
Purpose: This function is called to allow the dll to update
Purpose: This function is called to allow the DLL to update
things on a regular basis (check how long to sound to
go, copy more stuff to the buffer, anyhting you like).
go, copy more stuff to the buffer, anything you like).
The function is designed to go in to the message loop
of the main window ... but can be placed anywhere you
of the main window...but can be placed anywhere you
like.
input: if Wait is set to true, then this function should wait
till there is a messgae in the its message queue.
till there is a message in its message queue.
output: none
*******************************************************************/
*/
EXPORT void CALL AiUpdate(int32_t Wait);
/******************************************************************
/*
Function: CloseDLL
Purpose: This function is called when the emulator is closing
down allowing the dll to de-initialise.
down allowing the DLL to de-initialize.
input: none
output: none
*******************************************************************/
*/
EXPORT void CALL CloseDLL(void);
/******************************************************************
/*
Function: DllAbout
Purpose: This function is optional function that is provided
to give further information about the DLL.
input: a handle to the window that calls this function
output: none
*******************************************************************/
*/
EXPORT void CALL DllAbout(void * hParent);
/******************************************************************
/*
Function: DllConfig
Purpose: This function is optional function that is provided
to allow the user to configure the dll
to allow the user to configure the DLL
input: a handle to the window that calls this function
output: none
*******************************************************************/
*/
EXPORT void CALL DllConfig(void * hParent);
/******************************************************************
/*
Function: DllTest
Purpose: This function is optional function that is provided
to allow the user to test the dll
to allow the user to test the DLL
input: a handle to the window that calls this function
output: none
*******************************************************************/
*/
EXPORT void CALL DllTest(void * hParent);
/******************************************************************
/*
Function: GetDllInfo
Purpose: This function allows the emulator to gather information
about the dll by filling in the PluginInfo structure.
input: a pointer to a PLUGIN_INFO stucture that needs to be
about the DLL by filling in the PluginInfo structure.
input: a pointer to a PLUGIN_INFO structure that needs to be
filled by the function. (see def above)
output: none
*******************************************************************/
*/
EXPORT void CALL GetDllInfo(PLUGIN_INFO * PluginInfo);
/******************************************************************
/*
Function: InitiateSound
Purpose: This function is called when the DLL is started to give
information from the emulator that the n64 audio
information from the emulator that the N64 audio
interface needs
Input: Audio_Info is passed to this function which is defined
above.
Output: TRUE on success
FALSE on failure to initialise
FALSE on failure to initialize
** note on interrupts **:
** Note on interrupts **:
To generate an interrupt set the appropriate bit in MI_INTR_REG
and then call the function CheckInterrupts to tell the emulator
that there is a waiting interrupt.
*******************************************************************/
*/
EXPORT int32_t CALL InitiateAudio(AUDIO_INFO Audio_Info);
/******************************************************************
/*
Function: ProcessAList
Purpose: This function is called when there is a Alist to be
processed. The Dll will have to work out all the info
processed. The DLL will have to work out all the info
about the AList itself.
input: none
output: none
*******************************************************************/
*/
EXPORT void CALL ProcessAList(void);
/******************************************************************
/*
Function: RomClosed
Purpose: This function is called when a rom is closed.
Purpose: This function is called when a ROM is closed.
input: none
output: none
*******************************************************************/
*/
EXPORT void CALL RomClosed(void);

View File

@ -1,3 +1,3 @@
#pragma once
void ConfigAudio(void * hParent);
void ConfigAudio(void * hParent);

View File

@ -3,6 +3,7 @@
// Copyright(C) 2001-2021 Project64.
// Copyright(C) 2000-2015 Azimer
// GNU/GPLv2 licensed: https://gnu.org/licenses/gpl-2.0.html
#include <windows.h>
#include <mmreg.h>
#include <dsound.h>
@ -87,7 +88,7 @@ void DirectSoundDriver::StopAudio()
m_AudioIsDone = true;
if (WaitForSingleObject((HANDLE)m_handleAudioThread, 5000) == WAIT_TIMEOUT)
{
WriteTrace(TraceAudioDriver, TraceError, "time out on close");
WriteTrace(TraceAudioDriver, TraceError, "Time out on close");
TerminateThread((HANDLE)m_handleAudioThread, 1);
}
@ -184,7 +185,7 @@ void DirectSoundDriver::AudioThreadProc()
if (!m_AudioIsDone)
{
WriteTrace(TraceAudioDriver, TraceDebug, "Audio Thread Started...");
WriteTrace(TraceAudioDriver, TraceDebug, "Audio thread started...");
DWORD dwStatus;
lpdsbuff->GetStatus(&dwStatus);
if ((dwStatus & DSBSTATUS_PLAYING) == 0)
@ -223,7 +224,7 @@ void DirectSoundDriver::AudioThreadProc()
// This means we had a buffer segment skipped
if (next_pos != write_pos)
{
WriteTrace(TraceAudioDriver, TraceDebug, "segment skipped");
WriteTrace(TraceAudioDriver, TraceDebug, "Buffer segment skipped");
}
// Store our last position
@ -244,7 +245,7 @@ void DirectSoundDriver::AudioThreadProc()
// Time to write out to the buffer
LPVOID lpvPtr1, lpvPtr2;
DWORD dwBytes1, dwBytes2;
WriteTrace(TraceAudioDriver, TraceVerbose, "Lock Buffer");
WriteTrace(TraceAudioDriver, TraceVerbose, "Lock buffer");
if (lpdsbuff->Lock(write_pos, m_LOCK_SIZE, &lpvPtr1, &dwBytes1, &lpvPtr2, &dwBytes2, 0) != DS_OK)
{
WriteTrace(TraceAudioDriver, TraceError, "Error locking sound buffer");
@ -262,8 +263,8 @@ void DirectSoundDriver::AudioThreadProc()
}
}
// Fills dwBytes to the Sound Buffer
WriteTrace(TraceAudioDriver, TraceVerbose, "Unlock Buffer");
// Fills dwBytes to the sound buffer
WriteTrace(TraceAudioDriver, TraceVerbose, "Unlock buffer");
if (FAILED(lpdsbuff->Unlock(lpvPtr1, dwBytes1, lpvPtr2, dwBytes2)))
{
WriteTrace(TraceAudioDriver, TraceError, "Error unlocking sound buffer");
@ -276,5 +277,5 @@ void DirectSoundDriver::AudioThreadProc()
{
lpdsbuf->Stop();
}
WriteTrace(TraceAudioDriver, TraceDebug, "Audio Thread Terminated...");
WriteTrace(TraceAudioDriver, TraceDebug, "Audio thread terminated...");
}

View File

@ -9,8 +9,8 @@ class DirectSoundDriver :
public:
DirectSoundDriver();
bool Initialize();
void StopAudio(); // Stops the Audio PlayBack (as if paused)
void StartAudio(); // Starts the Audio PlayBack (as if unpaused)
void StopAudio(); // Stops the audio playback (as if paused)
void StartAudio(); // Starts the audio playback (as if unpaused)
void SetFrequency(uint32_t Frequency, uint32_t BufferSize);
void SetVolume(uint32_t Volume);

View File

@ -7,6 +7,7 @@
// Copyright(C) 2003 JttL
// Copyright(C) 2002 Hacktarux
// GNU/GPLv2 licensed: https://gnu.org/licenses/gpl-2.0.html
#include "OpenSLES.h"
#include <Project64-audio/trace.h>
#include <Project64-audio/SettingsID.h>
@ -27,76 +28,80 @@ typedef struct threadLock_
} threadLock;
#endif
/* Default start-time size of primary buffer (in equivalent output samples).
This is the buffer where audio is loaded after it's extracted from n64's memory. */
// Default start-time size of primary buffer (in equivalent output samples)
// This is the buffer where audio is loaded after it's extracted from N64's memory
enum { PRIMARY_BUFFER_SIZE = 16384 };
/* Size of a single secondary buffer, in output samples. This is the requested size of OpenSLES's
hardware buffer, this should be a power of two. */
// Size of a single secondary buffer, in output samples. This is the requested size of OpenSLES's
// hardware buffer, this should be a power of two.
enum { SECONDARY_BUFFER_SIZE = 1024 };
/* This is the requested number of OpenSLES's hardware buffers */
// This is the requested number of OpenSLES's hardware buffers
enum { SECONDARY_BUFFER_NBR = 2 };
/* This sets default frequency what is used if rom doesn't want to change it.
Probably only game that needs this is Zelda: Ocarina Of Time Master Quest
*NOTICE* We should try to find out why Demos' frequencies are always wrong
They tend to rely on a default frequency, apparently, never the same one ;) */
// This sets default frequency what is used if ROM doesn't want to change it.
// Probably only game that needs this is Zelda: Ocarina Of Time Master Quest
// TODO: We should try to find out why Demos' frequencies are always wrong
// They tend to rely on a default frequency, but apparently never the same one ;)
enum { DEFAULT_FREQUENCY = 33600 };
/* number of bytes per sample */
// Number of bytes per sample
enum
{
N64_SAMPLE_BYTES = 4,
SLES_SAMPLE_BYTES = 4,
};
/* Pointer to the primary audio buffer */
// Pointer to the primary audio buffer
uint8_t * g_primaryBuffer = NULL;
/* Size of the primary buffer */
// Size of the primary buffer
uint32_t g_primaryBufferBytes = 0;
/* Pointer to secondary buffers */
// Pointer to secondary buffers
uint8_t ** g_secondaryBuffers = NULL;
/* Size of a single secondary buffer */
// Size of a single secondary buffer
uint32_t g_secondaryBufferBytes = 0;
/* Position in the primary buffer where next audio chunk should be placed */
// Position in the primary buffer where next audio chunk should be placed
uint32_t g_primaryBufferPos = 0;
/* Index of the next secondary buffer available */
// Index of the next secondary buffer available
uint32_t g_secondaryBufferIndex = 0;
/* Audio frequency, this is usually obtained from the game, but for compatibility we set default value */
// Audio frequency, this is usually obtained from the game, but for compatibility we set default value
uint32_t g_GameFreq = DEFAULT_FREQUENCY;
/* SpeedFactor is used to increase/decrease game playback speed */
// SpeedFactor is used to increase/decrease game playback speed
uint32_t g_speed_factor = 100;
/* Output Audio frequency */
// Output audio frequency
int g_OutputFreq = 44100;
/* Indicate that the audio plugin failed to initialize, so the emulator can keep running without sound */
// Indicate that the audio plugin failed to initialize, so the emulator can keep running without sound
bool g_critical_failure = false;
#ifdef ANDROID
/* Thread Lock */
// Thread Lock
threadLock g_lock;
/* Engine interfaces */
// Engine interfaces
SLObjectItf g_engineObject = NULL;
SLEngineItf g_engineEngine = NULL;
/* Output mix interfaces */
// Output mix interfaces
SLObjectItf g_outputMixObject = NULL;
/* Player interfaces */
// Player interfaces
SLObjectItf g_playerObject = NULL;
SLPlayItf g_playerPlay = NULL;
/* Buffer queue interfaces */
// Buffer queue interfaces
SLAndroidSimpleBufferQueueItf g_bufferQueue = NULL;
#endif
@ -128,7 +133,7 @@ static void CloseAudio(void)
g_primaryBufferPos = 0;
g_secondaryBufferIndex = 0;
/* Delete Primary buffer */
// Delete primary buffer
if (g_primaryBuffer != NULL)
{
WriteTrace(TraceAudioInitShutdown, TraceDebug, "Delete g_primaryBuffer (%p)", g_primaryBuffer);
@ -137,7 +142,7 @@ static void CloseAudio(void)
g_primaryBuffer = NULL;
}
/* Delete Secondary buffers */
// Delete secondary buffers
if (g_secondaryBuffers != NULL)
{
for (uint32_t i = 0; i < SECONDARY_BUFFER_NBR; i++)
@ -155,7 +160,7 @@ static void CloseAudio(void)
g_secondaryBuffers = NULL;
}
#ifdef ANDROID
/* Destroy buffer queue audio player object, and invalidate all associated interfaces */
// Destroy buffer queue audio player object, and invalidate all associated interfaces
if (g_playerObject != NULL)
{
SLuint32 state = SL_PLAYSTATE_PLAYING;
@ -172,14 +177,14 @@ static void CloseAudio(void)
g_bufferQueue = NULL;
}
/* Destroy output mix object, and invalidate all associated interfaces */
// Destroy output mix object, and invalidate all associated interfaces
if (g_outputMixObject != NULL)
{
(*g_outputMixObject)->Destroy(g_outputMixObject);
g_outputMixObject = NULL;
}
/* Destroy engine object, and invalidate all associated interfaces */
// Destroy engine object, and invalidate all associated interfaces
if (g_engineObject != NULL)
{
(*g_engineObject)->Destroy(g_engineObject);
@ -187,7 +192,7 @@ static void CloseAudio(void)
g_engineEngine = NULL;
}
/* Destroy thread Locks */
// Destroy thread Locks
pthread_cond_signal(&(g_lock.cond));
pthread_mutex_unlock(&(g_lock.mutex));
pthread_cond_destroy(&(g_lock.cond));
@ -204,7 +209,7 @@ static bool CreateSecondaryBuffers(void)
WriteTrace(TraceAudioInitShutdown, TraceDebug, "Allocating memory for %d secondary audio buffers: %i bytes.", SECONDARY_BUFFER_NBR, secondaryBytes);
/* Allocate number of secondary buffers */
// Allocate number of secondary buffers
g_secondaryBuffers = new uint8_t *[SECONDARY_BUFFER_NBR];
if (g_secondaryBuffers == NULL)
@ -214,7 +219,7 @@ static bool CreateSecondaryBuffers(void)
return false;
}
/* Allocate size of each secondary buffers */
// Allocate size of each secondary buffers
for (uint32_t i = 0; i < SECONDARY_BUFFER_NBR; i++)
{
g_secondaryBuffers[i] = new uint8_t[secondaryBytes];
@ -259,7 +264,7 @@ static int resample(unsigned char *input, int /*input_avail*/, int oldsamplerate
if ((error = speex_resampler_process_interleaved_int(spx_state, (const spx_int16_t *)input, &in_len, (spx_int16_t *)output, &out_len)))
{
memset(output, 0, output_needed);
return input_avail; // number of bytes consumed
return input_avail; // Number of bytes consumed
}
return in_len * 4;
}
@ -267,9 +272,9 @@ static int resample(unsigned char *input, int /*input_avail*/, int oldsamplerate
#ifdef USE_SRC
if (Resample == RESAMPLER_SRC)
{
// the high quality resampler needs more input than the samplerate ratio would indicate to work properly
// The high quality resampler needs more input than the sample rate ratio would indicate to work properly
if (input_avail > output_needed * 3 / 2)
input_avail = output_needed * 3 / 2; // just to avoid too much short-float-short conversion time
input_avail = output_needed * 3 / 2; // Just to avoid too much short-float-short conversion time
if (_src_len < input_avail * 2 && input_avail > 0)
{
if (_src) free(_src);
@ -303,7 +308,7 @@ static int resample(unsigned char *input, int /*input_avail*/, int oldsamplerate
if ((error = src_process(src_state, &src_data)))
{
memset(output, 0, output_needed);
return input_avail; // number of bytes consumed
return input_avail; // Number of bytes consumed
}
src_float_to_short_array(_dest, (short *)output, output_needed / 2);
return src_data.input_frames_used * 4;
@ -327,7 +332,7 @@ static int resample(unsigned char *input, int /*input_avail*/, int oldsamplerate
}
else criteria += const2;
}
return j * 4; //number of bytes consumed
return j * 4; // Number of bytes consumed
}
// newsamplerate < oldsamplerate, this only happens when speed_factor > 1
for (i = 0; i < output_needed / 4; i++)
@ -335,10 +340,10 @@ static int resample(unsigned char *input, int /*input_avail*/, int oldsamplerate
j = i * oldsamplerate / newsamplerate;
pdest[i] = psrc[j];
}
return j * 4; //number of bytes consumed
return j * 4; // Number of bytes consumed
}
/* This callback handler is called every time a buffer finishes playing */
// This callback handler is called every time a buffer finishes playing
#ifdef ANDROID
void queueCallback(SLAndroidSimpleBufferQueueItf caller, void *context)
{
@ -367,19 +372,19 @@ void OpenSLESDriver::AI_SetFrequency(uint32_t freq, uint32_t BufferSize)
if (g_GameFreq == freq && g_primaryBuffer != NULL)
{
WriteTrace(TraceAudioInitShutdown, TraceInfo, "we are already using this frequency, so ignore it (freq: %d)", freq);
WriteTrace(TraceAudioInitShutdown, TraceInfo, "We are already using this frequency, so ignore it (freq: %d)", freq);
WriteTrace(TraceAudioInitShutdown, TraceDebug, "Done");
return;
}
if (g_critical_failure)
{
WriteTrace(TraceAudioInitShutdown, TraceInfo, "had a critical failure in setting up plugin, so ignore init");
WriteTrace(TraceAudioInitShutdown, TraceInfo, "Critical failure in setting up plugin, ignoring init...");
WriteTrace(TraceAudioInitShutdown, TraceDebug, "Done");
return;
}
/* This is important for the sync */
// This is important for the sync
g_GameFreq = freq;
#ifdef ANDROID
@ -408,10 +413,10 @@ void OpenSLESDriver::AI_SetFrequency(uint32_t freq, uint32_t BufferSize)
WriteTrace(TraceAudioInitShutdown, TraceInfo, "Requesting frequency: %iHz.", g_OutputFreq);
/* Close everything because InitializeAudio can be called more than once */
// Close everything because InitializeAudio can be called more than once
CloseAudio();
/* Create primary buffer */
// Create primary buffer
if (!CreatePrimaryBuffer())
{
WriteTrace(TraceAudioInitShutdown, TraceError, "CreatePrimaryBuffer failed");
@ -421,7 +426,7 @@ void OpenSLESDriver::AI_SetFrequency(uint32_t freq, uint32_t BufferSize)
return;
}
/* Create secondary buffers */
// Create secondary buffers
if (!CreateSecondaryBuffers())
{
WriteTrace(TraceAudioInitShutdown, TraceError, "CreateSecondaryBuffers failed");
@ -432,7 +437,7 @@ void OpenSLESDriver::AI_SetFrequency(uint32_t freq, uint32_t BufferSize)
}
#ifdef ANDROID
/* Create thread Locks to ensure synchronization between callback and processing code */
// Create thread Locks to ensure synchronization between callback and processing code
if (pthread_mutex_init(&(g_lock.mutex), (pthread_mutexattr_t*)NULL) != 0)
{
WriteTrace(TraceAudioInitShutdown, TraceError, "pthread_mutex_init failed");
@ -453,7 +458,7 @@ void OpenSLESDriver::AI_SetFrequency(uint32_t freq, uint32_t BufferSize)
g_lock.value = g_lock.limit = SECONDARY_BUFFER_NBR;
pthread_mutex_unlock(&(g_lock.mutex));
/* Engine object */
// Engine object
SLresult result = slCreateEngine(&g_engineObject, 0, NULL, 0, NULL, NULL);
if (result != SL_RESULT_SUCCESS)
{
@ -480,7 +485,7 @@ void OpenSLESDriver::AI_SetFrequency(uint32_t freq, uint32_t BufferSize)
if (result == SL_RESULT_SUCCESS)
{
/* Output mix object */
// Output mix object
result = (*g_engineEngine)->CreateOutputMix(g_engineEngine, &g_outputMixObject, 0, NULL, NULL);
if (result != SL_RESULT_SUCCESS)
{
@ -506,11 +511,11 @@ void OpenSLESDriver::AI_SetFrequency(uint32_t freq, uint32_t BufferSize)
SLDataSource audioSrc = { &loc_bufq, &format_pcm };
/* Configure audio sink */
// Configure audio sink
SLDataLocator_OutputMix loc_outmix = { SL_DATALOCATOR_OUTPUTMIX, g_outputMixObject };
SLDataSink audioSnk = { &loc_outmix, NULL };
/* Create audio player */
// Create audio player
const SLInterfaceID ids1[] = { SL_IID_ANDROIDSIMPLEBUFFERQUEUE };
const SLboolean req1[] = { SL_BOOLEAN_TRUE };
result = (*g_engineEngine)->CreateAudioPlayer(g_engineEngine, &(g_playerObject), &audioSrc, &audioSnk, 1, ids1, req1);
@ -520,7 +525,7 @@ void OpenSLESDriver::AI_SetFrequency(uint32_t freq, uint32_t BufferSize)
}
}
/* Realize the player */
// Realize the player
if (result == SL_RESULT_SUCCESS)
{
result = (*g_playerObject)->Realize(g_playerObject, SL_BOOLEAN_FALSE);
@ -530,7 +535,7 @@ void OpenSLESDriver::AI_SetFrequency(uint32_t freq, uint32_t BufferSize)
}
}
/* Get the play interface */
// Get the play interface
if (result == SL_RESULT_SUCCESS)
{
result = (*g_playerObject)->GetInterface(g_playerObject, SL_IID_PLAY, &(g_playerPlay));
@ -540,7 +545,7 @@ void OpenSLESDriver::AI_SetFrequency(uint32_t freq, uint32_t BufferSize)
}
}
/* Get the buffer queue interface */
// Get the buffer queue interface
if (result == SL_RESULT_SUCCESS)
{
result = (*g_playerObject)->GetInterface(g_playerObject, SL_IID_ANDROIDSIMPLEBUFFERQUEUE, &(g_bufferQueue));
@ -550,7 +555,7 @@ void OpenSLESDriver::AI_SetFrequency(uint32_t freq, uint32_t BufferSize)
}
}
/* register callback on the buffer queue */
// Register callback on the buffer queue
if (result == SL_RESULT_SUCCESS)
{
result = (*g_bufferQueue)->RegisterCallback(g_bufferQueue, queueCallback, &g_lock);
@ -560,7 +565,7 @@ void OpenSLESDriver::AI_SetFrequency(uint32_t freq, uint32_t BufferSize)
}
}
/* set the player's state to playing */
// Set the player's state to playing
if (result == SL_RESULT_SUCCESS)
{
result = (*g_playerPlay)->SetPlayState(g_playerPlay, SL_PLAYSTATE_PLAYING);
@ -600,11 +605,11 @@ void OpenSLESDriver::AI_LenChanged(uint8_t *start, uint32_t length)
for (i = 0; i < length; i += 4)
{
/* Left channel */
// Left channel
g_primaryBuffer[g_primaryBufferPos + i] = start[i + 2];
g_primaryBuffer[g_primaryBufferPos + i + 1] = start[i + 3];
/* Right channel */
// Right channel
g_primaryBuffer[g_primaryBufferPos + i + 2] = start[i];
g_primaryBuffer[g_primaryBufferPos + i + 3] = start[i + 1];
}
@ -628,7 +633,7 @@ void OpenSLESDriver::AI_LenChanged(uint8_t *start, uint32_t length)
#ifdef ANDROID
pthread_mutex_lock(&(g_lock.mutex));
/* Wait for the next callback if no more output buffers available */
// Wait for the next callback if no more output buffers available
while (g_lock.value == 0)
{
pthread_cond_wait(&(g_lock.cond), &(g_lock.mutex));
@ -640,7 +645,7 @@ void OpenSLESDriver::AI_LenChanged(uint8_t *start, uint32_t length)
#endif
WriteTrace(TraceAudioInterface, TraceDebug, "Finished with lock");
// TODO: don't resample if speed_factor = 100 and newsamplerate ~= oldsamplerate
// TODO: Don't resample if speed_factor = 100 and newsamplerate ~= oldsamplerate
int input_used = resample(g_primaryBuffer, g_primaryBufferPos, oldsamplerate, g_secondaryBuffers[g_secondaryBufferIndex], g_secondaryBufferBytes, newsamplerate);
#ifdef ANDROID
@ -662,4 +667,4 @@ void OpenSLESDriver::AI_LenChanged(uint8_t *start, uint32_t length)
void OpenSLESDriver::AI_Update(bool Wait)
{
m_AiUpdateEvent.IsTriggered(Wait ? SyncEvent::INFINITE_TIMEOUT : 0);
}
}

View File

@ -7,6 +7,7 @@
// Copyright(C) 2003 JttL
// Copyright(C) 2002 Hacktarux
// GNU/GPLv2 licensed: https://gnu.org/licenses/gpl-2.0.html
#pragma once
#include <Common/SyncEvent.h>
#include <Project64-audio/Audio_1.1.h>
@ -24,4 +25,4 @@ public:
private:
SyncEvent m_AiUpdateEvent;
};
};

View File

@ -3,6 +3,7 @@
// Copyright(C) 2001-2021 Project64
// Copyright(C) 2000-2015 Azimer
// GNU/GPLv2 licensed: https://gnu.org/licenses/gpl-2.0.html
#include "SoundBase.h"
#include <Common/Util.h>
#include <Project64-audio/AudioSettings.h>
@ -164,7 +165,7 @@ void SoundDriverBase::BufferAudio()
m_AI_DMAPrimaryBytes -= 4;
if (m_AI_DMAPrimaryBytes == 0)
{
WriteTrace(TraceAudioDriver, TraceVerbose, "Emptied Primary Buffer");
WriteTrace(TraceAudioDriver, TraceVerbose, "Emptied primary buffer");
m_AI_DMAPrimaryBytes = m_AI_DMASecondaryBytes; m_AI_DMAPrimaryBuffer = m_AI_DMASecondaryBuffer; // Switch
m_AI_DMASecondaryBytes = 0; m_AI_DMASecondaryBuffer = NULL;
*g_AudioInfo.AI_STATUS_REG = AI_STATUS_DMA_BUSY;

View File

@ -3,6 +3,7 @@
// Copyright(C) 2001-2021 Project64
// Copyright(C) 2000-2015 Azimer
// GNU/GPLv2 licensed: https://gnu.org/licenses/gpl-2.0.html
#pragma once
#include <Common/SyncEvent.h>
#include <Common/CriticalSection.h>
@ -24,11 +25,11 @@ public:
virtual void StopAudio();
protected:
enum { MAX_SIZE = 48000 * 2 * 2 }; // Max Buffer Size (44100Hz * 16bit * Stereo)
enum { MAX_SIZE = 48000 * 2 * 2 }; // Max buffer size (44100Hz * 16-bit * stereo)
virtual bool Initialize();
void LoadAiBuffer(uint8_t *start, uint32_t length); // Reads in length amount of audio bytes
uint32_t m_MaxBufferSize; // Variable size determined by Playback rate
uint32_t m_MaxBufferSize; // Variable size determined by playback rate
CriticalSection m_CS;
private:
@ -38,7 +39,7 @@ private:
uint8_t *m_AI_DMAPrimaryBuffer, *m_AI_DMASecondaryBuffer;
uint32_t m_AI_DMAPrimaryBytes, m_AI_DMASecondaryBytes;
uint32_t m_BufferRemaining; // Buffer remaining
uint32_t m_CurrentReadLoc; // Currently playing Buffer
uint32_t m_CurrentWriteLoc; // Currently writing Buffer
uint32_t m_CurrentReadLoc; // Currently playing buffer
uint32_t m_CurrentWriteLoc; // Currently writing buffer
uint8_t m_Buffer[MAX_SIZE]; // Emulated buffers
};