Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
4
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Sign in / Register
Toggle navigation
C
crowbx
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Iterations
Merge Requests
0
Merge Requests
0
Requirements
Requirements
List
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Test Cases
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issue
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacob Vosmaer
crowbx
Commits
70a997ec
Commit
70a997ec
authored
May 01, 2020
by
Jacob Vosmaer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
More inlining
parent
4531b71a
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
62 additions
and
75 deletions
+62
-75
crowbx.c
crowbx.c
+61
-65
midi.c
midi.c
+0
-1
midi.h
midi.h
+1
-1
uart.h
uart.h
+0
-8
No files found.
crowbx.c
View file @
70a997ec
...
...
@@ -8,7 +8,6 @@
#include "list.h"
#include "midi.h"
#include "pitch_env.h"
#include "uart.h"
#include "vibrato_rate.h"
#include "voice.h"
...
...
@@ -41,55 +40,6 @@ void pitch_env_set_decay(uint8_t decay);
void
pitch_env_set_amount
(
uint8_t
amount
);
void
pitch_env_trigger
(
uint8_t
voice
);
static
struct
{
uint8_t
data
[
16
];
uint8_t
head
;
uint8_t
tail
;
}
uart_buffer
;
void
uart_buffer_push
(
uint8_t
x
)
{
ATOMIC_BLOCK
(
ATOMIC_RESTORESTATE
)
{
uart_buffer
.
data
[
uart_buffer
.
tail
]
=
x
;
uart_buffer
.
tail
=
(
uart_buffer
.
tail
+
1
)
%
ARRAY_SIZE
(
uart_buffer
.
data
);
}
}
uint8_t
uart_buffer_pop
(
uint8_t
*
x
)
{
ATOMIC_BLOCK
(
ATOMIC_RESTORESTATE
)
{
if
(
uart_buffer
.
head
==
uart_buffer
.
tail
)
{
return
false
;
// error: uart_buffer is empty
}
*
x
=
uart_buffer
.
data
[
uart_buffer
.
head
];
uart_buffer
.
head
=
(
uart_buffer
.
head
+
1
)
%
ARRAY_SIZE
(
uart_buffer
.
data
);
}
return
true
;
}
ISR
(
USART_RX_vect
)
{
uint8_t
uart_status
=
UCSR0A
;
if
(
!
(
uart_status
&
_BV
(
RXC0
)))
{
// No UART data available
return
;
}
// Read data to clear all status bits
uint8_t
uart_data
=
UDR0
;
if
(
uart_status
&
(
_BV
(
FE0
)
|
_BV
(
DOR0
)
|
_BV
(
UPE0
)))
{
// There was a UART error
return
;
}
uart_buffer_push
(
uart_data
);
}
uint8_t
uart_read
(
uint8_t
*
data
)
{
return
uart_buffer_pop
(
data
);
}
void
poly_init
(
void
);
void
poly_note_on
(
uint8_t
note
);
void
poly_note_off
(
uint8_t
note
);
...
...
@@ -372,15 +322,7 @@ void poly2_note_off(uint8_t note) {
poly2_assign_available_voices
();
}
static
uint8_t
_gate_retrig
[
NUM_VOICES
];
enum
{
// RETRIG_DELAY should be as low as possible to reduce MIDI latency, but
// high enough to allow the hardware envelope generators in the CrowBX
// to
// reset. I know 0x3f to be too low.
RETRIG_DELAY
=
0x5f
,
};
static
uint8_t
gate_counters
[
NUM_VOICES
];
void
gate_init
(
void
)
{
for_each_voice
(
v
)
{
gate_off
(
v
);
}
...
...
@@ -401,7 +343,7 @@ void gate_off(uint8_t v) {
return
;
}
_gate_retrig
[
v
]
=
0
;
gate_counters
[
v
]
=
0
;
*
(
g
->
port
)
&=
~
(
g
->
mask
);
}
...
...
@@ -411,21 +353,27 @@ void gate_on(uint8_t v) {
}
gate_off
(
v
);
_gate_retrig
[
v
]
=
RETRIG_DELAY
;
// RETRIG_DELAY should be as low as possible to reduce MIDI latency, but
// high enough to allow the hardware envelope generators in the CrowBX
// to reset. I know 0x3f to be too low.
enum
{
RETRIG_DELAY
=
0x5f
};
gate_counters
[
v
]
=
RETRIG_DELAY
;
}
void
gate_update
(
uint8_t
delta
)
{
for_each_voice
(
v
)
{
if
(
_gate_retrig
[
v
]
==
0
)
{
if
(
gate_counters
[
v
]
==
0
)
{
continue
;
}
if
(
delta
<
_gate_retrig
[
v
])
{
_gate_retrig
[
v
]
-=
delta
;
if
(
delta
<
gate_counters
[
v
])
{
gate_counters
[
v
]
-=
delta
;
continue
;
}
_gate_retrig
[
v
]
=
0
;
gate_counters
[
v
]
=
0
;
gate_on_legato
(
v
);
pitch_env_trigger
(
v
);
}
...
...
@@ -685,3 +633,51 @@ uint16_t clamp_add(uint16_t x, int16_t delta) {
}
return
x
+
add
;
}
static
struct
{
uint8_t
data
[
16
];
uint8_t
head
;
uint8_t
tail
;
}
uart_buffer
;
void
uart_buffer_push
(
uint8_t
x
)
{
ATOMIC_BLOCK
(
ATOMIC_RESTORESTATE
)
{
uart_buffer
.
data
[
uart_buffer
.
tail
]
=
x
;
uart_buffer
.
tail
=
(
uart_buffer
.
tail
+
1
)
%
ARRAY_SIZE
(
uart_buffer
.
data
);
}
}
uint8_t
uart_buffer_pop
(
uint8_t
*
x
)
{
ATOMIC_BLOCK
(
ATOMIC_RESTORESTATE
)
{
if
(
uart_buffer
.
head
==
uart_buffer
.
tail
)
{
return
false
;
// error: uart_buffer is empty
}
*
x
=
uart_buffer
.
data
[
uart_buffer
.
head
];
uart_buffer
.
head
=
(
uart_buffer
.
head
+
1
)
%
ARRAY_SIZE
(
uart_buffer
.
data
);
}
return
true
;
}
ISR
(
USART_RX_vect
)
{
uint8_t
uart_status
=
UCSR0A
;
if
(
!
(
uart_status
&
_BV
(
RXC0
)))
{
// No UART data available
return
;
}
// Read data to clear all status bits
uint8_t
uart_data
=
UDR0
;
if
(
uart_status
&
(
_BV
(
FE0
)
|
_BV
(
DOR0
)
|
_BV
(
UPE0
)))
{
// There was a UART error
return
;
}
uart_buffer_push
(
uart_data
);
}
uint8_t
uart_read
(
uint8_t
*
data
)
{
return
uart_buffer_pop
(
data
);
}
midi.c
View file @
70a997ec
#include "midi.h"
#include "array_size.h"
#include "uart.h"
#include <string.h>
static
struct
{
...
...
midi.h
View file @
70a997ec
...
...
@@ -24,7 +24,7 @@ enum _cc {
void
midi_init
(
void
);
void
midi_set_channel
(
uint8_t
channel
);
bool
midi_read
(
uint8_t
*
status
,
uint8_t
*
data1
,
uint8_t
*
data2
);
uint8_t
uart_read
(
uint8_t
*
data
);
#endif
uart.h
deleted
100644 → 0
View file @
4531b71a
#ifndef UART_H
#define UART_H
#include <stdint.h>
uint8_t
uart_read
(
uint8_t
*
data
);
#endif
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment