remove drum code and read from audio hw instead
This commit is contained in:
parent
9350f90a42
commit
f8e5a84bd1
3 changed files with 6 additions and 98 deletions
|
@ -201,7 +201,7 @@ osclsk_scope::is_triggering(float sample)
|
||||||
void
|
void
|
||||||
osclsk_scope::trig_lkb_wr_block(void)
|
osclsk_scope::trig_lkb_wr_block(void)
|
||||||
{
|
{
|
||||||
size_t lkb_start, n;
|
size_t lkb_start;
|
||||||
size_t lkb_cpy, lkb_cpy_part;
|
size_t lkb_cpy, lkb_cpy_part;
|
||||||
|
|
||||||
if (trig_mode == osc_trig_mode::INSTANT)
|
if (trig_mode == osc_trig_mode::INSTANT)
|
||||||
|
|
|
@ -12,7 +12,7 @@ using namespace daisy;
|
||||||
#define OSCLSK_SCREEN_YSZ ILI9341_TFTWIDTH
|
#define OSCLSK_SCREEN_YSZ ILI9341_TFTWIDTH
|
||||||
|
|
||||||
|
|
||||||
#define OSCLSK_RATE_DIV 48
|
#define OSCLSK_RATE_DIV 16
|
||||||
#define OSCLSK_LKB_AMOUNT 10
|
#define OSCLSK_LKB_AMOUNT 10
|
||||||
|
|
||||||
#define OSCLSK_BLOCK_LEN OSCLSK_SCREEN_XSZ
|
#define OSCLSK_BLOCK_LEN OSCLSK_SCREEN_XSZ
|
||||||
|
|
|
@ -26,13 +26,6 @@ uint8_t DMA_BUFFER_MEM_SECTION dma_area[DMA_AREA_SIZE];
|
||||||
static void audio_cb(AudioHandle::InputBuffer in,
|
static void audio_cb(AudioHandle::InputBuffer in,
|
||||||
AudioHandle::OutputBuffer out, size_t sz);
|
AudioHandle::OutputBuffer out, size_t sz);
|
||||||
|
|
||||||
Oscillator osc;
|
|
||||||
WhiteNoise noise;
|
|
||||||
|
|
||||||
AdEnv kickVolEnv, kickPitchEnv, snareEnv;
|
|
||||||
|
|
||||||
Switch kick, snare;
|
|
||||||
|
|
||||||
RingBuffer<float, SCOPE_RING_BUF_SIZE> scope_in;
|
RingBuffer<float, SCOPE_RING_BUF_SIZE> scope_in;
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -42,52 +35,15 @@ audio_cb(AudioHandle::InputBuffer in,
|
||||||
#ifdef AUDIOC_DEBUG
|
#ifdef AUDIOC_DEBUG
|
||||||
load_meter.OnBlockStart();
|
load_meter.OnBlockStart();
|
||||||
#endif
|
#endif
|
||||||
float osc_out, noise_out, snr_env_out, kck_env_out;
|
|
||||||
float sig[AUDIO_BLOCK_SIZE];
|
float sig[AUDIO_BLOCK_SIZE];
|
||||||
|
size_t i;
|
||||||
|
|
||||||
//Get rid of any bouncing
|
for (i = 0; i < sz; i++) {
|
||||||
snare.Debounce();
|
sig[i] = in[0][i];
|
||||||
kick.Debounce();
|
|
||||||
|
|
||||||
//If you press the kick button...
|
|
||||||
if(kick.RisingEdge())
|
|
||||||
{
|
|
||||||
//Trigger both envelopes!
|
|
||||||
kickVolEnv.Trigger();
|
|
||||||
kickPitchEnv.Trigger();
|
|
||||||
}
|
|
||||||
|
|
||||||
//If press the snare button trigger its envelope
|
|
||||||
if(snare.RisingEdge())
|
|
||||||
{
|
|
||||||
snareEnv.Trigger();
|
|
||||||
}
|
|
||||||
|
|
||||||
//Prepare the audio block
|
|
||||||
for(size_t i = 0; i < sz; i++)
|
|
||||||
{
|
|
||||||
//Get the next volume samples
|
|
||||||
snr_env_out = snareEnv.Process();
|
|
||||||
kck_env_out = kickVolEnv.Process();
|
|
||||||
|
|
||||||
//Apply the pitch envelope to the kick
|
|
||||||
osc.SetFreq(kickPitchEnv.Process());
|
|
||||||
//Set the kick volume to the envelope's output
|
|
||||||
osc.SetAmp(kck_env_out);
|
|
||||||
//Process the next oscillator sample
|
|
||||||
osc_out = osc.Process();
|
|
||||||
|
|
||||||
//Get the next snare sample
|
|
||||||
noise_out = noise.Process();
|
|
||||||
//Set the sample to the correct volume
|
|
||||||
noise_out *= snr_env_out;
|
|
||||||
|
|
||||||
//Mix the two signals at half volume
|
|
||||||
sig[i] = .5 * noise_out + .5 * osc_out;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* write to output */
|
/* write to output */
|
||||||
for (size_t i = 0; i < sz; i++) {
|
for (i = 0; i < sz; i++) {
|
||||||
out[0][i] = sig[i];
|
out[0][i] = sig[i];
|
||||||
out[1][i] = sig[i];
|
out[1][i] = sig[i];
|
||||||
}
|
}
|
||||||
|
@ -99,51 +55,6 @@ audio_cb(AudioHandle::InputBuffer in,
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
setup_drums(void)
|
|
||||||
{
|
|
||||||
float samplerate;
|
|
||||||
|
|
||||||
/* kick n snare */
|
|
||||||
samplerate = daisy_hw.AudioSampleRate();
|
|
||||||
|
|
||||||
//Initialize oscillator for kickdrum
|
|
||||||
osc.Init(samplerate);
|
|
||||||
osc.SetWaveform(Oscillator::WAVE_TRI);
|
|
||||||
osc.SetAmp(1);
|
|
||||||
|
|
||||||
//Initialize noise
|
|
||||||
noise.Init();
|
|
||||||
|
|
||||||
//Initialize envelopes, this one's for the snare amplitude
|
|
||||||
snareEnv.Init(samplerate);
|
|
||||||
snareEnv.SetTime(ADENV_SEG_ATTACK, .01);
|
|
||||||
snareEnv.SetTime(ADENV_SEG_DECAY, .2);
|
|
||||||
snareEnv.SetMax(1);
|
|
||||||
snareEnv.SetMin(0);
|
|
||||||
|
|
||||||
//This envelope will control the kick oscillator's pitch
|
|
||||||
//Note that this envelope is much faster than the volume
|
|
||||||
kickPitchEnv.Init(samplerate);
|
|
||||||
kickPitchEnv.SetTime(ADENV_SEG_ATTACK, .01);
|
|
||||||
kickPitchEnv.SetTime(ADENV_SEG_DECAY, .05);
|
|
||||||
kickPitchEnv.SetMax(400);
|
|
||||||
kickPitchEnv.SetMin(50);
|
|
||||||
|
|
||||||
//This one will control the kick's volume
|
|
||||||
kickVolEnv.Init(samplerate);
|
|
||||||
kickVolEnv.SetTime(ADENV_SEG_ATTACK, .01);
|
|
||||||
kickVolEnv.SetTime(ADENV_SEG_DECAY, 1);
|
|
||||||
kickVolEnv.SetMax(1);
|
|
||||||
kickVolEnv.SetMin(0);
|
|
||||||
|
|
||||||
//Initialize the kick and snare buttons on pins 27 and 28
|
|
||||||
//The callback rate is samplerate / blocksize (48)
|
|
||||||
snare.Init(daisy_hw.GetPin(27), samplerate / (float)AUDIO_BLOCK_SIZE);
|
|
||||||
kick.Init(daisy_hw.GetPin(28), samplerate / (float)AUDIO_BLOCK_SIZE);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#define LOAD_FREQ 5
|
#define LOAD_FREQ 5
|
||||||
#define LOAD_PERIOD (1000u / LOAD_FREQ)
|
#define LOAD_PERIOD (1000u / LOAD_FREQ)
|
||||||
int
|
int
|
||||||
|
@ -167,13 +78,10 @@ main(void)
|
||||||
|
|
||||||
scope_in.Init();
|
scope_in.Init();
|
||||||
|
|
||||||
setup_drums();
|
|
||||||
|
|
||||||
daisy_hw.StartAudio(audio_cb);
|
daisy_hw.StartAudio(audio_cb);
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
|
|
||||||
|
|
||||||
switch (scope.state()) {
|
switch (scope.state()) {
|
||||||
case osclsk_scope::osc_state::SAMPLE_DONE:
|
case osclsk_scope::osc_state::SAMPLE_DONE:
|
||||||
scope.render_block();
|
scope.render_block();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue