Skip to content

Commit

Permalink
Fix windowws audio backend
Browse files Browse the repository at this point in the history
  • Loading branch information
UnknownShadow200 committed Mar 25, 2024
1 parent 56177f9 commit 17f0e51
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
3 changes: 0 additions & 3 deletions src/Audio.h
Expand Up @@ -66,11 +66,8 @@ cc_result Audio_Play(struct AudioContext* ctx);
cc_result Audio_Poll(struct AudioContext* ctx, int* inUse);
cc_result Audio_Pause(struct AudioContext* ctx); /* Only implemented with OpenSL ES backend */

/* Whether the given audio data can be played without recreating the underlying audio device */
cc_bool Audio_FastPlay(struct AudioContext* ctx, struct AudioData* data);
/* Outputs more detailed information about errors with audio. */
cc_bool Audio_DescribeError(cc_result res, cc_string* dst);

/* Allocates a group of chunks of data to store audio samples */
void Audio_AllocChunks(cc_uint32 size, void** chunks, int numChunks);
/* Frees a previously allocated group of chunks of data */
Expand Down
28 changes: 14 additions & 14 deletions src/AudioBackend.c
Expand Up @@ -10,6 +10,9 @@ void Audio_Warn(cc_result res, const char* action) {
Logger_Warn(res, action, Audio_DescribeError);
}

/* Whether the given audio data can be played without recreating the underlying audio device */
static cc_bool Audio_FastPlay(struct AudioContext* ctx, struct AudioData* data);

/* Common/Base methods */
static void AudioBase_Clear(struct AudioContext* ctx);
static cc_bool AudioBase_AdjustSound(struct AudioContext* ctx, void** data, cc_uint32* size);
Expand Down Expand Up @@ -264,7 +267,7 @@ cc_result Audio_Poll(struct AudioContext* ctx, int* inUse) {
*inUse = ctx->count - ctx->free; return 0;
}

cc_bool Audio_FastPlay(struct AudioContext* ctx, struct AudioData* data) {
static cc_bool Audio_FastPlay(struct AudioContext* ctx, struct AudioData* data) {
/* Channels/Sample rate is per buffer, not a per source property */
return true;
}
Expand Down Expand Up @@ -430,7 +433,7 @@ cc_result Audio_SetFormat(struct AudioContext* ctx, int channels, int sampleRate
void Audio_SetVolume(struct AudioContext* ctx, int volume) { ctx->volume = volume; }

cc_result Audio_QueueChunk(struct AudioContext* ctx, void* chunk, cc_uint32 dataSize) {
cc_result res = 0;
cc_result res;
WAVEHDR* hdr;
int i;

Expand All @@ -442,8 +445,8 @@ cc_result Audio_QueueChunk(struct AudioContext* ctx, void* chunk, cc_uint32 data
if (!(hdr->dwFlags & WHDR_DONE)) continue;

Mem_Set(hdr, 0, sizeof(WAVEHDR));
hdr->lpData = (LPSTR)ctx->_tmpData;
hdr->dwBufferLength = ctx->_tmpSize;
hdr->lpData = (LPSTR)chunk;
hdr->dwBufferLength = dataSize;
hdr->dwLoops = 1;

if ((res = waveOutPrepareHeader(ctx->handle, hdr, sizeof(WAVEHDR)))) return res;
Expand Down Expand Up @@ -475,7 +478,7 @@ cc_result Audio_Poll(struct AudioContext* ctx, int* inUse) {
}


cc_bool Audio_FastPlay(struct AudioContext* ctx, struct AudioData* data) {
static cc_bool Audio_FastPlay(struct AudioContext* ctx, struct AudioData* data) {
int channels = data->channels;
int sampleRate = Audio_AdjustSampleRate(data->sampleRate, data->rate);
return !ctx->channels || (ctx->channels == channels && ctx->sampleRate == sampleRate);
Expand Down Expand Up @@ -703,7 +706,7 @@ cc_result Audio_Poll(struct AudioContext* ctx, int* inUse) {
return res;
}

cc_bool Audio_FastPlay(struct AudioContext* ctx, struct AudioData* data) {
static cc_bool Audio_FastPlay(struct AudioContext* ctx, struct AudioData* data) {
return !ctx->channels || (ctx->channels == data->channels && ctx->sampleRate == data->sampleRate);
}

Expand Down Expand Up @@ -826,13 +829,11 @@ cc_result Audio_QueueChunk(struct AudioContext* ctx, void* chunk, cc_uint32 data
for (int i = 0; i < ctx->count; i++)
{
buf = &ctx->bufs[i];
//Platform_Log2("QUEUE_CHUNK: %i = %i", &ctx->chanID, &buf->status);
if (buf->status == NDSP_WBUF_QUEUED || buf->status == NDSP_WBUF_PLAYING)
continue;

buf->data_pcm16 = chunk;
buf->nsamples = dataSize / (sizeof(cc_int16) * (ctx->stereo ? 2 : 1));
//Platform_Log1("PLAYING ON: %i", &ctx->chanID);
DSP_FlushDataCache(buf->data_pcm16, dataSize);
ndspChnWaveBufAdd(ctx->chanID, buf);
return 0;
Expand All @@ -850,7 +851,6 @@ cc_result Audio_Poll(struct AudioContext* ctx, int* inUse) {
for (int i = 0; i < ctx->count; i++)
{
buf = &ctx->bufs[i];
//Platform_Log2("CHECK_CHUNK: %i = %i", &ctx->chanID, &buf->status);
if (buf->status == NDSP_WBUF_QUEUED || buf->status == NDSP_WBUF_PLAYING) {
count++; continue;
}
Expand All @@ -861,7 +861,7 @@ cc_result Audio_Poll(struct AudioContext* ctx, int* inUse) {
}


cc_bool Audio_FastPlay(struct AudioContext* ctx, struct AudioData* data) {
static cc_bool Audio_FastPlay(struct AudioContext* ctx, struct AudioData* data) {
return true;
}

Expand Down Expand Up @@ -1061,7 +1061,7 @@ cc_result Audio_Poll(struct AudioContext* ctx, int* inUse) {
return 0;
}

cc_bool Audio_FastPlay(struct AudioContext* ctx, struct AudioData* data) {
static cc_bool Audio_FastPlay(struct AudioContext* ctx, struct AudioData* data) {
return true;
}

Expand Down Expand Up @@ -1231,7 +1231,7 @@ cc_result Audio_Poll(struct AudioContext* ctx, int* inUse) {
return 0;
}

cc_bool Audio_FastPlay(struct AudioContext* ctx, struct AudioData* data) {
static cc_bool Audio_FastPlay(struct AudioContext* ctx, struct AudioData* data) {
return true;
}

Expand Down Expand Up @@ -1310,7 +1310,7 @@ cc_result Audio_Poll(struct AudioContext* ctx, int* inUse) {
return interop_AudioPoll(ctx->contextID, inUse);
}

cc_bool Audio_FastPlay(struct AudioContext* ctx, struct AudioData* data) {
static cc_bool Audio_FastPlay(struct AudioContext* ctx, struct AudioData* data) {
/* Channels/Sample rate is per buffer, not a per source property */
return true;
}
Expand Down Expand Up @@ -1364,7 +1364,7 @@ cc_result Audio_Poll(struct AudioContext* ctx, int* inUse) {
return ERR_NOT_SUPPORTED;
}

cc_bool Audio_FastPlay(struct AudioContext* ctx, struct AudioData* data) { return false; }
static cc_bool Audio_FastPlay(struct AudioContext* ctx, struct AudioData* data) { return false; }

cc_bool Audio_DescribeError(cc_result res, cc_string* dst) { return false; }
#endif
Expand Down

0 comments on commit 17f0e51

Please sign in to comment.