Also some code cleanup (more sensible variable names).
Showing the changes to src (3 of 4 files). Show all
Unified · Split
| @@ -20,7 +20,7 @@ · 19 unmodified lines | |||
| 20 | 20 | ||
| 21 | static int8_t pmpCountDiv, pmpChannels = 2; | 21 | static int8_t pmpCountDiv, pmpChannels = 2; |
| 22 | static uint16_t smpBuffSize; | 22 | static uint16_t smpBuffSize; |
| 23 | static int32_t masterVol, oldAudioFreq, pmpLeft, randSeed = INITIAL_DITHER_SEED; | 23 | static int32_t masterVol, oldAudioFreq, randSeed = INITIAL_DITHER_SEED; |
| 24 | static int32_t prngStateL, prngStateR; | 24 | static int32_t prngStateL, prngStateR; |
| 25 | static uint32_t tickTimeLen, tickTimeLenFrac; | 25 | static uint32_t tickTimeLen, tickTimeLenFrac; |
| 26 | static float fAudioAmpMul; | 26 | static float fAudioAmpMul; |
| @@ -161,7 +161,7 @@ void setSpeed(uint16_t bpm) · 134 unmodified lines | |||
| 161 | if (bpm > MAX_BPM) | 161 | if (bpm > MAX_BPM) |
| 162 | return; | 162 | return; |
| 163 | 163 | ||
| 164 | audio.speedVal = audio.speedValTab[bpm]; | 164 | audio.samplesPerTick = audio.speedValTab[bpm]; |
| 165 | 165 | ||
| 166 | // get tick time length for audio/video sync timestamp | 166 | // get tick time length for audio/video sync timestamp |
| 167 | const uint64_t tickTimeLen64 = audio.tickTimeLengthTab[bpm]; | 167 | const uint64_t tickTimeLen64 = audio.tickTimeLengthTab[bpm]; |
| @@ -261,7 +261,7 @@ static void voiceUpdateVolumes(int32_t i, uint8_t status) · 93 unmodified lines | |||
| 261 | } | 261 | } |
| 262 | else | 262 | else |
| 263 | { | 263 | { |
| 264 | v->SVolIPLen = audio.speedVal; | 264 | v->SVolIPLen = audio.samplesPerTick; |
| 265 | v->SLVolIP = ((int64_t)destVolL * audio.rampSpeedValMul) >> 32; | 265 | v->SLVolIP = ((int64_t)destVolL * audio.rampSpeedValMul) >> 32; |
| 266 | v->SRVolIP = ((int64_t)destVolR * audio.rampSpeedValMul) >> 32; | 266 | v->SRVolIP = ((int64_t)destVolR * audio.rampSpeedValMul) >> 32; |
| 267 | } | 267 | } |
| @@ -584,8 +584,8 @@ uint32_t mixReplayerTickToBuffer(uint8_t *stream, uint8_t bitDepth) · 316 unmodified lines | |||
| 584 | voice_t *v, *r; | 584 | voice_t *v, *r; |
| 585 | 585 | ||
| 586 | assert(audio.speedVal <= MAX_WAV_RENDER_SAMPLES_PER_TICK); | 586 | assert(audio.speedVal <= MAX_WAV_RENDER_SAMPLES_PER_TICK); |
| 587 | memset(audio.mixBufferL, 0, audio.speedVal * sizeof (int32_t)); | 587 | memset(audio.mixBufferL, 0, audio.samplesPerTick * sizeof (int32_t)); |
| 588 | memset(audio.mixBufferR, 0, audio.speedVal * sizeof (int32_t)); | 588 | memset(audio.mixBufferR, 0, audio.samplesPerTick * sizeof (int32_t)); |
| 589 | 589 | ||
| 590 | // mix channels | 590 | // mix channels |
| 591 | v = voice; // normal voices | 591 | v = voice; // normal voices |
| @@ -594,24 +594,24 @@ uint32_t mixReplayerTickToBuffer(uint8_t *stream, uint8_t bitDepth) · 2 unmodified lines | |||
| 594 | for (int32_t i = 0; i < song.antChn; i++, v++, r++) | 594 | for (int32_t i = 0; i < song.antChn; i++, v++, r++) |
| 595 | { | 595 | { |
| 596 | // call the mixing routine currently set for the voice | 596 | // call the mixing routine currently set for the voice |
| 597 | if (v->mixRoutine != NULL) v->mixRoutine(v, audio.speedVal); // mix normal voice | 597 | if (v->mixRoutine != NULL) v->mixRoutine(v, audio.samplesPerTick); // mix normal voice |
| 598 | if (r->mixRoutine != NULL) r->mixRoutine(r, audio.speedVal); // mix volume ramp voice | 598 | if (r->mixRoutine != NULL) r->mixRoutine(r, audio.samplesPerTick); // mix volume ramp voice |
| 599 | } | 599 | } |
| 600 | 600 | ||
| 601 | // normalize mix buffer and send to audio stream | 601 | // normalize mix buffer and send to audio stream |
| 602 | if (bitDepth == 16) | 602 | if (bitDepth == 16) |
| 603 | { | 603 | { |
| 604 | if (config.specialFlags2 & DITHERED_AUDIO) | 604 | if (config.specialFlags2 & DITHERED_AUDIO) |
| 605 | sendSamples16BitDitherStereo(stream, audio.speedVal, 2); | 605 | sendSamples16BitDitherStereo(stream, audio.samplesPerTick, 2); |
| 606 | else | 606 | else |
| 607 | sendSamples16BitStereo(stream, audio.speedVal, 2); | 607 | sendSamples16BitStereo(stream, audio.samplesPerTick, 2); |
| 608 | } | 608 | } |
| 609 | else | 609 | else |
| 610 | { | 610 | { |
| 611 | sendSamples24BitStereo(stream, audio.speedVal, 2); | 611 | sendSamples24BitStereo(stream, audio.samplesPerTick, 2); |
| 612 | } | 612 | } |
| 613 | 613 | ||
| 614 | return audio.speedVal; | 614 | return audio.samplesPerTick; |
| 615 | } | 615 | } |
| 616 | 616 | ||
| 617 | int32_t pattQueueReadSize(void) | 617 | int32_t pattQueueReadSize(void) |
| @@ -930,18 +930,16 @@ static void fillVisualsSyncBuffer(void) · 312 unmodified lines | |||
| 930 | 930 | ||
| 931 | static void SDLCALL audioCallback(void *userdata, Uint8 *stream, int len) | 931 | static void SDLCALL audioCallback(void *userdata, Uint8 *stream, int len) |
| 932 | { | 932 | { |
| 933 | int32_t a, b; | ||
| 934 | |||
| 935 | assert(len < 65536); // limitation in mixer | 933 | assert(len < 65536); // limitation in mixer |
| 936 | assert(pmpCountDiv > 0); | 934 | assert(pmpCountDiv > 0); |
| 937 | 935 | ||
| 938 | a = len / pmpCountDiv; | 936 | int32_t samplesLeft = len / pmpCountDiv; |
| 939 | if (a <= 0) | 937 | if (samplesLeft <= 0) |
| 940 | return; | 938 | return; |
| 941 | 939 | ||
| 942 | while (a > 0) | 940 | while (samplesLeft > 0) |
| 943 | { | 941 | { |
| 944 | if (pmpLeft == 0) | 942 | if (audio.tickSampleCounter == 0) |
| 945 | { | 943 | { |
| 946 | // new replayer tick | 944 | // new replayer tick |
| 947 | 945 | ||
| @@ -954,20 +952,20 @@ static void SDLCALL audioCallback(void *userdata, Uint8 *stream, int len) · 6 unmodified lines | |||
| 954 | mix_UpdateChannelVolPanFrq(); | 952 | mix_UpdateChannelVolPanFrq(); |
| 955 | fillVisualsSyncBuffer(); | 953 | fillVisualsSyncBuffer(); |
| 956 | 954 | ||
| 957 | pmpLeft = audio.speedVal; | 955 | audio.tickSampleCounter = audio.samplesPerTick; |
| 958 | 956 | ||
| 959 | replayerBusy = false; | 957 | replayerBusy = false; |
| 960 | } | 958 | } |
| 961 | 959 | ||
| 962 | b = a; | 960 | int32_t samplesToMix = samplesLeft; |
| 963 | if (b > pmpLeft) | 961 | if (samplesToMix > audio.tickSampleCounter) |
| 964 | b = pmpLeft; | 962 | samplesToMix = audio.tickSampleCounter; |
| 965 | 963 | ||
| 966 | mixAudio(stream, b, pmpChannels); | 964 | mixAudio(stream, samplesToMix, pmpChannels); |
| 967 | stream += b * pmpCountDiv; | 965 | stream += samplesToMix * pmpCountDiv; |
| 968 | 966 | ||
| 969 | a -= b; | 967 | samplesLeft -= samplesToMix; |
| 970 | pmpLeft -= b; | 968 | audio.tickSampleCounter -= samplesToMix; |
| 971 | } | 969 | } |
| 972 | 970 | ||
| 973 | (void)userdata; | 971 | (void)userdata; |
| @@ -1225,7 +1223,7 @@ bool setupAudio(bool showErrorMsg) · 251 unmodified lines | |||
| 1225 | 1223 | ||
| 1226 | stopAllScopes(); | 1224 | stopAllScopes(); |
| 1227 | 1225 | ||
| 1228 | pmpLeft = 0; // reset sample counter | 1226 | audio.tickSampleCounter = 0; // zero tick sample counter so that it will instantly initiate a tick |
| 1229 | 1227 | ||
| 1230 | calcReplayRate(audio.freq); | 1228 | calcReplayRate(audio.freq); |
| 1231 | 1229 | ||
| @@ -51,8 +51,9 @@ typedef struct audio_t · 50 unmodified lines | |||
| 51 | int32_t inputDeviceNum, outputDeviceNum, lastWorkingAudioFreq, lastWorkingAudioBits; | 51 | int32_t inputDeviceNum, outputDeviceNum, lastWorkingAudioFreq, lastWorkingAudioBits; |
| 52 | int32_t quickVolSizeVal, *mixBufferL, *mixBufferR, *mixBufferLUnaligned, *mixBufferRUnaligned; | 52 | int32_t quickVolSizeVal, *mixBufferL, *mixBufferR, *mixBufferLUnaligned, *mixBufferRUnaligned; |
| 53 | int32_t rampQuickVolMul, rampSpeedValMul, speedValTab[MAX_BPM+1], rampSpeedValMulTab[MAX_BPM+1]; | 53 | int32_t rampQuickVolMul, rampSpeedValMul, speedValTab[MAX_BPM+1], rampSpeedValMulTab[MAX_BPM+1]; |
| 54 | int32_t tickSampleCounter; | ||
| 54 | uint32_t freq; | 55 | uint32_t freq; |
| 55 | uint32_t audLatencyPerfValInt, audLatencyPerfValFrac, speedVal, musicTimeSpeedVal; | 56 | uint32_t audLatencyPerfValInt, audLatencyPerfValFrac, samplesPerTick, musicTimeSpeedVal; |
| 56 | uint64_t tickTime64, tickTime64Frac, tickTimeLengthTab[MAX_BPM+1]; | 57 | uint64_t tickTime64, tickTime64Frac, tickTimeLengthTab[MAX_BPM+1]; |
| 57 | double dAudioLatencyMs; | 58 | double dAudioLatencyMs; |
| 58 | SDL_AudioDeviceID dev; | 59 | SDL_AudioDeviceID dev; |
| @@ -2780,6 +2780,8 @@ void startPlaying(int8_t mode, int16_t row) · 2779 unmodified lines | |||
| 2780 | if (song.tempo == 0) | 2780 | if (song.tempo == 0) |
| 2781 | song.tempo = song.initialTempo; | 2781 | song.tempo = song.initialTempo; |
| 2782 | 2782 | ||
| 2783 | audio.tickSampleCounter = 0; // zero tick sample counter so that it will instantly initiate a tick | ||
| 2784 | |||
| 2783 | unlockMixerCallback(); | 2785 | unlockMixerCallback(); |
| 2784 | 2786 | ||
| 2785 | ui.updatePosSections = true; | 2787 | ui.updatePosSections = true; |