From 791d6bc62c8d609d7d358ffe9a5841f7bf2670b1 Mon Sep 17 00:00:00 2001 From: alfran Date: Tue, 14 Mar 2017 17:31:40 +0100 Subject: [PATCH 01/11] fixed microphones low volume issue --- libraries/Audio/src/Audio.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/Audio/src/Audio.h b/libraries/Audio/src/Audio.h index 37f8588..c3461f6 100644 --- a/libraries/Audio/src/Audio.h +++ b/libraries/Audio/src/Audio.h @@ -75,7 +75,7 @@ class AudioClass : public Print { uint32_t bufferIn_fptr = 0; //fptr private: - uint32_t volume = 60; + uint32_t volume = 100; AudioMode mode; }; From 0318e84b45cd50c39c7f5c10c816f3fda705a67f Mon Sep 17 00:00:00 2001 From: alfran Date: Wed, 15 Mar 2017 12:40:28 +0100 Subject: [PATCH 02/11] Improved Volume management --- libraries/Audio/src/Audio.cpp | 72 ++++++++++++++++++----------------- 1 file changed, 38 insertions(+), 34 deletions(-) diff --git a/libraries/Audio/src/Audio.cpp b/libraries/Audio/src/Audio.cpp index 7a2328c..33d06e3 100644 --- a/libraries/Audio/src/Audio.cpp +++ b/libraries/Audio/src/Audio.cpp @@ -11,7 +11,7 @@ #include "Audio.h" #include "otto_audio_inout.h" - +int audioVolume = 100; AudioClass Audio; @@ -53,7 +53,7 @@ void AudioClass::end() { BSP_AUDIO_IN_Stop(CODEC_PDWN_SW); } BSP_AUDIO_OUT_Stop(CODEC_PDWN_SW); - if (bufferOut) + if (bufferOut) { free(bufferOut); bufferOut = NULL; @@ -65,46 +65,50 @@ void AudioClass::prepare(int16_t *buffer, int S, int volume){ uint16_t *ubuffer = (uint16_t*) buffer; if(volume >= 100) - volume = 100; - if (volume <= 10) - volume = 10; + audioVolume = 100; + if (volume <= 0) + audioVolume = 0; + BSP_AUDIO_OUT_SetVolume(audioVolume); + BSP_AUDIO_IN_SetVolume(audioVolume); } size_t AudioClass::write(const uint32_t *data, size_t size) { int i; + BSP_AUDIO_OUT_SetVolume(audioVolume); + BSP_AUDIO_IN_SetVolume(audioVolume); + + if(size > (bufferOutSize / 2)) + return size; + + /* not running yet, need to fill-in full FIFO */ + if(running == NULL) { + memcpy(next, (uint8_t *) data, size); + /* First half FIFO */ + if(next == bufferOut) { + next = half; + /* Second half FIfO, when copied, start playing */ + } else { + next = bufferOut; + running = bufferOut; + BSP_AUDIO_OUT_Play((uint16_t*)bufferOut, bufferOutSize); + } + _receivedBytes += size; + return size; + } - if(size > (bufferOutSize / 2)) - return size; - - /* not running yet, need to fill-in full FIFO */ - if(running == NULL) { - memcpy(next, (uint8_t *) data, size); - /* First half FIFO */ - if(next == bufferOut) { - next = half; - /* Second half FIfO, when copied, start playing */ - } else { - next = bufferOut; - running = bufferOut; - BSP_AUDIO_OUT_Play((uint16_t*)bufferOut, bufferOutSize); - } - _receivedBytes += size; - return size; - } - - /* Wait for room in FIFO*/ - while((int)next == (int) running); + /* Wait for room in FIFO*/ + while((int)next == (int) running); - _receivedBytes += size; + _receivedBytes += size; - /* If running is not next there is room in fifo */ - memcpy(next,(uint8_t *) data, size); + /* If running is not next there is room in fifo */ + memcpy(next,(uint8_t *) data, size); - if(next == bufferOut) { - next = half; - } else { - next = bufferOut; - } + if(next == bufferOut) { + next = half; + } else { + next = bufferOut; + } return size; } From 14bfab4d00d72ac25204866eb6ef5d35f1097f45 Mon Sep 17 00:00:00 2001 From: alfran Date: Wed, 15 Mar 2017 12:41:47 +0100 Subject: [PATCH 03/11] Improved Simple Audio Recorder Example --- .../SimpleAudioRecorder.ino | 38 ++++++++++++++++--- 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/libraries/Audio/example/SimpleAudioRecorder/SimpleAudioRecorder.ino b/libraries/Audio/example/SimpleAudioRecorder/SimpleAudioRecorder.ino index 6bef58c..7345bbe 100644 --- a/libraries/Audio/example/SimpleAudioRecorder/SimpleAudioRecorder.ino +++ b/libraries/Audio/example/SimpleAudioRecorder/SimpleAudioRecorder.ino @@ -1,4 +1,4 @@ -/* +//* Simple Audio Recorder Demonstrates the use of the Audio library for the Arduino OTTO @@ -8,6 +8,7 @@ * Only 48kHz supported for now Original by Frederic Pillon November 09, 2016 + Modified by Francesco Alessi March 15 2017 This example code is in the public domain @@ -21,7 +22,7 @@ const char recFile[] = "record.wav"; #define AUDIO_IN_FREQUENCY BSP_AUDIO_FREQUENCY_48K -#define DEFAULT_TIME_REC 30 // Recording time in second (default: 30s) +#define DEFAULT_TIME_REC 3 // Recording time in second (default: 30s) #define REC_SAMPLE_LENGTH (DEFAULT_TIME_REC * AUDIO_IN_FREQUENCY * DEFAULT_AUDIO_IN_CHANNEL_NBR * 2) #define RECORD_5PERCENT ((5*REC_SAMPLE_LENGTH)/100) @@ -29,11 +30,23 @@ void setup() { // initialize SerialUSB communication at 115200 bits per second: SerialUSB.begin(115200); while(!SerialUSB); - + SerialUSB.print("Detecting SD"); + int counter = 0; while (SD.begin(SD_DETECT_PIN) != TRUE) { - delay(10); + SerialUSB.print("."); + delay(500); + if (counter == 10) + { + SerialUSB.println("."); + SerialUSB.println("SD Card not detected!"); + SerialUSB.print("Detecting SD"); + counter = 0; + } + counter++; } + //SerialUSB.println(""); + SerialUSB.println("done."); } void loop() { @@ -43,10 +56,22 @@ void loop() { const int S = 1024; // Number of samples to read in block uint32_t byteswritten = 0; uint32_t count = 0; - delay(4000); // delay for console + delay(1000); + // removing old file + while(SD.exists(recFile) == TRUE) + { + SerialUSB.print("Removing file "); + SerialUSB.print(recFile); + SerialUSB.print("..."); + SD.remove(recFile); + SerialUSB.println("done"); + } + File myFile = SD.open(recFile, FILE_WRITE); + if (!SD.exists(recFile)) { + // If the file didn't open, print an error and stop SerialUSB.print("Error: failed to create "); SerialUSB.println(recFile); @@ -70,7 +95,7 @@ void loop() { } delay(1000); - SerialUSB.println("Start AUDIO record"); + SerialUSB.println("Starting AUDIO recorder"); delay(1000); status = Audio.begin(WaveFormat.SampleRate, 100, AUDIO_IN); if (status != 0) { @@ -84,6 +109,7 @@ void loop() { delay(1000); // Prepare samples + SerialUSB.println("Recording..."); int volume = 100; Audio.prepare(NULL, S, volume); delay(1000); From 4aa96be4343798f9b33aeeaa22b46956a3d521f9 Mon Sep 17 00:00:00 2001 From: alfran Date: Wed, 15 Mar 2017 18:16:39 +0100 Subject: [PATCH 04/11] improved Volume management and audio related sketch --- .../SimpleAudioPlayer/SimpleAudioPlayer.ino | 28 ++++++++++++++----- .../SimpleAudioRecorder.ino | 5 ++-- libraries/Audio/src/Audio.cpp | 28 +++++++++++-------- 3 files changed, 40 insertions(+), 21 deletions(-) diff --git a/libraries/Audio/example/SimpleAudioPlayer/SimpleAudioPlayer.ino b/libraries/Audio/example/SimpleAudioPlayer/SimpleAudioPlayer.ino index 47a6e48..09e08ce 100644 --- a/libraries/Audio/example/SimpleAudioPlayer/SimpleAudioPlayer.ino +++ b/libraries/Audio/example/SimpleAudioPlayer/SimpleAudioPlayer.ino @@ -20,16 +20,28 @@ #include #include +const char recFile[] = "record.wav"; + void setup() { // initialize serial communication at 9600 bits per second: SerialUSB.begin(115200); while(!SerialUSB); - - /* Test begin() method */ + SerialUSB.print("Detecting SD"); + int counter = 0; while (SD.begin(SD_DETECT_PIN) != TRUE) { - delay(10); + SerialUSB.print("."); + delay(500); + if (counter == 10) + { + SerialUSB.println("."); + SerialUSB.println("SD Card not detected!"); + SerialUSB.print("Detecting SD"); + counter = 0; + } + counter++; } + SerialUSB.println("...done."); } void loop() { @@ -40,19 +52,21 @@ void loop() { int duration; delay(1000); // delay for console - File myFile = SD.open("test.wav"); + File myFile = SD.open(recFile); if (!myFile.available()) { // if the file didn't open, print an error and stop - SerialUSB.println("error opening test.wav"); + SerialUSB.print("error opening "); + SerialUSB.println(recFile); while (true); } else { - SerialUSB.println("test.wav open OK"); + SerialUSB.println(recFile); + SerialUSB.println(" open OK"); } myFile.read((void*) &WaveFormat, sizeof(WaveFormat)); delay(1000); - SerialUSB.println("STARTUP AUDIO\r\n"); + SerialUSB.println("Starting Playback"); delay(1000); Audio.begin(WaveFormat.SampleRate, 100); diff --git a/libraries/Audio/example/SimpleAudioRecorder/SimpleAudioRecorder.ino b/libraries/Audio/example/SimpleAudioRecorder/SimpleAudioRecorder.ino index 7345bbe..c3b11ac 100644 --- a/libraries/Audio/example/SimpleAudioRecorder/SimpleAudioRecorder.ino +++ b/libraries/Audio/example/SimpleAudioRecorder/SimpleAudioRecorder.ino @@ -1,4 +1,4 @@ -//* +/* Simple Audio Recorder Demonstrates the use of the Audio library for the Arduino OTTO @@ -45,8 +45,7 @@ void setup() { } counter++; } - //SerialUSB.println(""); - SerialUSB.println("done."); + SerialUSB.println("...done."); } void loop() { diff --git a/libraries/Audio/src/Audio.cpp b/libraries/Audio/src/Audio.cpp index 33d06e3..a3deaef 100644 --- a/libraries/Audio/src/Audio.cpp +++ b/libraries/Audio/src/Audio.cpp @@ -11,8 +11,6 @@ #include "Audio.h" #include "otto_audio_inout.h" -int audioVolume = 100; - AudioClass Audio; /* Begin class can be extended to support more options */ @@ -33,12 +31,12 @@ int AudioClass::begin(uint32_t sampleRate, uint32_t msPreBuffer, AudioMode audio next = bufferOut; } - ret = BSP_AUDIO_OUT_Init(OUTPUT_DEVICE_HEADPHONE, volume, sampleRate); + ret = BSP_AUDIO_OUT_Init(OUTPUT_DEVICE_HEADPHONE, 0, sampleRate); /* Audio In */ if(mode != AUDIO_OUT) { - ret += BSP_AUDIO_IN_Init(INPUT_DEVICE_DIGITAL_MICROPHONE_2, volume, sampleRate); + ret += BSP_AUDIO_IN_Init(INPUT_DEVICE_DIGITAL_MICROPHONE_2, 0, sampleRate); ret += BSP_AUDIO_IN_Record((uint16_t*)&bufferIn[0], bufferInSize); bufferIn_fptr += 44; } @@ -64,18 +62,26 @@ void AudioClass::end() { void AudioClass::prepare(int16_t *buffer, int S, int volume){ uint16_t *ubuffer = (uint16_t*) buffer; - if(volume >= 100) - audioVolume = 100; + if (volume >= 100) + volume = 100; if (volume <= 0) - audioVolume = 0; - BSP_AUDIO_OUT_SetVolume(audioVolume); - BSP_AUDIO_IN_SetVolume(audioVolume); + volume = 0; + + if (mode == AUDIO_OUT) + BSP_AUDIO_OUT_SetVolume(volume); + if (mode == AUDIO_IN) + BSP_AUDIO_IN_SetVolume(volume); + if (mode == AUDIO_BOTH) { + BSP_AUDIO_OUT_SetVolume(volume); + BSP_AUDIO_IN_SetVolume(volume); + } + + } size_t AudioClass::write(const uint32_t *data, size_t size) { + int i; - BSP_AUDIO_OUT_SetVolume(audioVolume); - BSP_AUDIO_IN_SetVolume(audioVolume); if(size > (bufferOutSize / 2)) return size; From e109f978285d42ff111f2f7f41ed40633cfa579d Mon Sep 17 00:00:00 2001 From: alfran Date: Wed, 15 Mar 2017 18:23:57 +0100 Subject: [PATCH 05/11] Fixed SimpleAudioRecorder Sketch --- .../Audio/example/SimpleAudioRecorder/SimpleAudioRecorder.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/Audio/example/SimpleAudioRecorder/SimpleAudioRecorder.ino b/libraries/Audio/example/SimpleAudioRecorder/SimpleAudioRecorder.ino index c3b11ac..bd00433 100644 --- a/libraries/Audio/example/SimpleAudioRecorder/SimpleAudioRecorder.ino +++ b/libraries/Audio/example/SimpleAudioRecorder/SimpleAudioRecorder.ino @@ -20,9 +20,9 @@ #include #include -const char recFile[] = "record.wav"; +const char recFile[] = "test.wav"; #define AUDIO_IN_FREQUENCY BSP_AUDIO_FREQUENCY_48K -#define DEFAULT_TIME_REC 3 // Recording time in second (default: 30s) +#define DEFAULT_TIME_REC 30 // Recording time in second (default: 30s) #define REC_SAMPLE_LENGTH (DEFAULT_TIME_REC * AUDIO_IN_FREQUENCY * DEFAULT_AUDIO_IN_CHANNEL_NBR * 2) #define RECORD_5PERCENT ((5*REC_SAMPLE_LENGTH)/100) From 1e7dfe6ab681512b87259d11a562a54c02d64ff2 Mon Sep 17 00:00:00 2001 From: alfran Date: Thu, 16 Mar 2017 17:00:54 +0100 Subject: [PATCH 06/11] Firmware side of Linux64 Upload issue, also dfu-util is patched --- variants/otto/usb/usbd_cdc_if.c | 51 ++++++++++++--------------------- 1 file changed, 19 insertions(+), 32 deletions(-) diff --git a/variants/otto/usb/usbd_cdc_if.c b/variants/otto/usb/usbd_cdc_if.c index 5becd64..2b2959d 100644 --- a/variants/otto/usb/usbd_cdc_if.c +++ b/variants/otto/usb/usbd_cdc_if.c @@ -115,12 +115,16 @@ __IO uint32_t lineState = 0; uint8_t cptlineState = 0; /* Default configuration: 115200, 8N1 */ -uint8_t lineSetup[] = {0x00, 0x00, 0x20, 0x1c, 0x00, 0x00, 0x08}; +uint8_t lineSetup[] = {0x00, 0xc2, 0x01, 0x00, 0x00, 0x00, 0x08}; #define CDC_POLLING_INTERVAL 5 /* in ms. The max is 65 and the min is 1 */ TIM_HandleTypeDef TimHandle; +volatile uint8_t dfu_request = 0; +/* For a bug in some Linux 64 bit PC we need to delay the reset of the CPU of 500m second */ +int counter_dfu_reset = 100; /* the unit is equal to CDC_POLLING_INTERVAL that is 5ms by default */ + static void TIM_Config(void); /* USB handler declaration */ @@ -276,9 +280,7 @@ static int8_t CDC_Control_FS (uint8_t cmd, uint8_t* pbuf, uint16_t length) memcpy(lineSetup, pbuf, 7); if(*((uint32_t*)pbuf) == 1200){ - /* Set magic number in SRAM so application enters DFU after reset */ - *((unsigned int*)0x2004FFF0) = 0xb311a21a; - NVIC_SystemReset(); + dfu_request = 1; } break; @@ -468,6 +470,18 @@ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) { uint8_t status; + if(dfu_request) + { + counter_dfu_reset--; + if(counter_dfu_reset == 0) + { + dfu_request = 0; + /* Set magic number in SRAM so application enters DFU after reset */ + *((unsigned int*)0x2004FFF0) = 0xb311a21a; + NVIC_SystemReset(); + } + } + if(UserTxBufPtrOut != UserTxBufPtrIn) { if(UserTxBufPtrOut > UserTxBufPtrIn) /* Roll-back */ @@ -487,31 +501,4 @@ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) } else { - USBD_CDC_SetTxBuffer(&hUsbDeviceFS, (uint8_t*)&UserTxBufferFS[UserTxBufPtrOut], (UserTxBufPtrIn - UserTxBufPtrOut)); - - status = USBD_CDC_TransmitPacket(&hUsbDeviceFS); - - if(status == USBD_OK) - { - UserTxBufPtrOut = UserTxBufPtrIn; - } - } - } -} - -/* USER CODE BEGIN PRIVATE_FUNCTIONS_IMPLEMENTATION */ -/* USER CODE END PRIVATE_FUNCTIONS_IMPLEMENTATION */ - -/** - * @} - */ - -/** - * @} - */ - -#ifdef __cplusplus -} -#endif - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ + USBD_CDC_SetTxBuffer(&hUsbDeviceFS, (uint8_t*)&UserTxBufferFS[UserTxBufPtrO From 093ed4858c66d7e6d136691ffd5091b6577858ff Mon Sep 17 00:00:00 2001 From: alfran Date: Thu, 16 Mar 2017 17:52:59 +0100 Subject: [PATCH 07/11] Fixed compiling issue for Firmware side of Linux64 Upload issue, also dfu-util is patched --- variants/otto/usb/usbd_cdc_if.c | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/variants/otto/usb/usbd_cdc_if.c b/variants/otto/usb/usbd_cdc_if.c index 2b2959d..ac81dc1 100644 --- a/variants/otto/usb/usbd_cdc_if.c +++ b/variants/otto/usb/usbd_cdc_if.c @@ -122,7 +122,7 @@ uint8_t lineSetup[] = {0x00, 0xc2, 0x01, 0x00, 0x00, 0x00, 0x08}; TIM_HandleTypeDef TimHandle; volatile uint8_t dfu_request = 0; -/* For a bug in some Linux 64 bit PC we need to delay the reset of the CPU of 500m second */ +/* For a bug in some Linux 64 bit PC we need to delay the reset of the CPU of 500ms seconds */ int counter_dfu_reset = 100; /* the unit is equal to CDC_POLLING_INTERVAL that is 5ms by default */ static void TIM_Config(void); @@ -501,4 +501,31 @@ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) } else { - USBD_CDC_SetTxBuffer(&hUsbDeviceFS, (uint8_t*)&UserTxBufferFS[UserTxBufPtrO + USBD_CDC_SetTxBuffer(&hUsbDeviceFS, (uint8_t*)&UserTxBufferFS[UserTxBufPtrOut], (UserTxBufPtrIn - UserTxBufPtrOut)); + + status = USBD_CDC_TransmitPacket(&hUsbDeviceFS); + + if(status == USBD_OK) + { + UserTxBufPtrOut = UserTxBufPtrIn; + } + } + } +} + +/* USER CODE BEGIN PRIVATE_FUNCTIONS_IMPLEMENTATION */ +/* USER CODE END PRIVATE_FUNCTIONS_IMPLEMENTATION */ + +/** + * @} + */ + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ From 395c7929f5c680221375f50e8f1ab014001dadd3 Mon Sep 17 00:00:00 2001 From: alfran Date: Thu, 16 Mar 2017 18:17:35 +0100 Subject: [PATCH 08/11] modified Platform.txt for Linux64 issue --- platform.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/platform.txt b/platform.txt index ae57a4c..8975e65 100644 --- a/platform.txt +++ b/platform.txt @@ -1,4 +1,3 @@ - # Arduino STM32F4 Core and platform # ------------------------------ # @@ -96,7 +95,7 @@ tools.dfu-util.cmd.windows=dfu-util.cmd tools.dfu-util.upload.params.verbose=-v tools.dfu-util.upload.params.quiet= -tools.dfu-util.upload.pattern="{path}/{cmd}" "{path}" {upload.usbID} {upload.altID} {upload.mem_start} "{build.path}/{build.project_name}.bin" +tools.dfu-util.upload.pattern="{path}/{cmd}" "{path}" {upload.usbID} {upload.altID} {upload.mem_start} "{build.path}/{build.project_name}.bin" "{serial.port}" # # USB Flags From 006c9520cf0ebb3142c2d862d2460c4f48e7b049 Mon Sep 17 00:00:00 2001 From: alfran Date: Fri, 17 Mar 2017 11:02:01 +0100 Subject: [PATCH 09/11] Fixed 'word()', renamed and cleaned files --- cores/arduino/Arduino.h | 1 + cores/arduino/HardwareTimer.cpp | 4 +- cores/arduino/WMath.cpp | 68 ++++++++++++++ cores/arduino/WMath.h | 47 ++++++++++ cores/arduino/wiring.h | 3 +- cores/arduino/wiring_math.cpp | 49 ----------- cores/arduino/wiring_math.h | 151 -------------------------------- 7 files changed, 121 insertions(+), 202 deletions(-) create mode 100644 cores/arduino/WMath.cpp create mode 100644 cores/arduino/WMath.h delete mode 100755 cores/arduino/wiring_math.cpp delete mode 100755 cores/arduino/wiring_math.h diff --git a/cores/arduino/Arduino.h b/cores/arduino/Arduino.h index af99be3..a60b0e1 100755 --- a/cores/arduino/Arduino.h +++ b/cores/arduino/Arduino.h @@ -37,3 +37,4 @@ typedef uint8 byte; #include "variant.h" #include "Tone.h" #include "WCharacter.h" +#include "WMath.h" diff --git a/cores/arduino/HardwareTimer.cpp b/cores/arduino/HardwareTimer.cpp index 8ca22fb..2e7953f 100755 --- a/cores/arduino/HardwareTimer.cpp +++ b/cores/arduino/HardwareTimer.cpp @@ -31,7 +31,9 @@ #include "HardwareTimer.h" #include "boards.h" // for CYCLES_PER_MICROSECOND -#include "wiring_math.h" +//#include "wiring_math.h" +#include "WMath.h" + #define NR_TIMERS 14 diff --git a/cores/arduino/WMath.cpp b/cores/arduino/WMath.cpp new file mode 100644 index 0000000..34bf341 --- /dev/null +++ b/cores/arduino/WMath.cpp @@ -0,0 +1,68 @@ +/* + Copyright (c) 2011 Arduino. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +extern "C" { + #include "stdlib.h" + #include "stdint.h" +} +#include "WMath.h" + +extern void randomSeed( uint32_t dwSeed ) +{ + if ( dwSeed != 0 ) + { + srand( dwSeed ) ; + } +} + +extern long random( long howbig ) +{ + if ( howbig == 0 ) + { + return 0 ; + } + + return rand() % howbig; +} + +extern long random( long howsmall, long howbig ) +{ + if (howsmall >= howbig) + { + return howsmall; + } + + long diff = howbig - howsmall; + + return random(diff) + howsmall; +} + +extern long map(long x, long in_min, long in_max, long out_min, long out_max) +{ + return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; +} + +extern uint16_t makeWord( uint16_t w ) +{ + return w ; +} + +extern uint16_t makeWord( uint8_t h, uint8_t l ) +{ + return (h << 8) | l ; +} diff --git a/cores/arduino/WMath.h b/cores/arduino/WMath.h new file mode 100644 index 0000000..063229d --- /dev/null +++ b/cores/arduino/WMath.h @@ -0,0 +1,47 @@ +/* + Copyright (c) 2011 Arduino. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifndef _WIRING_MATH_ +#define _WIRING_MATH_ + +extern long random( long ) ; +extern long random( long, long ) ; +extern void randomSeed( uint32_t dwSeed ) ; +extern long map( long, long, long, long, long ) ; + +extern uint16_t makeWord( uint16_t w ) ; +extern uint16_t makeWord( uint8_t h, uint8_t l ) ; + +#define word(...) makeWord(__VA_ARGS__) + +#define min(a,b) ((a)<(b)?(a):(b)) +#define max(a,b) ((a)>(b)?(a):(b)) +#define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt))) +#define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5)) +#define radians(deg) ((deg)*DEG_TO_RAD) +#define degrees(rad) ((rad)*RAD_TO_DEG) +#define sq(x) ((x)*(x)) + +/* undefine stdlib's abs if encountered */ +#ifdef abs +#undef abs +#endif +#define abs(x) (((x) > 0) ? (x) : -(x)) + + +#endif /* _WIRING_MATH_ */ diff --git a/cores/arduino/wiring.h b/cores/arduino/wiring.h index 905f5ae..38c4fea 100755 --- a/cores/arduino/wiring.h +++ b/cores/arduino/wiring.h @@ -48,7 +48,8 @@ #include "pwm.h" #include "interrupts.h" #include "wiring_debug.h" -#include "wiring_math.h" +#include "WMath.h" + #include "wiring_time.h" #include #include "SPI.h" diff --git a/cores/arduino/wiring_math.cpp b/cores/arduino/wiring_math.cpp deleted file mode 100755 index 5aa6510..0000000 --- a/cores/arduino/wiring_math.cpp +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Modified by LeafLabs, LLC. - * - * Part of the Wiring project - http://wiring.org.co Copyright (c) - * 2004-06 Hernando Barragan Modified 13 August 2006, David A. Mellis - * for Arduino - http://www.arduino.cc/ - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ - -#include -#include "math.h" - -void randomSeed(unsigned int seed) { - if (seed != 0) { - srand(seed); - } -} - -long random(long howbig) { - if (howbig == 0) { - return 0; - } - - return rand() % howbig; -} - -long random(long howsmall, long howbig) { - if (howsmall >= howbig) { - return howsmall; - } - - long diff = howbig - howsmall; - return random(diff) + howsmall; -} - diff --git a/cores/arduino/wiring_math.h b/cores/arduino/wiring_math.h deleted file mode 100755 index 1fa45dc..0000000 --- a/cores/arduino/wiring_math.h +++ /dev/null @@ -1,151 +0,0 @@ -/****************************************************************************** - * The MIT License - * - * Copyright (c) 2010 Perry Hung. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - *****************************************************************************/ - -/** - * @file wiring_math.h - * @brief Includes ; provides Arduino-compatible math routines. - */ - -#ifndef _WIRING_MATH_H_ -#define _WIRING_MATH_H_ - -#include - -/** - * @brief Initialize the pseudo-random number generator. - * @param seed the number used to initialize the seed; cannot be zero. - */ -void randomSeed(unsigned int seed); - -/** - * @brief Generate a pseudo-random number with upper bound. - * @param max An upper bound on the returned value, exclusive. - * @return A pseudo-random number in the range [0,max). - * @see randomSeed() - */ -long random(long max); - -/** - * @brief Generate a pseudo-random number with lower and upper bounds. - * @param min Lower bound on the returned value, inclusive. - * @param max Upper bound on the returned value, exclusive. - * @return A pseudo-random number in the range [min, max). - * @see randomSeed() - */ -long random(long min, long max); - -/** - * @brief Remap a number from one range to another. - * - * That is, a value equal to fromStart gets mapped to toStart, a value - * of fromEnd to toEnd, and other values are mapped proportionately. - * - * Does not constrain value to lie within [fromStart, fromEnd]. - * - * If a "start" value is larger than its corresponding "end", the - * ranges are reversed, so map(n, 1, 10, 10, 1) would reverse the - * range [1,10]. - * - * Negative numbers may appear as any argument. - * - * @param value the value to map. - * @param fromStart the beginning of the value's current range. - * @param fromEnd the end of the value's current range. - * @param toStart the beginning of the value's mapped range. - * @param toEnd the end of the value's mapped range. - * @return the mapped value. - */ -static inline long map(long value, long fromStart, long fromEnd, - long toStart, long toEnd) { - return (value - fromStart) * (toEnd - toStart) / (fromEnd - fromStart) + - toStart; -} - -#define PI 3.1415926535897932384626433832795 -#define HALF_PI 1.5707963267948966192313216916398 -#define TWO_PI 6.283185307179586476925286766559 -#define DEG_TO_RAD 0.017453292519943295769236907684886 -#define RAD_TO_DEG 57.295779513082320876798154814105 - -#define min(a,b) ((a)<(b)?(a):(b)) -#define max(a,b) ((a)>(b)?(a):(b)) -#define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt))) -#define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5)) -#define radians(deg) ((deg)*DEG_TO_RAD) -#define degrees(rad) ((rad)*RAD_TO_DEG) -#define sq(x) ((x)*(x)) - -/* undefine stdlib's abs if encountered */ -#ifdef abs -#undef abs -#endif -#define abs(x) (((x) > 0) ? (x) : -(x)) - -/* Following are duplicate declarations (with Doxygen comments) for - * some of the math.h functions; this is for the convenience of the - * Sphinx docs. - */ - -/** - * Compute the cosine of an angle, in radians. - * @param x The radian measure of the angle. - * @return The cosine of x. This value will be between -1 and 1. - */ -double cos(double x); - -/** - * Compute the sine of an angle, in radians. - * @param x The radian measure of the angle. - * @return The sine of x. This value will be between -1 and 1. - */ -double sin(double x); - -/** - * Compute the tangent of an angle, in radians. - * @param x The radian measure of the angle. - * @return The tangent of x. There are no limits on the return value - * of this function. - */ -double tan(double x); - -/** - * Compute the square root of a number. - * @param x The number whose square root to find. This value cannot - * be negative. - * @return The square root of x. The return value is never negative. - */ -double sqrt(double x); - -/** - * Compute an exponentiation. - * @param x the base. This value cannot be zero if y <= 0. This value - * cannot be negative if y is not an integral value. - * @param y the exponent. - * @return x raised to the power y. - */ -double pow(double x, double y); - -#endif From af7165f3afabbf73197521a36a87e32bf860f0f7 Mon Sep 17 00:00:00 2001 From: alfran Date: Mon, 20 Mar 2017 12:00:55 +0100 Subject: [PATCH 10/11] modified README.adoc and library.properties --- libraries/Audio/README.adoc | 4 +++- libraries/Audio/library.properties | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/libraries/Audio/README.adoc b/libraries/Audio/README.adoc index 0a973bb..25b788a 100644 --- a/libraries/Audio/README.adoc +++ b/libraries/Audio/README.adoc @@ -2,8 +2,10 @@ The Audio library enables an Arduino OTTO board to play back .wav files from a storage device like an SD card. It is an adaptation of library supported on DUE board. -For more information about this library please visit us at +For more information about this library for DUE and OTTO common methods, please visit us at http://arduino.cc/en/Reference/Audio +for Otto specific implementation please visit +http://arduino.org/en/Reference/Audio == License == diff --git a/libraries/Audio/library.properties b/libraries/Audio/library.properties index a52fdb4..8348eb9 100644 --- a/libraries/Audio/library.properties +++ b/libraries/Audio/library.properties @@ -1,8 +1,8 @@ name=Audio version=1.0 author=Arduino -maintainer=Arduino -sentence=Allows playing audio files from an SD card. Adapted from Arduino DUE to OTTO. +maintainer=Arduino +sentence=Allows playing audio files from an SD card. Adapted from Arduino DUE to OTTO. Use some Processing Methods To have more flexibility. paragraph=With this library you can use the Arduino OTTO CODEC output to play audio files.
The audio files must be in the raw .wav format. category=Signal Input/Output url=http://arduino.cc/en/Reference/Audio From 09eecde59264269dfc470e0899bd73701911d4be Mon Sep 17 00:00:00 2001 From: alfran Date: Mon, 20 Mar 2017 12:52:31 +0100 Subject: [PATCH 11/11] modified mantainer email --- libraries/Audio/library.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/Audio/library.properties b/libraries/Audio/library.properties index 8348eb9..245f96d 100644 --- a/libraries/Audio/library.properties +++ b/libraries/Audio/library.properties @@ -1,7 +1,7 @@ name=Audio version=1.0 author=Arduino -maintainer=Arduino +maintainer=Arduino sentence=Allows playing audio files from an SD card. Adapted from Arduino DUE to OTTO. Use some Processing Methods To have more flexibility. paragraph=With this library you can use the Arduino OTTO CODEC output to play audio files.
The audio files must be in the raw .wav format. category=Signal Input/Output