Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix low notes; clean code #7

Merged
merged 18 commits into from
May 11, 2022
Prev Previous commit
Next Next commit
rm C++ fluff
  • Loading branch information
cvonk committed May 8, 2022
commit 7703b682ad58b9cf44da375b4219a78ec5f3c356
3 changes: 0 additions & 3 deletions main/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@
# define GKEY (GKEY_LORES)
#endif

// debug option: simple ASCII plot of samples waveform on serial monitor
#define SHOW_SAMPLES (0)

// help reduce the number of #if statements in other files
#if SHOW_MEMORY_USAGE
# define SHOW_MEMORY_USAGE_ONLY(a) do { a; } while (0)
Expand Down
14 changes: 7 additions & 7 deletions main/main.ino
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ setup()
pianoroll_init(SPI_TFT_CS, SPI_DC, SPI_RST);

#if 0
if (MidiFile::begin(SPI_SD_CS) != 0) {
if (midifile_init(SPI_SD_CS) != 0) {
Serial.println("No SD Card"); // uSD card inserted/formatted ??
}
#endif
Expand All @@ -253,7 +253,7 @@ setup()
#endif

#if SRC == SRC_MICR
Microphone::begin(MICROPHONE_IN);
microphone_begin(MICROPHONE_IN);
#endif
// loop() never stops, so there is no need for corresponding end() methods
}
Expand All @@ -276,13 +276,13 @@ loop()
// get samples from microphone, samples will be dynamically allocated on first invocation

amplitude_t amplitude;
samples_t samples = Microphone::getSamples(&amplitude);
samples_t samples = microphone_get_samples(&amplitude);

// find frequency from samples
float freq = Frequency::calculate(samples);

// no longer need the samples, so reuse it and start gathering samples for next time around
Microphone::update(); // async
microphone_start(); // async

// ignore notes under audible threshold (2BD: already done in getSamples())
if (amplitude < CONFIG_MIDIMIKE_AUDIBLE_THRESHOLD) {
Expand All @@ -306,13 +306,13 @@ loop()
// or maybe just start playing the buffer over MIDI ..

if (USB_MIDI && digitalRead(BUTTON_IN) == 0) {
MidiSerial::send(mv.segmentBuf);
midiserial_send_notes(mv.segmentBuf);
pianoroll_clear();
}

#if 0
if (MidiFile::write(mv.segmentBuf, "arduino.mid") != 0) {
Serial.println("MidiFile::write is mad");
if (midifile_write(mv.segmentBuf, "arduino.mid") != 0) {
Serial.println("midifile_write is mad");
}
#endif

Expand Down
20 changes: 10 additions & 10 deletions main/src/display/staff.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ static staff_t _my = {
};

// resize screen
void
static void
_resize(int const width,
int const height)
{
Expand All @@ -125,21 +125,21 @@ _resize(int const width,
_my.distance.noteRadius = _my.distance.staffLine2line / 2 - 1;
}

INLINE bool
static INLINE bool
_isFlat(noteNr_t const noteNr)
{
return _my.notes[static_cast<int>(noteNr)].flat;
}

INLINE vStaffPos_t
static INLINE vStaffPos_t
_nr2vStaffPos(noteNr_t const number,
octaveNr_t const octave)
{
uint16_t const staffPositionsInOctave = 7;
return staffPositionsInOctave * octave + _my.notes[static_cast<int>(number)].posInOctave;
}

INLINE vStaffPos_t
static INLINE vStaffPos_t
_freq2vStaffPos(frequency_t const freq)
{
segmentPitch_t const pitch = Pitch::freq2pitch(freq);
Expand All @@ -149,21 +149,21 @@ _freq2vStaffPos(frequency_t const freq)
}

// horizontal staff position to screen x coordinate
INLINE int16_t
static INLINE int16_t
_hStaffPos2x(int const n)
{
// 2BD: one could move the notes closer to each other as they shift to the left
return GKEY_WIDTH + (n * _my.distance.note2note + _my.distance.note2note / 2);
}

vStaffPos_t
static vStaffPos_t
_getVStaffPos(Pitch & pitch)
{
return _nr2vStaffPos(pitch.getNoteNr(), pitch.getOctaveNr());
}

// position on staff to screen y coordinate
int16_t
static int16_t
_vStaffPos2y(vStaffPos_t const n)
{
vStaffPos_t const distAbove1stNoteOnStaff = n - _my.position.staff.min; // could be negative!
Expand All @@ -172,7 +172,7 @@ _vStaffPos2y(vStaffPos_t const n)
distAbove1stNoteOnStaff * _my.distance.staffLine2line / 2;
}

void
static void
_displayStaff(void)
{
for (int ii = 0; ii < LINES_ON_STAFF; ii++) {
Expand All @@ -181,7 +181,7 @@ _displayStaff(void)
}
}

void
static void
_drawHelperLine(uint16_t const x, vStaffPos_t const positionOnStaff, uint16_t const barColor)
{
uint16_t len = _my.distance.note2note * 4 / 5;
Expand All @@ -191,7 +191,7 @@ _drawHelperLine(uint16_t const x, vStaffPos_t const positionOnStaff, uint16_t co
len, barColor);
}

void
static void
_drawNote(uint_least8_t const hpos, Pitch & pitch, bool const erase)
{
vStaffPos_t const n = _getVStaffPos(pitch);
Expand Down
36 changes: 17 additions & 19 deletions main/src/microphone/adc_t.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@

enum ADMUX_REFS_t {
ADMUX_REFERENCE_EXT = 0,
ADMUX_REFERENCE_VCC = bit( 6 ), // 5V on Arduino Uno
ADMUX_REFERENCE_1V1 = bit( 6 ) | bit( 7 )
ADMUX_REFERENCE_VCC = bit(6), // 5V on Arduino Uno
ADMUX_REFERENCE_1V1 = bit(6) | bit(7)
};
enum ADMUX_ADLAR_t {
ADMUX_RIGHT_ALIGN = 0,
ADMUX_LEFT_ALIGN = bit( 5 )
ADMUX_LEFT_ALIGN = bit(5)
};
enum ADMUX_MUX_t {
ADMUX_INPUT_A0 = 0,
Expand All @@ -34,23 +34,23 @@ uint8_t const ADMUX_INPUT_MASK = 0x0F;

enum ADCSRA_ADEN_t {
ADCSRA_CONVERT_DISABLE = 0,
ADCSRA_CONVERT_ENABLE = bit( 7 ),
ADCSRA_CONVERT_ENABLE = bit(7),
};
enum ADCSRA_ADSC_t {
ADCSRA_CONVERT_FINISHED = 0,
ADCSRA_CONVERT_START = bit( 6 ),
ADCSRA_CONVERT_START = bit(6),
};
enum ADCSRA_ADATE_t {
ADCSRA_AUTO_TRIGGER_DISABLE = 0,
ADCSRA_AUTO_TRIGGER_ENABLE = bit( 5 )
ADCSRA_AUTO_TRIGGER_ENABLE = bit(5)
};
enum ADCSRA_ADIF_t {
ADCSRA_IRQ_NOTYET = 0,
ADCSRA_IRQ_ACTIVE = bit( 4 )
ADCSRA_IRQ_ACTIVE = bit(4)
};
enum ADCSRA_ADIE_t {
ADCSRA_IRQ_DISABLE = 0,
ADCSRA_IRQ_ENABLE = bit( 3 )
ADCSRA_IRQ_ENABLE = bit(3)
};
enum ADCSRA_ADPS_t {
ADCSRA_PRESCALER_DIV1 = 0,
Expand All @@ -64,16 +64,14 @@ enum ADCSRA_ADPS_t {
};

// 24.9.3 ADCL and ADCH ~ The ADC Data Register

/* with ADMUX_RESULT_RIGHT_ALIGN .. ADCH[1:0] = b9..b8, ADCL[7:0] = b7..b0 */
/* with ADMUX_RESULT_LEFT_ALIGN ... ADCH[7:0] = b9..b2, ADCL[7:6] = b1..b0 */

// with ADMUX_RESULT_RIGHT_ALIGN .. ADCH[1:0] = b9..b8, ADCL[7:0] = b7..b0
// with ADMUX_RESULT_LEFT_ALIGN ... ADCH[7:0] = b9..b2, ADCL[7:6] = b1..b0

// 24.9.4 ADCSRB ~ ADC Control and Status Register B

enum ADCSRB_ACME_t { // see 23.3.1
ADCSRB_MULTIPLEXER_DISABLE = 0,
ADCSRB_MULTIPLEXER_ENABLE = bit( 6 )
ADCSRB_MULTIPLEXER_ENABLE = bit(6)
};
enum ADCSRB_ADTS_t {
ADCSRB_TRIGGERSRC_FREERUNNING = 0,
Expand All @@ -89,10 +87,10 @@ enum ADCSRB_ADTS_t {
// 24.9.5 DIDR0 ~ Digital Input Disable Register 0

enum DIDR0_ADCxD_t {
DIDR0_DISABLE_DIGBUF_0 = bit( 0 ),
DIDR0_DISABLE_DIGBUF_1 = bit( 1 ),
DIDR0_DISABLE_DIGBUF_2 = bit( 2 ),
DIDR0_DISABLE_DIGBUF_3 = bit( 3 ),
DIDR0_DISABLE_DIGBUF_4 = bit( 4 ),
DIDR0_DISABLE_DIGBUF_5 = bit( 5 )
DIDR0_DISABLE_DIGBUF_0 = bit(0),
DIDR0_DISABLE_DIGBUF_1 = bit(1),
DIDR0_DISABLE_DIGBUF_2 = bit(2),
DIDR0_DISABLE_DIGBUF_3 = bit(3),
DIDR0_DISABLE_DIGBUF_4 = bit(4),
DIDR0_DISABLE_DIGBUF_5 = bit(5)
};
Loading