mirror of
https://github.com/qmk/qmk_firmware.git
synced 2026-10-02 00:27:15 +08:00
add sample and wavetable examples, parsers for both
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef AUDIO_ENABLE
|
||||
#define STARTUP_SONG SONG(PLANCK_SOUND)
|
||||
// #define STARTUP_SONG SONG(NO_SOUND)
|
||||
|
||||
#define DEFAULT_LAYER_SONGS { SONG(QWERTY_SOUND), \
|
||||
SONG(COLEMAK_SOUND), \
|
||||
SONG(DVORAK_SOUND) \
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* MIDI options
|
||||
*/
|
||||
|
||||
/* Prevent use of disabled MIDI features in the keymap */
|
||||
//#define MIDI_ENABLE_STRICT 1
|
||||
|
||||
/* enable basic MIDI features:
|
||||
- MIDI notes can be sent when in Music mode is on
|
||||
*/
|
||||
|
||||
#define MIDI_BASIC
|
||||
|
||||
/* enable advanced MIDI features:
|
||||
- MIDI notes can be added to the keymap
|
||||
- Octave shift and transpose
|
||||
- Virtual sustain, portamento, and modulation wheel
|
||||
- etc.
|
||||
*/
|
||||
//#define MIDI_ADVANCED
|
||||
|
||||
/* override number of MIDI tone keycodes (each octave adds 12 keycodes and allocates 12 bytes) */
|
||||
//#define MIDI_TONE_KEYCODE_OCTAVES 2
|
||||
|
||||
// Most tactile encoders have detents every 4 stages
|
||||
#define ENCODER_RESOLUTION 4
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,39 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef AUDIO_ENABLE
|
||||
#define STARTUP_SONG SONG(PLANCK_SOUND)
|
||||
// #define STARTUP_SONG SONG(NO_SOUND)
|
||||
|
||||
#define DEFAULT_LAYER_SONGS { SONG(QWERTY_SOUND), \
|
||||
SONG(COLEMAK_SOUND), \
|
||||
SONG(DVORAK_SOUND) \
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* MIDI options
|
||||
*/
|
||||
|
||||
/* Prevent use of disabled MIDI features in the keymap */
|
||||
//#define MIDI_ENABLE_STRICT 1
|
||||
|
||||
/* enable basic MIDI features:
|
||||
- MIDI notes can be sent when in Music mode is on
|
||||
*/
|
||||
|
||||
#define MIDI_BASIC
|
||||
|
||||
/* enable advanced MIDI features:
|
||||
- MIDI notes can be added to the keymap
|
||||
- Octave shift and transpose
|
||||
- Virtual sustain, portamento, and modulation wheel
|
||||
- etc.
|
||||
*/
|
||||
//#define MIDI_ADVANCED
|
||||
|
||||
/* override number of MIDI tone keycodes (each octave adds 12 keycodes and allocates 12 bytes) */
|
||||
//#define MIDI_TONE_KEYCODE_OCTAVES 2
|
||||
|
||||
// Most tactile encoders have detents every 4 stages
|
||||
#define ENCODER_RESOLUTION 4
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -13,8 +13,8 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef AUDIO_H
|
||||
#define AUDIO_H
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
@@ -27,6 +27,9 @@
|
||||
#include "voices.h"
|
||||
#include "quantum.h"
|
||||
#include <math.h>
|
||||
#if defined(PROTOCOL_CHIBIOS)
|
||||
#include "audio_arm.h"
|
||||
#endif
|
||||
|
||||
// Largely untested PWM audio mode (doesn't sound as good)
|
||||
// #define PWM_AUDIO
|
||||
@@ -107,6 +110,5 @@ void play_notes(float (*np)[][2], uint16_t n_count, bool n_repeat);
|
||||
#define PLAY_SONG(note_array) play_notes(¬e_array, NOTE_ARRAY_SIZE((note_array)), false)
|
||||
#define PLAY_LOOP(note_array) play_notes(¬e_array, NOTE_ARRAY_SIZE((note_array)), true)
|
||||
|
||||
bool is_playing_note(void);
|
||||
bool is_playing_notes(void);
|
||||
|
||||
#endif
|
||||
|
||||
+48
-143
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,89 @@
|
||||
/* Copyright 2019 Jack Humbert
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "ch.h"
|
||||
|
||||
/**
|
||||
* Size of the dac_buffer arrays. All must be the same size.
|
||||
*/
|
||||
#define DAC_BUFFER_SIZE 256U
|
||||
|
||||
/**
|
||||
* Highest value allowed by our 12bit DAC.
|
||||
*/
|
||||
#ifndef DAC_SAMPLE_MAX
|
||||
#define DAC_SAMPLE_MAX 4095U
|
||||
#endif
|
||||
|
||||
// #define DAC_LOW_QUALITY
|
||||
|
||||
/**
|
||||
* These presets allow you to quickly switch between quality/voice settings for
|
||||
* the DAC. The sample rate and number of voices roughly has an inverse
|
||||
* relationship - slightly higher sample rates may be possible.
|
||||
*/
|
||||
#ifdef DAC_VERY_LOW_QUALITY
|
||||
#define DAC_SAMPLE_RATE 11025U
|
||||
#define DAC_VOICES_MAX 8
|
||||
#endif
|
||||
|
||||
#ifdef DAC_LOW_QUALITY
|
||||
#define DAC_SAMPLE_RATE 22050U
|
||||
#define DAC_VOICES_MAX 4
|
||||
#endif
|
||||
|
||||
#ifdef DAC_HIGH_QUALITY
|
||||
#define DAC_SAMPLE_RATE 44100U
|
||||
#define DAC_VOICES_MAX 2
|
||||
#endif
|
||||
|
||||
#ifdef DAC_VERY_HIGH_QUALITY
|
||||
#define DAC_SAMPLE_RATE 88200U
|
||||
#define DAC_VOICES_MAX 1
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Effective bitrate of the DAC. 44.1khz is the standard for most audio - any
|
||||
* lower will sacrifice perceptible audio quality. Any higher will limit the
|
||||
* number of simultaneous voices. In most situations, a tenth (1/10) of the
|
||||
* sample rate is where notes become unbearable.
|
||||
*/
|
||||
#ifndef DAC_SAMPLE_RATE
|
||||
#define DAC_SAMPLE_RATE 44100U
|
||||
#endif
|
||||
|
||||
/**
|
||||
* The number of voices (in polyphony) that are supported. If too high a value
|
||||
* is used here, the keyboard will freeze and glitch-out when that many voices
|
||||
* are being played.
|
||||
*/
|
||||
#ifndef DAC_VOICES_MAX
|
||||
#define DAC_VOICES_MAX 2
|
||||
#endif
|
||||
|
||||
/**
|
||||
* The default value of the DAC when not playing anything. Certain hardware
|
||||
* setups may require a high (DAC_SAMPLE_MAX) or low (0) value here.
|
||||
*/
|
||||
#ifndef DAC_OFF_VALUE
|
||||
#define DAC_OFF_VALUE DAC_SAMPLE_MAX / 2
|
||||
#endif
|
||||
|
||||
uint8_t dac_number_of_voices(void);
|
||||
float dac_get_frequency(uint8_t index);
|
||||
uint16_t dac_value_generate(void);
|
||||
void dac_setup_note(void);
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,39 @@
|
||||
#! /bin/python
|
||||
#
|
||||
# Copyright 2019 Jack Humbert
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
|
||||
import wave, struct, sys
|
||||
|
||||
waveFile = wave.open(sys.argv[1], 'r')
|
||||
# print(str(waveFile.getparams()))
|
||||
# sys.exit()
|
||||
|
||||
if (waveFile.getsampwidth() != 2):
|
||||
raise(Exception("This script currently only works with 16bit audio files"))
|
||||
|
||||
length = waveFile.getnframes()
|
||||
out = "#define DAC_SAMPLE_CUSTOM_LENGTH " + str(length) + "\n\n"
|
||||
out += "static const dacsample_t dac_sample_custom[" + str(length) + "] = {"
|
||||
for i in range(0,length):
|
||||
if (i % 8 == 0):
|
||||
out += "\n "
|
||||
waveData = waveFile.readframes(1)
|
||||
data = struct.unpack("<h", waveData)
|
||||
out += str(int((int(data[0]) + 0x8000) / 16)) + ", "
|
||||
out = out[:-2]
|
||||
out += "\n};"
|
||||
print(out)
|
||||
@@ -1,23 +0,0 @@
|
||||
#! /bin/python
|
||||
|
||||
import wave, struct, sys
|
||||
|
||||
waveFile = wave.open(sys.argv[1], 'r')
|
||||
|
||||
length = waveFile.getnframes()
|
||||
out = "static const dacsample_t dac_buffer_custom[" + str(int(length / 256)) + "][256] = {"
|
||||
for i in range(0,length):
|
||||
if (i % 8 == 0):
|
||||
out += "\n "
|
||||
if (i % 256 == 0):
|
||||
out = out[:-2]
|
||||
out += "{\n "
|
||||
waveData = waveFile.readframes(1)
|
||||
data = struct.unpack("<h", waveData)
|
||||
out += str(int((int(data[0]) + 0x8000) / 16)) + ", "
|
||||
if (i % 256 == 255):
|
||||
out = out[:-2]
|
||||
out += "\n },"
|
||||
out = out[:-1]
|
||||
out += "\n};"
|
||||
print(out)
|
||||
@@ -0,0 +1,40 @@
|
||||
#! /bin/python
|
||||
#
|
||||
# Copyright 2019 Jack Humbert
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
|
||||
import wave, struct, sys
|
||||
|
||||
waveFile = wave.open(sys.argv[1], 'r')
|
||||
|
||||
length = waveFile.getnframes()
|
||||
out = "#define DAC_WAVETABLE_CUSTOM_LENGTH " + str(int(length / 256)) + "\n\n"
|
||||
out += "static const dacsample_t dac_wavetable_custom[" + str(int(length / 256)) + "][256] = {"
|
||||
for i in range(0,length):
|
||||
if (i % 8 == 0):
|
||||
out += "\n "
|
||||
if (i % 256 == 0):
|
||||
out = out[:-2]
|
||||
out += "{\n "
|
||||
waveData = waveFile.readframes(1)
|
||||
data = struct.unpack("<h", waveData)
|
||||
out += str(int((int(data[0]) + 0x8000) / 16)) + ", "
|
||||
if (i % 256 == 255):
|
||||
out = out[:-2]
|
||||
out += "\n },"
|
||||
out = out[:-1]
|
||||
out += "\n};"
|
||||
print(out)
|
||||
Reference in New Issue
Block a user