Skip to content

Commit

Permalink
Minor updates to get the FFT sample running again.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
microbit-carlos committed Mar 29, 2023
1 parent 7bf3cce commit 22920ba
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
matrix:
os: [ubuntu-20.04, macos-11, windows-2019]
gcc: ['7-2017-q4', 'latest']
cmake: ['3.6.0', ''] # Empty string installs the latest CMake release
cmake: ['3.13.0', ''] # Empty string installs the latest CMake release
fail-fast: false
runs-on: ${{ matrix.os }}
name: ${{ matrix.os }}, gcc ${{ matrix.gcc }}, cmake ${{ matrix.cmake || 'latest'}}
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/size-diff.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ jobs:
run: |
cd libraries/codal-microbit-v2
git checkout ${GIT_BASE_SHA}
git restore .
- name: Build 'base' project using build.py
run: python build.py --clean

Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ RECURSIVE_FIND_FILE(LIB_ARCHIVE_FILES "${CMAKE_CURRENT_LIST_DIR}/lib" "*.a")

set(CMAKE_SYSTEM_PROCESSOR "armv7-m" PARENT_SCOPE)

set(ROOT "${CMAKE_CURRENT_LIST_DIR}/CMSIS_5/")
set(ROOT "${CMAKE_CURRENT_LIST_DIR}/CMSIS_5")
list(APPEND INCLUDE_DIRS "${ROOT}/CMSIS/Core/Include/")


Expand Down
22 changes: 10 additions & 12 deletions samples/fft_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#include "CodalDmesg.h"
#include "MicroBitAudioProcessor.h"
#include "StreamNormalizer.h"
#include "Tests.h"

static NRF52ADCChannel *mic = NULL;
static StreamNormalizer *processor = NULL;
Expand All @@ -14,8 +13,9 @@ MicroBit uBit;
* fft_test function - creates an example MicroBitAudioProcessor and then queries it for results.
* Currently configured to use 1024 samples with 8bit signed data.
*/
void fft_test(){
void fft_test() {
uBit.display.print("L");
/*
if (mic == NULL){
mic = uBit.adc.getChannel(uBit.io.microphone);
mic->setGain(7,0);
Expand All @@ -29,13 +29,17 @@ void fft_test(){
uBit.io.runmic.setDigitalValue(1);
uBit.io.runmic.setHighDrive(true);
*/

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

//Start fft running
fft->startRecording();


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



int
main()
{

int main() {
uBit.init();
fft_test();

}
}
6 changes: 2 additions & 4 deletions source/MicroBitAudioProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ MicroBitAudioProcessor::~MicroBitAudioProcessor()

int MicroBitAudioProcessor::pullRequest()
{

int s;
int result;

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

uint32_t freq = ((uint32_t)MIC_SAMPLE_RATE / AUDIO_SAMPLES_NUMBER) * (index + 1);
lastFreq = ((uint32_t)MIC_SAMPLE_RATE / AUDIO_SAMPLES_NUMBER) * (index + 1);
DMESG("Freq: %d (max: %d.%d, Index: %d)",
freq,
lastFreq,
(int)maxValue,
((int)(maxValue * 100) % 100),
index);
Expand Down
4 changes: 2 additions & 2 deletions target-locked.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"USE_ACCEL_LSB": 0
},
"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",
"cpu_opts": "-mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=softfp",
"cpu_opts": "-mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=hard",
"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",
"device": "MICROBIT",
"generate_bin": true,
Expand All @@ -69,7 +69,7 @@
"url": "https://github.com/microbit-foundation/codal-microbit-nrf5sdk"
}
],
"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",
"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",
"post_process": "",
"processor": "NRF52833",
"snapshot_version": "v0.2.50",
Expand Down

0 comments on commit 22920ba

Please sign in to comment.