Skip to content

Commit

Permalink
chore: more code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
lmichaelis committed Apr 30, 2024
1 parent 1c4cd12 commit dd4db01
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/Band.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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,
Expand Down
8 changes: 2 additions & 6 deletions src/Dls.c
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down
6 changes: 0 additions & 6 deletions src/Style.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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;
}

Expand Down
2 changes: 0 additions & 2 deletions src/Synth.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions src/_Dls.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/_Internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/io/Common.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion src/io/Segment.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions src/util/Tsf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit dd4db01

Please sign in to comment.