Skip to content

Pitch shift don't work #2105

@sadbass

Description

@sadbass

Problem Description

The example arduino-audio-tools/examples/examples-audiokit
/streams-audiokit-ram-ptichshift-audiokit
I have the board (AudioKitEs8388V1)
The example without pitch shift work well (if I remove the line smooth transition, if I remove also the one in the example with pitch shift, still not work)
The example streaming a MP3 from SD card work well
All 3 the version
VariableSpeedRingBuffer
VariableSpeedRingBuffer180
VariableSpeedRingBufferSimple
Don't work
This afternoon I can report the error via serial

Device Description

I've selected esp32 dev module in Arduino ide with the library downloaded today
I have a esp32 audiokit v2.2
All the example using the device (AudioKitEs8388V1)
Work well

Sketch

/**
 * @file streams-audiokit-sd-audiokit.ino
 * @author Phil Schatzmann
 * @brief We record the input from the microphone to SPI RAM and constantly repeat to play the file
 * The input is triggered by pressing key 1. Recording stops when key 1 is released!
 * The output pitch is shifted by 1 octave!
 * @version 0.1
 * @date 2022-11-21
 * 
 * @copyright Copyright (c) 2022
 * 
 */
#include "AudioTools.h"
#include "AudioTools/AudioLibs/AudioBoardStream.h"
#include "AudioTools/AudioLibs/MemoryManager.h"

AudioInfo info(16000, 1, 16);
MemoryManager memory(500); // Activate SPI RAM for objects > 500 bytes
AudioBoardStream kit(AudioKitEs8388V1);
//use one of VariableSpeedRingBufferSimple, VariableSpeedRingBuffer, VariableSpeedRingBuffer180 
PitchShiftOutput<int16_t, VariableSpeedRingBuffer<int16_t>> pitch_shift(kit);
DynamicMemoryStream recording(false); // Audio stored on heap, non repeating
StreamCopy copier; // copies data
 

void record_start(bool pinStatus, int pin, void* ref){
  Serial.println("Recording...");
  recording.begin();
  copier.begin(recording, kit);  
}

void record_end(bool pinStatus, int pin, void* ref){
  Serial.println("Playing...");

  // Remove popping noise, from button: we delete 6 segments at the beginning and end 
  // and on the resulting audio we slowly raise the volume on the first segment
  // end decrease it on the last segment
  recording.postProcessSmoothTransition<int16_t>(info.channels, 0.01, 6);

  // output with pitch shifting
  copier.begin(pitch_shift, recording);  // start playback
}

void setup(){
  Serial.begin(115200);
  while(!Serial); // wait for serial to be ready
  AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Info);  

  // setup input and output
  auto cfg = kit.defaultConfig(RXTX_MODE);
  cfg.sd_active = true;
  cfg.copyFrom(info);
  cfg.input_device = ADC_INPUT_LINE2;
  kit.begin(cfg);
  kit.setVolume(1.0);

  // setup pitch shift
  auto cfg_pc = pitch_shift.defaultConfig();
  cfg_pc.pitch_shift = 2; // one octave up
  cfg_pc.buffer_size = 1000;
  cfg_pc.copyFrom(info);
  pitch_shift.begin(cfg_pc);

  // record when key 1 is pressed
  kit.audioActions().add(kit.getKey(1), record_start, record_end);
  Serial.println("Press Key 1 to record");
}

void loop(){
  // record or play recording
  copier.copy();  

  // Process keys
  kit.processActions();
}
  • I confirm I have checked existing issues, discussions and online documentation

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions