From dd4db01c775e210331e2d75fca7c71869cc84c39 Mon Sep 17 00:00:00 2001 From: Luis Michaelis Date: Tue, 30 Apr 2024 14:22:39 +0200 Subject: [PATCH] chore: more code cleanup --- src/Band.c | 4 ++-- src/Dls.c | 8 ++------ src/Style.c | 6 ------ src/Synth.c | 2 -- src/_Dls.h | 6 ++++++ src/_Internal.h | 1 + src/io/Common.c | 2 ++ src/io/Segment.c | 2 +- src/util/Tsf.c | 3 +-- 9 files changed, 15 insertions(+), 19 deletions(-) diff --git a/src/Band.c b/src/Band.c index 1694d27..03c2939 100644 --- a/src/Band.c +++ b/src/Band.c @@ -52,7 +52,7 @@ static DmDlsInstrument* DmBand_findDlsInstrument(DmInstrument* slf, DmDls* dls) ins = &dls->instruments[i]; // TODO(lmichaelis): We need to ignore drum kits for now since I don't know how to handle them properly - if (ins->bank & (1U << 31U)) { + if (ins->bank & DmDls_DRUM_KIT) { Dm_report(DmLogLevel_DEBUG, "DmBand: Ignoring DLS drum-kit instrument '%s'", ins->info.inam); continue; } @@ -63,7 +63,7 @@ static DmDlsInstrument* DmBand_findDlsInstrument(DmInstrument* slf, DmDls* dls) } } - Dm_report(DmLogLevel_ERROR, + Dm_report(DmLogLevel_WARN, "DmBand: Instrument patch %d:%d not found in band '%s'", bank, patch, diff --git a/src/Dls.c b/src/Dls.c index 0252f87..eb77a36 100644 --- a/src/Dls.c +++ b/src/Dls.c @@ -148,10 +148,6 @@ static int clamp_16bit(int v) { return v; } -static int max(int a, int b) { - return a >= b ? a : b; -} - // TODO(lmichaelis): These are the 'built in' set of 7 predictor value pairs; additional values can be added // to this table by including them as metadata chunks in the WAVE header static int ADPCM_ADAPT_COEFF1[7] = {256, 512, 0, 192, 240, 460, 392}; @@ -196,7 +192,7 @@ static uint8_t const* DmDls_decodeAdpcmBlock(uint8_t const* adpcm, float* pcm, u *pcm++ = (float) ((int16_t) predictor) / INT16_MAX; sample_b = sample_a; sample_a = (int16_t) (predictor); - delta = max((ADPCM_ADAPT_TABLE[(b & 0xF0) >> 4] * delta) / 256, 16); + delta = max_s32((ADPCM_ADAPT_TABLE[(b & 0xF0) >> 4] * delta) / 256, 16); // Low Nibble nibble = signed_4bit((b & 0x0F) >> 0); @@ -206,7 +202,7 @@ static uint8_t const* DmDls_decodeAdpcmBlock(uint8_t const* adpcm, float* pcm, u *pcm++ = (float) ((int16_t) predictor) / INT16_MAX; sample_b = sample_a; sample_a = (int16_t) (predictor); - delta = max((ADPCM_ADAPT_TABLE[b & 0x0F] * delta) / 256, 16); + delta = max_s32((ADPCM_ADAPT_TABLE[b & 0x0F] * delta) / 256, 16); } return adpcm; diff --git a/src/Style.c b/src/Style.c index 34ae7e3..0bc8d99 100644 --- a/src/Style.c +++ b/src/Style.c @@ -79,7 +79,6 @@ DmPart* DmStyle_findPart(DmStyle* slf, DmPartReference* pref) { void DmPart_init(DmPart* slf) { if (slf == NULL) { - Dm_report(DmLogLevel_ERROR, "DmPart: Internal error: DmPart_init called with a `NULL` pointer"); return; } @@ -88,7 +87,6 @@ void DmPart_init(DmPart* slf) { void DmPart_free(DmPart* slf) { if (slf == NULL) { - Dm_report(DmLogLevel_ERROR, "DmPart: Internal error: DmPart_free called with a `NULL` pointer"); return; } @@ -113,8 +111,6 @@ uint32_t DmPart_getValidVariationCount(DmPart* slf) { void DmPartReference_init(DmPartReference* slf) { if (slf == NULL) { - Dm_report(DmLogLevel_ERROR, - "DmPartReference: Internal error: DmPartReference_init called with a `NULL` pointer"); return; } @@ -127,7 +123,6 @@ void DmPartReference_free(DmPartReference* slf) { void DmPattern_init(DmPattern* slf) { if (slf == NULL) { - Dm_report(DmLogLevel_ERROR, "DmPattern: Internal error: DmPattern_init called with a `NULL` pointer"); return; } @@ -137,7 +132,6 @@ void DmPattern_init(DmPattern* slf) { void DmPattern_free(DmPattern* slf) { if (slf == NULL) { - Dm_report(DmLogLevel_ERROR, "DmPattern: Internal error: DmPattern_free called with a `NULL` pointer"); return; } diff --git a/src/Synth.c b/src/Synth.c index caf472e..e309745 100644 --- a/src/Synth.c +++ b/src/Synth.c @@ -14,8 +14,6 @@ enum { #define DmInt_PAN_CENTER 0.5F #define DmInt_VOLUME_MAX 1.0F -extern DmResult DmSynth_createTsfForInstrument(DmInstrument* slf, tsf** out); - void DmSynth_init(DmSynth* slf) { if (slf == NULL) { return; diff --git a/src/_Dls.h b/src/_Dls.h index c69b655..11c25c5 100644 --- a/src/_Dls.h +++ b/src/_Dls.h @@ -84,6 +84,12 @@ typedef enum DmDlsArticulatorTransform { DmDlsArticulatorTransform_SWITCH = 3, } DmDlsArticulatorTransform; +enum { + // If this flag is set in the DLS instrument bank (`DmDlsInstrument.bank`), this instrument + // is considered to be a "drum kit". + DmDls_DRUM_KIT = 1 << 31, +}; + typedef struct DmDlsWaveSample { uint16_t unity_note; uint16_t fine_tune; diff --git a/src/_Internal.h b/src/_Internal.h index 615fc1f..b017733 100644 --- a/src/_Internal.h +++ b/src/_Internal.h @@ -505,6 +505,7 @@ DMINT void DmSynth_init(DmSynth* slf); DMINT void DmSynth_free(DmSynth* slf); DMINT void DmSynth_reset(DmSynth* slf); +DMINT DmResult DmSynth_createTsfForInstrument(DmInstrument* slf, tsf** out); DMINT void DmSynth_sendBandUpdate(DmSynth* slf, DmBand* band); DMINT void DmSynth_sendControl(DmSynth* slf, uint32_t channel, uint8_t control, float value); DMINT void DmSynth_sendControlReset(DmSynth* slf, uint32_t channel, uint8_t control, float reset); diff --git a/src/io/Common.c b/src/io/Common.c index 754d20f..ed9521d 100644 --- a/src/io/Common.c +++ b/src/io/Common.c @@ -24,6 +24,8 @@ static char* Dm_utf16ToUtf8Inline(char* out, char16_t const* u16) { #ifndef _WIN32 j += c16rtomb(out + j, u16[i], &state); #else + // NOTE: MinGW on Windows does not correctly implement `c16romb`, thus we just use `wcrtomb`. + // According to MinGW, `char16_t` should be equivalent to `wchar_t` on Windows. j += wcrtomb(out + j, (wchar_t) u16[i], &state); #endif } diff --git a/src/io/Segment.c b/src/io/Segment.c index 7e20a0c..f4103af 100644 --- a/src/io/Segment.c +++ b/src/io/Segment.c @@ -118,7 +118,7 @@ static void DmSegment_parseChordItem(DmMessage_Chord* slf, DmRiff* rif) { uint32_t max_subchord_count = (sizeof slf->subchords) / (sizeof *slf->subchords); if (slf->subchord_count > max_subchord_count) { - Dm_report(DmLogLevel_ERROR, + Dm_report(DmLogLevel_WARN, "DmMessage: Chord message reports too many sub-chords: got %d, expected at maximum %d", slf->subchord_count, max_subchord_count); diff --git a/src/util/Tsf.c b/src/util/Tsf.c index f023f54..5a55168 100644 --- a/src/util/Tsf.c +++ b/src/util/Tsf.c @@ -49,10 +49,9 @@ static size_t DmSynth_convertGeneratorArticulators(struct tsf_hydra_igen* gens, } if (art->level != 1) { - Dm_report(DmLogLevel_ERROR, "DmSynth: DLS Level 2 articulators are not implemented, expect weird results"); + Dm_report(DmLogLevel_WARN, "DmSynth: DLS Level 2 articulators are not implemented, expect weird results"); } - switch (con->destination) { case DmDlsArticulatorDestination_PAN: gen->genOper = kPan;