mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-10 16:03:15 -04:00
Symbian: audio fixes
This commit is contained in:
parent
74bb2a5fb3
commit
bae80d369f
@ -12,6 +12,11 @@ extern "C" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#define AUDIO_COMMON_ALLOC
|
#define AUDIO_COMMON_ALLOC
|
||||||
|
#if defined CC_BUILD_SYMBIAN_3
|
||||||
|
#define POOL_MAX_CONTEXTS 8
|
||||||
|
#else
|
||||||
|
#define POOL_MAX_CONTEXTS 2
|
||||||
|
#endif
|
||||||
|
|
||||||
struct AudioBuffer {
|
struct AudioBuffer {
|
||||||
int available;
|
int available;
|
||||||
@ -49,9 +54,7 @@ public:
|
|||||||
void MaoscPlayComplete(TInt aError);
|
void MaoscPlayComplete(TInt aError);
|
||||||
void Open();
|
void Open();
|
||||||
void Stop();
|
void Stop();
|
||||||
void Close();
|
|
||||||
void Start();
|
void Start();
|
||||||
void Write(struct AudioChunk* chunk);
|
|
||||||
void Request();
|
void Request();
|
||||||
|
|
||||||
|
|
||||||
@ -65,10 +68,10 @@ private:
|
|||||||
TMdaAudioDataSettings iAudioSettings;
|
TMdaAudioDataSettings iAudioSettings;
|
||||||
struct AudioContext* iContext;
|
struct AudioContext* iContext;
|
||||||
TPtrC8 iPtr;
|
TPtrC8 iPtr;
|
||||||
TBuf8<256> iSilence;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
CAudioStream::CAudioStream(struct AudioContext* ctx) :
|
CAudioStream::CAudioStream(struct AudioContext* ctx) :
|
||||||
|
iState(STATE_STOPPED),
|
||||||
iContext(ctx) { }
|
iContext(ctx) { }
|
||||||
|
|
||||||
CAudioStream::~CAudioStream() {
|
CAudioStream::~CAudioStream() {
|
||||||
@ -89,8 +92,6 @@ CAudioStream* CAudioStream::NewL(struct AudioContext* ctx) {
|
|||||||
|
|
||||||
void CAudioStream::ConstructL() {
|
void CAudioStream::ConstructL() {
|
||||||
iOutputStream = CMdaAudioOutputStream::NewL(*this);
|
iOutputStream = CMdaAudioOutputStream::NewL(*this);
|
||||||
iSilence.SetMax();
|
|
||||||
iSilence.FillZ();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CAudioStream::Open() {
|
void CAudioStream::Open() {
|
||||||
@ -101,15 +102,15 @@ void CAudioStream::Open() {
|
|||||||
|
|
||||||
void CAudioStream::Stop() {
|
void CAudioStream::Stop() {
|
||||||
if (iState & (STATE_STARTED | STATE_INITIALIZED)) {
|
if (iState & (STATE_STARTED | STATE_INITIALIZED)) {
|
||||||
Close();
|
iState &= ~STATE_INITIALIZED;
|
||||||
|
iOutputStream->Stop();
|
||||||
|
iState &= ~STATE_STARTED;
|
||||||
iState |= STATE_STOPPED;
|
iState |= STATE_STOPPED;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
for (int i = 0; i < iContext->count; i++) {
|
||||||
void CAudioStream::Close() {
|
iContext->bufs[i].available = true;
|
||||||
iState &= ~STATE_INITIALIZED;
|
}
|
||||||
iOutputStream->Stop();
|
|
||||||
iState &= ~STATE_STARTED;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CAudioStream::Start() {
|
void CAudioStream::Start() {
|
||||||
@ -171,14 +172,19 @@ void CAudioStream::MaoscOpenComplete(TInt aError) {
|
|||||||
Request();
|
Request();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Audio_Warn(aError, "Failed to open audio stream");
|
Audio_Warn(aError, "opening audio stream");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CAudioStream::MaoscBufferCopied(TInt aError, const TDesC8& aBuffer) {
|
void CAudioStream::MaoscBufferCopied(TInt aError, const TDesC8& aBuffer) {
|
||||||
iPtr.Set(KNullDesC8);
|
iPtr.Set(KNullDesC8);
|
||||||
|
|
||||||
|
// MaoscPlayComplete() is not called in older versions
|
||||||
|
#if defined CC_BUILD_SYMBIAN_3
|
||||||
|
if (iContext->count > 1) {
|
||||||
|
#else
|
||||||
if (iContext->count) {
|
if (iContext->count) {
|
||||||
|
#endif
|
||||||
struct AudioBuffer* buf = &iContext->bufs[iContext->bufHead];
|
struct AudioBuffer* buf = &iContext->bufs[iContext->bufHead];
|
||||||
iContext->bufHead = (iContext->bufHead + 1) % iContext->count;
|
iContext->bufHead = (iContext->bufHead + 1) % iContext->count;
|
||||||
buf->available = true;
|
buf->available = true;
|
||||||
@ -197,18 +203,15 @@ void CAudioStream::MaoscPlayComplete(TInt aError) {
|
|||||||
iPtr.Set(KNullDesC8);
|
iPtr.Set(KNullDesC8);
|
||||||
iState &= ~STATE_STARTED;
|
iState &= ~STATE_STARTED;
|
||||||
|
|
||||||
if (aError != KErrNone) {
|
for (int i = 0; i < iContext->count; i++) {
|
||||||
// Audio_Warn(aError, "MaoscPlayComplete");
|
iContext->bufs[i].available = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CAudioStream::Write(struct AudioChunk* chunk) {
|
|
||||||
iPtr.Set((const TUint8*)chunk->data, (TInt)chunk->size);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CAudioStream::Request() {
|
void CAudioStream::Request() {
|
||||||
if (iState & STATE_INITIALIZED) {
|
if (iState & STATE_INITIALIZED) {
|
||||||
iPtr.Set(KNullDesC8);
|
iPtr.Set(KNullDesC8);
|
||||||
|
TInt err = 0;
|
||||||
|
|
||||||
if (iState & STATE_CHANGE_FORMAT) {
|
if (iState & STATE_CHANGE_FORMAT) {
|
||||||
iState &= ~STATE_CHANGE_FORMAT;
|
iState &= ~STATE_CHANGE_FORMAT;
|
||||||
@ -223,7 +226,12 @@ void CAudioStream::Request() {
|
|||||||
channels = TMdaAudioDataSettings::EChannelsStereo;
|
channels = TMdaAudioDataSettings::EChannelsStereo;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
iOutputStream->SetAudioPropertiesL(sampleRate, channels);
|
TRAP(err, iOutputStream->SetAudioPropertiesL(sampleRate, channels));
|
||||||
|
if (err != 0) {
|
||||||
|
Audio_Warn(err, "setting audio properties");
|
||||||
|
Stop();
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (iState & STATE_CHANGE_VOLUME) {
|
if (iState & STATE_CHANGE_VOLUME) {
|
||||||
@ -232,7 +240,7 @@ void CAudioStream::Request() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (iState & STATE_STARTED) {
|
if (iState & STATE_STARTED) {
|
||||||
struct AudioBuffer* buf = &iContext->bufs[iContext->bufHead];
|
struct AudioBuffer* buf = &iContext->bufs[iContext->bufHead];
|
||||||
if (buf->size == 0 && buf->samples == NULL) {
|
if (buf->size == 0 && buf->samples == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -242,12 +250,12 @@ void CAudioStream::Request() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (iPtr.Length() == 0) {
|
if (iPtr.Length() == 0) {
|
||||||
iPtr.Set(iSilence);
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
TRAPD(err, iOutputStream->WriteL(iPtr));
|
TRAP(err, iOutputStream->WriteL(iPtr));
|
||||||
if (err != KErrNone) {
|
if (err != KErrNone) {
|
||||||
Audio_Warn(err, "Failed to write to audio stream");
|
Audio_Warn(err, "writing to audio stream");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -299,7 +307,7 @@ cc_result Audio_QueueChunk(struct AudioContext* ctx, struct AudioChunk* chunk) {
|
|||||||
if (!buf->available) continue;
|
if (!buf->available) continue;
|
||||||
|
|
||||||
buf->samples = chunk->data;
|
buf->samples = chunk->data;
|
||||||
buf->size = chunk->size;
|
buf->size = chunk->size;
|
||||||
buf->available = false;
|
buf->available = false;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -313,16 +321,16 @@ cc_result Audio_Play(struct AudioContext* ctx) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
cc_result Audio_SetFormat(struct AudioContext* ctx, int channels, int sampleRate, int playbackRate) {
|
cc_result Audio_SetFormat(struct AudioContext* ctx, int channels, int sampleRate, int playbackRate) {
|
||||||
int sampleRateNew = Audio_AdjustSampleRate(sampleRate, playbackRate);
|
// playbackRate not supported
|
||||||
|
int sampleRateNew = /* Audio_AdjustSampleRate(sampleRate, playbackRate) */ sampleRate;
|
||||||
|
|
||||||
if (ctx->channels != channels || ctx->sampleRate != sampleRateNew) {
|
if (ctx->channels != channels || ctx->sampleRate != sampleRateNew) {
|
||||||
ctx->stream->Stop();
|
|
||||||
ctx->channels = channels;
|
ctx->channels = channels;
|
||||||
ctx->sampleRate = sampleRateNew;
|
ctx->sampleRate = sampleRateNew;
|
||||||
ctx->stream->iState |= STATE_CHANGE_FORMAT;
|
ctx->stream->iState |= STATE_CHANGE_FORMAT;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(ctx->stream->iState & STATE_INITIALIZED)) {
|
if (ctx->stream->iState & STATE_STOPPED) {
|
||||||
ctx->stream->Open();
|
ctx->stream->Open();
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@ -376,9 +384,7 @@ cc_result StreamContext_Update(struct AudioContext* ctx, int* inUse) {
|
|||||||
*------------------------------------------------------Sound context------------------------------------------------------*
|
*------------------------------------------------------Sound context------------------------------------------------------*
|
||||||
*#########################################################################################################################*/
|
*#########################################################################################################################*/
|
||||||
cc_bool SoundContext_FastPlay(struct AudioContext* ctx, struct AudioData* data) {
|
cc_bool SoundContext_FastPlay(struct AudioContext* ctx, struct AudioData* data) {
|
||||||
int channels = data->channels;
|
return !ctx->channels || (ctx->channels == data->channels && ctx->sampleRate == data->sampleRate);
|
||||||
int sampleRate = Audio_AdjustSampleRate(data->sampleRate, data->rate);
|
|
||||||
return !ctx->channels || (ctx->channels == channels && ctx->sampleRate == sampleRate);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cc_result SoundContext_PlayData(struct AudioContext* ctx, struct AudioData* data) {
|
cc_result SoundContext_PlayData(struct AudioContext* ctx, struct AudioData* data) {
|
||||||
|
@ -114,7 +114,9 @@ void AudioBackend_LoadSounds(void) { Sounds_LoadDefault(); }
|
|||||||
*---------------------------------------------------Audio context code----------------------------------------------------*
|
*---------------------------------------------------Audio context code----------------------------------------------------*
|
||||||
*#########################################################################################################################*/
|
*#########################################################################################################################*/
|
||||||
struct AudioContext music_ctx;
|
struct AudioContext music_ctx;
|
||||||
|
#ifndef POOL_MAX_CONTEXTS
|
||||||
#define POOL_MAX_CONTEXTS 8
|
#define POOL_MAX_CONTEXTS 8
|
||||||
|
#endif
|
||||||
static struct AudioContext context_pool[POOL_MAX_CONTEXTS];
|
static struct AudioContext context_pool[POOL_MAX_CONTEXTS];
|
||||||
|
|
||||||
#ifndef CC_BUILD_NOSOUNDS
|
#ifndef CC_BUILD_NOSOUNDS
|
||||||
|
Loading…
x
Reference in New Issue
Block a user