Permalink
Browse files

revert MixerImpl to 22050 Hz

  • Loading branch information...
1 parent 395d257 commit 288250760823d2cbbf30551bff209077bce38863 @cyxx committed Jul 1, 2015
Showing with 26 additions and 21 deletions.
  1. +17 −16 avi_player.cpp
  2. +2 −2 avi_player.h
  3. +7 −3 mixer.cpp
View
@@ -329,7 +329,7 @@ void Cinepak_Decoder::decode(const uint8_t *data, int dataSize) {
}
AVI_Player::AVI_Player(Mixer *mixer, SystemStub *stub)
- : _soundQueue(0), _mixer(mixer), _stub(stub) {
+ : _soundQueue(0), _soundTailQueue(0), _mixer(mixer), _stub(stub) {
}
AVI_Player::~AVI_Player() {
@@ -390,25 +390,21 @@ void AVI_Player::decodeAudioChunk(AVI_Chunk &c) {
sbq = 0;
}
}
-// _stub->lockAudio();
+ _stub->lockAudio();
if (sbq) {
if (!_soundQueue) {
_soundQueue = sbq;
} else {
- AVI_SoundBufferQueue *p = _soundQueue;
- while (1) {
- if (!p->next) {
- p->next = sbq;
- break;
- }
- p = p->next;
- }
+ AVI_SoundBufferQueue *p = _soundTailQueue;
+ assert(!p->next);
+ p->next = sbq;
}
+ _soundTailQueue = sbq;
if (_soundQueuePreloadSize < kSoundPreloadSize) {
++_soundQueuePreloadSize;
}
}
-// _stub->unlockAudio();
+ _stub->unlockAudio();
}
void AVI_Player::decodeVideoChunk(AVI_Chunk &c) {
@@ -424,11 +420,10 @@ void AVI_Player::mix(int16_t *buf, int samples) {
return;
}
while (_soundQueue && samples > 0) {
- int16_t sample = (_soundQueue->buffer[_soundQueue->offset] << 8) ^ 0x8000;
- *buf++ = sample;
- *buf++ = sample;
-// _soundQueue->offset += 2; // skip every second sample (44Khz stream vs 22Khz mixer)
- ++_soundQueue->offset;
+ int sample = (_soundQueue->buffer[_soundQueue->offset] << 8) ^ 0x8000;
+ *buf++ = (int16_t)sample;
+ *buf++ = (int16_t)sample;
+ _soundQueue->offset += 2; // skip every second sample (44Khz stream vs 22Khz mixer)
if (_soundQueue->offset >= _soundQueue->size) {
AVI_SoundBufferQueue *next = _soundQueue->next;
free(_soundQueue->buffer);
@@ -437,6 +432,12 @@ void AVI_Player::mix(int16_t *buf, int samples) {
}
--samples;
}
+ if (!_soundQueue) {
+ _soundTailQueue = 0;
+ }
+ if (samples > 0) {
+ warning("AVI_Player::mix() soundQueue underrun %d", samples);
+ }
}
void AVI_Player::mixCallback(void *param, uint8_t *buf, int len) {
View
@@ -113,7 +113,7 @@ struct AVI_Player {
enum {
kDefaultFrameWidth = 320,
kDefaultFrameHeight = 200,
- kSoundPreloadSize = 16
+ kSoundPreloadSize = 4,
};
AVI_Player(Mixer *mixer, SystemStub *stub);
@@ -127,7 +127,7 @@ struct AVI_Player {
static void mixCallback(void *param, uint8_t *buf, int len);
AVI_Demuxer _demux;
- AVI_SoundBufferQueue *_soundQueue;
+ AVI_SoundBufferQueue *_soundQueue, *_soundTailQueue;
int _soundQueuePreloadSize;
Cinepak_Decoder _cinepak;
Mixer *_mixer;
View
@@ -379,7 +379,7 @@ void Mixer::unbindChannel(int channel) {
struct MixerImpl {
- static const int kMixFreq = 44100;
+ static const int kMixFreq = 22050;
static const int kMixBufSize = 4096;
static const int kChannels = 4;
@@ -502,8 +502,12 @@ void Mixer::stopAll() {
}
void Mixer::setMusicMix(void *param, void (*mix)(void *, uint8_t *, int)) {
- _impl->open();
- _impl->setMusicMix(param, mix);
+ if (mix) {
+ _impl->open();
+ _impl->setMusicMix(param, mix);
+ } else {
+ _impl->setMusicMix(0, 0);
+ }
}
#endif

0 comments on commit 2882507

Please sign in to comment.