Skip to content

Commit 22920ba

Browse files
Minor updates to get the FFT sample running again.
Although it currently calculates frequencies that are twice the signal frequency, but that might be a simple fix once somebody can look into the audio configuration.
1 parent 7bf3cce commit 22920ba

File tree

6 files changed

+17
-20
lines changed

6 files changed

+17
-20
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
matrix:
1313
os: [ubuntu-20.04, macos-11, windows-2019]
1414
gcc: ['7-2017-q4', 'latest']
15-
cmake: ['3.6.0', ''] # Empty string installs the latest CMake release
15+
cmake: ['3.13.0', ''] # Empty string installs the latest CMake release
1616
fail-fast: false
1717
runs-on: ${{ matrix.os }}
1818
name: ${{ matrix.os }}, gcc ${{ matrix.gcc }}, cmake ${{ matrix.cmake || 'latest'}}

.github/workflows/size-diff.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ jobs:
116116
run: |
117117
cd libraries/codal-microbit-v2
118118
git checkout ${GIT_BASE_SHA}
119+
git restore .
119120
- name: Build 'base' project using build.py
120121
run: python build.py --clean
121122

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ RECURSIVE_FIND_FILE(LIB_ARCHIVE_FILES "${CMAKE_CURRENT_LIST_DIR}/lib" "*.a")
5050

5151
set(CMAKE_SYSTEM_PROCESSOR "armv7-m" PARENT_SCOPE)
5252

53-
set(ROOT "${CMAKE_CURRENT_LIST_DIR}/CMSIS_5/")
53+
set(ROOT "${CMAKE_CURRENT_LIST_DIR}/CMSIS_5")
5454
list(APPEND INCLUDE_DIRS "${ROOT}/CMSIS/Core/Include/")
5555

5656

samples/fft_example.cpp

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#include "CodalDmesg.h"
33
#include "MicroBitAudioProcessor.h"
44
#include "StreamNormalizer.h"
5-
#include "Tests.h"
65

76
static NRF52ADCChannel *mic = NULL;
87
static StreamNormalizer *processor = NULL;
@@ -14,8 +13,9 @@ MicroBit uBit;
1413
* fft_test function - creates an example MicroBitAudioProcessor and then queries it for results.
1514
* Currently configured to use 1024 samples with 8bit signed data.
1615
*/
17-
void fft_test(){
16+
void fft_test() {
1817
uBit.display.print("L");
18+
/*
1919
if (mic == NULL){
2020
mic = uBit.adc.getChannel(uBit.io.microphone);
2121
mic->setGain(7,0);
@@ -29,13 +29,17 @@ void fft_test(){
2929
3030
uBit.io.runmic.setDigitalValue(1);
3131
uBit.io.runmic.setHighDrive(true);
32+
*/
3233

34+
// Code above commented out was from the original example, which can
35+
// probably be replaced with this single line, but we need to double check
36+
// the configuration because the fft calculation results are twice the frequency
37+
fft = new MicroBitAudioProcessor(*uBit.audio.splitter->createChannel());
3338

3439
//Start fft running
3540
fft->startRecording();
3641

37-
38-
while(1){
42+
while (1){
3943
//TODO - de-noise : if last X samples are same - display ect.
4044
//The output values depend on the input type (DATASTREAM_FORMAT_8BIT_SIGNED) and the size
4145
//of the FFT - which is changed using the 'AUDIO_SAMPLES_NUMBER' in MicroBitAudioProcessor.h
@@ -64,13 +68,7 @@ void fft_test(){
6468
}
6569
}
6670

67-
68-
69-
int
70-
main()
71-
{
72-
71+
int main() {
7372
uBit.init();
7473
fft_test();
75-
76-
}
74+
}

source/MicroBitAudioProcessor.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@ MicroBitAudioProcessor::~MicroBitAudioProcessor()
5555

5656
int MicroBitAudioProcessor::pullRequest()
5757
{
58-
59-
int s;
6058
int result;
6159

6260
auto mic_samples = audiostream.pull();
@@ -99,9 +97,9 @@ int MicroBitAudioProcessor::pullRequest()
9997
//DMESG("Before FFT: %d", (int)a);
10098
//DMESG("After FFT: %d (%d)", (int)b, (int)(b - a));
10199

102-
uint32_t freq = ((uint32_t)MIC_SAMPLE_RATE / AUDIO_SAMPLES_NUMBER) * (index + 1);
100+
lastFreq = ((uint32_t)MIC_SAMPLE_RATE / AUDIO_SAMPLES_NUMBER) * (index + 1);
103101
DMESG("Freq: %d (max: %d.%d, Index: %d)",
104-
freq,
102+
lastFreq,
105103
(int)maxValue,
106104
((int)(maxValue * 100) % 100),
107105
index);

target-locked.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"USE_ACCEL_LSB": 0
4545
},
4646
"cpp_flags": "-std=c++11 -fwrapv -fno-rtti -fno-threadsafe-statics -fno-exceptions -fno-unwind-tables -Wl,--gc-sections -Wl,--sort-common -Wl,--sort-section=alignment -Wno-array-bounds",
47-
"cpu_opts": "-mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=softfp",
47+
"cpu_opts": "-mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=hard",
4848
"definitions": "-DAPP_TIMER_V2 -DAPP_TIMER_V2_RTC1_ENABLED -DNRF_DFU_TRANSPORT_BLE=1 -DNRF52833_XXAA -DNRF52833 -DTARGET_MCU_NRF52833 -DNRF5 -DNRF52833 -D__CORTEX_M4 -DS113 -DTOOLCHAIN_GCC -D__START=target_start",
4949
"device": "MICROBIT",
5050
"generate_bin": true,
@@ -69,7 +69,7 @@
6969
"url": "https://github.com/microbit-foundation/codal-microbit-nrf5sdk"
7070
}
7171
],
72-
"linker_flags": "-Wl,--no-wchar-size-warning -Wl,--gc-sections -Wl,--wrap,atexit -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=softfp -Wl,--start-group -lstdc++ -lsupc++ -lm -lc -lgcc -lnosys -Wl,--end-group",
72+
"linker_flags": "-Wl,--no-wchar-size-warning -Wl,--gc-sections -Wl,--wrap,atexit -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=hard -Wl,--start-group -lstdc++ -lsupc++ -lm -lc -lgcc -lnosys -Wl,--end-group",
7373
"post_process": "",
7474
"processor": "NRF52833",
7575
"snapshot_version": "v0.2.50",

0 commit comments

Comments
 (0)