Corrected example SineCosOut.ino

pull/11/head
boblark 4 years ago
parent 40c7fbc979
commit aea31613c4
  1. 19
      examples/SineCosOut/SineCosOut.ino
  2. 4
      output_i2s_f32.cpp
  3. 6
      output_i2s_f32.h
  4. 2
      readme.md

@ -1,5 +1,7 @@
/*
SineCosOut.ino - Sine left, Cos right
Selectable: Frequency, Hz
Amplitude, 0.00 to 1.00
Bob Larkin 28 Dec 2020
Basic test of I2S input and output.
@ -9,12 +11,18 @@
#include "Audio.h" // Teensy I16 Audio Library
#include "OpenAudio_ArduinoLibrary.h" // F32 library
#include "AudioStream_F32.h"
// T3.x supported sample rates: 2000, 8000, 11025, 16000, 22050, 24000, 32000, 44100, 44117, 48000,
// 88200, 88235 (44117*2), 95680, 96000, 176400, 176470, 192000
// T4.x supports any sample rate the codec will hanedle.
const float sample_rate_Hz = 24000.0f ; // 24000, 44117, or other frequencies listed above
const int audio_block_samples = 128; // Always 128, which is AUDIO_BLOCK_SAMPLES from AudioStream.h
AudioSettings_F32 audio_settings(sample_rate_Hz, audio_block_samples);
AudioSynthSineCosine_F32 sineCos;
AudioAnalyzePeak_F32 peakL;
AudioAnalyzePeak_F32 peakR;
//AudioOutputI2S_OA_F32 i2sOut;
AudioOutputI2S_F32 i2sOut;
AudioOutputI2S_F32 i2sOut(audio_settings);
AudioConnection_F32 patchCord0(sineCos, 0, peakL, 0);
AudioConnection_F32 patchCord1(sineCos, 1, peakR, 0);
AudioConnection_F32 patchCord2(sineCos, 0, i2sOut, 0); // Sine
@ -27,18 +35,19 @@ void setup() {
Serial.println("OpenAudio_ArduinoLibrary - Sine-Cosine Stereo");
// Internally, I16 memory blocks are used. Needs modification, but
// for now, supply 4 for F32 input and 4 for F32 output (shared).
AudioMemory(4);
//AudioMemory(4);
AudioMemory_F32(20);
codec1.enable(); // MUST be before inputSelect()
codec1.inputSelect(AUDIO_INPUT_LINEIN);
sineCos.amplitude(0.2); sineCos.frequency(600.0f);
float fr = 600.0f; // Sine wave frequency and correction for sample rate
sineCos.amplitude(0.2); sineCos.frequency(fr*44117.647f/sample_rate_Hz);
}
void loop() {
Serial.print("Max float memory = ");
Serial.println(AudioStream_F32::f32_memory_used_max);
if(peakL.available()) Serial.print(peakL.read(), 6);
Serial.print(" <-L R-> ");
Serial.print(" <-L Peak level R-> ");
if(peakR.available()) Serial.println(peakR.read(), 6);
delay(500);
}

@ -786,10 +786,10 @@ void AudioOutputI2S_F32::update(void)
#endif
#endif
void AudioOutputI2S_F32::config_i2s(void) { config_i2s(false, AudioOutputI2S_F32::sample_rate_Hz); }
void AudioOutputI2S_F32::config_i2s(bool transferUsing32bit) { config_i2s(transferUsing32bit, AudioOutputI2S_F32::sample_rate_Hz); }
void AudioOutputI2S_F32::config_i2s(float fs_Hz) { config_i2s(false, fs_Hz); }
void AudioOutputI2S_F32::config_i2s(bool transferUsing32bit, float fs_Hz)
{
#if defined(KINETISK) || defined(KINETISL)
@ -834,9 +834,7 @@ void AudioOutputI2S_F32::config_i2s(bool transferUsing32bit, float fs_Hz)
// change the I2S frequencies to make the requested sample rate
setI2SFreq_T3(fs_Hz); //for T3.x only!
#elif defined(__IMXRT1062__)
CCM_CCGR5 |= CCM_CCGR5_SAI1(CCM_CCGR_ON);
// if either transmitter or receiver is enabled, do nothing

@ -75,10 +75,8 @@ public:
static void scale_f32_to_i16( float32_t *p_f32, float32_t *p_i16, int len) ;
static void scale_f32_to_i24( float32_t *p_f32, float32_t *p_i16, int len) ;
static void scale_f32_to_i32( float32_t *p_f32, float32_t *p_i32, int len) ;
static float setI2SFreq_T3(const float);
static float setI2SFreq_T3(const float); // I2S clock for T3,x
protected:
AudioOutputI2S_F32(int dummy): AudioStream_F32(2, inputQueueArray) {} // to be used only inside AudioOutputI2Sslave !!
static void config_i2s(void);

@ -3,7 +3,7 @@ OpenAudio Library for Teensy
*** Special Note *** 6 January 2021- This library is undergoing revision to make Teensy 4.x compatible and to add functionality. The Tympan Library
files and associated classes output_i2s_f32.h, output_i2s_f32.cpp, input_i2s_f32.h, input_i2s_f32.cpp are now
ready to be used for T3.x and T4.x. There are some restrictions, particularly this should be used with 16-bit I2S codec data. Notes and details are at the bottom of this page. Work on the F32 i/o routines is continuing. Thanks to Chip and @jcj83429 .
ready to be used for T3.x and T4.x. There are some restrictions, particularly this should be used with 16-bit I2S codec data. Codec sample rates can be varied. Block size needsto be left at 128 for now. Work on the F32 i/o routines is continuing. Thanks to Chip and @jcj83429 .
**Purpose**: The purpose of this library is to build upon the [Teensy Audio Library](http://www.pjrc.com/teensy/td_libs_Audio.html) to enable new functionality for real-time audio processing.

Loading…
Cancel
Save