Skip to content

Commit 6b60a97

Browse files
committed
first commit
Former-commit-id: 0384f53
1 parent 7cbe2c7 commit 6b60a97

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

104 files changed

+13331
-3
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Prerequisites
22
*.d
3-
3+
pico-extras*
44
# Object files
55
*.o
66
*.ko

CMakeLists.txt

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Set minimum required version of CMake
2+
cmake_minimum_required(VERSION 3.12)
3+
4+
# Pull in PICO SDK (must be before project)
5+
include(pico_sdk_import.cmake)
6+
7+
# We also need PICO EXTRAS
8+
include(pico_extras_import.cmake)
9+
10+
11+
# Set name of project (as PROJECT_NAME) and C/C++ standards
12+
project(picocore C CXX ASM)
13+
set(CMAKE_C_STANDARD 11)
14+
set(CMAKE_CXX_STANDARD 17)
15+
16+
# Creates a pico-sdk subdirectory in our project for the libraries
17+
pico_sdk_init()
18+
19+
# Tell CMake where to find the executable source file
20+
add_executable(${PROJECT_NAME}
21+
main.c
22+
hw_config.c
23+
)
24+
25+
# Tell CMake where to find other source code
26+
add_subdirectory(lib/my_pico_audio)
27+
add_subdirectory(lib/my_pico_audio_i2s)
28+
add_subdirectory(lib/sdio build)
29+
30+
# Create map/bin/hex/uf2 files
31+
pico_add_extra_outputs(${PROJECT_NAME})
32+
33+
# Link to pico_stdlib (gpio, time, etc. functions)
34+
target_link_libraries(${PROJECT_NAME}
35+
pico_stdlib
36+
my_pico_audio_i2s
37+
FatFs_SPI
38+
hardware_clocks
39+
hardware_adc
40+
)
41+
42+
# target_compile_options(command_line PUBLIC -Wall -Wextra -Wno-unused-function -Wno-unused-parameter)
43+
# target_compile_options(${PROJECT_NAME} PUBLIC -Wall -Wextra -Wno-unused-parameter)
44+
45+
# This program is useless without standard standard input and output.
46+
# add_compile_definitions(USE_PRINTF USE_DBG_PRINTF)
47+
add_compile_definitions(USE_PRINTF)
48+
49+
set_property(TARGET ${PROJECT_NAME} APPEND_STRING PROPERTY LINK_FLAGS "-Wl,--print-memory-usage")
50+
51+
# Enable usb output, disable uart output
52+
pico_enable_stdio_usb(${PROJECT_NAME} 1)
53+
pico_enable_stdio_uart(${PROJECT_NAME} 1)
54+
55+
target_compile_definitions(${PROJECT_NAME} PRIVATE
56+
#define for our example code
57+
USE_AUDIO_I2S=1
58+
)
59+
60+
pico_add_extra_outputs(${PROJECT_NAME})

Makefile

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
dobuild: pico-extras build
2+
cd lib && python3 biquad.py > biquad.h
3+
cd build && PICO_EXTRAS_PATH=pico-extras make
4+
5+
pico-extras:
6+
git clone https://github.com/raspberrypi/pico-extras.git
7+
cd pico-extras && git submodule update -i
8+
9+
upload: dobuild
10+
./dev/upload.sh
11+
12+
build:
13+
rm -rf build
14+
mkdir build
15+
cd build && cmake ..
16+
cd build && make -j32
17+
echo "build success"
18+
19+
audio:
20+
sox lib/audio/amen_5c2d11c8_beats16_bpm170.flac -c 1 --bits 16 --encoding signed-integer --endian little amen_bpm170.wav
21+
sox lib/audio/amen_0efedaab_beats8_bpm165.flac -c 1 --bits 16 --encoding signed-integer --endian little amen_bpm165.wav
22+
23+
clean:
24+
rm -rf build
25+
rm -rf *.wav
26+

README.md

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,18 @@
1-
# zeptocore
2-
zeptocore
1+
## pinout
2+
3+
### pcm5102
4+
5+
```
6+
GPIO13 -> DIN
7+
GPIO14 -> BCK
8+
GPIO15 -> LCK
9+
```
10+
11+
## todo
12+
13+
- [x] reverse audio (needs doing)
14+
- [x] re-reverse audio
15+
- [x] get number of beats
16+
- [ ] reverse audio -> problem when phase drops to 0
17+
- [ ] low-pass filter (needs troubleshooting)
18+
- [ ] re-reverse audio fx

dev/upload.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
3+
while true
4+
do
5+
if mount | grep RPI-RP2 > /dev/null; then
6+
sleep 0.5
7+
echo "uploading!"
8+
time pv -batep build/picocore.uf2 > /media/zns/RPI-RP2/picocore.uf2
9+
exit
10+
fi
11+
sleep 0.1
12+
done

hw_config.c

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/* hw_config.c
2+
Copyright 2021 Carl John Kugler III
3+
4+
Licensed under the Apache License, Version 2.0 (the License); you may not use
5+
this file except in compliance with the License. You may obtain a copy of the
6+
License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
Unless required by applicable law or agreed to in writing, software distributed
10+
under the License is distributed on an AS IS BASIS, WITHOUT WARRANTIES OR
11+
CONDITIONS OF ANY KIND, either express or implied. See the License for the
12+
specific language governing permissions and limitations under the License.
13+
*/
14+
/*
15+
16+
This file should be tailored to match the hardware design.
17+
18+
There should be one element of the spi[] array for each hardware SPI used.
19+
20+
There should be one element of the sd_cards[] array for each SD card slot.
21+
The name is should correspond to the FatFs "logical drive" identifier.
22+
(See http://elm-chan.org/fsw/ff/doc/filename.html#vol)
23+
The rest of the constants will depend on the type of
24+
socket, which SPI it is driven by, and how it is wired.
25+
26+
*/
27+
28+
#include <string.h>
29+
//
30+
#include "my_debug.h"
31+
//
32+
#include "hw_config.h"
33+
//
34+
#include "ff.h" /* Obtains integer types */
35+
//
36+
#include "diskio.h" /* Declarations of disk functions */
37+
38+
// Hardware Configuration of SPI "objects"
39+
// Note: multiple SD cards can be driven by one SPI if they use different slave
40+
// selects.
41+
static spi_t spis[] = {
42+
// One for each SPI.
43+
};
44+
45+
// Hardware Configuration of the SD Card "objects"
46+
static sd_card_t sd_cards[] = { // One for each SD card
47+
{
48+
.pcName = "0:", // Name used to mount device
49+
.type = SD_IF_SDIO,
50+
/*
51+
Pins CLK_gpio, D1_gpio, D2_gpio, and D3_gpio are at offsets from pin
52+
D0_gpio. The offsets are determined by sd_driver\SDIO\rp2040_sdio.pio.
53+
CLK_gpio = (D0_gpio + SDIO_CLK_PIN_D0_OFFSET) % 32;
54+
As of this writing, SDIO_CLK_PIN_D0_OFFSET is 30,
55+
which is -2 in mod32 arithmetic, so:
56+
CLK_gpio = D0_gpio -2.
57+
D1_gpio = D0_gpio + 1;
58+
D2_gpio = D0_gpio + 2;
59+
D3_gpio = D0_gpio + 3;
60+
*/
61+
.sdio_if = {.CMD_gpio = 18,
62+
.D0_gpio = 19,
63+
.SDIO_PIO = pio1,
64+
.DMA_IRQ_num = DMA_IRQ_0},
65+
.use_card_detect = true,
66+
.card_detect_gpio = 16, // Card detect
67+
.card_detected_true = 1 // What the GPIO read returns when a card is
68+
// present.
69+
}};
70+
71+
/* ********************************************************************** */
72+
size_t sd_get_num() { return count_of(sd_cards); }
73+
sd_card_t *sd_get_by_num(size_t num) {
74+
if (num <= sd_get_num()) {
75+
return &sd_cards[num];
76+
} else {
77+
return NULL;
78+
}
79+
}
80+
size_t spi_get_num() { return count_of(spis); }
81+
spi_t *spi_get_by_num(size_t num) {
82+
if (num <= spi_get_num()) {
83+
return &spis[num];
84+
} else {
85+
return NULL;
86+
}
87+
}
88+
89+
/* [] END OF FILE */

lib/array_resample.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#define INTERPOLATE_VALUE 512
2+
int16_t *array_resample_linear(int16_t *arr, int16_t arr_size,
3+
int16_t newSize) {
4+
int16_t *newArray;
5+
newArray = malloc(sizeof(int16_t) * newSize);
6+
7+
uint32_t stepSize = (arr_size - 1) * INTERPOLATE_VALUE / (newSize - 1);
8+
9+
for (int16_t i = 0; i < newSize; i++) {
10+
uint32_t index = (i * stepSize) / INTERPOLATE_VALUE;
11+
int32_t frac = (i * stepSize) - (index * INTERPOLATE_VALUE);
12+
// printf("stepSize: %d, i: %d, index: %d, frac: %d, arr[index]: %d\n",
13+
// stepSize, i, index, frac, arr[index]);
14+
if (index < arr_size - 1) {
15+
int32_t x = ((int32_t)arr[index] * (INTERPOLATE_VALUE - frac)) +
16+
((int32_t)arr[index + 1] * frac);
17+
// round to nearest interpolate value
18+
// printf("%d, x: %d\n", i, x);
19+
int16_t round_int = x / INTERPOLATE_VALUE;
20+
if (x % INTERPOLATE_VALUE > INTERPOLATE_VALUE / 2) {
21+
round_int++;
22+
}
23+
newArray[i] = round_int;
24+
} else {
25+
newArray[i] = arr[arr_size - 1];
26+
}
27+
}
28+
return newArray;
29+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
c0964f4026830b8ed51507c614ae275f65a0d83f
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
a4979bcaed9759f4a6498799f67dc203dee2d9fa

0 commit comments

Comments
 (0)