-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move pitch shift and bending utils to separate module
- Loading branch information
1 parent
1ed1410
commit 8081877
Showing
9 changed files
with
148 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#include "pitchcents.h" | ||
#include "midi.h" | ||
|
||
PitchCents pitchcents_bend(u8 pitch, s8 cents, u16 pitchBend) | ||
{ | ||
s16 centsAdd = ((pitchBend - MIDI_PITCH_BEND_CENTRE) * 25) / 1024; | ||
PitchCents pc = { .pitch = pitch, .cents = cents }; | ||
return pitchcents_shift(pc, centsAdd); | ||
} | ||
|
||
PitchCents pitchcents_shift(PitchCents pc, s16 centsAdd) | ||
{ | ||
u16 totalCents = (pc.pitch * 100) + pc.cents; | ||
totalCents += centsAdd; | ||
|
||
pc.pitch = totalCents / 100; | ||
pc.cents = totalCents % 100; | ||
return pc; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#pragma once | ||
#include "types.h" | ||
|
||
typedef struct PitchCents { | ||
u8 pitch; | ||
s8 cents; | ||
} PitchCents; | ||
|
||
PitchCents pitchcents_bend(u8 pitch, s8 cents, u16 pitchBend); | ||
PitchCents pitchcents_shift(PitchCents pc, s16 centsAdd); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
#include "test_midi.h" | ||
|
||
static void test_pitchcents_bend_nil(UNUSED void** state) | ||
{ | ||
PitchCents pc = pitchcents_bend(50, 0, 0x2000); | ||
|
||
assert_int_equal(pc.pitch, 50); | ||
assert_int_equal(pc.cents, 0); | ||
} | ||
|
||
static void test_pitchcents_bend_down_fully(UNUSED void** state) | ||
{ | ||
PitchCents pc = pitchcents_bend(50, 0, 0); | ||
|
||
assert_int_equal(pc.pitch, 48); | ||
assert_int_equal(pc.cents, 0); | ||
} | ||
|
||
static void test_pitchcents_bend_up_fully(UNUSED void** state) | ||
{ | ||
PitchCents pc = pitchcents_bend(50, 0, 0x4000); | ||
|
||
assert_int_equal(pc.pitch, 52); | ||
assert_int_equal(pc.cents, 0); | ||
} | ||
|
||
static void test_pitchcents_bend_up(UNUSED void** state) | ||
{ | ||
PitchCents pc = pitchcents_bend(50, 0, 0x3000); | ||
|
||
assert_int_equal(pc.pitch, 51); | ||
assert_int_equal(pc.cents, 0); | ||
} | ||
|
||
static void test_pitchcents_bend_down(UNUSED void** state) | ||
{ | ||
PitchCents pc = pitchcents_bend(50, 0, 0x1800); | ||
|
||
assert_int_equal(pc.pitch, 49); | ||
assert_int_equal(pc.cents, 50); | ||
} | ||
|
||
static void test_pitchcents_bend_up_2(UNUSED void** state) | ||
{ | ||
PitchCents pc = pitchcents_bend(50, 0, 0x2800); | ||
|
||
assert_int_equal(pc.pitch, 50); | ||
assert_int_equal(pc.cents, 50); | ||
} | ||
|
||
static void test_pitchcents_bend_cents_with_partial_bend_down(UNUSED void** state) | ||
{ | ||
PitchCents pc = pitchcents_bend(50, 25, 0x1800); | ||
|
||
assert_int_equal(pc.pitch, 49); | ||
assert_int_equal(pc.cents, 75); | ||
} | ||
|
||
static void test_pitchcents_bend_high_cents_with_partial_bend_down(UNUSED void** state) | ||
{ | ||
PitchCents pc = pitchcents_bend(50, 80, 0x1800); | ||
|
||
assert_int_equal(pc.pitch, 50); | ||
assert_int_equal(pc.cents, 30); | ||
} | ||
|
||
static void test_pitchcents_bend_cents_with_full_bend_up(UNUSED void** state) | ||
{ | ||
PitchCents pc = pitchcents_bend(50, 25, 0x4000); | ||
|
||
assert_int_equal(pc.pitch, 52); | ||
assert_int_equal(pc.cents, 25); | ||
} | ||
|
||
static void test_pitchcents_bend_high_cents_with_full_bend_up(UNUSED void** state) | ||
{ | ||
PitchCents pc = pitchcents_bend(50, 80, 0x4000); | ||
|
||
assert_int_equal(pc.pitch, 52); | ||
assert_int_equal(pc.cents, 80); | ||
} |