- The BLEP synthesis has been improved for slightly less resampling aliasing. aciddose (the writer of the BLEP implementation) is currently working on it to see if it can be further improved, but as for now this should in theory be a little bit better than the old one. - Bugfix: Reset play mode to "Play song" when double-clicking files associated with the PT2 clone. - Bugfix: The MOD2WAV buffer was too small and could cause nasty issues when rendering a song with low BPM values. - MOD2WAV now renders the song at 96kHz, so that the user has more resolution before converting the WAV to the format/frequency of choice. - Don't include high-pass filter and dithering in PAT2SMP - Code cleanup
Unified · Split
| @@ -30,6 +30,7 @@ · 29 unmodified lines | |||
| 30 | #include "pt2_textout.h" | 30 | #include "pt2_textout.h" |
| 31 | #include "pt2_visuals.h" | 31 | #include "pt2_visuals.h" |
| 32 | #include "pt2_scopes.h" | 32 | #include "pt2_scopes.h" |
| 33 | #include "pt2_mod2wav.h" | ||
| 33 | 34 | ||
| 34 | #define INITIAL_DITHER_SEED 0x12345000 | 35 | #define INITIAL_DITHER_SEED 0x12345000 |
| 35 | 36 | ||
| @@ -49,10 +50,10 @@ typedef struct voice_t · 13 unmodified lines | |||
| 49 | 50 | ||
| 50 | static volatile int8_t filterFlags; | 51 | static volatile int8_t filterFlags; |
| 51 | static int8_t defStereoSep; | 52 | static int8_t defStereoSep; |
| 52 | static bool amigaPanFlag, wavRenderingDone; | 53 | static bool amigaPanFlag; |
| 53 | static uint16_t ch1Pan, ch2Pan, ch3Pan, ch4Pan; | 54 | static uint16_t ch1Pan, ch2Pan, ch3Pan, ch4Pan; |
| 54 | static int32_t oldPeriod, sampleCounter, randSeed = INITIAL_DITHER_SEED; | 55 | static int32_t oldPeriod, randSeed = INITIAL_DITHER_SEED; |
| 55 | static uint32_t oldScopeDelta; | 56 | static uint32_t oldScopeDelta, sampleCounter; |
| 56 | static double *dMixBufferL, *dMixBufferR, *dMixBufferLUnaligned, *dMixBufferRUnaligned, dOldVoiceDelta, dOldVoiceDeltaMul; | 57 | static double *dMixBufferL, *dMixBufferR, *dMixBufferLUnaligned, *dMixBufferRUnaligned, dOldVoiceDelta, dOldVoiceDeltaMul; |
| 57 | static double dPrngStateL, dPrngStateR; | 58 | static double dPrngStateL, dPrngStateR; |
| 58 | static blep_t blep[AMIGA_VOICES], blepVol[AMIGA_VOICES]; | 59 | static blep_t blep[AMIGA_VOICES], blepVol[AMIGA_VOICES]; |
| @@ -62,12 +63,9 @@ static paulaVoice_t paula[AMIGA_VOICES]; · 3 unmodified lines | |||
| 62 | static SDL_AudioDeviceID dev; | 63 | static SDL_AudioDeviceID dev; |
| 63 | 64 | ||
| 64 | // globalized | 65 | // globalized |
| 65 | int32_t samplesPerTick; | 66 | uint32_t samplesPerTick; |
| 66 | 67 | ||
| 67 | bool intMusic(void); // defined in pt_modplayer.c | 68 | bool intMusic(void); // defined in pt_modplayer.c |
| 68 | void storeTempVariables(void); // defined in pt_modplayer.c | ||
| 69 | |||
| 70 | void calcMod2WavTotalRows(void); | ||
| 71 | 69 | ||
| 72 | static uint16_t bpm2SmpsPerTick(uint32_t bpm, uint32_t audioFreq) | 70 | static uint16_t bpm2SmpsPerTick(uint32_t bpm, uint32_t audioFreq) |
| 73 | { | 71 | { |
| @@ -77,7 +75,7 @@ static uint16_t bpm2SmpsPerTick(uint32_t bpm, uint32_t audioFreq) · 3 unmodified lines | |||
| 77 | const uint32_t ciaVal = (uint32_t)(1773447 / bpm); // yes, PT truncates here | 75 | const uint32_t ciaVal = (uint32_t)(1773447 / bpm); // yes, PT truncates here |
| 78 | const double dCiaHz = (double)CIA_PAL_CLK / ciaVal; | 76 | const double dCiaHz = (double)CIA_PAL_CLK / ciaVal; |
| 79 | 77 | ||
| 80 | int32_t smpsPerTick = (int32_t)((audioFreq / dCiaHz) + 0.5); | 78 | int32_t smpsPerTick = (int32_t)((audioFreq / dCiaHz) + 0.5); // rounded |
| 81 | return (uint16_t)smpsPerTick; | 79 | return (uint16_t)smpsPerTick; |
| 82 | } | 80 | } |
| 83 | 81 | ||
| @@ -86,8 +84,9 @@ static void generateBpmTables(void) · 2 unmodified lines | |||
| 86 | for (uint32_t i = 32; i <= 255; i++) | 84 | for (uint32_t i = 32; i <= 255; i++) |
| 87 | { | 85 | { |
| 88 | audio.bpmTab[i-32] = bpm2SmpsPerTick(i, audio.outputRate); | 86 | audio.bpmTab[i-32] = bpm2SmpsPerTick(i, audio.outputRate); |
| 89 | audio.bpmTab28kHz[i-32] = bpm2SmpsPerTick(i, 28836); | 87 | audio.bpmTab28kHz[i-32] = bpm2SmpsPerTick(i, 28836); // PAT2SMP hi quality |
| 90 | audio.bpmTab22kHz[i-32] = bpm2SmpsPerTick(i, 22168); | 88 | audio.bpmTab22kHz[i-32] = bpm2SmpsPerTick(i, 22168); // PAT2SMP low quality |
| 89 | audio.bpmTabMod2Wav[i-32] = bpm2SmpsPerTick(i, MOD2WAV_FREQ); // MOD2WAV | ||
| 91 | } | 90 | } |
| 92 | } | 91 | } |
| 93 | 92 | ||
| @@ -404,9 +403,11 @@ void paulaSetPeriod(uint8_t ch, uint16_t period) · 310 unmodified lines | |||
| 404 | #if SCOPE_HZ != 64 | 403 | #if SCOPE_HZ != 64 |
| 405 | #error Scope Hz is not 64 (2^n), change rate calc. to use doubles+round in pt2_scope.c | 404 | #error Scope Hz is not 64 (2^n), change rate calc. to use doubles+round in pt2_scope.c |
| 406 | #endif | 405 | #endif |
| 407 | // if we are rendering pattern to sample (PAT2SMP), use different frequencies | 406 | // during PAT2SMP or doing MOD2WAV, use different audio output rates |
| 408 | if (editor.isSMPRendering) | 407 | if (editor.isSMPRendering) |
| 409 | dPeriodToDeltaDiv = editor.pat2SmpHQ ? (PAULA_PAL_CLK / 28836.0) : (PAULA_PAL_CLK / 22168.0); | 408 | dPeriodToDeltaDiv = editor.pat2SmpHQ ? (PAULA_PAL_CLK / 28836.0) : (PAULA_PAL_CLK / 22168.0); |
| 409 | else if (editor.isWAVRendering) | ||
| 410 | dPeriodToDeltaDiv = PAULA_PAL_CLK / (double)MOD2WAV_FREQ; | ||
| 410 | else | 411 | else |
| 411 | dPeriodToDeltaDiv = audio.dPeriodToDeltaDiv; | 412 | dPeriodToDeltaDiv = audio.dPeriodToDeltaDiv; |
| 412 | 413 | ||
| @@ -594,8 +595,8 @@ void mixChannels(int32_t numSamples) · 181 unmodified lines | |||
| 594 | bVol->dLastValue = dVol; | 595 | bVol->dLastValue = dVol; |
| 595 | } | 596 | } |
| 596 | 597 | ||
| 597 | if (bSmp->samplesLeft > 0) dSmp += blepRun(bSmp); | 598 | if (bSmp->samplesLeft > 0) dSmp = blepRun(bSmp, dSmp); |
| 598 | if (bVol->samplesLeft > 0) dVol += blepRun(bVol); | 599 | if (bVol->samplesLeft > 0) dVol = blepRun(bVol, dVol); |
| 599 | 600 | ||
| 600 | dSmp *= dVol; | 601 | dSmp *= dVol; |
| 601 | 602 | ||
| @@ -665,8 +666,8 @@ void mixChannelsMultiStep(int32_t numSamples) // for PAT2SMP · 63 unmodified lines | |||
| 665 | bVol->dLastValue = dVol; | 666 | bVol->dLastValue = dVol; |
| 666 | } | 667 | } |
| 667 | 668 | ||
| 668 | if (bSmp->samplesLeft > 0) dSmp += blepRun(bSmp); | 669 | if (bSmp->samplesLeft > 0) dSmp = blepRun(bSmp, dSmp); |
| 669 | if (bVol->samplesLeft > 0) dVol += blepRun(bVol); | 670 | if (bVol->samplesLeft > 0) dVol = blepRun(bVol, dVol); |
| 670 | 671 | ||
| 671 | dSmp *= dVol; | 672 | dSmp *= dVol; |
| 672 | 673 | ||
| @@ -724,8 +725,8 @@ static inline void processMixedSamplesA1200(int32_t i, int16_t *out) · 51 unmodified lines | |||
| 724 | RCHighPassFilter(&filterHi, dOut, dOut); | 725 | RCHighPassFilter(&filterHi, dOut, dOut); |
| 725 | 726 | ||
| 726 | // normalize and flip phase (A500/A1200 has an inverted audio signal) | 727 | // normalize and flip phase (A500/A1200 has an inverted audio signal) |
| 727 | dOut[0] *= -(INT16_MAX / AMIGA_VOICES); | 728 | dOut[0] *= (-INT16_MAX / (double)AMIGA_VOICES); |
| 728 | dOut[1] *= -(INT16_MAX / AMIGA_VOICES); | 729 | dOut[1] *= (-INT16_MAX / (double)AMIGA_VOICES); |
| 729 | 730 | ||
| 730 | // left channel - 1-bit triangular dithering (high-pass filtered) | 731 | // left channel - 1-bit triangular dithering (high-pass filtered) |
| 731 | dPrng = random32() * (0.5 / INT32_MAX); // -0.5..0.5 | 732 | dPrng = random32() * (0.5 / INT32_MAX); // -0.5..0.5 |
| @@ -761,8 +762,8 @@ static inline void processMixedSamplesA1200LED(int32_t i, int16_t *out) · 29 unmodified lines | |||
| 761 | RCHighPassFilter(&filterHi, dOut, dOut); | 762 | RCHighPassFilter(&filterHi, dOut, dOut); |
| 762 | 763 | ||
| 763 | // normalize and flip phase (A500/A1200 has an inverted audio signal) | 764 | // normalize and flip phase (A500/A1200 has an inverted audio signal) |
| 764 | dOut[0] *= -(INT16_MAX / AMIGA_VOICES); | 765 | dOut[0] *= (-INT16_MAX / (double)AMIGA_VOICES); |
| 765 | dOut[1] *= -(INT16_MAX / AMIGA_VOICES); | 766 | dOut[1] *= (-INT16_MAX / (double)AMIGA_VOICES); |
| 766 | 767 | ||
| 767 | // left channel - 1-bit triangular dithering (high-pass filtered) | 768 | // left channel - 1-bit triangular dithering (high-pass filtered) |
| 768 | dPrng = random32() * (0.5 / INT32_MAX); // -0.5..0.5 | 769 | dPrng = random32() * (0.5 / INT32_MAX); // -0.5..0.5 |
| @@ -795,8 +796,8 @@ static inline void processMixedSamplesA500(int32_t i, int16_t *out) · 26 unmodified lines | |||
| 795 | // process high-pass filter | 796 | // process high-pass filter |
| 796 | RCHighPassFilter(&filterHi, dOut, dOut); | 797 | RCHighPassFilter(&filterHi, dOut, dOut); |
| 797 | 798 | ||
| 798 | dOut[0] *= -(INT16_MAX / AMIGA_VOICES); | 799 | dOut[0] *= (-INT16_MAX / (double)AMIGA_VOICES); |
| 799 | dOut[1] *= -(INT16_MAX / AMIGA_VOICES); | 800 | dOut[1] *= (-INT16_MAX / (double)AMIGA_VOICES); |
| 800 | 801 | ||
| 801 | // left channel - 1-bit triangular dithering (high-pass filtered) | 802 | // left channel - 1-bit triangular dithering (high-pass filtered) |
| 802 | dPrng = random32() * (0.5 / INT32_MAX); // -0.5..0.5 | 803 | dPrng = random32() * (0.5 / INT32_MAX); // -0.5..0.5 |
| @@ -832,8 +833,8 @@ static inline void processMixedSamplesA500LED(int32_t i, int16_t *out) · 29 unmodified lines | |||
| 832 | // process high-pass filter | 833 | // process high-pass filter |
| 833 | RCHighPassFilter(&filterHi, dOut, dOut); | 834 | RCHighPassFilter(&filterHi, dOut, dOut); |
| 834 | 835 | ||
| 835 | dOut[0] *= -(INT16_MAX / AMIGA_VOICES); | 836 | dOut[0] *= (-INT16_MAX / (double)AMIGA_VOICES); |
| 836 | dOut[1] *= -(INT16_MAX / AMIGA_VOICES); | 837 | dOut[1] *= (-INT16_MAX / (double)AMIGA_VOICES); |
| 837 | 838 | ||
| 838 | // left channel - 1-bit triangular dithering (high-pass filtered) | 839 | // left channel - 1-bit triangular dithering (high-pass filtered) |
| 839 | dPrng = random32() * (0.5 / INT32_MAX); // -0.5..0.5 | 840 | dPrng = random32() * (0.5 / INT32_MAX); // -0.5..0.5 |
| @@ -852,28 +853,53 @@ static inline void processMixedSamplesA500LED(int32_t i, int16_t *out) · 12 unmodified lines | |||
| 852 | out[1] = (int16_t)smp32; | 853 | out[1] = (int16_t)smp32; |
| 853 | } | 854 | } |
| 854 | 855 | ||
| 856 | // for PAT2SMP | ||
| 857 | static inline void processMixedSamplesRaw(int32_t i, int16_t *out) | ||
| 858 | { | ||
| 859 | int32_t smp32; | ||
| 860 | double dOut[2]; | ||
| 861 | |||
| 862 | dOut[0] = dMixBufferL[i]; | ||
| 863 | dOut[1] = dMixBufferR[i]; | ||
| 864 | |||
| 865 | // normalize | ||
| 866 | dOut[0] *= (INT16_MAX / (double)AMIGA_VOICES); | ||
| 867 | dOut[1] *= (INT16_MAX / (double)AMIGA_VOICES); | ||
| 868 | |||
| 869 | dOut[0] = (dOut[0] + dOut[1]) * 0.5; // mix to mono | ||
| 870 | |||
| 871 | smp32 = (int32_t)dOut[0]; | ||
| 872 | CLAMP16(smp32); | ||
| 873 | out[0] = (int16_t)smp32; | ||
| 874 | } | ||
| 875 | |||
| 855 | void outputAudio(int16_t *target, int32_t numSamples) | 876 | void outputAudio(int16_t *target, int32_t numSamples) |
| 856 | { | 877 | { |
| 857 | int16_t *outStream, out[2]; | 878 | int16_t *outStream, out[2]; |
| 858 | int32_t j; | 879 | int32_t i; |
| 859 | 880 | ||
| 860 | if (editor.isSMPRendering) | 881 | if (editor.isSMPRendering) |
| 861 | { | 882 | { |
| 862 | // render to sample (PAT2SMP) | 883 | // render to sample (PAT2SMP) |
| 863 | 884 | ||
| 885 | int32_t samplesTodo = numSamples; | ||
| 886 | if (editor.pat2SmpPos+samplesTodo > MAX_SAMPLE_LEN) | ||
| 887 | samplesTodo = MAX_SAMPLE_LEN-editor.pat2SmpPos; | ||
| 888 | |||
| 864 | mixChannelsMultiStep(numSamples); | 889 | mixChannelsMultiStep(numSamples); |
| 865 | 890 | ||
| 866 | for (j = 0; j < numSamples; j++) | 891 | outStream = &editor.pat2SmpBuf[editor.pat2SmpPos]; |
| 892 | for (i = 0; i < samplesTodo; i++) | ||
| 867 | { | 893 | { |
| 868 | processMixedSamplesA1200(j, out); | 894 | processMixedSamplesA1200(i, out); |
| 869 | editor.pat2SmpBuf[editor.pat2SmpPos++] = (int16_t)((out[0] + out[1]) >> 1); // mix to mono | 895 | outStream[i] = (out[0] + out[1]) >> 1; |
| 896 | } | ||
| 870 | 897 | ||
| 871 | if (editor.pat2SmpPos >= MAX_SAMPLE_LEN) | 898 | editor.pat2SmpPos += samplesTodo; |
| 872 | { | 899 | if (editor.pat2SmpPos >= MAX_SAMPLE_LEN) |
| 873 | editor.smpRenderingDone = true; | 900 | { |
| 874 | updateWindowTitle(MOD_IS_MODIFIED); | 901 | editor.smpRenderingDone = true; |
| 875 | break; | 902 | updateWindowTitle(MOD_IS_MODIFIED); |
| 876 | } | ||
| 877 | } | 903 | } |
| 878 | } | 904 | } |
| 879 | else | 905 | else |
| @@ -889,18 +915,18 @@ void outputAudio(int16_t *target, int32_t numSamples) · 9 unmodified lines | |||
| 889 | 915 | ||
| 890 | if (filterFlags & FILTER_LED_ENABLED) | 916 | if (filterFlags & FILTER_LED_ENABLED) |
| 891 | { | 917 | { |
| 892 | for (j = 0; j < numSamples; j++) | 918 | for (i = 0; i < numSamples; i++) |
| 893 | { | 919 | { |
| 894 | processMixedSamplesA500LED(j, out); | 920 | processMixedSamplesA500LED(i, out); |
| 895 | *outStream++ = out[0]; | 921 | *outStream++ = out[0]; |
| 896 | *outStream++ = out[1]; | 922 | *outStream++ = out[1]; |
| 897 | } | 923 | } |
| 898 | } | 924 | } |
| 899 | else | 925 | else |
| 900 | { | 926 | { |
| 901 | for (j = 0; j < numSamples; j++) | 927 | for (i = 0; i < numSamples; i++) |
| 902 | { | 928 | { |
| 903 | processMixedSamplesA500(j, out); | 929 | processMixedSamplesA500(i, out); |
| 904 | *outStream++ = out[0]; | 930 | *outStream++ = out[0]; |
| 905 | *outStream++ = out[1]; | 931 | *outStream++ = out[1]; |
| 906 | } | 932 | } |
| @@ -912,18 +938,18 @@ void outputAudio(int16_t *target, int32_t numSamples) · 5 unmodified lines | |||
| 912 | 938 | ||
| 913 | if (filterFlags & FILTER_LED_ENABLED) | 939 | if (filterFlags & FILTER_LED_ENABLED) |
| 914 | { | 940 | { |
| 915 | for (j = 0; j < numSamples; j++) | 941 | for (i = 0; i < numSamples; i++) |
| 916 | { | 942 | { |
| 917 | processMixedSamplesA1200LED(j, out); | 943 | processMixedSamplesA1200LED(i, out); |
| 918 | *outStream++ = out[0]; | 944 | *outStream++ = out[0]; |
| 919 | *outStream++ = out[1]; | 945 | *outStream++ = out[1]; |
| 920 | } | 946 | } |
| 921 | } | 947 | } |
| 922 | else | 948 | else |
| 923 | { | 949 | { |
| 924 | for (j = 0; j < numSamples; j++) | 950 | for (i = 0; i < numSamples; i++) |
| 925 | { | 951 | { |
| 926 | processMixedSamplesA1200(j, out); | 952 | processMixedSamplesA1200(i, out); |
| 927 | *outStream++ = out[0]; | 953 | *outStream++ = out[0]; |
| 928 | *outStream++ = out[1]; | 954 | *outStream++ = out[1]; |
| 929 | } | 955 | } |
| @@ -934,8 +960,8 @@ void outputAudio(int16_t *target, int32_t numSamples) · 4 unmodified lines | |||
| 934 | 960 | ||
| 935 | static void SDLCALL audioCallback(void *userdata, Uint8 *stream, int len) | 961 | static void SDLCALL audioCallback(void *userdata, Uint8 *stream, int len) |
| 936 | { | 962 | { |
| 937 | int16_t *out; | 963 | int16_t *streamOut; |
| 938 | int32_t sampleBlock, samplesTodo; | 964 | uint32_t samplesLeft; |
| 939 | 965 | ||
| 940 | if (audio.forceMixerOff) // during MOD2WAV | 966 | if (audio.forceMixerOff) // during MOD2WAV |
| 941 | { | 967 | { |
| @@ -943,27 +969,28 @@ static void SDLCALL audioCallback(void *userdata, Uint8 *stream, int len) · 1 unmodified line | |||
| 943 | return; | 969 | return; |
| 944 | } | 970 | } |
| 945 | 971 | ||
| 946 | out = (int16_t *)stream; | 972 | streamOut = (int16_t *)stream; |
| 947 | 973 | ||
| 948 | sampleBlock = len >> 2; | 974 | samplesLeft = len >> 2; |
| 949 | while (sampleBlock) | 975 | while (samplesLeft > 0) |
| 950 | { | 976 | { |
| 951 | samplesTodo = (sampleBlock < sampleCounter) ? sampleBlock : sampleCounter; | 977 | if (sampleCounter == 0) |
| 952 | if (samplesTodo > 0) | ||
| 953 | { | ||
| 954 | outputAudio(out, samplesTodo); | ||
| 955 | out += (uint32_t)samplesTodo * 2; | ||
| 956 | |||
| 957 | sampleBlock -= samplesTodo; | ||
| 958 | sampleCounter -= samplesTodo; | ||
| 959 | } | ||
| 960 | else | ||
| 961 | { | 978 | { |
| 962 | if (editor.songPlaying) | 979 | if (editor.songPlaying) |
| 963 | intMusic(); | 980 | intMusic(); |
| 964 | 981 | ||
| 965 | sampleCounter = samplesPerTick; | 982 | sampleCounter = samplesPerTick; |
| 966 | } | 983 | } |
| 984 | |||
| 985 | uint32_t samplesTodo = sampleCounter; | ||
| 986 | if (samplesTodo > samplesLeft) | ||
| 987 | samplesTodo = samplesLeft; | ||
| 988 | |||
| 989 | outputAudio(streamOut, samplesTodo); | ||
| 990 | streamOut += samplesTodo << 1; | ||
| 991 | |||
| 992 | samplesLeft -= samplesTodo; | ||
| 993 | sampleCounter -= samplesTodo; | ||
| 967 | } | 994 | } |
| 968 | 995 | ||
| 969 | (void)userdata; | 996 | (void)userdata; |
| @@ -1081,13 +1108,22 @@ bool setupAudio(void) · 111 unmodified lines | |||
| 1081 | audio.dPeriodToDeltaDiv = (double)PAULA_PAL_CLK / audio.outputRate; | 1108 | audio.dPeriodToDeltaDiv = (double)PAULA_PAL_CLK / audio.outputRate; |
| 1082 | 1109 | ||
| 1083 | generateBpmTables(); | 1110 | generateBpmTables(); |
| 1084 | const int32_t maxSamplesToMix = audio.bpmTab[0]; // BPM 32 | 1111 | |
| 1112 | /* If the audio output rate is lower than MOD2WAV_FREQ, we need | ||
| 1113 | ** to allocate slightly more space so that MOD2WAV rendering | ||
| 1114 | ** won't overflow. | ||
| 1115 | */ | ||
| 1116 | |||
| 1117 | uint32_t maxSamplesToMix; | ||
| 1118 | if (MOD2WAV_FREQ > audio.outputRate) | ||
| 1119 | maxSamplesToMix = audio.bpmTabMod2Wav[32-32]; // BPM 32 | ||
| 1120 | else | ||
| 1121 | maxSamplesToMix = audio.bpmTab[32-32]; // BPM 32 | ||
| 1085 | 1122 | ||
| 1086 | dMixBufferLUnaligned = (double *)MALLOC_PAD(maxSamplesToMix * sizeof (double), 256); | 1123 | dMixBufferLUnaligned = (double *)MALLOC_PAD(maxSamplesToMix * sizeof (double), 256); |
| 1087 | dMixBufferRUnaligned = (double *)MALLOC_PAD(maxSamplesToMix * sizeof (double), 256); | 1124 | dMixBufferRUnaligned = (double *)MALLOC_PAD(maxSamplesToMix * sizeof (double), 256); |
| 1088 | editor.mod2WavBuffer = (int16_t *)malloc(maxSamplesToMix * sizeof (int16_t)); | ||
| 1089 | 1125 | ||
| 1090 | if (dMixBufferLUnaligned == NULL || dMixBufferRUnaligned == NULL || editor.mod2WavBuffer == NULL) | 1126 | if (dMixBufferLUnaligned == NULL || dMixBufferRUnaligned == NULL) |
| 1091 | { | 1127 | { |
| 1092 | showErrorMsgBox("Out of memory!"); | 1128 | showErrorMsgBox("Out of memory!"); |
| 1093 | return false; | 1129 | return false; |
| @@ -1102,7 +1138,7 @@ bool setupAudio(void) · 8 unmodified lines | |||
| 1102 | filterFlags = config.a500LowPassFilter ? FILTER_A500 : 0; | 1138 | filterFlags = config.a500LowPassFilter ? FILTER_A500 : 0; |
| 1103 | calculateFilterCoeffs(); | 1139 | calculateFilterCoeffs(); |
| 1104 | 1140 | ||
| 1105 | samplesPerTick = 0; | 1141 | samplesPerTick = audio.bpmTab[125-32]; // BPM 125 |
| 1106 | sampleCounter = 0; | 1142 | sampleCounter = 0; |
| 1107 | 1143 | ||
| 1108 | SDL_PauseAudioDevice(dev, false); | 1144 | SDL_PauseAudioDevice(dev, false); |
| @@ -1129,15 +1165,9 @@ void audioClose(void) · 20 unmodified lines | |||
| 1129 | free(dMixBufferRUnaligned); | 1165 | free(dMixBufferRUnaligned); |
| 1130 | dMixBufferRUnaligned = NULL; | 1166 | dMixBufferRUnaligned = NULL; |
| 1131 | } | 1167 | } |
| 1132 | |||
| 1133 | if (editor.mod2WavBuffer != NULL) | ||
| 1134 | { | ||
| 1135 | free(editor.mod2WavBuffer); | ||
| 1136 | editor.mod2WavBuffer = NULL; | ||
| 1137 | } | ||
| 1138 | } | 1168 | } |
| 1139 | 1169 | ||
| 1140 | void mixerSetSamplesPerTick(int32_t val) | 1170 | void mixerSetSamplesPerTick(uint32_t val) |
| 1141 | { | 1171 | { |
| 1142 | samplesPerTick = val; | 1172 | samplesPerTick = val; |
| 1143 | } | 1173 | } |
| @@ -1162,280 +1192,6 @@ void toggleAmigaPanMode(void) · 18 unmodified lines | |||
| 1162 | } | 1192 | } |
| 1163 | } | 1193 | } |
| 1164 | 1194 | ||
| 1165 | // PAT2SMP RELATED STUFF | ||
| 1166 | |||
| 1167 | uint32_t getAudioFrame(int16_t *outStream) | ||
| 1168 | { | ||
| 1169 | int32_t smpCounter, samplesToMix; | ||
| 1170 | |||
| 1171 | if (!intMusic()) | ||
| 1172 | wavRenderingDone = true; | ||
| 1173 | |||
| 1174 | smpCounter = samplesPerTick; | ||
| 1175 | while (smpCounter > 0) | ||
| 1176 | { | ||
| 1177 | samplesToMix = smpCounter; | ||
| 1178 | |||
| 1179 | outputAudio(outStream, samplesToMix); | ||
| 1180 | outStream += (uint32_t)samplesToMix * 2; | ||
| 1181 | |||
| 1182 | smpCounter -= samplesToMix; | ||
| 1183 | } | ||
| 1184 | |||
| 1185 | return (uint32_t)samplesPerTick * 2; // * 2 for stereo | ||
| 1186 | } | ||
| 1187 | |||
| 1188 | static int32_t SDLCALL mod2WavThreadFunc(void *ptr) | ||
| 1189 | { | ||
| 1190 | uint32_t size, totalSampleCounter, totalRiffChunkLen; | ||
| 1191 | FILE *fOut; | ||
| 1192 | wavHeader_t wavHeader; | ||
| 1193 | |||
| 1194 | fOut = (FILE *)ptr; | ||
| 1195 | if (fOut == NULL) | ||
| 1196 | return true; | ||
| 1197 | |||
| 1198 | // skip wav header place, render data first | ||
| 1199 | fseek(fOut, sizeof (wavHeader_t), SEEK_SET); | ||
| 1200 | |||
| 1201 | wavRenderingDone = false; | ||
| 1202 | |||
| 1203 | totalSampleCounter = 0; | ||
| 1204 | while (editor.isWAVRendering && !wavRenderingDone && !editor.abortMod2Wav) | ||
| 1205 | { | ||
| 1206 | size = getAudioFrame(editor.mod2WavBuffer); | ||
| 1207 | if (size > 0) | ||
| 1208 | { | ||
| 1209 | fwrite(editor.mod2WavBuffer, sizeof (int16_t), size, fOut); | ||
| 1210 | totalSampleCounter += size; | ||
| 1211 | } | ||
| 1212 | |||
| 1213 | editor.ui.updateMod2WavDialog = true; | ||
| 1214 | } | ||
| 1215 | |||
| 1216 | if (totalSampleCounter & 1) | ||
| 1217 | fputc(0, fOut); // pad align byte | ||
| 1218 | |||
| 1219 | if ((ftell(fOut) - 8) > 0) | ||
| 1220 | totalRiffChunkLen = ftell(fOut) - 8; | ||
| 1221 | else | ||
| 1222 | totalRiffChunkLen = 0; | ||
| 1223 | |||
| 1224 | editor.ui.mod2WavFinished = true; | ||
| 1225 | editor.ui.updateMod2WavDialog = true; | ||
| 1226 | |||
| 1227 | // go back and fill the missing WAV header | ||
| 1228 | fseek(fOut, 0, SEEK_SET); | ||
| 1229 | |||
| 1230 | wavHeader.chunkID = 0x46464952; // "RIFF" | ||
| 1231 | wavHeader.chunkSize = totalRiffChunkLen; | ||
| 1232 | wavHeader.format = 0x45564157; // "WAVE" | ||
| 1233 | wavHeader.subchunk1ID = 0x20746D66; // "fmt " | ||
| 1234 | wavHeader.subchunk1Size = 16; | ||
| 1235 | wavHeader.audioFormat = 1; | ||
| 1236 | wavHeader.numChannels = 2; | ||
| 1237 | wavHeader.sampleRate = audio.outputRate; | ||
| 1238 | wavHeader.bitsPerSample = 16; | ||
| 1239 | wavHeader.byteRate = wavHeader.sampleRate * wavHeader.numChannels * (wavHeader.bitsPerSample / 8); | ||
| 1240 | wavHeader.blockAlign = wavHeader.numChannels * (wavHeader.bitsPerSample / 8); | ||
| 1241 | wavHeader.subchunk2ID = 0x61746164; // "data" | ||
| 1242 | wavHeader.subchunk2Size = totalSampleCounter * (wavHeader.bitsPerSample / 8); | ||
| 1243 | |||
| 1244 | fwrite(&wavHeader, sizeof (wavHeader_t), 1, fOut); | ||
| 1245 | fclose(fOut); | ||
| 1246 | |||
| 1247 | return true; | ||
| 1248 | } | ||
| 1249 | |||
| 1250 | bool renderToWav(char *fileName, bool checkIfFileExist) | ||
| 1251 | { | ||
| 1252 | FILE *fOut; | ||
| 1253 | struct stat statBuffer; | ||
| 1254 | |||
| 1255 | if (checkIfFileExist) | ||
| 1256 | { | ||
| 1257 | if (stat(fileName, &statBuffer) == 0) | ||
| 1258 | { | ||
| 1259 | editor.ui.askScreenShown = true; | ||
| 1260 | editor.ui.askScreenType = ASK_MOD2WAV_OVERWRITE; | ||
| 1261 | |||
| 1262 | pointerSetMode(POINTER_MODE_MSG1, NO_CARRY); | ||
| 1263 | setStatusMessage("OVERWRITE FILE?", NO_CARRY); | ||
| 1264 | |||
| 1265 | renderAskDialog(); | ||
| 1266 | |||
| 1267 | return false; | ||
| 1268 | } | ||
| 1269 | } | ||
| 1270 | |||
| 1271 | if (editor.ui.askScreenShown) | ||
| 1272 | { | ||
| 1273 | editor.ui.askScreenShown = false; | ||
| 1274 | editor.ui.answerNo = false; | ||
| 1275 | editor.ui.answerYes = false; | ||
| 1276 | } | ||
| 1277 | |||
| 1278 | fOut = fopen(fileName, "wb"); | ||
| 1279 | if (fOut == NULL) | ||
| 1280 | { | ||
| 1281 | displayErrorMsg("FILE I/O ERROR"); | ||
| 1282 | return false; | ||
| 1283 | } | ||
| 1284 | |||
| 1285 | storeTempVariables(); | ||
| 1286 | calcMod2WavTotalRows(); | ||
| 1287 | restartSong(); | ||
| 1288 | |||
| 1289 | editor.blockMarkFlag = false; | ||
| 1290 | |||
| 1291 | pointerSetMode(POINTER_MODE_MSG2, NO_CARRY); | ||
| 1292 | setStatusMessage("RENDERING MOD...", NO_CARRY); | ||
| 1293 | |||
| 1294 | editor.ui.disableVisualizer = true; | ||
| 1295 | editor.isWAVRendering = true; | ||
| 1296 | renderMOD2WAVDialog(); | ||
| 1297 | |||
| 1298 | editor.abortMod2Wav = false; | ||
| 1299 | |||
| 1300 | editor.mod2WavThread = SDL_CreateThread(mod2WavThreadFunc, NULL, fOut); | ||
| 1301 | if (editor.mod2WavThread != NULL) | ||
| 1302 | { | ||
| 1303 | SDL_DetachThread(editor.mod2WavThread); | ||
| 1304 | } | ||
| 1305 | else | ||
| 1306 | { | ||
| 1307 | editor.ui.disableVisualizer = false; | ||
| 1308 | editor.isWAVRendering = false; | ||
| 1309 | |||
| 1310 | displayErrorMsg("THREAD ERROR"); | ||
| 1311 | |||
| 1312 | pointerSetMode(POINTER_MODE_IDLE, DO_CARRY); | ||
| 1313 | statusAllRight(); | ||
| 1314 | |||
| 1315 | return false; | ||
| 1316 | } | ||
| 1317 | |||
| 1318 | return true; | ||
| 1319 | } | ||
| 1320 | |||
| 1321 | // for MOD2WAV - ONLY used for a visual percentage counter, so accuracy is not important | ||
| 1322 | void calcMod2WavTotalRows(void) | ||
| 1323 | { | ||
| 1324 | bool pBreakFlag, posJumpAssert, calcingRows; | ||
| 1325 | int8_t n_pattpos[AMIGA_VOICES], n_loopcount[AMIGA_VOICES]; | ||
| 1326 | uint8_t modRow, pBreakPosition, ch, pos; | ||
| 1327 | int16_t modOrder; | ||
| 1328 | uint16_t modPattern; | ||
| 1329 | note_t *note; | ||
| 1330 | |||
| 1331 | // for pattern loop | ||
| 1332 | memset(n_pattpos, 0, sizeof (n_pattpos)); | ||
| 1333 | memset(n_loopcount, 0, sizeof (n_loopcount)); | ||
| 1334 | |||
| 1335 | modEntry->rowsCounter = 0; | ||
| 1336 | modEntry->rowsInTotal = 0; | ||
| 1337 | |||
| 1338 | modRow = 0; | ||
| 1339 | modOrder = 0; | ||
| 1340 | modPattern = modEntry->head.order[0]; | ||
| 1341 | pBreakPosition = 0; | ||
| 1342 | posJumpAssert = false; | ||
| 1343 | pBreakFlag = false; | ||
| 1344 | calcingRows = true; | ||
| 1345 | |||
| 1346 | memset(editor.rowVisitTable, 0, MOD_ORDERS * MOD_ROWS); | ||
| 1347 | while (calcingRows) | ||
| 1348 | { | ||
| 1349 | editor.rowVisitTable[(modOrder * MOD_ROWS) + modRow] = true; | ||
| 1350 | |||
| 1351 | for (ch = 0; ch < AMIGA_VOICES; ch++) | ||
| 1352 | { | ||
| 1353 | note = &modEntry->patterns[modPattern][(modRow * AMIGA_VOICES) + ch]; | ||
| 1354 | if (note->command == 0x0B) // Bxx - Position Jump | ||
| 1355 | { | ||
| 1356 | modOrder = note->param - 1; | ||
| 1357 | pBreakPosition = 0; | ||
| 1358 | posJumpAssert = true; | ||
| 1359 | } | ||
| 1360 | else if (note->command == 0x0D) // Dxx - Pattern Break | ||
| 1361 | { | ||
| 1362 | pBreakPosition = (((note->param >> 4) * 10) + (note->param & 0x0F)); | ||
| 1363 | if (pBreakPosition > 63) | ||
| 1364 | pBreakPosition = 0; | ||
| 1365 | |||
| 1366 | posJumpAssert = true; | ||
| 1367 | } | ||
| 1368 | else if (note->command == 0x0F && note->param == 0) // F00 - Set Speed 0 (stop) | ||
| 1369 | { | ||
| 1370 | calcingRows = false; | ||
| 1371 | break; | ||
| 1372 | } | ||
| 1373 | else if (note->command == 0x0E && (note->param >> 4) == 0x06) // E6x - Pattern Loop | ||
| 1374 | { | ||
| 1375 | pos = note->param & 0x0F; | ||
| 1376 | if (pos == 0) | ||
| 1377 | { | ||
| 1378 | n_pattpos[ch] = modRow; | ||
| 1379 | } | ||
| 1380 | else if (n_loopcount[ch] == 0) | ||
| 1381 | { | ||
| 1382 | n_loopcount[ch] = pos; | ||
| 1383 | |||
| 1384 | pBreakPosition = n_pattpos[ch]; | ||
| 1385 | pBreakFlag = true; | ||
| 1386 | |||
| 1387 | for (pos = pBreakPosition; pos <= modRow; pos++) | ||
| 1388 | editor.rowVisitTable[(modOrder * MOD_ROWS) + pos] = false; | ||
| 1389 | } | ||
| 1390 | else if (--n_loopcount[ch]) | ||
| 1391 | { | ||
| 1392 | pBreakPosition = n_pattpos[ch]; | ||
| 1393 | pBreakFlag = true; | ||
| 1394 | |||
| 1395 | for (pos = pBreakPosition; pos <= modRow; pos++) | ||
| 1396 | editor.rowVisitTable[(modOrder * MOD_ROWS) + pos] = false; | ||
| 1397 | } | ||
| 1398 | } | ||
| 1399 | } | ||
| 1400 | |||
| 1401 | modRow++; | ||
| 1402 | modEntry->rowsInTotal++; | ||
| 1403 | |||
| 1404 | if (pBreakFlag) | ||
| 1405 | { | ||
| 1406 | modRow = pBreakPosition; | ||
| 1407 | pBreakPosition = 0; | ||
| 1408 | pBreakFlag = false; | ||
| 1409 | } | ||
| 1410 | |||
| 1411 | if (modRow >= MOD_ROWS || posJumpAssert) | ||
| 1412 | { | ||
| 1413 | modRow = pBreakPosition; | ||
| 1414 | pBreakPosition = 0; | ||
| 1415 | posJumpAssert = false; | ||
| 1416 | |||
| 1417 | modOrder = (modOrder + 1) & 0x7F; | ||
| 1418 | if (modOrder >= modEntry->head.orderCount) | ||
| 1419 | { | ||
| 1420 | modOrder = 0; | ||
| 1421 | calcingRows = false; | ||
| 1422 | break; | ||
| 1423 | } | ||
| 1424 | |||
| 1425 | modPattern = modEntry->head.order[modOrder]; | ||
| 1426 | if (modPattern > MAX_PATTERNS-1) | ||
| 1427 | modPattern = MAX_PATTERNS-1; | ||
| 1428 | } | ||
| 1429 | |||
| 1430 | if (editor.rowVisitTable[(modOrder * MOD_ROWS) + modRow]) | ||
| 1431 | { | ||
| 1432 | // row has been visited before, we're now done! | ||
| 1433 | calcingRows = false; | ||
| 1434 | break; | ||
| 1435 | } | ||
| 1436 | } | ||
| 1437 | } | ||
| 1438 | |||
| 1439 | void normalize32bitSigned(int32_t *sampleData, uint32_t sampleLength) | 1195 | void normalize32bitSigned(int32_t *sampleData, uint32_t sampleLength) |
| 1440 | { | 1196 | { |
| 1441 | int32_t sample, sampleVolPeak; | 1197 | int32_t sample, sampleVolPeak; |
| @@ -29,7 +29,6 @@ void normalize8bitFloatSigned(float *fSampleData, uint32_t sampleLength); · 28 unmodified lines | |||
| 29 | void normalize8bitDoubleSigned(double *dSampleData, uint32_t sampleLength); | 29 | void normalize8bitDoubleSigned(double *dSampleData, uint32_t sampleLength); |
| 30 | void setLEDFilter(bool state); | 30 | void setLEDFilter(bool state); |
| 31 | void toggleLEDFilter(void); | 31 | void toggleLEDFilter(void); |
| 32 | bool renderToWav(char *fileName, bool checkIfFileExist); | ||
| 33 | void toggleAmigaPanMode(void); | 32 | void toggleAmigaPanMode(void); |
| 34 | void toggleA500Filters(void); | 33 | void toggleA500Filters(void); |
| 35 | void paulaStopDMA(uint8_t ch); | 34 | void paulaStopDMA(uint8_t ch); |
| @@ -44,6 +43,6 @@ void mixerUpdateLoops(void); · 8 unmodified lines | |||
| 44 | void mixerKillVoice(uint8_t ch); | 43 | void mixerKillVoice(uint8_t ch); |
| 45 | void turnOffVoices(void); | 44 | void turnOffVoices(void); |
| 46 | void mixerCalcVoicePans(uint8_t stereoSeparation); | 45 | void mixerCalcVoicePans(uint8_t stereoSeparation); |
| 47 | void mixerSetSamplesPerTick(int32_t val); | 46 | void mixerSetSamplesPerTick(uint32_t val); |
| 48 | void mixerClearSampleCounter(void); | 47 | void mixerClearSampleCounter(void); |
| 49 | void outputAudio(int16_t *target, int32_t numSamples); | 48 | void outputAudio(int16_t *target, int32_t numSamples); |
| @@ -1,74 +1,119 @@ | |||
| 1 | // These BLEP routines were coded by aciddose/adejr | 1 | // these BLEP routines were coded by aciddose |
| 2 | 2 | ||
| 3 | #include <stdint.h> | 3 | #include <stdint.h> |
| 4 | #include "pt2_blep.h" | 4 | #include "pt2_blep.h" |
| 5 | #include "pt2_helpers.h" | 5 | #include "pt2_helpers.h" |
| 6 | 6 | ||
| 7 | /* Why this table is not represented as readable floating-point numbers: | 7 | /* Why this table is not represented as readable floating-point numbers: |
| 8 | ** Accurate float (double) representation in string format requires at least 14 digits and normalized | 8 | ** Accurate double representation in string format requires at least 14 digits and normalized |
| 9 | ** (scientific) notation, notwithstanding compiler issues with precision or rounding error. | 9 | ** (scientific) notation, notwithstanding compiler issues with precision or rounding error. |
| 10 | ** Also, don't touch this table ever, just keep it exactly identical! */ | 10 | ** Also, don't touch this table ever, just keep it exactly identical! |
| 11 | */ | ||
| 11 | 12 | ||
| 12 | // TODO: get a proper double-precision table. This one is converted from float. | 13 | static const uint64_t minblepdata[] = |
| 13 | static const uint64_t dBlepData[48] = | ||
| 14 | { | 14 | { |
| 15 | 0x3FEFFC3E20000000, 0x3FEFFAA900000000, 0x3FEFFAD460000000, 0x3FEFFA9C60000000, | 15 | 0x3FF000320C7E95A6,0x3FF00049BE220FD5,0x3FF0001B92A41ACA,0x3FEFFF4425AA9724, |
| 16 | 0x3FEFF5B0A0000000, 0x3FEFE42A40000000, 0x3FEFB7F5C0000000, 0x3FEF599BE0000000, | 16 | 0x3FEFFDABDF6CF05C,0x3FEFFB5AF233EF1A,0x3FEFF837E2AE85F3,0x3FEFF4217B80E938, |
| 17 | 0x3FEEA5E3C0000000, 0x3FED6E7080000000, 0x3FEB7F7960000000, 0x3FE8AB9E40000000, | 17 | 0x3FEFEEECEB4E0444,0x3FEFE863A8358B5F,0x3FEFE04126292670,0x3FEFD63072A0D592, |
| 18 | 0x3FE4DCA480000000, 0x3FE0251880000000, 0x3FD598FB80000000, 0x3FC53D0D60000000, | 18 | 0x3FEFC9C9CD36F56F,0x3FEFBA90594BD8C3,0x3FEFA7F008BA9F13,0x3FEF913BE2A0E0E2, |
| 19 | 0x3F8383A520000000, 0xBFBC977CC0000000, 0xBFC755C080000000, 0xBFC91BDBA0000000, | 19 | 0x3FEF75ACCB01A327,0x3FEF5460F06A4E8F,0x3FEF2C5C0389BD3C,0x3FEEFC8859BF6BCB, |
| 20 | 0xBFC455AFC0000000, 0xBFB6461340000000, 0xBF7056C400000000, 0x3FB1028220000000, | 20 | 0x3FEEC3B916FD8D19,0x3FEE80AD74F0AD16,0x3FEE32153552E2C7,0x3FEDD69643CB9778, |
| 21 | 0x3FBB5B7E60000000, 0x3FBC5903A0000000, 0x3FB55403E0000000, 0x3FA3CED340000000, | 21 | 0x3FED6CD380FFA864,0x3FECF374A4D2961A,0x3FEC692F19B34E54,0x3FEBCCCFA695DD5C, |
| 22 | 0xBF7822DAE0000000, 0xBFA2805D00000000, 0xBFA7140D20000000, 0xBFA18A7760000000, | 22 | 0x3FEB1D44B168764A,0x3FEA59A8D8E4527F,0x3FE9814D9B10A9A3,0x3FE893C5B62135F2, |
| 23 | 0xBF87FF7180000000, 0x3F88CBFA40000000, 0x3F9D4AEC80000000, 0x3FA14A3AC0000000, | 23 | 0x3FE790EEEBF9DABD,0x3FE678FACDEE27FF,0x3FE54C763699791A,0x3FE40C4F1B1EB7A3, |
| 24 | 0x3F9D5C5AA0000000, 0x3F92558B40000000, 0x3F7C997EE0000000, 0x0000000000000000, | 24 | 0x3FE2B9D863D4E0F3,0x3FE156CB86586B0B,0x3FDFCA8F5005B828,0x3FDCCF9C3F455DAC, |
| 25 | 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, | 25 | 0x3FD9C2787F20D06E,0x3FD6A984CAD0F3E5,0x3FD38BB0C452732E,0x3FD0705EC7135366, |
| 26 | 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000 | 26 | 0x3FCABE86754E238F,0x3FC4C0801A6E9A04,0x3FBDECF490C5EA17,0x3FB2DFFACE9CE44B, |
| 27 | 0x3FA0EFD4449F4620,0xBF72F4A65E22806D,0xBFA3F872D761F927,0xBFB1D89F0FD31F7C, | ||
| 28 | 0xBFB8B1EA652EC270,0xBFBE79B82A37C92D,0xBFC1931B697E685E,0xBFC359383D4C8ADA, | ||
| 29 | 0xBFC48F3BFF81B06B,0xBFC537BBA8D6B15C,0xBFC557CEF2168326,0xBFC4F6F781B3347A, | ||
| 30 | 0xBFC41EF872F0E009,0xBFC2DB9F119D54D3,0xBFC13A7E196CB44F,0xBFBE953A67843504, | ||
| 31 | 0xBFBA383D9C597E74,0xBFB57FBD67AD55D6,0xBFB08E18234E5CB3,0xBFA70B06D699FFD1, | ||
| 32 | 0xBF9A1CFB65370184,0xBF7B2CEB901D2067,0x3F86D5DE2C267C78,0x3F9C1D9EF73F384D, | ||
| 33 | 0x3FA579C530950503,0x3FABD1E5FFF9B1D0,0x3FB07DCDC3A4FB5B,0x3FB2724A856EEC1B, | ||
| 34 | 0x3FB3C1F7199FC822,0x3FB46D0979F5043B,0x3FB47831387E0110,0x3FB3EC4A58A3D527, | ||
| 35 | 0x3FB2D5F45F8889B3,0x3FB145113E25B749,0x3FAE9860D18779BC,0x3FA9FFD5F5AB96EA, | ||
| 36 | 0x3FA4EC6C4F47777E,0x3F9F16C5B2604C3A,0x3F9413D801124DB7,0x3F824F668CBB5BDF, | ||
| 37 | 0xBF55B3FA2EE30D66,0xBF86541863B38183,0xBF94031BBBD551DE,0xBF9BAFC27DC5E769, | ||
| 38 | 0xBFA102B3683C57EC,0xBFA3731E608CC6E4,0xBFA520C9F5B5DEBD,0xBFA609DC89BE6ECE, | ||
| 39 | 0xBFA632B83BC5F52F,0xBFA5A58885841AD4,0xBFA471A5D2FF02F3,0xBFA2AAD5CD0377C7, | ||
| 40 | 0xBFA0686FFE4B9B05,0xBF9B88DE413ACB69,0xBF95B4EF6D93F1C5,0xBF8F1B72860B27FA, | ||
| 41 | 0xBF8296A865CDF612,0xBF691BEEDABE928B,0x3F65C04E6AF9D4F1,0x3F8035D8FFCDB0F8, | ||
| 42 | 0x3F89BED23C431BE3,0x3F90E737811A1D21,0x3F941C2040BD7CB1,0x3F967046EC629A09, | ||
| 43 | 0x3F97DE27ECE9ED89,0x3F98684DE31E7040,0x3F9818C4B07718FA,0x3F97005261F91F60, | ||
| 44 | 0x3F95357FDD157646,0x3F92D37C696C572A,0x3F8FF1CFF2BEECB5,0x3F898D20C7A72AC4, | ||
| 45 | 0x3F82BC5B3B0AE2DF,0x3F7784A1B8E9E667,0x3F637BB14081726B,0xBF4B2DACA70C60A9, | ||
| 46 | 0xBF6EFB00AD083727,0xBF7A313758DC6AE9,0xBF819D6A99164BE0,0xBF8533F57533403B, | ||
| 47 | 0xBF87CD120DB5D340,0xBF89638549CD25DE,0xBF89FB8B8D37B1BB,0xBF89A21163F9204E, | ||
| 48 | 0xBF886BA8931297D4,0xBF8673477783D71E,0xBF83D8E1CB165DB8,0xBF80BFEA7216142A, | ||
| 49 | 0xBF7A9B9BC2E40EBF,0xBF7350E806435A7E,0xBF67D35D3734AB5E,0xBF52ADE8FEAB8DB9, | ||
| 50 | 0x3F415669446478E4,0x3F60C56A092AFB48,0x3F6B9F4334A4561F,0x3F724FB908FD87AA, | ||
| 51 | 0x3F75CC56DFE382EA,0x3F783A0C23969A7B,0x3F799833C40C3B82,0x3F79F02721981BF3, | ||
| 52 | 0x3F7954212AB35261,0x3F77DDE0C5FC15C9,0x3F75AD1C98FE0777,0x3F72E5DACC0849F2, | ||
| 53 | 0x3F6F5D7E69DFDE1B,0x3F685EC2CA09E1FD,0x3F611D750E54DF3A,0x3F53C6E392A46D17, | ||
| 54 | 0x3F37A046885F3365,0xBF3BB034D2EE45C2,0xBF5254267B04B482,0xBF5C0516F9CECDC6, | ||
| 55 | 0xBF61E5736853564D,0xBF64C464B9CC47AB,0xBF669C1AEF258F56,0xBF67739985DD0E60, | ||
| 56 | 0xBF675AFD6446395B,0xBF666A0C909B4F78,0xBF64BE9879A7A07B,0xBF627AC74B119DBD, | ||
| 57 | 0xBF5F86B04069DC9B,0xBF597BE8F754AF5E,0xBF531F3EAAE9A1B1,0xBF496D3DE6AD7EA3, | ||
| 58 | 0xBF3A05FFDE4670CF,0xBF06DF95C93A85CA,0x3F31EE2B2C6547AC,0x3F41E694A378C129, | ||
| 59 | 0x3F4930BF840E23C9,0x3F4EBB5D05A0D47D,0x3F51404DA0539855,0x3F524698F56B3F33, | ||
| 60 | 0x3F527EF85309E28F,0x3F51FE70FE2513DE,0x3F50DF1642009B74,0x3F4E7CDA93517CAE, | ||
| 61 | 0x3F4A77AE24F9A533,0x3F45EE226AA69E10,0x3F411DB747374F52,0x3F387F39D229D97F, | ||
| 62 | 0x3F2E1B3D39AF5F8B,0x3F18F557BB082715,0xBEFAC04896E68DDB,0xBF20F5BC77DF558A, | ||
| 63 | 0xBF2C1B6DF3EE94A4,0xBF3254602A816876,0xBF354E90F6EAC26B,0xBF3709F2E5AF1624, | ||
| 64 | 0xBF379FCCB331CE8E,0xBF37327192ADDAD3,0xBF35EA998A894237,0xBF33F4C4977B3489, | ||
| 65 | 0xBF317EC5F68E887B,0xBF2D6B1F793EB773,0xBF2786A226B076D9,0xBF219BE6CEC2CA36, | ||
| 66 | 0xBF17D7F36D2A3A18,0xBF0AAEC5BBAB42AB,0xBEF01818DC224040,0x3EEF2F6E21093846, | ||
| 67 | 0x3F049D6E0060B71F,0x3F0E598CCAFABEFD,0x3F128BC14BE97261,0x3F148703BC70EF6A, | ||
| 68 | 0x3F1545E1579CAA25,0x3F14F7DDF5F8D766,0x3F13D10FF9A1BE0C,0x3F1206D5738ECE3A, | ||
| 69 | 0x3F0F99F6BF17C5D4,0x3F0AA6D7EA524E96,0x3F0588DDF740E1F4,0x3F0086FB6FEA9839, | ||
| 70 | 0x3EF7B28F6D6F5EED,0x3EEEA300DCBAF74A,0x3EE03F904789777C,0x3EC1BFEB320501ED, | ||
| 71 | 0xBEC310D8E585A031,0xBED6F55ECA7E151F,0xBEDFDAA5DACDD0B7,0xBEE26944F3CF6E90, | ||
| 72 | 0xBEE346894453BD1F,0xBEE2E099305CD5A8,0xBEE190385A7EA8B2,0xBEDF4D5FA2FB6BA2, | ||
| 73 | 0xBEDAD4F371257BA0,0xBED62A9CDEB0AB32,0xBED1A6DF97B88316,0xBECB100096894E58, | ||
| 74 | 0xBEC3E8A76257D275,0xBEBBF6C29A5150C9,0xBEB296292998088E,0xBEA70A10498F0E5E, | ||
| 75 | 0xBE99E52D02F887A1,0xBE88C17F4066D432,0xBE702A716CFF56CA,0x3E409F820F781F78, | ||
| 76 | 0x3E643EA99B770FE7,0x3E67DE40CDE0A550,0x3E64F4D534A2335C,0x3E5F194536BDDF7A, | ||
| 77 | 0x3E5425CEBE1FA40A,0x3E46D7B7CC631E73,0x3E364746B6582E54,0x3E21FC07B13031DE, | ||
| 78 | 0x3E064C3D91CF7665,0x3DE224F901A0AFC7,0x3DA97D57859C74A4,0x0000000000000000, | ||
| 79 | |||
| 80 | // extra padding needed for interpolation | ||
| 81 | 0x0000000000000000 | ||
| 27 | }; | 82 | }; |
| 28 | 83 | ||
| 84 | const double *get_minblep_table(void) { return (const double *)minblepdata; } | ||
| 85 | |||
| 29 | void blepAdd(blep_t *b, double dOffset, double dAmplitude) | 86 | void blepAdd(blep_t *b, double dOffset, double dAmplitude) |
| 30 | { | 87 | { |
| 31 | int8_t n; | ||
| 32 | int32_t i; | ||
| 33 | const double *dBlepSrc; | ||
| 34 | double f; | ||
| 35 | |||
| 36 | assert(dOffset >= 0.0 && dOffset < 1.0); | 88 | assert(dOffset >= 0.0 && dOffset < 1.0); |
| 37 | 89 | ||
| 38 | f = dOffset * BLEP_SP; | 90 | double f = dOffset * BLEP_SP; |
| 39 | 91 | ||
| 40 | i = (int32_t)f; // get integer part of f | 92 | int32_t i = (int32_t)f; // get integer part of f |
| 41 | dBlepSrc = (const double *)dBlepData + i + BLEP_OS; | 93 | const double *dBlepSrc = get_minblep_table() + i; |
| 42 | f -= i; // remove integer part from f | 94 | f -= i; // remove integer part from f |
| 43 | 95 | ||
| 44 | i = b->index; | 96 | i = b->index; |
| 45 | 97 | for (int32_t n = 0; n < BLEP_NS; n++) | |
| 46 | n = BLEP_NS; | ||
| 47 | while (n--) | ||
| 48 | { | 98 | { |
| 49 | b->dBuffer[i] += dAmplitude * LERP(dBlepSrc[0], dBlepSrc[1], f); | 99 | b->dBuffer[i] += dAmplitude * LERP(dBlepSrc[0], dBlepSrc[1], f); |
| 50 | i = (i + 1) & BLEP_RNS; | ||
| 51 | dBlepSrc += BLEP_SP; | 100 | dBlepSrc += BLEP_SP; |
| 101 | |||
| 102 | i = (i + 1) & BLEP_RNS; | ||
| 52 | } | 103 | } |
| 53 | 104 | ||
| 54 | b->samplesLeft = BLEP_NS; | 105 | b->samplesLeft = BLEP_NS; |
| 55 | } | 106 | } |
| 56 | 107 | ||
| 57 | /* 8bitbubsy: simplified, faster version of blepAdd for blep'ing voice volume. | 108 | /* 8bitbubsy: simplified, faster version of blepAdd for blep'ing voice volume. |
| 58 | ** Result is identical! (confirmed with binary comparison) | 109 | ** Result is identical! (confirmed with binary comparison w/ MOD2WAV) |
| 59 | */ | 110 | */ |
| 60 | void blepVolAdd(blep_t *b, double dAmplitude) | 111 | void blepVolAdd(blep_t *b, double dAmplitude) |
| 61 | { | 112 | { |
| 62 | int8_t n; | 113 | const double *dBlepSrc = get_minblep_table(); |
| 63 | int32_t i; | ||
| 64 | const double *dBlepSrc; | ||
| 65 | |||
| 66 | dBlepSrc = (const double *)dBlepData + BLEP_OS; | ||
| 67 | 114 | ||
| 68 | i = b->index; | 115 | int32_t i = b->index; |
| 69 | 116 | for (int32_t n = 0; n < BLEP_NS; n++) | |
| 70 | n = BLEP_NS; | ||
| 71 | while (n--) | ||
| 72 | { | 117 | { |
| 73 | b->dBuffer[i] += dAmplitude * (*dBlepSrc); | 118 | b->dBuffer[i] += dAmplitude * (*dBlepSrc); |
| 74 | i = (i + 1) & BLEP_RNS; | 119 | i = (i + 1) & BLEP_RNS; |
| @@ -78,15 +123,13 @@ void blepVolAdd(blep_t *b, double dAmplitude) · 3 unmodified lines | |||
| 78 | b->samplesLeft = BLEP_NS; | 123 | b->samplesLeft = BLEP_NS; |
| 79 | } | 124 | } |
| 80 | 125 | ||
| 81 | double blepRun(blep_t *b) | 126 | double blepRun(blep_t *b, double dInput) |
| 82 | { | 127 | { |
| 83 | double fBlepOutput; | 128 | double dBlepOutput = dInput + b->dBuffer[b->index]; |
| 84 | |||
| 85 | fBlepOutput = b->dBuffer[b->index]; | ||
| 86 | b->dBuffer[b->index] = 0.0; | 129 | b->dBuffer[b->index] = 0.0; |
| 87 | 130 | ||
| 88 | b->index = (b->index + 1) & BLEP_RNS; | 131 | b->index = (b->index + 1) & BLEP_RNS; |
| 89 | 132 | ||
| 90 | b->samplesLeft--; | 133 | b->samplesLeft--; |
| 91 | return fBlepOutput; | 134 | return dBlepOutput; |
| 92 | } | 135 | } |
| @@ -19,11 +19,11 @@ · 18 unmodified lines | |||
| 19 | ** the result of that is the filter cutoff is set at nyquist * (SP/OS), in this case nyquist/5. | 19 | ** the result of that is the filter cutoff is set at nyquist * (SP/OS), in this case nyquist/5. |
| 20 | */ | 20 | */ |
| 21 | 21 | ||
| 22 | #define BLEP_ZC 8 | 22 | #define BLEP_ZC 16 |
| 23 | #define BLEP_OS 5 | 23 | #define BLEP_OS 16 |
| 24 | #define BLEP_SP 5 | 24 | #define BLEP_SP 16 |
| 25 | #define BLEP_NS (BLEP_ZC * BLEP_OS / BLEP_SP) | 25 | #define BLEP_NS (BLEP_ZC * BLEP_OS / BLEP_SP) |
| 26 | #define BLEP_RNS 7 // RNS = (2^ > NS) - 1 | 26 | #define BLEP_RNS 31 // RNS = (2^ > NS) - 1 |
| 27 | 27 | ||
| 28 | typedef struct blep_t | 28 | typedef struct blep_t |
| 29 | { | 29 | { |
| @@ -33,4 +33,4 @@ typedef struct blep_t · 3 unmodified lines | |||
| 33 | 33 | ||
| 34 | void blepAdd(blep_t *b, double dOffset, double dAmplitude); | 34 | void blepAdd(blep_t *b, double dOffset, double dAmplitude); |
| 35 | void blepVolAdd(blep_t *b, double dAmplitude); | 35 | void blepVolAdd(blep_t *b, double dAmplitude); |
| 36 | double blepRun(blep_t *b); | 36 | double blepRun(blep_t *b, double dInput); |
| @@ -14,7 +14,7 @@ · 13 unmodified lines | |||
| 14 | #include "pt2_unicode.h" | 14 | #include "pt2_unicode.h" |
| 15 | #include "pt2_palette.h" | 15 | #include "pt2_palette.h" |
| 16 | 16 | ||
| 17 | #define PROG_VER_STR "1.10" | 17 | #define PROG_VER_STR "1.11" |
| 18 | 18 | ||
| 19 | #ifdef _WIN32 | 19 | #ifdef _WIN32 |
| 20 | #define DIR_DELIMITER '\\' | 20 | #define DIR_DELIMITER '\\' |
| @@ -291,7 +291,7 @@ struct audio_t · 270 unmodified lines | |||
| 291 | { | 291 | { |
| 292 | volatile bool locked; | 292 | volatile bool locked; |
| 293 | bool forceMixerOff; | 293 | bool forceMixerOff; |
| 294 | uint16_t bpmTab[256-32], bpmTab28kHz[256-32], bpmTab22kHz[256-32]; | 294 | uint16_t bpmTab[256-32], bpmTab28kHz[256-32], bpmTab22kHz[256-32], bpmTabMod2Wav[256-32]; |
| 295 | uint32_t outputRate, audioBufferSize; | 295 | uint32_t outputRate, audioBufferSize; |
| 296 | double dPeriodToDeltaDiv; | 296 | double dPeriodToDeltaDiv; |
| 297 | } audio; | 297 | } audio; |
| @@ -365,7 +365,7 @@ struct editor_t · 67 unmodified lines | |||
| 365 | uint8_t blockFromPos, blockToPos, timingMode, f6Pos, f7Pos, f8Pos, f9Pos, f10Pos, keyOctave, pNoteFlag; | 365 | uint8_t blockFromPos, blockToPos, timingMode, f6Pos, f7Pos, f8Pos, f9Pos, f10Pos, keyOctave, pNoteFlag; |
| 366 | uint8_t tuningNote, resampleNote, initialTempo, initialSpeed, editMoveAdd; | 366 | uint8_t tuningNote, resampleNote, initialTempo, initialSpeed, editMoveAdd; |
| 367 | 367 | ||
| 368 | int16_t *mod2WavBuffer, *pat2SmpBuf, modulateSpeed; | 368 | int16_t *pat2SmpBuf, modulateSpeed; |
| 369 | uint16_t metroSpeed, metroChannel, sampleVol, samplePos, chordLength; | 369 | uint16_t metroSpeed, metroChannel, sampleVol, samplePos, chordLength; |
| 370 | uint16_t effectMacros[10], oldTempo, currPlayNote, vol1, vol2, lpCutOff, hpCutOff; | 370 | uint16_t effectMacros[10], oldTempo, currPlayNote, vol1, vol2, lpCutOff, hpCutOff; |
| 371 | int32_t smpRedoLoopStarts[MOD_SAMPLES], smpRedoLoopLengths[MOD_SAMPLES], smpRedoLengths[MOD_SAMPLES]; | 371 | int32_t smpRedoLoopStarts[MOD_SAMPLES], smpRedoLoopLengths[MOD_SAMPLES], smpRedoLengths[MOD_SAMPLES]; |
| @@ -0,0 +1,320 @@ | |||
| 1 | // for finding memory leaks in debug mode with Visual Studio | ||
| 2 | #if defined _DEBUG && defined _MSC_VER | ||
| 3 | #include <crtdbg.h> | ||
| 4 | #endif | ||
| 5 | |||
| 6 | #include <stdio.h> | ||
| 7 | #include <stdint.h> | ||
| 8 | #include <stdbool.h> | ||
| 9 | #include "pt2_header.h" | ||
| 10 | #include "pt2_audio.h" | ||
| 11 | #include "pt2_mouse.h" | ||
| 12 | #include "pt2_textout.h" | ||
| 13 | #include "pt2_visuals.h" | ||
| 14 | #include "pt2_mod2wav.h" | ||
| 15 | |||
| 16 | #define TICKS_PER_RENDER_CHUNK 32 | ||
| 17 | |||
| 18 | void storeTempVariables(void); // pt_modplayer.c | ||
| 19 | bool intMusic(void); // pt_modplayer.c | ||
| 20 | extern uint32_t samplesPerTick; // pt_audio.c | ||
| 21 | |||
| 22 | static volatile bool wavRenderingDone; | ||
| 23 | static int16_t *mod2WavBuffer; | ||
| 24 | |||
| 25 | static void calcMod2WavTotalRows(void); | ||
| 26 | |||
| 27 | static uint32_t getAudioFrame(int16_t *outStream) | ||
| 28 | { | ||
| 29 | if (!intMusic()) | ||
| 30 | wavRenderingDone = true; | ||
| 31 | |||
| 32 | outputAudio(outStream, samplesPerTick); | ||
| 33 | return samplesPerTick; | ||
| 34 | } | ||
| 35 | |||
| 36 | static int32_t SDLCALL mod2WavThreadFunc(void *ptr) | ||
| 37 | { | ||
| 38 | wavHeader_t wavHeader; | ||
| 39 | |||
| 40 | FILE *f = (FILE *)ptr; | ||
| 41 | assert(mod2WavBuffer != NULL && f != NULL); | ||
| 42 | |||
| 43 | // skip wav header place, render data first | ||
| 44 | fseek(f, sizeof (wavHeader_t), SEEK_SET); | ||
| 45 | |||
| 46 | wavRenderingDone = false; | ||
| 47 | |||
| 48 | uint8_t loopCounter = 8; | ||
| 49 | uint32_t totalSampleCounter = 0; | ||
| 50 | |||
| 51 | bool renderDone = false; | ||
| 52 | while (!renderDone) | ||
| 53 | { | ||
| 54 | uint32_t samplesInChunk = 0; | ||
| 55 | |||
| 56 | // render several ticks at once to prevent frequent disk I/O (can speed up the process) | ||
| 57 | int16_t *ptr16 = mod2WavBuffer; | ||
| 58 | for (uint32_t i = 0; i < TICKS_PER_RENDER_CHUNK; i++) | ||
| 59 | { | ||
| 60 | if (!editor.isWAVRendering || wavRenderingDone || editor.abortMod2Wav) | ||
| 61 | { | ||
| 62 | renderDone = true; | ||
| 63 | break; | ||
| 64 | } | ||
| 65 | |||
| 66 | uint32_t tickSamples = getAudioFrame(ptr16) << 1; // *2 for stereo | ||
| 67 | |||
| 68 | samplesInChunk += tickSamples; | ||
| 69 | totalSampleCounter += tickSamples; | ||
| 70 | |||
| 71 | // increase buffer pointer | ||
| 72 | ptr16 += tickSamples; | ||
| 73 | |||
| 74 | if (++loopCounter >= 8) | ||
| 75 | { | ||
| 76 | loopCounter = 0; | ||
| 77 | editor.ui.updateMod2WavDialog = true; | ||
| 78 | } | ||
| 79 | } | ||
| 80 | |||
| 81 | // write buffer to disk | ||
| 82 | if (samplesInChunk > 0) | ||
| 83 | fwrite(mod2WavBuffer, sizeof (int16_t), samplesInChunk, f); | ||
| 84 | } | ||
| 85 | |||
| 86 | free(mod2WavBuffer); | ||
| 87 | |||
| 88 | if (totalSampleCounter & 1) | ||
| 89 | fputc(0, f); // pad align byte | ||
| 90 | |||
| 91 | uint32_t totalRiffChunkLen = (uint32_t)ftell(f) - 8; | ||
| 92 | |||
| 93 | // go back and fill in WAV header | ||
| 94 | rewind(f); | ||
| 95 | |||
| 96 | wavHeader.chunkID = 0x46464952; // "RIFF" | ||
| 97 | wavHeader.chunkSize = totalRiffChunkLen; | ||
| 98 | wavHeader.format = 0x45564157; // "WAVE" | ||
| 99 | wavHeader.subchunk1ID = 0x20746D66; // "fmt " | ||
| 100 | wavHeader.subchunk1Size = 16; | ||
| 101 | wavHeader.audioFormat = 1; | ||
| 102 | wavHeader.numChannels = 2; | ||
| 103 | wavHeader.sampleRate = MOD2WAV_FREQ; | ||
| 104 | wavHeader.bitsPerSample = 16; | ||
| 105 | wavHeader.byteRate = (wavHeader.sampleRate * wavHeader.numChannels * wavHeader.bitsPerSample) / 8; | ||
| 106 | wavHeader.blockAlign = (wavHeader.numChannels * wavHeader.bitsPerSample) / 8; | ||
| 107 | wavHeader.subchunk2ID = 0x61746164; // "data" | ||
| 108 | wavHeader.subchunk2Size = totalSampleCounter * sizeof (int16_t); | ||
| 109 | |||
| 110 | // write main header | ||
| 111 | fwrite(&wavHeader, sizeof (wavHeader_t), 1, f); | ||
| 112 | fclose(f); | ||
| 113 | |||
| 114 | editor.ui.mod2WavFinished = true; | ||
| 115 | editor.ui.updateMod2WavDialog = true; | ||
| 116 | |||
| 117 | return true; | ||
| 118 | } | ||
| 119 | |||
| 120 | bool renderToWav(char *fileName, bool checkIfFileExist) | ||
| 121 | { | ||
| 122 | FILE *fOut; | ||
| 123 | struct stat statBuffer; | ||
| 124 | |||
| 125 | if (checkIfFileExist) | ||
| 126 | { | ||
| 127 | if (stat(fileName, &statBuffer) == 0) | ||
| 128 | { | ||
| 129 | editor.ui.askScreenShown = true; | ||
| 130 | editor.ui.askScreenType = ASK_MOD2WAV_OVERWRITE; | ||
| 131 | |||
| 132 | pointerSetMode(POINTER_MODE_MSG1, NO_CARRY); | ||
| 133 | setStatusMessage("OVERWRITE FILE?", NO_CARRY); | ||
| 134 | |||
| 135 | renderAskDialog(); | ||
| 136 | |||
| 137 | return false; | ||
| 138 | } | ||
| 139 | } | ||
| 140 | |||
| 141 | if (editor.ui.askScreenShown) | ||
| 142 | { | ||
| 143 | editor.ui.askScreenShown = false; | ||
| 144 | editor.ui.answerNo = false; | ||
| 145 | editor.ui.answerYes = false; | ||
| 146 | } | ||
| 147 | |||
| 148 | fOut = fopen(fileName, "wb"); | ||
| 149 | if (fOut == NULL) | ||
| 150 | { | ||
| 151 | displayErrorMsg("FILE I/O ERROR"); | ||
| 152 | return false; | ||
| 153 | } | ||
| 154 | |||
| 155 | const uint32_t maxSamplesToMix = TICKS_PER_RENDER_CHUNK * audio.bpmTabMod2Wav[32-32]; // BPM 32, stereo | ||
| 156 | |||
| 157 | mod2WavBuffer = (int16_t *)malloc(maxSamplesToMix * (2 * sizeof (int16_t))); | ||
| 158 | if (mod2WavBuffer == NULL) | ||
| 159 | { | ||
| 160 | statusOutOfMemory(); | ||
| 161 | return false; | ||
| 162 | } | ||
| 163 | |||
| 164 | storeTempVariables(); | ||
| 165 | calcMod2WavTotalRows(); | ||
| 166 | restartSong(); | ||
| 167 | |||
| 168 | editor.blockMarkFlag = false; | ||
| 169 | |||
| 170 | pointerSetMode(POINTER_MODE_MSG2, NO_CARRY); | ||
| 171 | setStatusMessage("RENDERING MOD...", NO_CARRY); | ||
| 172 | |||
| 173 | editor.ui.disableVisualizer = true; | ||
| 174 | editor.isWAVRendering = true; | ||
| 175 | renderMOD2WAVDialog(); | ||
| 176 | |||
| 177 | editor.abortMod2Wav = false; | ||
| 178 | |||
| 179 | modSetTempo(modEntry->currBPM); // update BPM with MOD2WAV audio output rate | ||
| 180 | |||
| 181 | editor.mod2WavThread = SDL_CreateThread(mod2WavThreadFunc, NULL, fOut); | ||
| 182 | if (editor.mod2WavThread != NULL) | ||
| 183 | { | ||
| 184 | SDL_DetachThread(editor.mod2WavThread); | ||
| 185 | } | ||
| 186 | else | ||
| 187 | { | ||
| 188 | free(mod2WavBuffer); | ||
| 189 | |||
| 190 | editor.ui.disableVisualizer = false; | ||
| 191 | editor.isWAVRendering = false; | ||
| 192 | |||
| 193 | displayErrorMsg("THREAD ERROR"); | ||
| 194 | |||
| 195 | pointerSetMode(POINTER_MODE_IDLE, DO_CARRY); | ||
| 196 | statusAllRight(); | ||
| 197 | |||
| 198 | return false; | ||
| 199 | } | ||
| 200 | |||
| 201 | return true; | ||
| 202 | } | ||
| 203 | |||
| 204 | // ONLY used for a visual percentage counter, so accuracy is not very important | ||
| 205 | static void calcMod2WavTotalRows(void) | ||
| 206 | { | ||
| 207 | bool pBreakFlag, posJumpAssert, calcingRows; | ||
| 208 | int8_t n_pattpos[AMIGA_VOICES], n_loopcount[AMIGA_VOICES]; | ||
| 209 | uint8_t modRow, pBreakPosition, ch, pos; | ||
| 210 | int16_t modOrder; | ||
| 211 | uint16_t modPattern; | ||
| 212 | note_t *note; | ||
| 213 | |||
| 214 | // for pattern loop | ||
| 215 | memset(n_pattpos, 0, sizeof (n_pattpos)); | ||
| 216 | memset(n_loopcount, 0, sizeof (n_loopcount)); | ||
| 217 | |||
| 218 | modEntry->rowsCounter = 0; | ||
| 219 | modEntry->rowsInTotal = 0; | ||
| 220 | |||
| 221 | modRow = 0; | ||
| 222 | modOrder = 0; | ||
| 223 | modPattern = modEntry->head.order[0]; | ||
| 224 | pBreakPosition = 0; | ||
| 225 | posJumpAssert = false; | ||
| 226 | pBreakFlag = false; | ||
| 227 | calcingRows = true; | ||
| 228 | |||
| 229 | memset(editor.rowVisitTable, 0, MOD_ORDERS * MOD_ROWS); | ||
| 230 | while (calcingRows) | ||
| 231 | { | ||
| 232 | editor.rowVisitTable[(modOrder * MOD_ROWS) + modRow] = true; | ||
| 233 | |||
| 234 | for (ch = 0; ch < AMIGA_VOICES; ch++) | ||
| 235 | { | ||
| 236 | note = &modEntry->patterns[modPattern][(modRow * AMIGA_VOICES) + ch]; | ||
| 237 | if (note->command == 0x0B) // Bxx - Position Jump | ||
| 238 | { | ||
| 239 | modOrder = note->param - 1; | ||
| 240 | pBreakPosition = 0; | ||
| 241 | posJumpAssert = true; | ||
| 242 | } | ||
| 243 | else if (note->command == 0x0D) // Dxx - Pattern Break | ||
| 244 | { | ||
| 245 | pBreakPosition = (((note->param >> 4) * 10) + (note->param & 0x0F)); | ||
| 246 | if (pBreakPosition > 63) | ||
| 247 | pBreakPosition = 0; | ||
| 248 | |||
| 249 | posJumpAssert = true; | ||
| 250 | } | ||
| 251 | else if (note->command == 0x0F && note->param == 0) // F00 - Set Speed 0 (stop) | ||
| 252 | { | ||
| 253 | calcingRows = false; | ||
| 254 | break; | ||
| 255 | } | ||
| 256 | else if (note->command == 0x0E && (note->param >> 4) == 0x06) // E6x - Pattern Loop | ||
| 257 | { | ||
| 258 | pos = note->param & 0x0F; | ||
| 259 | if (pos == 0) | ||
| 260 | { | ||
| 261 | n_pattpos[ch] = modRow; | ||
| 262 | } | ||
| 263 | else if (n_loopcount[ch] == 0) | ||
| 264 | { | ||
| 265 | n_loopcount[ch] = pos; | ||
| 266 | |||
| 267 | pBreakPosition = n_pattpos[ch]; | ||
| 268 | pBreakFlag = true; | ||
| 269 | |||
| 270 | for (pos = pBreakPosition; pos <= modRow; pos++) | ||
| 271 | editor.rowVisitTable[(modOrder * MOD_ROWS) + pos] = false; | ||
| 272 | } | ||
| 273 | else if (--n_loopcount[ch]) | ||
| 274 | { | ||
| 275 | pBreakPosition = n_pattpos[ch]; | ||
| 276 | pBreakFlag = true; | ||
| 277 | |||
| 278 | for (pos = pBreakPosition; pos <= modRow; pos++) | ||
| 279 | editor.rowVisitTable[(modOrder * MOD_ROWS) + pos] = false; | ||
| 280 | } | ||
| 281 | } | ||
| 282 | } | ||
| 283 | |||
| 284 | modRow++; | ||
| 285 | modEntry->rowsInTotal++; | ||
| 286 | |||
| 287 | if (pBreakFlag) | ||
| 288 | { | ||
| 289 | modRow = pBreakPosition; | ||
| 290 | pBreakPosition = 0; | ||
| 291 | pBreakFlag = false; | ||
| 292 | } | ||
| 293 | |||
| 294 | if (modRow >= MOD_ROWS || posJumpAssert) | ||
| 295 | { | ||
| 296 | modRow = pBreakPosition; | ||
| 297 | pBreakPosition = 0; | ||
| 298 | posJumpAssert = false; | ||
| 299 | |||
| 300 | modOrder = (modOrder + 1) & 0x7F; | ||
| 301 | if (modOrder >= modEntry->head.orderCount) | ||
| 302 | { | ||
| 303 | modOrder = 0; | ||
| 304 | calcingRows = false; | ||
| 305 | break; | ||
| 306 | } | ||
| 307 | |||
| 308 | modPattern = modEntry->head.order[modOrder]; | ||
| 309 | if (modPattern > MAX_PATTERNS-1) | ||
| 310 | modPattern = MAX_PATTERNS-1; | ||
| 311 | } | ||
| 312 | |||
| 313 | if (editor.rowVisitTable[(modOrder * MOD_ROWS) + modRow]) | ||
| 314 | { | ||
| 315 | // row has been visited before, we're now done! | ||
| 316 | calcingRows = false; | ||
| 317 | break; | ||
| 318 | } | ||
| 319 | } | ||
| 320 | } | ||
| @@ -0,0 +1,7 @@ | |||
| 1 | #pragma once | ||
| 2 | |||
| 3 | #include <stdbool.h> | ||
| 4 | |||
| 5 | #define MOD2WAV_FREQ 96000 | ||
| 6 | |||
| 7 | bool renderToWav(char *fileName, bool checkIfFileExist); | ||
| @@ -1349,17 +1349,19 @@ void loadDroppedFile(char *fullPath, uint32_t fullPathLen, bool autoPlay, bool s · 1348 unmodified lines | |||
| 1349 | 1349 | ||
| 1350 | if (autoPlay) | 1350 | if (autoPlay) |
| 1351 | { | 1351 | { |
| 1352 | // start normal playback | ||
| 1353 | editor.playMode = PLAY_MODE_NORMAL; | 1352 | editor.playMode = PLAY_MODE_NORMAL; |
| 1354 | modPlay(DONT_SET_PATTERN, 0, 0); | ||
| 1355 | editor.currMode = MODE_PLAY; | 1353 | editor.currMode = MODE_PLAY; |
| 1354 | |||
| 1355 | // start normal playback | ||
| 1356 | modPlay(DONT_SET_PATTERN, 0, 0); | ||
| 1357 | |||
| 1356 | pointerSetMode(POINTER_MODE_PLAY, DO_CARRY); | 1358 | pointerSetMode(POINTER_MODE_PLAY, DO_CARRY); |
| 1357 | } | 1359 | } |
| 1358 | else if ((oldMode == MODE_PLAY) || (oldMode == MODE_RECORD)) | 1360 | else if (oldMode == MODE_PLAY || oldMode == MODE_RECORD) |
| 1359 | { | 1361 | { |
| 1360 | // use last mode | 1362 | // use last mode |
| 1361 | editor.playMode = oldPlayMode; | 1363 | editor.playMode = oldPlayMode; |
| 1362 | if ((oldPlayMode == PLAY_MODE_PATTERN) || (oldMode == MODE_RECORD)) | 1364 | if (oldPlayMode == PLAY_MODE_PATTERN || oldMode == MODE_RECORD) |
| 1363 | modPlay(0, 0, 0); | 1365 | modPlay(0, 0, 0); |
| 1364 | else | 1366 | else |
| 1365 | modPlay(DONT_SET_PATTERN, 0, 0); | 1367 | modPlay(DONT_SET_PATTERN, 0, 0); |
| @@ -1174,7 +1174,7 @@ void modSetPos(int16_t order, int16_t row) · 1173 unmodified lines | |||
| 1174 | 1174 | ||
| 1175 | void modSetTempo(uint16_t bpm) | 1175 | void modSetTempo(uint16_t bpm) |
| 1176 | { | 1176 | { |
| 1177 | int16_t smpsPerTick; | 1177 | uint32_t smpsPerTick; |
| 1178 | 1178 | ||
| 1179 | if (bpm < 32) | 1179 | if (bpm < 32) |
| 1180 | return; | 1180 | return; |
| @@ -1190,6 +1190,8 @@ void modSetTempo(uint16_t bpm) · 9 unmodified lines | |||
| 1190 | 1190 | ||
| 1191 | if (editor.isSMPRendering) | 1191 | if (editor.isSMPRendering) |
| 1192 | smpsPerTick = editor.pat2SmpHQ ? audio.bpmTab28kHz[bpm] : audio.bpmTab22kHz[bpm]; | 1192 | smpsPerTick = editor.pat2SmpHQ ? audio.bpmTab28kHz[bpm] : audio.bpmTab22kHz[bpm]; |
| 1193 | else if (editor.isWAVRendering) | ||
| 1194 | smpsPerTick = audio.bpmTabMod2Wav[bpm]; | ||
| 1193 | else | 1195 | else |
| 1194 | smpsPerTick = audio.bpmTab[bpm]; | 1196 | smpsPerTick = audio.bpmTab[bpm]; |
| 1195 | 1197 | ||
| @@ -0,0 +1,102 @@ | |||
| 1 | // for finding memory leaks in debug mode with Visual Studio | ||
| 2 | #if defined _DEBUG && defined _MSC_VER | ||
| 3 | #include <crtdbg.h> | ||
| 4 | #endif | ||
| 5 | |||
| 6 | #include <stdint.h> | ||
| 7 | #include <stdbool.h> | ||
| 8 | #include "pt2_header.h" | ||
| 9 | #include "pt2_helpers.h" | ||
| 10 | #include "pt2_visuals.h" | ||
| 11 | #include "pt2_mouse.h" | ||
| 12 | #include "pt2_audio.h" | ||
| 13 | #include "pt2_sampler.h" | ||
| 14 | #include "pt2_textout.h" | ||
| 15 | |||
| 16 | bool intMusic(void); // pt_modplayer.c | ||
| 17 | extern uint32_t samplesPerTick; // pt_audio.c | ||
| 18 | void storeTempVariables(void); // pt_modplayer.c | ||
| 19 | |||
| 20 | void doPat2Smp(void) | ||
| 21 | { | ||
| 22 | moduleSample_t *s; | ||
| 23 | |||
| 24 | editor.ui.pat2SmpDialogShown = false; | ||
| 25 | |||
| 26 | editor.pat2SmpBuf = (int16_t *)malloc(MAX_SAMPLE_LEN * sizeof (int16_t)); | ||
| 27 | if (editor.pat2SmpBuf == NULL) | ||
| 28 | { | ||
| 29 | statusOutOfMemory(); | ||
| 30 | return; | ||
| 31 | } | ||
| 32 | |||
| 33 | int8_t oldRow = editor.songPlaying ? 0 : modEntry->currRow; | ||
| 34 | uint32_t oldSamplesPerTick = samplesPerTick; | ||
| 35 | |||
| 36 | editor.isSMPRendering = true; // this must be set before restartSong() | ||
| 37 | storeTempVariables(); | ||
| 38 | restartSong(); | ||
| 39 | modEntry->row = oldRow; | ||
| 40 | modEntry->currRow = modEntry->row; | ||
| 41 | |||
| 42 | editor.blockMarkFlag = false; | ||
| 43 | pointerSetMode(POINTER_MODE_MSG2, NO_CARRY); | ||
| 44 | setStatusMessage("RENDERING...", NO_CARRY); | ||
| 45 | modSetTempo(modEntry->currBPM); | ||
| 46 | editor.pat2SmpPos = 0; | ||
| 47 | |||
| 48 | editor.smpRenderingDone = false; | ||
| 49 | while (!editor.smpRenderingDone) | ||
| 50 | { | ||
| 51 | if (!intMusic()) | ||
| 52 | editor.smpRenderingDone = true; | ||
| 53 | |||
| 54 | outputAudio(NULL, samplesPerTick); | ||
| 55 | } | ||
| 56 | editor.isSMPRendering = false; | ||
| 57 | resetSong(); | ||
| 58 | |||
| 59 | // set back old row and samplesPerTick | ||
| 60 | modEntry->row = oldRow; | ||
| 61 | modEntry->currRow = modEntry->row; | ||
| 62 | mixerSetSamplesPerTick(oldSamplesPerTick); | ||
| 63 | |||
| 64 | normalize16bitSigned(editor.pat2SmpBuf, MIN(editor.pat2SmpPos, MAX_SAMPLE_LEN)); | ||
| 65 | |||
| 66 | s = &modEntry->samples[editor.currSample]; | ||
| 67 | |||
| 68 | // quantize to 8-bit | ||
| 69 | for (uint32_t i = 0; i < editor.pat2SmpPos; i++) | ||
| 70 | modEntry->sampleData[s->offset+i] = editor.pat2SmpBuf[i] >> 8; | ||
| 71 | |||
| 72 | // clear the rest of the sample | ||
| 73 | if (editor.pat2SmpPos < MAX_SAMPLE_LEN) | ||
| 74 | memset(&modEntry->sampleData[s->offset+editor.pat2SmpPos], 0, MAX_SAMPLE_LEN - editor.pat2SmpPos); | ||
| 75 | |||
| 76 | free(editor.pat2SmpBuf); | ||
| 77 | |||
| 78 | memset(s->text, 0, sizeof (s->text)); | ||
| 79 | if (editor.pat2SmpHQ) | ||
| 80 | { | ||
| 81 | strcpy(s->text, "pat2smp (a-3 tune:+5)"); | ||
| 82 | s->fineTune = 5; | ||
| 83 | } | ||
| 84 | else | ||
| 85 | { | ||
| 86 | strcpy(s->text, "pat2smp (f-3 tune:+1)"); | ||
| 87 | s->fineTune = 1; | ||
| 88 | } | ||
| 89 | |||
| 90 | s->length = editor.pat2SmpPos; | ||
| 91 | s->volume = 64; | ||
| 92 | s->loopStart = 0; | ||
| 93 | s->loopLength = 2; | ||
| 94 | |||
| 95 | editor.samplePos = 0; | ||
| 96 | fixSampleBeep(s); | ||
| 97 | updateCurrSample(); | ||
| 98 | |||
| 99 | pointerSetMode(POINTER_MODE_IDLE, DO_CARRY); | ||
| 100 | displayMsg("ROWS RENDERED!"); | ||
| 101 | setMsgPointer(); | ||
| 102 | } | ||
| @@ -0,0 +1,3 @@ | |||
| 1 | #pragma once | ||
| 2 | |||
| 3 | void doPat2Smp(void); | ||
| @@ -44,6 +44,87 @@ static const int8_t tuneToneData[32] = // Tuning Tone (Sine Wave) · 43 unmodified lines | |||
| 44 | }; | 44 | }; |
| 45 | 45 | ||
| 46 | void setLoopSprites(void); | 46 | void setLoopSprites(void); |
| 47 | void fixSampleBeep(moduleSample_t *s); | ||
| 48 | |||
| 49 | void upSample(void) | ||
| 50 | { | ||
| 51 | moduleSample_t *s = &modEntry->samples[editor.currSample]; | ||
| 52 | |||
| 53 | uint32_t newLength = (s->length >> 1) & 0xFFFE; | ||
| 54 | if (newLength < 2) | ||
| 55 | return; | ||
| 56 | |||
| 57 | turnOffVoices(); | ||
| 58 | |||
| 59 | // upsample | ||
| 60 | int8_t *ptr8 = &modEntry->sampleData[s->offset]; | ||
| 61 | for (uint32_t i = 0; i < newLength; i++) | ||
| 62 | ptr8[i] = ptr8[i << 1]; | ||
| 63 | |||
| 64 | // clear junk after shrunk sample | ||
| 65 | if (newLength < MAX_SAMPLE_LEN) | ||
| 66 | memset(&ptr8[newLength], 0, MAX_SAMPLE_LEN - newLength); | ||
| 67 | |||
| 68 | s->length = (uint16_t)newLength; | ||
| 69 | s->loopStart = (s->loopStart >> 1) & 0xFFFE; | ||
| 70 | s->loopLength = (s->loopLength >> 1) & 0xFFFE; | ||
| 71 | |||
| 72 | if (s->loopLength < 2) | ||
| 73 | { | ||
| 74 | s->loopStart = 0; | ||
| 75 | s->loopLength = 2; | ||
| 76 | } | ||
| 77 | |||
| 78 | fixSampleBeep(s); | ||
| 79 | updateCurrSample(); | ||
| 80 | |||
| 81 | editor.ui.updateSongSize = true; | ||
| 82 | updateWindowTitle(MOD_IS_MODIFIED); | ||
| 83 | } | ||
| 84 | |||
| 85 | void downSample(void) | ||
| 86 | { | ||
| 87 | moduleSample_t *s = &modEntry->samples[editor.currSample]; | ||
| 88 | |||
| 89 | uint32_t newLength = s->length << 1; | ||
| 90 | if (newLength > MAX_SAMPLE_LEN) | ||
| 91 | newLength = MAX_SAMPLE_LEN; | ||
| 92 | |||
| 93 | turnOffVoices(); | ||
| 94 | |||
| 95 | // downsample | ||
| 96 | |||
| 97 | int8_t *ptr8 = &modEntry->sampleData[s->offset]; | ||
| 98 | int8_t *ptr8_2 = ptr8 - 1; | ||
| 99 | for (int32_t i = s->length-1; i > 0; i--) | ||
| 100 | { | ||
| 101 | ptr8[i<<1] = ptr8[i]; | ||
| 102 | ptr8_2[i<<1] = ptr8_2[i]; | ||
| 103 | } | ||
| 104 | |||
| 105 | s->length = newLength; | ||
| 106 | |||
| 107 | if (s->loopLength > 2) | ||
| 108 | { | ||
| 109 | uint32_t loopStart = s->loopStart << 1; | ||
| 110 | uint32_t loopLength = s->loopLength << 1; | ||
| 111 | |||
| 112 | if (loopStart+loopLength > s->length) | ||
| 113 | { | ||
| 114 | loopStart = 0; | ||
| 115 | loopLength = 2; | ||
| 116 | } | ||
| 117 | |||
| 118 | s->loopStart = (uint16_t)loopStart; | ||
| 119 | s->loopLength = (uint16_t)loopLength; | ||
| 120 | } | ||
| 121 | |||
| 122 | fixSampleBeep(s); | ||
| 123 | updateCurrSample(); | ||
| 124 | |||
| 125 | editor.ui.updateSongSize = true; | ||
| 126 | updateWindowTitle(MOD_IS_MODIFIED); | ||
| 127 | } | ||
| 47 | 128 | ||
| 48 | void createSampleMarkTable(void) | 129 | void createSampleMarkTable(void) |
| 49 | { | 130 | { |
| @@ -3,6 +3,8 @@ · 2 unmodified lines | |||
| 3 | #include <stdint.h> | 3 | #include <stdint.h> |
| 4 | #include <stdbool.h> | 4 | #include <stdbool.h> |
| 5 | 5 | ||
| 6 | void downSample(void); | ||
| 7 | void upSample(void); | ||
| 6 | void createSampleMarkTable(void); | 8 | void createSampleMarkTable(void); |
| 7 | int32_t smpPos2Scr(int32_t pos); | 9 | int32_t smpPos2Scr(int32_t pos); |
| 8 | int32_t scr2SmpPos(int32_t x); | 10 | int32_t scr2SmpPos(int32_t x); |
| @@ -35,6 +35,8 @@ · 34 unmodified lines | |||
| 35 | #include "pt2_helpers.h" | 35 | #include "pt2_helpers.h" |
| 36 | #include "pt2_scopes.h" | 36 | #include "pt2_scopes.h" |
| 37 | #include "pt2_edit.h" | 37 | #include "pt2_edit.h" |
| 38 | #include "pt2_pat2smp.h" | ||
| 39 | #include "pt2_mod2wav.h" | ||
| 38 | 40 | ||
| 39 | typedef struct sprite_t | 41 | typedef struct sprite_t |
| 40 | { | 42 | { |
| @@ -58,9 +60,7 @@ static const uint16_t cursorPosTable[24] = · 17 unmodified lines | |||
| 58 | 246, 270, 278, 286, 294, 302 | 60 | 246, 270, 278, 286, 294, 302 |
| 59 | }; | 61 | }; |
| 60 | 62 | ||
| 61 | bool intMusic(void); // pt_modplayer.c | 63 | |
| 62 | extern int32_t samplesPerTick; // pt_audio.c | ||
| 63 | void storeTempVariables(void); // pt_modplayer.c | ||
| 64 | void updateSongInfo1(void); | 64 | void updateSongInfo1(void); |
| 65 | void updateSongInfo2(void); | 65 | void updateSongInfo2(void); |
| 66 | void updateSampler(void); | 66 | void updateSampler(void); |
| @@ -1449,6 +1449,7 @@ void updateMOD2WAVDialog(void) · 1382 unmodified lines | |||
| 1449 | } | 1449 | } |
| 1450 | 1450 | ||
| 1451 | editor.isWAVRendering = false; | 1451 | editor.isWAVRendering = false; |
| 1452 | modSetTempo(modEntry->currBPM); // update BPM with normal audio output rate | ||
| 1452 | displayMainScreen(); | 1453 | displayMainScreen(); |
| 1453 | } | 1454 | } |
| 1454 | else | 1455 | else |
| @@ -1785,8 +1786,7 @@ void handleAskNo(void) · 330 unmodified lines | |||
| 1785 | void handleAskYes(void) | 1786 | void handleAskYes(void) |
| 1786 | { | 1787 | { |
| 1787 | char fileName[20 + 4 + 1]; | 1788 | char fileName[20 + 4 + 1]; |
| 1788 | int8_t *tmpSmpBuffer, oldSample, oldRow; | 1789 | int8_t oldSample; |
| 1789 | int32_t j, newLength, oldSamplesPerTick, loopStart, loopLength; | ||
| 1790 | uint32_t i; | 1790 | uint32_t i; |
| 1791 | moduleSample_t *s; | 1791 | moduleSample_t *s; |
| 1792 | 1792 | ||
| @@ -1816,90 +1816,7 @@ void handleAskYes(void) · 23 unmodified lines | |||
| 1816 | case ASK_PAT2SMP: | 1816 | case ASK_PAT2SMP: |
| 1817 | { | 1817 | { |
| 1818 | restoreStatusAndMousePointer(); | 1818 | restoreStatusAndMousePointer(); |
| 1819 | 1819 | doPat2Smp(); | |
| 1820 | editor.ui.pat2SmpDialogShown = false; | ||
| 1821 | |||
| 1822 | editor.pat2SmpBuf = (int16_t *)malloc(MAX_SAMPLE_LEN * sizeof (int16_t)); | ||
| 1823 | if (editor.pat2SmpBuf == NULL) | ||
| 1824 | { | ||
| 1825 | statusOutOfMemory(); | ||
| 1826 | return; | ||
| 1827 | } | ||
| 1828 | |||
| 1829 | oldRow = editor.songPlaying ? 0 : modEntry->currRow; | ||
| 1830 | oldSamplesPerTick = samplesPerTick; | ||
| 1831 | |||
| 1832 | editor.isSMPRendering = true; // this must be set before restartSong() | ||
| 1833 | storeTempVariables(); | ||
| 1834 | restartSong(); | ||
| 1835 | modEntry->row = oldRow; | ||
| 1836 | modEntry->currRow = modEntry->row; | ||
| 1837 | |||
| 1838 | editor.blockMarkFlag = false; | ||
| 1839 | pointerSetMode(POINTER_MODE_MSG2, NO_CARRY); | ||
| 1840 | setStatusMessage("RENDERING...", NO_CARRY); | ||
| 1841 | modSetTempo(modEntry->currBPM); | ||
| 1842 | editor.pat2SmpPos = 0; | ||
| 1843 | |||
| 1844 | editor.smpRenderingDone = false; | ||
| 1845 | while (!editor.smpRenderingDone) | ||
| 1846 | { | ||
| 1847 | if (!intMusic()) | ||
| 1848 | editor.smpRenderingDone = true; | ||
| 1849 | |||
| 1850 | outputAudio(NULL, samplesPerTick); | ||
| 1851 | } | ||
| 1852 | editor.isSMPRendering = false; | ||
| 1853 | resetSong(); | ||
| 1854 | |||
| 1855 | // set back old row and samplesPerTick | ||
| 1856 | modEntry->row = oldRow; | ||
| 1857 | modEntry->currRow = modEntry->row; | ||
| 1858 | mixerSetSamplesPerTick(oldSamplesPerTick); | ||
| 1859 | |||
| 1860 | // normalize 16-bit samples | ||
| 1861 | normalize16bitSigned(editor.pat2SmpBuf, MIN(editor.pat2SmpPos, MAX_SAMPLE_LEN)); | ||
| 1862 | |||
| 1863 | s = &modEntry->samples[editor.currSample]; | ||
| 1864 | |||
| 1865 | // quantize to 8-bit | ||
| 1866 | for (i = 0; i < editor.pat2SmpPos; i++) | ||
| 1867 | modEntry->sampleData[s->offset+i] = editor.pat2SmpBuf[i] >> 8; | ||
| 1868 | |||
| 1869 | // clear the rest of the sample | ||
| 1870 | if (editor.pat2SmpPos < MAX_SAMPLE_LEN) | ||
| 1871 | memset(&modEntry->sampleData[s->offset+editor.pat2SmpPos], 0, MAX_SAMPLE_LEN - editor.pat2SmpPos); | ||
| 1872 | |||
| 1873 | // free temp mixing buffer | ||
| 1874 | free(editor.pat2SmpBuf); | ||
| 1875 | |||
| 1876 | // zero out sample text | ||
| 1877 | memset(s->text, 0, sizeof (s->text)); | ||
| 1878 | |||
| 1879 | // set new sample text | ||
| 1880 | if (editor.pat2SmpHQ) | ||
| 1881 | { | ||
| 1882 | strcpy(s->text, "pat2smp (a-3 tune:+5)"); | ||
| 1883 | s->fineTune = 5; | ||
| 1884 | } | ||
| 1885 | else | ||
| 1886 | { | ||
| 1887 | strcpy(s->text, "pat2smp (f-3 tune:+1)"); | ||
| 1888 | s->fineTune = 1; | ||
| 1889 | } | ||
| 1890 | |||
| 1891 | // new sample attributes | ||
| 1892 | s->length = editor.pat2SmpPos; | ||
| 1893 | s->volume = 64; | ||
| 1894 | s->loopStart = 0; | ||
| 1895 | s->loopLength = 2; | ||
| 1896 | |||
| 1897 | pointerSetMode(POINTER_MODE_IDLE, DO_CARRY); | ||
| 1898 | displayMsg("ROWS RENDERED!"); | ||
| 1899 | setMsgPointer(); | ||
| 1900 | editor.samplePos = 0; | ||
| 1901 | fixSampleBeep(s); | ||
| 1902 | updateCurrSample(); | ||
| 1903 | } | 1820 | } |
| 1904 | break; | 1821 | break; |
| 1905 | 1822 | ||
| @@ -1961,103 +1878,14 @@ void handleAskYes(void) · 55 unmodified lines | |||
| 1961 | case ASK_UPSAMPLE: | 1878 | case ASK_UPSAMPLE: |
| 1962 | { | 1879 | { |
| 1963 | restoreStatusAndMousePointer(); | 1880 | restoreStatusAndMousePointer(); |
| 1964 | 1881 | upSample(); | |
| 1965 | s = &modEntry->samples[editor.currSample]; | ||
| 1966 | |||
| 1967 | tmpSmpBuffer = (int8_t *)malloc(s->length); | ||
| 1968 | if (tmpSmpBuffer == NULL) | ||
| 1969 | { | ||
| 1970 | statusOutOfMemory(); | ||
| 1971 | return; | ||
| 1972 | } | ||
| 1973 | |||
| 1974 | newLength = (s->length / 2) & 0xFFFE; | ||
| 1975 | if (newLength < 2) | ||
| 1976 | return; | ||
| 1977 | |||
| 1978 | turnOffVoices(); | ||
| 1979 | |||
| 1980 | memcpy(tmpSmpBuffer, &modEntry->sampleData[s->offset], s->length); | ||
| 1981 | |||
| 1982 | // upsample | ||
| 1983 | for (j = 0; j < newLength; j++) | ||
| 1984 | modEntry->sampleData[s->offset + j] = tmpSmpBuffer[j * 2]; | ||
| 1985 | |||
| 1986 | if (newLength < MAX_SAMPLE_LEN) | ||
| 1987 | memset(&modEntry->sampleData[s->offset + newLength], 0, MAX_SAMPLE_LEN - newLength); | ||
| 1988 | |||
| 1989 | free(tmpSmpBuffer); | ||
| 1990 | |||
| 1991 | s->length = newLength; | ||
| 1992 | s->loopStart = (s->loopStart / 2) & 0xFFFE; | ||
| 1993 | s->loopLength = (s->loopLength / 2) & 0xFFFE; | ||
| 1994 | |||
| 1995 | if (s->loopLength < 2) | ||
| 1996 | { | ||
| 1997 | s->loopStart = 0; | ||
| 1998 | s->loopLength = 2; | ||
| 1999 | } | ||
| 2000 | |||
| 2001 | fixSampleBeep(s); | ||
| 2002 | updateCurrSample(); | ||
| 2003 | |||
| 2004 | editor.ui.updateSongSize = true; | ||
| 2005 | updateWindowTitle(MOD_IS_MODIFIED); | ||
| 2006 | } | 1882 | } |
| 2007 | break; | 1883 | break; |
| 2008 | 1884 | ||
| 2009 | case ASK_DOWNSAMPLE: | 1885 | case ASK_DOWNSAMPLE: |
| 2010 | { | 1886 | { |
| 2011 | restoreStatusAndMousePointer(); | 1887 | restoreStatusAndMousePointer(); |
| 2012 | 1888 | downSample(); | |
| 2013 | s = &modEntry->samples[editor.currSample]; | ||
| 2014 | |||
| 2015 | tmpSmpBuffer = (int8_t *)malloc(s->length); | ||
| 2016 | if (tmpSmpBuffer == NULL) | ||
| 2017 | { | ||
| 2018 | statusOutOfMemory(); | ||
| 2019 | return; | ||
| 2020 | } | ||
| 2021 | |||
| 2022 | newLength = s->length * 2; | ||
| 2023 | if (newLength > MAX_SAMPLE_LEN) | ||
| 2024 | newLength = MAX_SAMPLE_LEN; | ||
| 2025 | |||
| 2026 | turnOffVoices(); | ||
| 2027 | |||
| 2028 | memcpy(tmpSmpBuffer, &modEntry->sampleData[s->offset], s->length); | ||
| 2029 | |||
| 2030 | // downsample | ||
| 2031 | for (j = 0; j < newLength; j++) | ||
| 2032 | modEntry->sampleData[s->offset+j] = tmpSmpBuffer[j >> 1]; | ||
| 2033 | |||
| 2034 | if (newLength < MAX_SAMPLE_LEN) | ||
| 2035 | memset(&modEntry->sampleData[s->offset+newLength], 0, MAX_SAMPLE_LEN - newLength); | ||
| 2036 | |||
| 2037 | free(tmpSmpBuffer); | ||
| 2038 | |||
| 2039 | s->length = newLength; | ||
| 2040 | |||
| 2041 | if (s->loopLength > 2) | ||
| 2042 | { | ||
| 2043 | loopStart = s->loopStart * 2; | ||
| 2044 | loopLength = s->loopLength * 2; | ||
| 2045 | |||
| 2046 | if (loopStart+loopLength > s->length) | ||
| 2047 | { | ||
| 2048 | loopStart = 0; | ||
| 2049 | loopLength = 2; | ||
| 2050 | } | ||
| 2051 | |||
| 2052 | s->loopStart = (uint16_t)loopStart; | ||
| 2053 | s->loopLength = (uint16_t)loopLength; | ||
| 2054 | } | ||
| 2055 | |||
| 2056 | fixSampleBeep(s); | ||
| 2057 | updateCurrSample(); | ||
| 2058 | |||
| 2059 | editor.ui.updateSongSize = true; | ||
| 2060 | updateWindowTitle(MOD_IS_MODIFIED); | ||
| 2061 | } | 1889 | } |
| 2062 | break; | 1890 | break; |
| 2063 | 1891 | ||
| @@ -290,9 +290,11 @@ · 289 unmodified lines | |||
| 290 | <ClInclude Include="..\..\src\pt2_header.h" /> | 290 | <ClInclude Include="..\..\src\pt2_header.h" /> |
| 291 | <ClInclude Include="..\..\src\pt2_helpers.h" /> | 291 | <ClInclude Include="..\..\src\pt2_helpers.h" /> |
| 292 | <ClInclude Include="..\..\src\pt2_keyboard.h" /> | 292 | <ClInclude Include="..\..\src\pt2_keyboard.h" /> |
| 293 | <ClInclude Include="..\..\src\pt2_mod2wav.h" /> | ||
| 293 | <ClInclude Include="..\..\src\pt2_modloader.h" /> | 294 | <ClInclude Include="..\..\src\pt2_modloader.h" /> |
| 294 | <ClInclude Include="..\..\src\pt2_mouse.h" /> | 295 | <ClInclude Include="..\..\src\pt2_mouse.h" /> |
| 295 | <ClInclude Include="..\..\src\pt2_palette.h" /> | 296 | <ClInclude Include="..\..\src\pt2_palette.h" /> |
| 297 | <ClInclude Include="..\..\src\pt2_pat2smp.h" /> | ||
| 296 | <ClInclude Include="..\..\src\pt2_patternviewer.h" /> | 298 | <ClInclude Include="..\..\src\pt2_patternviewer.h" /> |
| 297 | <ClInclude Include="..\..\src\pt2_sampleloader.h" /> | 299 | <ClInclude Include="..\..\src\pt2_sampleloader.h" /> |
| 298 | <ClInclude Include="..\..\src\pt2_sampler.h" /> | 300 | <ClInclude Include="..\..\src\pt2_sampler.h" /> |
| @@ -331,10 +333,12 @@ · 32 unmodified lines | |||
| 331 | <ClCompile Include="..\..\src\pt2_helpers.c" /> | 333 | <ClCompile Include="..\..\src\pt2_helpers.c" /> |
| 332 | <ClCompile Include="..\..\src\pt2_keyboard.c" /> | 334 | <ClCompile Include="..\..\src\pt2_keyboard.c" /> |
| 333 | <ClCompile Include="..\..\src\pt2_main.c" /> | 335 | <ClCompile Include="..\..\src\pt2_main.c" /> |
| 336 | <ClCompile Include="..\..\src\pt2_mod2wav.c" /> | ||
| 334 | <ClCompile Include="..\..\src\pt2_modloader.c" /> | 337 | <ClCompile Include="..\..\src\pt2_modloader.c" /> |
| 335 | <ClCompile Include="..\..\src\pt2_modplayer.c" /> | 338 | <ClCompile Include="..\..\src\pt2_modplayer.c" /> |
| 336 | <ClCompile Include="..\..\src\pt2_mouse.c" /> | 339 | <ClCompile Include="..\..\src\pt2_mouse.c" /> |
| 337 | <ClCompile Include="..\..\src\pt2_palette.c" /> | 340 | <ClCompile Include="..\..\src\pt2_palette.c" /> |
| 341 | <ClCompile Include="..\..\src\pt2_pat2smp.c" /> | ||
| 338 | <ClCompile Include="..\..\src\pt2_patternviewer.c" /> | 342 | <ClCompile Include="..\..\src\pt2_patternviewer.c" /> |
| 339 | <ClCompile Include="..\..\src\pt2_sampleloader.c" /> | 343 | <ClCompile Include="..\..\src\pt2_sampleloader.c" /> |
| 340 | <ClCompile Include="..\..\src\pt2_sampler.c" /> | 344 | <ClCompile Include="..\..\src\pt2_sampler.c" /> |
| @@ -66,6 +66,12 @@ · 65 unmodified lines | |||
| 66 | <ClInclude Include="..\..\src\pt2_visuals.h"> | 66 | <ClInclude Include="..\..\src\pt2_visuals.h"> |
| 67 | <Filter>headers</Filter> | 67 | <Filter>headers</Filter> |
| 68 | </ClInclude> | 68 | </ClInclude> |
| 69 | <ClInclude Include="..\..\src\pt2_mod2wav.h"> | ||
| 70 | <Filter>headers</Filter> | ||
| 71 | </ClInclude> | ||
| 72 | <ClInclude Include="..\..\src\pt2_pat2smp.h"> | ||
| 73 | <Filter>headers</Filter> | ||
| 74 | </ClInclude> | ||
| 69 | </ItemGroup> | 75 | </ItemGroup> |
| 70 | <ItemGroup> | 76 | <ItemGroup> |
| 71 | <ClCompile Include="..\..\src\pt2_audio.c" /> | 77 | <ClCompile Include="..\..\src\pt2_audio.c" /> |
| @@ -142,6 +148,8 @@ · 70 unmodified lines | |||
| 142 | <ClCompile Include="..\..\src\gfx\pt2_gfx_yes_no_dialog.c"> | 148 | <ClCompile Include="..\..\src\gfx\pt2_gfx_yes_no_dialog.c"> |
| 143 | <Filter>gfx</Filter> | 149 | <Filter>gfx</Filter> |
| 144 | </ClCompile> | 150 | </ClCompile> |
| 151 | <ClCompile Include="..\..\src\pt2_mod2wav.c" /> | ||
| 152 | <ClCompile Include="..\..\src\pt2_pat2smp.c" /> | ||
| 145 | </ItemGroup> | 153 | </ItemGroup> |
| 146 | <ItemGroup> | 154 | <ItemGroup> |
| 147 | <ResourceCompile Include="..\..\src\pt2-clone.rc" /> | 155 | <ResourceCompile Include="..\..\src\pt2-clone.rc" /> |