This commit is contained in:
cnlohr 2018-05-08 00:07:35 -04:00
commit 0cf43af8b6
50 changed files with 8628 additions and 216 deletions

2
.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
colorchord2/windows/colorchord.def
colorchord2/colorchord.def

241
colorchord2/DisplayHIDAPI.c Normal file
View file

@ -0,0 +1,241 @@
//Copyright 2015 <>< Charles Lohr under the ColorChord License.
#include "outdrivers.h"
#include "notefinder.h"
#include <stdio.h>
#include <string.h>
#include "parameters.h"
#include <stdlib.h>
#include "hidapi.h"
#include "color.h"
#include <math.h>
struct HIDAPIOutDriver
{
hid_device *devh;
int did_init;
int zigzag;
int total_leds;
int array;
float outamp;
uint8_t * last_leds;
int buffersize;
volatile int readyFlag;
int xn;
int yn;
int rot90;
int is_rgby;
int bank_size[4];
int bank_id[4];
};
static void * LEDOutThread( void * v )
{
struct HIDAPIOutDriver * led = (struct HIDAPIOutDriver*)v;
while(1)
{
int total_bytes = led->buffersize;
total_bytes = ((total_bytes-2)&0xffc0) + 0x41; //Round up.
if( led->readyFlag )
{
/*
int i;
printf( "%d -- ", total_bytes );
for( i = 0; i < total_bytes; i++ )
{
if( !( i & 0x0f ) ) printf( "\n" );
printf( "%02x ", led->last_leds[i] );
}
printf( "\n" );
*/
int r = hid_send_feature_report( led->devh, led->last_leds, total_bytes );
if( r < 0 )
{
led->did_init = 0;
printf( "Fault sending LEDs.\n" );
}
led->readyFlag = 0;
}
OGUSleep(100);
}
return 0;
}
static void LEDUpdate(void * id, struct NoteFinder*nf)
{
int i;
struct HIDAPIOutDriver * led = (struct HIDAPIOutDriver*)id;
if( !led->did_init )
{
led->did_init = 1;
hid_init();
led->devh = hid_open( 0xabcd, 0xf104, 0 );
if( !led->devh )
{
fprintf( stderr, "Error: Cannot find device.\n" );
// exit( -98 );
}
}
int leds_this_round = 0;
int ledbid = 0;
while( led->readyFlag ) OGUSleep(100);
int lastledplace = 1;
led->last_leds[0] = 0;
int k = 0;
//Advance the LEDs to this position when outputting the values.
for( i = 0; i < led->total_leds; i++ )
{
int source = i;
if( !led->array )
{
int sx, sy;
if( led->rot90 )
{
sy = i % led->yn;
sx = i / led->yn;
}
else
{
sx = i % led->xn;
sy = i / led->xn;
}
if( led->zigzag )
{
if( led->rot90 )
{
if( sx & 1 )
{
sy = led->yn - sy - 1;
}
}
else
{
if( sy & 1 )
{
sx = led->xn - sx - 1;
}
}
}
if( led->rot90 )
{
source = sx + sy * led->xn;
}
else
{
source = sx + sy * led->yn;
}
}
if( led->is_rgby )
{
int r = OutLEDs[k++];
int g = OutLEDs[k++];
int b = OutLEDs[k++];
int y = 0;
int rg_common;
if( r/2 > g ) rg_common = g;
else rg_common = r/2;
if( rg_common > 255 ) rg_common = 255;
y = rg_common;
r -= rg_common;
g -= rg_common;
if( r < 0 ) r = 0;
if( g < 0 ) g = 0;
if( (lastledplace % 64) == 1 ) led->last_leds[lastledplace++] = led->bank_id[ledbid];
led->last_leds[lastledplace++] = g * led->outamp;
if( (lastledplace % 64) == 1 ) led->last_leds[lastledplace++] = led->bank_id[ledbid];
led->last_leds[lastledplace++] = r * led->outamp;
if( (lastledplace % 64) == 1 ) led->last_leds[lastledplace++] = led->bank_id[ledbid];
led->last_leds[lastledplace++] = b * led->outamp;
if( (lastledplace % 64) == 1 ) led->last_leds[lastledplace++] = led->bank_id[ledbid];
led->last_leds[lastledplace++] = y * led->outamp;
}
else
{
if( (lastledplace % 64) == 1 ) led->last_leds[lastledplace++] = led->bank_id[ledbid];
led->last_leds[lastledplace++] = OutLEDs[source*3+1] * led->outamp;
if( (lastledplace % 64) == 1 ) led->last_leds[lastledplace++] = led->bank_id[ledbid];
led->last_leds[lastledplace++] = OutLEDs[source*3+0] * led->outamp;
if( (lastledplace % 64) == 1 ) led->last_leds[lastledplace++] = led->bank_id[ledbid];
led->last_leds[lastledplace++] = OutLEDs[source*3+2] * led->outamp;
}
//printf( "%3d -- %3d [%3d] == %d %d %d\n", ledbid, source, lastledplace, OutLEDs[source*3+1], OutLEDs[source*3+0], OutLEDs[source*3+2] );
leds_this_round++;
while( leds_this_round >= led->bank_size[ledbid] )
{
while( (lastledplace % 64) != 1 ) led->last_leds[lastledplace++] = 0;
ledbid++;
if( ledbid > 3 ) break;
if( led->bank_size[ledbid] != 0 )
led->last_leds[lastledplace++] = led->bank_id[ledbid];
else
continue;
leds_this_round = 0;
}
if( ledbid > 3 ) break;
}
led->buffersize = lastledplace;
led->readyFlag = 1;
}
static void LEDParams(void * id )
{
struct HIDAPIOutDriver * led = (struct HIDAPIOutDriver*)id;
led->total_leds = GetParameterI( "leds", 300 );
led->last_leds = malloc( led->total_leds * 5 + 4 );
led->outamp = .1; RegisterValue( "ledoutamp", PAFLOAT, &led->outamp, sizeof( led->outamp ) );
led->zigzag = 0; RegisterValue( "zigzag", PAINT, &led->zigzag, sizeof( led->zigzag ) );
led->xn = 16; RegisterValue( "lightx", PAINT, &led->xn, sizeof( led->xn ) );
led->yn = 9; RegisterValue( "lighty", PAINT, &led->yn, sizeof( led->yn ) );
led->rot90 = 0; RegisterValue( "rot90", PAINT, &led->rot90, sizeof( led->rot90 ) );
led->array = 0; RegisterValue( "ledarray", PAINT, &led->array, sizeof( led->array ) );
led->is_rgby = 0; RegisterValue( "ledisrgby", PAINT, &led->is_rgby, sizeof( led->is_rgby ) );
led->bank_size[0] = 0; RegisterValue( "bank1_size", PAINT, &led->bank_size[0], sizeof( led->bank_size[0] ) );
led->bank_size[1] = 0; RegisterValue( "bank2_size", PAINT, &led->bank_size[1], sizeof( led->bank_size[1] ) );
led->bank_size[2] = 0; RegisterValue( "bank3_size", PAINT, &led->bank_size[2], sizeof( led->bank_size[2] ) );
led->bank_size[3] = 0; RegisterValue( "bank4_size", PAINT, &led->bank_size[3], sizeof( led->bank_size[3] ) );
led->bank_id[0] = 0; RegisterValue( "bank1_id", PAINT, &led->bank_id[0], sizeof( led->bank_id[0] ) );
led->bank_id[1] = 0; RegisterValue( "bank2_id", PAINT, &led->bank_id[1], sizeof( led->bank_id[1] ) );
led->bank_id[2] = 0; RegisterValue( "bank3_id", PAINT, &led->bank_id[2], sizeof( led->bank_id[2] ) );
led->bank_id[3] = 0; RegisterValue( "bank4_id", PAINT, &led->bank_id[3], sizeof( led->bank_id[3] ) );
led->did_init = 0;
}
static struct DriverInstances * DisplayHIDAPI()
{
struct DriverInstances * ret = malloc( sizeof( struct DriverInstances ) );
memset( ret, 0, sizeof( struct DriverInstances ) );
struct HIDAPIOutDriver * led = ret->id = malloc( sizeof( struct HIDAPIOutDriver ) );
ret->Func = LEDUpdate;
ret->Params = LEDParams;
OGCreateThread( LEDOutThread, led );
led->readyFlag = 0;
LEDParams( led );
return ret;
}
REGISTER_OUT_DRIVER(DisplayHIDAPI);

View file

@ -9,10 +9,12 @@
#include <string.h>
#include "color.h"
#include "DrawFunctions.h"
#include <unistd.h>
#ifdef WIN32
#if defined(WIN32) || defined(WINDOWS)
#include <windows.h>
#ifdef TCC
#include <winsock2.h>
#endif
#define MSG_NOSIGNAL 0
#else
#include <sys/socket.h>

121
colorchord2/DisplaySHM.c Normal file
View file

@ -0,0 +1,121 @@
//Copyright 2015 <>< Charles Lohr under the ColorChord License.
#include "outdrivers.h"
#include "notefinder.h"
#include <stdio.h>
#include "parameters.h"
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include "color.h"
#include "DrawFunctions.h"
#include <sys/mman.h>
#include <sys/stat.h> /* For mode constants */
#include <fcntl.h> /* For O_* constants */
#include <unistd.h>
extern struct NoteFinder * nf;
struct SHMDriver
{
int lights_file;
int dft_file;
int notes_file;
uint8_t * dft_ptr;
uint8_t * lights_ptr;
uint8_t * notes_ptr;
int total_dft;
int total_leds;
};
static void SHMUpdate(void * id, struct NoteFinder*nf)
{
struct SHMDriver * d = (struct SHMDriver*)id;
if( !d->lights_file )
{
const char * shmname = GetParameterS( "shm_lights", 0 );
if( shmname )
{
d->lights_file = shm_open(shmname, O_CREAT | O_RDWR, 0644);
ftruncate( d->lights_file, 16384 );
d->lights_ptr = mmap(0,16384, PROT_READ | PROT_WRITE, MAP_SHARED, d->lights_file, 0);
}
}
if( !d->dft_file )
{
const char * shmname = GetParameterS( "shm_dft", 0 );
if( shmname )
{
d->dft_file = shm_open(shmname, O_CREAT | O_RDWR, 0644);
ftruncate( d->dft_file, 16384 );
d->dft_ptr = mmap(0,16384, PROT_READ | PROT_WRITE, MAP_SHARED, d->dft_file, 0);
}
}
if( !d->notes_file )
{
const char * shmname = GetParameterS( "shm_notes", 0 );
if( shmname )
{
d->notes_file = shm_open(shmname, O_CREAT | O_RDWR, 0644);
ftruncate( d->notes_file, 16384 );
d->notes_ptr = mmap(0,16384, PROT_READ | PROT_WRITE, MAP_SHARED, d->notes_file, 0);
}
}
if( d->dft_ptr )
{
d->total_dft = nf->octaves * nf->freqbins;
memcpy( d->dft_ptr+0, &nf->octaves, 4 );
memcpy( d->dft_ptr+4, &nf->freqbins, 4 );
memcpy( d->dft_ptr+8, nf->folded_bins, nf->freqbins * sizeof(float) );
memcpy( d->dft_ptr+8+nf->freqbins * sizeof(float),
nf->outbins, d->total_dft * sizeof(float) );
}
if( d->lights_ptr )
{
memcpy( d->lights_ptr, &d->total_leds, 4 );
memcpy( d->lights_ptr + 4, OutLEDs, d->total_leds*3 );
}
if( d->notes_ptr )
{
memcpy( d->notes_ptr, &nf->dists_count, 4 );
memcpy( d->notes_ptr+4, nf->dists, sizeof( nf->dists[0] ) * nf->dists_count );
}
}
static void SHMParams(void * id )
{
struct SHMDriver * d = (struct SHMDriver*)id;
d->total_leds = 300; RegisterValue( "leds", PAINT, &d->total_leds, sizeof( d->total_leds ));
}
static struct DriverInstances * DisplaySHM(const char * parameters)
{
struct DriverInstances * ret = malloc( sizeof( struct DriverInstances ) );
struct SHMDriver * d = ret->id = malloc( sizeof( struct SHMDriver ) );
memset( d, 0, sizeof( struct SHMDriver ) );
ret->Func = SHMUpdate;
ret->Params = SHMParams;
SHMParams( d );
return ret;
}
REGISTER_OUT_DRIVER(DisplaySHM);

View file

@ -3,14 +3,15 @@ all : colorchord
RAWDRAW:=DrawFunctions.o XDriver.o
SOUND:=sound.o sound_alsa.o sound_pulse.o sound_null.o
OUTS := OutputVoronoi.o DisplayArray.o OutputLinear.o DisplayPie.o DisplayNetwork.o DisplayUSB2812.o DisplayDMX.o OutputProminent.o RecorderPlugin.o OutputCells.o
OUTS := OutputVoronoi.o DisplayArray.o OutputLinear.o DisplayPie.o DisplayNetwork.o DisplayUSB2812.o DisplayDMX.o OutputProminent.o RecorderPlugin.o DisplayHIDAPI.o hidapi.o OutputCells.o DisplaySHM.o
WINGCC:= i686-w64-mingw32-gcc
WINGCCFLAGS:= -s -DICACHE_FLASH_ATTR= -I../embeddedcommon -I. -O1 #-O2 -Wl,--relax -Wl,--gc-sections -ffunction-sections -fdata-sections
WINLDFLAGS:=-lwinmm -lgdi32 -lws2_32
WINGCCFLAGS:= -g -DICACHE_FLASH_ATTR= -I../embeddedcommon -I. -O1 #-O2 -Wl,--relax -Wl,--gc-sections -ffunction-sections -fdata-sections
WINLDFLAGS:=-lwinmm -lgdi32 -lws2_32 -lsetupapi
RAWDRAWLIBS:=-lX11 -lm -lpthread -lXinerama -lXext
LDLIBS:=-lpthread -lasound -lm -lpulse-simple -lpulse
LDLIBS:=-lpthread -lasound -lm -lpulse-simple -lpulse -ludev -lrt
CFLAGS:=-g -O0 -flto -Wall -ffast-math -I../embeddedcommon -I. -DICACHE_FLASH_ATTR=
@ -19,7 +20,8 @@ EXTRALIBS:=-lusb-1.0
colorchord : os_generic.o main.o dft.o decompose.o filter.o color.o notefinder.o util.o outdrivers.o $(RAWDRAW) $(SOUND) $(OUTS) parameters.o chash.o hook.o ../embeddedcommon/DFT32.o configs.o
gcc -o $@ $^ $(CFLAGS) $(LDLIBS) $(EXTRALIBS) $(RAWDRAWLIBS)
colorchord.exe : os_generic.c main.c dft.c decompose.c filter.c color.c notefinder.c util.c outdrivers.c DrawFunctions.c parameters.c chash.c WinDriver.c sound.c sound_null.c sound_win.c OutputVoronoi.c OutputProminent.c DisplayArray.c OutputLinear.c DisplayPie.c DisplayNetwork.c hook.c RecorderPlugin.c ../embeddedcommon/DFT32.c OutputCells.c configs.c
colorchord.exe : os_generic.c main.c dft.c decompose.c filter.c color.c notefinder.c util.c outdrivers.c DrawFunctions.c parameters.c chash.c WinDriver.c sound.c sound_null.c sound_win.c OutputVoronoi.c OutputProminent.c DisplayArray.c OutputLinear.c DisplayPie.c DisplayNetwork.c hook.c RecorderPlugin.c ../embeddedcommon/DFT32.c OutputCells.c configs.c hidapi.c DisplayHIDAPI.c
$(WINGCC) $(WINGCCFLAGS) -o $@ $^ $(WINLDFLAGS)

View file

@ -12,7 +12,6 @@
#include "color.h"
#include <stdlib.h>
#include <math.h>
#include <unistd.h>
extern float DeltaFrameTime;
extern double Now;

View file

@ -12,7 +12,6 @@
#include "color.h"
#include <stdlib.h>
#include <math.h>
#include <unistd.h>
struct LEDOutDriver
{

View file

@ -11,7 +11,6 @@
#include "color.h"
#include <stdlib.h>
#include <math.h>
#include <unistd.h>
struct ProminentDriver
{

View file

@ -18,7 +18,7 @@ play = 0
rec = 1
channels = 2
samplerate = 44100
wininput = 0
wininput = 1
#Compiled version will default this.
#sound_source = ALSA

View file

@ -420,7 +420,9 @@ uint16_t Sdatspace[FIXBINS*4]; //(advances,places,isses,icses)
static uint8_t Sdo_this_octave[BINCYCLE];
static int16_t Saccum_octavebins[OCTAVES];
static uint8_t Swhichoctaveplace;
#ifndef INCLUDING_EMBEDDED
uint16_t embeddedbins[FIXBINS]; //This is updated every time the DFT hits the octavecount, or 1/32 updates.
#endif
//From: http://stackoverflow.com/questions/1100090/looking-for-an-efficient-integer-square-root-algorithm-for-arm-thumb2
/**

2918
colorchord2/hidapi.c Normal file

File diff suppressed because it is too large Load diff

30
colorchord2/hidapi.conf Normal file
View file

@ -0,0 +1,30 @@
#What display output driver should be used?
outdrivers = DisplayPie, OutputLinear, DisplayHIDAPI
leds = 107
light_siding = 2.2
satamp = 6.000
is_loop=1
led_floor = .1
note_attach_amp_iir2 = .0500
note_attach_amp_iir2 = .1500
note_attach_freq_iir = 0.3000
steady_bright = 0
pie_min=.15
pie_max=.25
lightx=300
lighty=1
ledoutamp = 1
sourcename = alsa_output.pci-0000_01_00.1.hdmi-stereo.monitor
bank1_size = 40
bank1_id = 8
bank2_size = 27
bank2_id = 2
bank3_size = 40
bank3_id = 4
bank4_size = 0
bank4_id = 0
ledisrgby = 1

405
colorchord2/hidapi.h Normal file
View file

@ -0,0 +1,405 @@
/*******************************************************
HIDAPI - Multi-Platform library for
communication with HID devices.
Alan Ott
Signal 11 Software
8/22/2009
Copyright 2009, All Rights Reserved.
At the discretion of the user of this library,
this software may be licensed under the terms of the
GNU General Public License v3, a BSD-Style license, or the
original HIDAPI license as outlined in the LICENSE.txt,
LICENSE-gpl3.txt, LICENSE-bsd.txt, and LICENSE-orig.txt
files located at the root of the source distribution.
These files may also be found in the public source
code repository located at:
http://github.com/signal11/hidapi .
********************************************************/
/* Copy of LICENSE-orig.txt (compatible with MIT/x11 license)
HIDAPI - Multi-Platform library for
communication with HID devices.
Copyright 2009, Alan Ott, Signal 11 Software.
All Rights Reserved.
This software may be used by anyone for any reason so
long as the copyright notice in the source files
remains intact.
*/
/** @file
* @defgroup API hidapi API
*/
#ifndef HIDAPI_H__
#define HIDAPI_H__
#include <wchar.h>
#ifdef _WIN32
#define HID_API_EXPORT __declspec(dllexport)
#define HID_API_CALL
#else
#define HID_API_EXPORT /**< API export macro */
#define HID_API_CALL /**< API call macro */
#endif
#define HID_API_EXPORT_CALL HID_API_EXPORT HID_API_CALL /**< API export and call macro*/
#ifdef __cplusplus
extern "C" {
#endif
struct hid_device_;
typedef struct hid_device_ hid_device; /**< opaque hidapi structure */
/** hidapi info structure */
struct hid_device_info {
/** Platform-specific device path */
char *path;
/** Device Vendor ID */
unsigned short vendor_id;
/** Device Product ID */
unsigned short product_id;
/** Serial Number */
wchar_t *serial_number;
/** Device Release Number in binary-coded decimal,
also known as Device Version Number */
unsigned short release_number;
/** Manufacturer String */
wchar_t *manufacturer_string;
/** Product string */
wchar_t *product_string;
/** Usage Page for this Device/Interface
(Windows/Mac only). */
unsigned short usage_page;
/** Usage for this Device/Interface
(Windows/Mac only).*/
unsigned short usage;
/** The USB interface which this logical device
represents. Valid on both Linux implementations
in all cases, and valid on the Windows implementation
only if the device contains more than one interface. */
int interface_number;
/** Pointer to the next device */
struct hid_device_info *next;
};
/** @brief Initialize the HIDAPI library.
This function initializes the HIDAPI library. Calling it is not
strictly necessary, as it will be called automatically by
hid_enumerate() and any of the hid_open_*() functions if it is
needed. This function should be called at the beginning of
execution however, if there is a chance of HIDAPI handles
being opened by different threads simultaneously.
@ingroup API
@returns
This function returns 0 on success and -1 on error.
*/
int HID_API_EXPORT HID_API_CALL hid_init(void);
/** @brief Finalize the HIDAPI library.
This function frees all of the static data associated with
HIDAPI. It should be called at the end of execution to avoid
memory leaks.
@ingroup API
@returns
This function returns 0 on success and -1 on error.
*/
int HID_API_EXPORT HID_API_CALL hid_exit(void);
/** @brief Enumerate the HID Devices.
This function returns a linked list of all the HID devices
attached to the system which match vendor_id and product_id.
If @p vendor_id is set to 0 then any vendor matches.
If @p product_id is set to 0 then any product matches.
If @p vendor_id and @p product_id are both set to 0, then
all HID devices will be returned.
@ingroup API
@param vendor_id The Vendor ID (VID) of the types of device
to open.
@param product_id The Product ID (PID) of the types of
device to open.
@returns
This function returns a pointer to a linked list of type
struct #hid_device, containing information about the HID devices
attached to the system, or NULL in the case of failure. Free
this linked list by calling hid_free_enumeration().
*/
struct hid_device_info HID_API_EXPORT * HID_API_CALL hid_enumerate(unsigned short vendor_id, unsigned short product_id);
/** @brief Free an enumeration Linked List
This function frees a linked list created by hid_enumerate().
@ingroup API
@param devs Pointer to a list of struct_device returned from
hid_enumerate().
*/
void HID_API_EXPORT HID_API_CALL hid_free_enumeration(struct hid_device_info *devs);
/** @brief Open a HID device using a Vendor ID (VID), Product ID
(PID) and optionally a serial number.
If @p serial_number is NULL, the first device with the
specified VID and PID is opened.
@ingroup API
@param vendor_id The Vendor ID (VID) of the device to open.
@param product_id The Product ID (PID) of the device to open.
@param serial_number The Serial Number of the device to open
(Optionally NULL).
@returns
This function returns a pointer to a #hid_device object on
success or NULL on failure.
*/
HID_API_EXPORT hid_device * HID_API_CALL hid_open(unsigned short vendor_id, unsigned short product_id, const wchar_t *serial_number);
/** @brief Open a HID device by its path name.
The path name be determined by calling hid_enumerate(), or a
platform-specific path name can be used (eg: /dev/hidraw0 on
Linux).
@ingroup API
@param path The path name of the device to open
@returns
This function returns a pointer to a #hid_device object on
success or NULL on failure.
*/
HID_API_EXPORT hid_device * HID_API_CALL hid_open_path(const char *path);
/** @brief Write an Output report to a HID device.
The first byte of @p data[] must contain the Report ID. For
devices which only support a single report, this must be set
to 0x0. The remaining bytes contain the report data. Since
the Report ID is mandatory, calls to hid_write() will always
contain one more byte than the report contains. For example,
if a hid report is 16 bytes long, 17 bytes must be passed to
hid_write(), the Report ID (or 0x0, for devices with a
single report), followed by the report data (16 bytes). In
this example, the length passed in would be 17.
hid_write() will send the data on the first OUT endpoint, if
one exists. If it does not, it will send the data through
the Control Endpoint (Endpoint 0).
@ingroup API
@param device A device handle returned from hid_open().
@param data The data to send, including the report number as
the first byte.
@param length The length in bytes of the data to send.
@returns
This function returns the actual number of bytes written and
-1 on error.
*/
int HID_API_EXPORT HID_API_CALL hid_write(hid_device *device, const unsigned char *data, size_t length);
/** @brief Read an Input report from a HID device with timeout.
Input reports are returned
to the host through the INTERRUPT IN endpoint. The first byte will
contain the Report number if the device uses numbered reports.
@ingroup API
@param device A device handle returned from hid_open().
@param data A buffer to put the read data into.
@param length The number of bytes to read. For devices with
multiple reports, make sure to read an extra byte for
the report number.
@param milliseconds timeout in milliseconds or -1 for blocking wait.
@returns
This function returns the actual number of bytes read and
-1 on error. If no packet was available to be read within
the timeout period, this function returns 0.
*/
int HID_API_EXPORT HID_API_CALL hid_read_timeout(hid_device *dev, unsigned char *data, size_t length, int milliseconds);
/** @brief Read an Input report from a HID device.
Input reports are returned
to the host through the INTERRUPT IN endpoint. The first byte will
contain the Report number if the device uses numbered reports.
@ingroup API
@param device A device handle returned from hid_open().
@param data A buffer to put the read data into.
@param length The number of bytes to read. For devices with
multiple reports, make sure to read an extra byte for
the report number.
@returns
This function returns the actual number of bytes read and
-1 on error. If no packet was available to be read and
the handle is in non-blocking mode, this function returns 0.
*/
int HID_API_EXPORT HID_API_CALL hid_read(hid_device *device, unsigned char *data, size_t length);
/** @brief Set the device handle to be non-blocking.
In non-blocking mode calls to hid_read() will return
immediately with a value of 0 if there is no data to be
read. In blocking mode, hid_read() will wait (block) until
there is data to read before returning.
Nonblocking can be turned on and off at any time.
@ingroup API
@param device A device handle returned from hid_open().
@param nonblock enable or not the nonblocking reads
- 1 to enable nonblocking
- 0 to disable nonblocking.
@returns
This function returns 0 on success and -1 on error.
*/
int HID_API_EXPORT HID_API_CALL hid_set_nonblocking(hid_device *device, int nonblock);
/** @brief Send a Feature report to the device.
Feature reports are sent over the Control endpoint as a
Set_Report transfer. The first byte of @p data[] must
contain the Report ID. For devices which only support a
single report, this must be set to 0x0. The remaining bytes
contain the report data. Since the Report ID is mandatory,
calls to hid_send_feature_report() will always contain one
more byte than the report contains. For example, if a hid
report is 16 bytes long, 17 bytes must be passed to
hid_send_feature_report(): the Report ID (or 0x0, for
devices which do not use numbered reports), followed by the
report data (16 bytes). In this example, the length passed
in would be 17.
@ingroup API
@param device A device handle returned from hid_open().
@param data The data to send, including the report number as
the first byte.
@param length The length in bytes of the data to send, including
the report number.
@returns
This function returns the actual number of bytes written and
-1 on error.
*/
int HID_API_EXPORT HID_API_CALL hid_send_feature_report(hid_device *device, const unsigned char *data, size_t length);
/** @brief Get a feature report from a HID device.
Set the first byte of @p data[] to the Report ID of the
report to be read. Make sure to allow space for this
extra byte in @p data[]. Upon return, the first byte will
still contain the Report ID, and the report data will
start in data[1].
@ingroup API
@param device A device handle returned from hid_open().
@param data A buffer to put the read data into, including
the Report ID. Set the first byte of @p data[] to the
Report ID of the report to be read, or set it to zero
if your device does not use numbered reports.
@param length The number of bytes to read, including an
extra byte for the report ID. The buffer can be longer
than the actual report.
@returns
This function returns the number of bytes read plus
one for the report ID (which is still in the first
byte), or -1 on error.
*/
int HID_API_EXPORT HID_API_CALL hid_get_feature_report(hid_device *device, unsigned char *data, size_t length);
/** @brief Close a HID device.
@ingroup API
@param device A device handle returned from hid_open().
*/
void HID_API_EXPORT HID_API_CALL hid_close(hid_device *device);
/** @brief Get The Manufacturer String from a HID device.
@ingroup API
@param device A device handle returned from hid_open().
@param string A wide string buffer to put the data into.
@param maxlen The length of the buffer in multiples of wchar_t.
@returns
This function returns 0 on success and -1 on error.
*/
int HID_API_EXPORT_CALL hid_get_manufacturer_string(hid_device *device, wchar_t *string, size_t maxlen);
/** @brief Get The Product String from a HID device.
@ingroup API
@param device A device handle returned from hid_open().
@param string A wide string buffer to put the data into.
@param maxlen The length of the buffer in multiples of wchar_t.
@returns
This function returns 0 on success and -1 on error.
*/
int HID_API_EXPORT_CALL hid_get_product_string(hid_device *device, wchar_t *string, size_t maxlen);
/** @brief Get The Serial Number String from a HID device.
@ingroup API
@param device A device handle returned from hid_open().
@param string A wide string buffer to put the data into.
@param maxlen The length of the buffer in multiples of wchar_t.
@returns
This function returns 0 on success and -1 on error.
*/
int HID_API_EXPORT_CALL hid_get_serial_number_string(hid_device *device, wchar_t *string, size_t maxlen);
/** @brief Get a string from a HID device, based on its string index.
@ingroup API
@param device A device handle returned from hid_open().
@param string_index The index of the string to get.
@param string A wide string buffer to put the data into.
@param maxlen The length of the buffer in multiples of wchar_t.
@returns
This function returns 0 on success and -1 on error.
*/
int HID_API_EXPORT_CALL hid_get_indexed_string(hid_device *device, int string_index, wchar_t *string, size_t maxlen);
/** @brief Get a string describing the last error which occurred.
@ingroup API
@param device A device handle returned from hid_open().
@returns
This function returns a string containing the last error
which occurred or NULL if none has occurred.
*/
HID_API_EXPORT const wchar_t* HID_API_CALL hid_error(hid_device *device);
#ifdef __cplusplus
}
#endif
#endif

View file

@ -20,7 +20,8 @@
struct SoundDriver * sd;
#ifdef WIN32
#if defined(WIN32) || defined(USE_WINDOWS)
#include <winsock2.h>
#include <windows.h>
#define ESCAPE_KEY 0x1B
@ -41,8 +42,8 @@ double Now = 0;
int lastfps;
short screenx, screeny;
struct DriverInstances * outdriver[MAX_OUT_DRIVERS];
struct DriverInstances * outdriver[MAX_OUT_DRIVERS];
int headless = 0; REGISTER_PARAM( headless, PAINT );
int set_screenx = 640; REGISTER_PARAM( set_screenx, PAINT );
@ -160,18 +161,19 @@ void SoundCB( float * out, float * in, int samplesr, int * samplesp, struct Soun
*samplesp = samplesr;
}
int main(int argc, char ** argv)
{
int i;
#ifdef TCC
ManuallyRegisterDevices();
#endif
printf( "Output Drivers:\n" );
for( i = 0; i < MAX_OUT_DRIVERS; i++ )
{
if( ODList[i].Name ) printf( "\t%s\n", ODList[i].Name );
}
#ifdef WIN32
#if defined(WIN32) || defined(USE_WINDOWS)
WSADATA wsaData;
WSAStartup(0x202, &wsaData);

View file

@ -12,7 +12,8 @@ steady_bright = 0
#dft_q = 20.0000
#dft_speedup = 1000.0000
sourcename = alsa_output.pci-0000_01_00.1.hdmi-stereo-extra1.monitor
sourcename = alsa_output.pci-0000_01_00.1.hdmi-stereo.monitor
# alsa_output.pci-0000_01_00.1.hdmi-stereo-extra1.monitor
#alsa_output.pci-0000_00_1f.3.analog-stereo.monitor
skipfirst = 1
firstval = 0

View file

@ -2,7 +2,6 @@
#include "os_generic.h"
#ifdef USE_WINDOWS
#include <windows.h>
@ -49,15 +48,16 @@ double OGGetFileTime( const char * file )
}
og_thread_t OGCreateThread( void * (function)( void * ), void * parameter )
og_thread_t OGCreateThread( void * (routine)( void * ), void * parameter )
{
return (og_thread_t)CreateThread( 0, 0, (LPTHREAD_START_ROUTINE)function, parameter, 0, 0 );
return (og_thread_t)CreateThread( 0, 0, (LPTHREAD_START_ROUTINE)routine, parameter, 0, 0 );
}
void * OGJoinThread( og_thread_t ot )
{
WaitForSingleObject( ot, INFINITE );
CloseHandle( ot );
return 0;
}
void OGCancelThread( og_thread_t ot )
@ -93,28 +93,23 @@ og_sema_t OGCreateSema()
return (og_sema_t)sem;
}
typedef LONG NTSTATUS;
typedef NTSTATUS (NTAPI *_NtQuerySemaphore)(
HANDLE SemaphoreHandle,
DWORD SemaphoreInformationClass, /* Would be SEMAPHORE_INFORMATION_CLASS */
PVOID SemaphoreInformation, /* but this is to much to dump here */
ULONG SemaphoreInformationLength,
PULONG ReturnLength OPTIONAL
);
typedef struct _SEMAPHORE_BASIC_INFORMATION {
ULONG CurrentCount;
ULONG MaximumCount;
} SEMAPHORE_BASIC_INFORMATION;
int OGGetSema( og_sema_t os )
{
typedef LONG NTSTATUS;
HANDLE sem = (HANDLE)os;
typedef NTSTATUS (NTAPI *_NtQuerySemaphore)(
HANDLE SemaphoreHandle,
DWORD SemaphoreInformationClass, /* Would be SEMAPHORE_INFORMATION_CLASS */
PVOID SemaphoreInformation, /* but this is to much to dump here */
ULONG SemaphoreInformationLength,
PULONG ReturnLength OPTIONAL
);
typedef struct _SEMAPHORE_BASIC_INFORMATION {
ULONG CurrentCount;
ULONG MaximumCount;
} SEMAPHORE_BASIC_INFORMATION;
static _NtQuerySemaphore NtQuerySemaphore;
SEMAPHORE_BASIC_INFORMATION BasicInfo;
@ -158,9 +153,8 @@ void OGDeleteSema( og_sema_t os )
#else
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
#include <sys/stat.h>
#include <stdlib.h>

View file

@ -1,9 +1,8 @@
//Copyright 2015 <>< Charles Lohr under the NewBSD or MIT/x11 License.
#ifndef _OS_GENERIC_H
#define _OS_GENERIC_H
#ifdef WIN32
#if defined( WIN32 ) || defined (WINDOWS) || defined( _WIN32)
#define USE_WINDOWS
#endif
@ -12,12 +11,7 @@
extern "C" {
#endif
#define EXECUTE_AT_BOOT( x, y ) \
\
void fn##x() __attribute__((constructor)); \
void fn##x() \
{ y; } \
//Things that shouldn't be macro'd
double OGGetAbsoluteTime();
void OGSleep( int is );
@ -55,7 +49,7 @@ void OGDeleteSema( og_sema_t os );
#endif
//Date Stamp: 2014-06-12
//Date Stamp: 2012-02-15
/*
NOTE: Portions (namely the top section) are part of headers from other

View file

@ -41,6 +41,6 @@ struct DriverInstances * SetupOutDriver( );
void RegOutDriver( const char * ron, struct DriverInstances * (*Init)( ) );
#define REGISTER_OUT_DRIVER( name ) \
EXECUTE_AT_BOOT( r##name, RegOutDriver( #name, name ) );
void __attribute__((constructor)) REGISTER##name() { RegOutDriver( #name, name ); }
#endif

View file

@ -58,8 +58,7 @@ void SetParametersFromString( const char * string );
void AddCallback( const char * name, ParamCallbackT t, void * v );
#define REGISTER_PARAM( parameter_name, type ) \
void Register##parameter_name() __attribute__((constructor)); \
void Register##parameter_name() { RegisterValue( #parameter_name, type, &parameter_name, sizeof( parameter_name ) ); }
void __attribute__((constructor)) REGISTER##parameter_name() { RegisterValue( #parameter_name, type, &parameter_name, sizeof( parameter_name ) ); }
#endif

50
colorchord2/shmtest.conf Normal file
View file

@ -0,0 +1,50 @@
cpu_autolimit = 1
#General GUI properties.
title = PA Test
set_screenx = 720
set_screeny = 480
sample_channel = -1
sourcename = alsa_output.pci-0000_01_00.1.hdmi-stereo-extra2.monitor
#alsa_output.pci-0000_00_1f.3.analog-stereo.monitor
#default
# alsa_output.pci-0000_00_1b.0.analog-stereo.monitor
#alsa_output.pci-0000_00_1f.3.analog-stereo.monitor << New laptop
#use pactl list | grep pci- | grep monitor
#How many bins a note can jump from frame to frame to be considered a slide.
#this is used to prevent notes from popping in and out a lot.
note_combine_distance = 0.5000
note_jumpability = 1.8000
note_minimum_new_distribution_value = 0.0200
note_out_chop = 0.05000
#compress_coefficient = 4.0
#compress_exponent = .5
#=======================================================================
#Outputs
#DisplayArray
outdrivers = OutputCells, DisplaySHM
shm_lights = /cclights
shm_dft = /ccdft
shm_notes = /ccnotes
lightx = 20
lighty = 4
fromsides = 1
leds = 120
qtyamp = 120
satamp = 2.800
amppow = 2.510
distpow = 1.500

View file

@ -55,7 +55,6 @@ struct SoundDriver * InitSound( const char * driver_name, SoundCBType cb )
{
int i;
struct SoundDriver * ret = 0;
if( driver_name == 0 || strlen( driver_name ) == 0 )
{
//Search for a driver.
@ -74,6 +73,7 @@ struct SoundDriver * InitSound( const char * driver_name, SoundCBType cb )
}
else
{
printf( "Initializing sound. Recommended driver: %s\n", driver_name );
for( i = 0; i < MAX_SOUND_DRIVERS; i++ )
{
if( SoundDrivers[i] == 0 )

View file

@ -34,5 +34,8 @@ void CloseSound( struct SoundDriver * soundobject );
//Called by various sound drivers. Notice priority must be greater than 0. Priority of 0 or less will not register.
void RegSound( int priority, const char * name, SoundInitFn * fn );
#define REGISTER_SOUND( sounddriver, priority, name, function ) \
void __attribute__((constructor)) REGISTER##sounddriver() { RegSound( priority, name, function ); }
#endif

View file

@ -337,5 +337,5 @@ void * InitSoundAlsa( SoundCBType cb )
return InitASound(r);
}
EXECUTE_AT_BOOT( AlsaSoundReg, RegSound( 10, "ALSA", InitSoundAlsa ) );
REGISTER_SOUND( AlsaSound, 10, "ALSA", InitSoundAlsa );

View file

@ -41,6 +41,5 @@ void * InitSoundNull( SoundCBType cb )
}
EXECUTE_AT_BOOT( NullSoundReg, RegSound( 1, "NULL", InitSoundNull ) );
REGISTER_SOUND( NullSound, 1, "NULL", InitSoundNull );

View file

@ -374,6 +374,6 @@ fail:
EXECUTE_AT_BOOT( PulseSoundReg, RegSound( 11, "PULSE", InitSoundPulse ) );
REGISTER_SOUND( PulseSound, 11, "PULSE", InitSoundPulse );

View file

@ -4,9 +4,9 @@
#include "parameters.h"
#include "sound.h"
#include "os_generic.h"
#include <mmsystem.h>
#include <stdio.h>
#include <stdint.h>
#include <mmsystem.h>
#if defined(WIN32)
#pragma comment(lib,"winmm.lib")
@ -106,7 +106,8 @@ static struct SoundDriverWin * InitWinSound( struct SoundDriverWin * r )
{
int i;
WAVEFORMATEX wfmt;
memset( &wfmt, 0, sizeof(wfmt) );
printf ("WFMT Size (debugging temp for TCC): %d\n", sizeof(wfmt) );
if( GetParameterI( "play", 0 ) )
{
fprintf( stderr, "Error: This Windows Sound Driver does not support playback.\n" );
@ -136,7 +137,7 @@ static struct SoundDriverWin * InitWinSound( struct SoundDriverWin * r )
int p = waveInOpen(&r->hMyWave, dwdevice, &wfmt,(DWORD)(void*)(&HANDLEMIC) , 0, CALLBACK_FUNCTION);
printf( "WIO: %d\n", p ); //On real windows, returns 11
printf( "WIO: %d\n", p );
for ( i=0;i<BUFFS;i++)
{
@ -150,7 +151,7 @@ static struct SoundDriverWin * InitWinSound( struct SoundDriverWin * r )
p = waveInStart(r->hMyWave);
printf( "WIS: %d\n", p ); //On real windows returns 5.
printf( "WIS: %d\n", p );
return r;
}
@ -159,7 +160,7 @@ static struct SoundDriverWin * InitWinSound( struct SoundDriverWin * r )
void * InitSoundWin( SoundCBType cb )
{
struct SoundDriverWin * r = malloc( sizeof( struct SoundDriverWin ) );
struct SoundDriverWin * r = (struct SoundDriverWin *)malloc( sizeof( struct SoundDriverWin ) );
r->CloseFn = CloseSoundWin;
r->SoundStateFn = SoundStateWin;
@ -177,5 +178,5 @@ void * InitSoundWin( SoundCBType cb )
return InitWinSound(r);
}
EXECUTE_AT_BOOT( WinSoundReg, RegSound( 10, "WIN", InitSoundWin ) );
REGISTER_SOUND( SoundWin, 10, "WIN", InitSoundWin );

View file

@ -2,8 +2,8 @@
//This file may be used in whole or part in any way for any purpose by anyone
//without restriction.
#include "util.h"
#include <math.h>
#include "util.h"
#include <stdlib.h>
//Take the absolute distance between two points on a torus.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -0,0 +1,8 @@
@echo off
echo Unzip https://download.savannah.gnu.org/releases/tinycc/tcc-0.9.26-win64-bin.zip to C:\tcc
set CFLAGS=-v -DHIDAPI -DWINDOWS -DWIN32 -DTCC -DRUNTIME_SYMNUM -Os -Itccinc -DINCLUDING_EMBEDDED -I.. -I. -I../../embeddedcommon -rdynamic -g
set LDFLAGS=-lkernel32 -lgdi32 -luser32 -lsetupapi -ldbghelp -ltcc1 -lwinmm -lws2_32
set SOURCES=..\chash.c ..\color.c ..\configs.c ..\decompose.c ..\dft.c ..\DisplayNetwork.c ..\DisplayArray.c ..\DisplayHIDAPI.c ..\DisplayOUTDriver.c ..\DisplayPie.c ..\DrawFunctions.c ..\filter.c ..\hidapi.c ..\hook.c ..\main.c ..\os_generic.c ..\outdrivers.c ..\OutputCells.c ..\OutputLinear.c ..\OutputProminent.c ..\OutputVoronoi.c ..\parameters.c ..\sound.c ..\sound_win.c ..\sound_null.c ..\util.c ..\WinDriver.c ..\notefinder.c ..\..\embeddedcommon\DFT32.c tcc_stubs.c symbol_enumerator.c
set ARCH_SPECIFIC=-L32
@echo on
C:\tcc\tcc %CFLAGS% %ARCH_SPECIFIC% %SOURCES% %LDFLAGS% -o ..\colorchord.exe

926
colorchord2/windows/math.h Normal file
View file

@ -0,0 +1,926 @@
/**
* This file has no copyright assigned and is placed in the Public Domain.
* This file is part of the w64 mingw-runtime package.
* No warranty is given; refer to the file DISCLAIMER within this package.
*/
#ifndef _MATH_H_
#define _MATH_H_
#if __GNUC__ >= 3
#pragma GCC system_header
#endif
#include <_mingw.h>
struct exception;
#pragma pack(push,_CRT_PACKING)
#define _DOMAIN 1
#define _SING 2
#define _OVERFLOW 3
#define _UNDERFLOW 4
#define _TLOSS 5
#define _PLOSS 6
#ifndef __STRICT_ANSI__
#ifndef NO_OLDNAMES
#define DOMAIN _DOMAIN
#define SING _SING
#define OVERFLOW _OVERFLOW
#define UNDERFLOW _UNDERFLOW
#define TLOSS _TLOSS
#define PLOSS _PLOSS
#endif
#endif
#ifndef __STRICT_ANSI__
#define M_E 2.71828182845904523536
#define M_LOG2E 1.44269504088896340736
#define M_LOG10E 0.434294481903251827651
#define M_LN2 0.693147180559945309417
#define M_LN10 2.30258509299404568402
#define M_PI 3.14159265358979323846
#define M_PI_2 1.57079632679489661923
#define M_PI_4 0.785398163397448309616
#define M_1_PI 0.318309886183790671538
#define M_2_PI 0.636619772367581343076
#define M_2_SQRTPI 1.12837916709551257390
#define M_SQRT2 1.41421356237309504880
#define M_SQRT1_2 0.707106781186547524401
#endif
#ifndef __STRICT_ANSI__
/* See also float.h */
#ifndef __MINGW_FPCLASS_DEFINED
#define __MINGW_FPCLASS_DEFINED 1
#define _FPCLASS_SNAN 0x0001 /* Signaling "Not a Number" */
#define _FPCLASS_QNAN 0x0002 /* Quiet "Not a Number" */
#define _FPCLASS_NINF 0x0004 /* Negative Infinity */
#define _FPCLASS_NN 0x0008 /* Negative Normal */
#define _FPCLASS_ND 0x0010 /* Negative Denormal */
#define _FPCLASS_NZ 0x0020 /* Negative Zero */
#define _FPCLASS_PZ 0x0040 /* Positive Zero */
#define _FPCLASS_PD 0x0080 /* Positive Denormal */
#define _FPCLASS_PN 0x0100 /* Positive Normal */
#define _FPCLASS_PINF 0x0200 /* Positive Infinity */
#endif
#endif
#ifdef __cplusplus
extern "C" {
#endif
#ifndef _EXCEPTION_DEFINED
#define _EXCEPTION_DEFINED
struct _exception {
int type;
char *name;
double arg1;
double arg2;
double retval;
};
#endif
#ifndef _COMPLEX_DEFINED
#define _COMPLEX_DEFINED
struct _complex {
double x,y;
};
#endif
#define EDOM 33
#define ERANGE 34
#ifndef _HUGE
#ifdef _MSVCRT_
extern double *_HUGE;
#else
extern double *_imp___HUGE;
#define _HUGE (*_imp___HUGE)
#endif
#endif
#define HUGE_VAL _HUGE
#ifndef _CRT_ABS_DEFINED
#define _CRT_ABS_DEFINED
int __cdecl abs(int _X);
long __cdecl labs(long _X);
#endif
double __cdecl acos(double _X);
double __cdecl asin(double _X);
double __cdecl atan(double _X);
double __cdecl atan2(double _Y,double _X);
#ifndef _SIGN_DEFINED
#define _SIGN_DEFINED
_CRTIMP double __cdecl _copysign (double _Number,double _Sign);
_CRTIMP double __cdecl _chgsign (double _X);
#endif
double __cdecl cos(double _X);
double __cdecl cosh(double _X);
double __cdecl exp(double _X);
double __cdecl expm1(double _X);
double __cdecl fabs(double _X);
double __cdecl fmod(double _X,double _Y);
double __cdecl log(double _X);
double __cdecl log10(double _X);
double __cdecl pow(double _X,double _Y);
double __cdecl sin(double _X);
double __cdecl sinh(double _X);
double __cdecl tan(double _X);
double __cdecl tanh(double _X);
double __cdecl sqrt(double _X);
#ifndef _CRT_ATOF_DEFINED
#define _CRT_ATOF_DEFINED
double __cdecl atof(const char *_String);
double __cdecl _atof_l(const char *_String,_locale_t _Locale);
#endif
_CRTIMP double __cdecl _cabs(struct _complex _ComplexA);
double __cdecl ceil(double _X);
double __cdecl floor(double _X);
double __cdecl frexp(double _X,int *_Y);
double __cdecl _hypot(double _X,double _Y);
_CRTIMP double __cdecl _j0(double _X);
_CRTIMP double __cdecl _j1(double _X);
_CRTIMP double __cdecl _jn(int _X,double _Y);
double __cdecl ldexp(double _X,int _Y);
#ifndef _CRT_MATHERR_DEFINED
#define _CRT_MATHERR_DEFINED
int __cdecl _matherr(struct _exception *_Except);
#endif
double __cdecl modf(double _X,double *_Y);
_CRTIMP double __cdecl _y0(double _X);
_CRTIMP double __cdecl _y1(double _X);
_CRTIMP double __cdecl _yn(int _X,double _Y);
#if(defined(_X86_) && !defined(__x86_64))
_CRTIMP int __cdecl _set_SSE2_enable(int _Flag);
/* from libmingwex */
float __cdecl _hypotf(float _X,float _Y);
#endif
float frexpf(float _X,int *_Y);
float __cdecl ldexpf(float _X,int _Y);
long double __cdecl ldexpl(long double _X,int _Y);
float __cdecl acosf(float _X);
float __cdecl asinf(float _X);
float __cdecl atanf(float _X);
float __cdecl atan2f(float _X,float _Y);
float __cdecl cosf(float _X);
float __cdecl sinf(float _X);
float __cdecl tanf(float _X);
float __cdecl coshf(float _X);
float __cdecl sinhf(float _X);
float __cdecl tanhf(float _X);
float __cdecl expf(float _X);
float __cdecl expm1f(float _X);
float __cdecl logf(float _X);
float __cdecl log10f(float _X);
float __cdecl modff(float _X,float *_Y);
float __cdecl powf(float _X,float _Y);
float __cdecl sqrtf(float _X);
float __cdecl ceilf(float _X);
float __cdecl floorf(float _X);
float __cdecl fmodf(float _X,float _Y);
float __cdecl _hypotf(float _X,float _Y);
float __cdecl fabsf(float _X);
#if !defined(__ia64__)
/* from libmingwex */
float __cdecl _copysignf (float _Number,float _Sign);
float __cdecl _chgsignf (float _X);
float __cdecl _logbf(float _X);
float __cdecl _nextafterf(float _X,float _Y);
int __cdecl _finitef(float _X);
int __cdecl _isnanf(float _X);
int __cdecl _fpclassf(float _X);
#endif
#ifndef __cplusplus
__CRT_INLINE long double __cdecl fabsl (long double x)
{
long double res;
__asm__ ("fabs;" : "=t" (res) : "0" (x));
return res;
}
#define _hypotl(x,y) ((long double)_hypot((double)(x),(double)(y)))
#define _matherrl _matherr
__CRT_INLINE long double _chgsignl(long double _Number) { return _chgsign((double)(_Number)); }
__CRT_INLINE long double _copysignl(long double _Number,long double _Sign) { return _copysign((double)(_Number),(double)(_Sign)); }
__CRT_INLINE float frexpf(float _X,int *_Y) { return ((float)frexp((double)_X,_Y)); }
#if !defined (__ia64__)
__CRT_INLINE float __cdecl fabsf (float x)
{
return fabs(x);
}
__CRT_INLINE float __cdecl ldexpf (float x, int expn) { return (float) ldexp (x, expn); }
#endif
#else
// cplusplus
__CRT_INLINE long double __cdecl fabsl (long double x)
{
long double res;
__asm__ ("fabs;" : "=t" (res) : "0" (x));
return res;
}
__CRT_INLINE long double modfl(long double _X,long double *_Y) {
double _Di,_Df = modf((double)_X,&_Di);
*_Y = (long double)_Di;
return (_Df);
}
__CRT_INLINE long double _chgsignl(long double _Number) { return _chgsign(static_cast<double>(_Number)); }
__CRT_INLINE long double _copysignl(long double _Number,long double _Sign) { return _copysign(static_cast<double>(_Number),static_cast<double>(_Sign)); }
__CRT_INLINE float frexpf(float _X,int *_Y) { return ((float)frexp((double)_X,_Y)); }
#ifndef __ia64__
__CRT_INLINE float __cdecl fabsf (float x)
{
float res;
__asm__ ("fabs;" : "=t" (res) : "0" (x));
return res;
}
__CRT_INLINE float __cdecl ldexpf (float x, int expn) { return (float) ldexp (x, expn); }
#ifndef __x86_64
__CRT_INLINE float acosf(float _X) { return ((float)acos((double)_X)); }
__CRT_INLINE float asinf(float _X) { return ((float)asin((double)_X)); }
__CRT_INLINE float atanf(float _X) { return ((float)atan((double)_X)); }
__CRT_INLINE float atan2f(float _X,float _Y) { return ((float)atan2((double)_X,(double)_Y)); }
__CRT_INLINE float ceilf(float _X) { return ((float)ceil((double)_X)); }
__CRT_INLINE float cosf(float _X) { return ((float)cos((double)_X)); }
__CRT_INLINE float coshf(float _X) { return ((float)cosh((double)_X)); }
__CRT_INLINE float expf(float _X) { return ((float)exp((double)_X)); }
__CRT_INLINE float floorf(float _X) { return ((float)floor((double)_X)); }
__CRT_INLINE float fmodf(float _X,float _Y) { return ((float)fmod((double)_X,(double)_Y)); }
__CRT_INLINE float logf(float _X) { return ((float)log((double)_X)); }
__CRT_INLINE float log10f(float _X) { return ((float)log10((double)_X)); }
__CRT_INLINE float modff(float _X,float *_Y) {
double _Di,_Df = modf((double)_X,&_Di);
*_Y = (float)_Di;
return ((float)_Df);
}
__CRT_INLINE float powf(float _X,float _Y) { return ((float)pow((double)_X,(double)_Y)); }
__CRT_INLINE float sinf(float _X) { return ((float)sin((double)_X)); }
__CRT_INLINE float sinhf(float _X) { return ((float)sinh((double)_X)); }
__CRT_INLINE float sqrtf(float _X) { return ((float)sqrt((double)_X)); }
__CRT_INLINE float tanf(float _X) { return ((float)tan((double)_X)); }
__CRT_INLINE float tanhf(float _X) { return ((float)tanh((double)_X)); }
#endif
#endif
#endif
#ifndef NO_OLDNAMES
#define matherr _matherr
#define HUGE _HUGE
/* double __cdecl cabs(struct _complex _X); */
double __cdecl hypot(double _X,double _Y);
_CRTIMP double __cdecl j0(double _X);
_CRTIMP double __cdecl j1(double _X);
_CRTIMP double __cdecl jn(int _X,double _Y);
_CRTIMP double __cdecl y0(double _X);
_CRTIMP double __cdecl y1(double _X);
_CRTIMP double __cdecl yn(int _X,double _Y);
#endif
#ifndef __NO_ISOCEXT
#if (defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) \
|| !defined __STRICT_ANSI__ || defined __GLIBCPP__
#define NAN (0.0F/0.0F)
#define HUGE_VALF (1.0F/0.0F)
#define HUGE_VALL (1.0L/0.0L)
#define INFINITY (1.0F/0.0F)
#define FP_NAN 0x0100
#define FP_NORMAL 0x0400
#define FP_INFINITE (FP_NAN | FP_NORMAL)
#define FP_ZERO 0x4000
#define FP_SUBNORMAL (FP_NORMAL | FP_ZERO)
/* 0x0200 is signbit mask */
/*
We can't __CRT_INLINE float or double, because we want to ensure truncation
to semantic type before classification.
(A normal long double value might become subnormal when
converted to double, and zero when converted to float.)
*/
extern int __cdecl __fpclassifyf (float);
extern int __cdecl __fpclassify (double);
extern int __cdecl __fpclassifyl (long double);
/* Implemented at tcc/tcc_libm.h */
#define fpclassify(x) (sizeof (x) == sizeof (float) ? __fpclassifyf (x) \
: sizeof (x) == sizeof (double) ? __fpclassify (x) \
: __fpclassifyl (x))
/* 7.12.3.2 */
#define isfinite(x) ((fpclassify(x) & FP_NAN) == 0)
/* 7.12.3.3 */
#define isinf(x) (fpclassify(x) == FP_INFINITE)
/* 7.12.3.4 */
/* We don't need to worry about trucation here:
A NaN stays a NaN. */
#define isnan(x) (fpclassify(x) == FP_NAN)
/* 7.12.3.5 */
#define isnormal(x) (fpclassify(x) == FP_NORMAL)
/* 7.12.3.6 The signbit macro */
extern int __cdecl __signbitf (float);
extern int __cdecl __signbit (double);
extern int __cdecl __signbitl (long double);
/* Implemented at tcc/tcc_libm.h */
#define signbit(x) (sizeof (x) == sizeof (float) ? __signbitf (x) \
: sizeof (x) == sizeof (double) ? __signbit (x) \
: __signbitl (x))
extern double __cdecl exp2(double);
extern float __cdecl exp2f(float);
extern long double __cdecl exp2l(long double);
#define FP_ILOGB0 ((int)0x80000000)
#define FP_ILOGBNAN ((int)0x80000000)
extern int __cdecl ilogb (double);
extern int __cdecl ilogbf (float);
extern int __cdecl ilogbl (long double);
extern double __cdecl log1p(double);
extern float __cdecl log1pf(float);
extern long double __cdecl log1pl(long double);
extern double __cdecl log2 (double);
extern float __cdecl log2f (float);
extern long double __cdecl log2l (long double);
extern double __cdecl logb (double);
extern float __cdecl logbf (float);
extern long double __cdecl logbl (long double);
__CRT_INLINE double __cdecl logb (double x)
{
double res;
__asm__ ("fxtract\n\t"
"fstp %%st" : "=t" (res) : "0" (x));
return res;
}
__CRT_INLINE float __cdecl logbf (float x)
{
float res;
__asm__ ("fxtract\n\t"
"fstp %%st" : "=t" (res) : "0" (x));
return res;
}
__CRT_INLINE long double __cdecl logbl (long double x)
{
long double res;
__asm__ ("fxtract\n\t"
"fstp %%st" : "=t" (res) : "0" (x));
return res;
}
extern long double __cdecl modfl (long double, long double*);
/* 7.12.6.13 */
extern double __cdecl scalbn (double, int);
extern float __cdecl scalbnf (float, int);
extern long double __cdecl scalbnl (long double, int);
extern double __cdecl scalbln (double, long);
extern float __cdecl scalblnf (float, long);
extern long double __cdecl scalblnl (long double, long);
/* 7.12.7.1 */
/* Implementations adapted from Cephes versions */
extern double __cdecl cbrt (double);
extern float __cdecl cbrtf (float);
extern long double __cdecl cbrtl (long double);
__CRT_INLINE float __cdecl hypotf (float x, float y)
{ return (float) hypot (x, y);}
extern long double __cdecl hypotl (long double, long double);
extern long double __cdecl powl (long double, long double);
extern long double __cdecl expl(long double);
extern long double __cdecl expm1l(long double);
extern long double __cdecl coshl(long double);
extern long double __cdecl fabsl (long double);
extern long double __cdecl acosl(long double);
extern long double __cdecl asinl(long double);
extern long double __cdecl atanl(long double);
extern long double __cdecl atan2l(long double,long double);
extern long double __cdecl sinhl(long double);
extern long double __cdecl tanhl(long double);
/* 7.12.8.1 The erf functions */
extern double __cdecl erf (double);
extern float __cdecl erff (float);
/* TODO
extern long double __cdecl erfl (long double);
*/
/* 7.12.8.2 The erfc functions */
extern double __cdecl erfc (double);
extern float __cdecl erfcf (float);
/* TODO
extern long double __cdecl erfcl (long double);
*/
/* 7.12.8.3 The lgamma functions */
extern double __cdecl lgamma (double);
extern float __cdecl lgammaf (float);
extern long double __cdecl lgammal (long double);
/* 7.12.8.4 The tgamma functions */
extern double __cdecl tgamma (double);
extern float __cdecl tgammaf (float);
extern long double __cdecl tgammal (long double);
extern long double __cdecl ceill (long double);
extern long double __cdecl floorl (long double);
extern long double __cdecl frexpl(long double,int *);
extern long double __cdecl log10l(long double);
extern long double __cdecl logl(long double);
extern long double __cdecl cosl(long double);
extern long double __cdecl sinl(long double);
extern long double __cdecl tanl(long double);
extern long double sqrtl(long double);
/* 7.12.9.3 */
extern double __cdecl nearbyint ( double);
extern float __cdecl nearbyintf (float);
extern long double __cdecl nearbyintl (long double);
/* 7.12.9.4 */
/* round, using fpu control word settings */
__CRT_INLINE double __cdecl rint (double x)
{
double retval;
__asm__ (
"fldl %1\n"
"frndint \n"
"fstl %0\n" : "=m" (retval) : "m" (x));
return retval;
}
__CRT_INLINE float __cdecl rintf (float x)
{
float retval;
__asm__ (
"flds %1\n"
"frndint \n"
"fsts %0\n" : "=m" (retval) : "m" (x));
return retval;
}
__CRT_INLINE long double __cdecl rintl (long double x)
{
long double retval;
__asm__ (
"fldt %1\n"
"frndint \n"
"fstt %0\n" : "=m" (retval) : "m" (x));
return retval;
}
/* 7.12.9.5 */
__CRT_INLINE long __cdecl lrint (double x)
{
long retval;
__asm__ __volatile__ \
("fldl %1\n" \
"fistpl %0" : "=m" (retval) : "m" (x)); \
return retval;
}
__CRT_INLINE long __cdecl lrintf (float x)
{
long retval;
__asm__ __volatile__ \
("flds %1\n" \
"fistpl %0" : "=m" (retval) : "m" (x)); \
return retval;
}
__CRT_INLINE long __cdecl lrintl (long double x)
{
long retval;
__asm__ __volatile__ \
("fldt %1\n" \
"fistpl %0" : "=m" (retval) : "m" (x)); \
return retval;
}
__CRT_INLINE long long __cdecl llrint (double x)
{
long long retval;
__asm__ __volatile__ \
("fldl %1\n" \
"fistpll %0" : "=m" (retval) : "m" (x)); \
return retval;
}
__CRT_INLINE long long __cdecl llrintf (float x)
{
long long retval;
__asm__ __volatile__ \
("flds %1\n" \
"fistpll %0" : "=m" (retval) : "m" (x)); \
return retval;
}
__CRT_INLINE long long __cdecl llrintl (long double x)
{
long long retval;
__asm__ __volatile__ \
("fldt %1\n" \
"fistpll %0" : "=m" (retval) : "m" (x)); \
return retval;
}
#define FE_TONEAREST 0x0000
#define FE_DOWNWARD 0x0400
#define FE_UPWARD 0x0800
#define FE_TOWARDZERO 0x0c00
__CRT_INLINE double trunc (double _x)
{
double retval;
unsigned short saved_cw;
unsigned short tmp_cw;
__asm__ ("fnstcw %0;" : "=m" (saved_cw)); /* save FPU control word */
tmp_cw = (saved_cw & ~(FE_TONEAREST | FE_DOWNWARD | FE_UPWARD | FE_TOWARDZERO))
| FE_TOWARDZERO;
__asm__ ("fldcw %0;" : : "m" (tmp_cw));
__asm__ ("fldl %1;"
"frndint;"
"fstl %0;" : "=m" (retval) : "m" (_x)); /* round towards zero */
__asm__ ("fldcw %0;" : : "m" (saved_cw) ); /* restore saved control word */
return retval;
}
/* 7.12.9.6 */
/* round away from zero, regardless of fpu control word settings */
extern double __cdecl round (double);
extern float __cdecl roundf (float);
extern long double __cdecl roundl (long double);
/* 7.12.9.7 */
extern long __cdecl lround (double);
extern long __cdecl lroundf (float);
extern long __cdecl lroundl (long double);
extern long long __cdecl llround (double);
extern long long __cdecl llroundf (float);
extern long long __cdecl llroundl (long double);
/* 7.12.9.8 */
/* round towards zero, regardless of fpu control word settings */
extern double __cdecl trunc (double);
extern float __cdecl truncf (float);
extern long double __cdecl truncl (long double);
extern long double __cdecl fmodl (long double, long double);
/* 7.12.10.2 */
extern double __cdecl remainder (double, double);
extern float __cdecl remainderf (float, float);
extern long double __cdecl remainderl (long double, long double);
/* 7.12.10.3 */
extern double __cdecl remquo(double, double, int *);
extern float __cdecl remquof(float, float, int *);
extern long double __cdecl remquol(long double, long double, int *);
/* 7.12.11.1 */
extern double __cdecl copysign (double, double); /* in libmoldname.a */
extern float __cdecl copysignf (float, float);
extern long double __cdecl copysignl (long double, long double);
/* 7.12.11.2 Return a NaN */
extern double __cdecl nan(const char *tagp);
extern float __cdecl nanf(const char *tagp);
extern long double __cdecl nanl(const char *tagp);
#ifndef __STRICT_ANSI__
#define _nan() nan("")
#define _nanf() nanf("")
#define _nanl() nanl("")
#endif
/* 7.12.11.3 */
extern double __cdecl nextafter (double, double); /* in libmoldname.a */
extern float __cdecl nextafterf (float, float);
extern long double __cdecl nextafterl (long double, long double);
/* 7.12.11.4 The nexttoward functions: TODO */
/* 7.12.12.1 */
/* x > y ? (x - y) : 0.0 */
extern double __cdecl fdim (double x, double y);
extern float __cdecl fdimf (float x, float y);
extern long double __cdecl fdiml (long double x, long double y);
/* fmax and fmin.
NaN arguments are treated as missing data: if one argument is a NaN
and the other numeric, then these functions choose the numeric
value. */
/* 7.12.12.2 */
extern double __cdecl fmax (double, double);
extern float __cdecl fmaxf (float, float);
extern long double __cdecl fmaxl (long double, long double);
/* 7.12.12.3 */
extern double __cdecl fmin (double, double);
extern float __cdecl fminf (float, float);
extern long double __cdecl fminl (long double, long double);
/* 7.12.13.1 */
/* return x * y + z as a ternary op */
extern double __cdecl fma (double, double, double);
extern float __cdecl fmaf (float, float, float);
extern long double __cdecl fmal (long double, long double, long double);
#if 0 // gr: duplicate, see below
/* 7.12.14 */
/*
* With these functions, comparisons involving quiet NaNs set the FP
* condition code to "unordered". The IEEE floating-point spec
* dictates that the result of floating-point comparisons should be
* false whenever a NaN is involved, with the exception of the != op,
* which always returns true: yes, (NaN != NaN) is true).
*/
#if __GNUC__ >= 3
#define isgreater(x, y) __builtin_isgreater(x, y)
#define isgreaterequal(x, y) __builtin_isgreaterequal(x, y)
#define isless(x, y) __builtin_isless(x, y)
#define islessequal(x, y) __builtin_islessequal(x, y)
#define islessgreater(x, y) __builtin_islessgreater(x, y)
#define isunordered(x, y) __builtin_isunordered(x, y)
#else
/* helper */
__CRT_INLINE int __cdecl
__fp_unordered_compare (long double x, long double y){
unsigned short retval;
__asm__ ("fucom %%st(1);"
"fnstsw;": "=a" (retval) : "t" (x), "u" (y));
return retval;
}
#define isgreater(x, y) ((__fp_unordered_compare(x, y) \
& 0x4500) == 0)
#define isless(x, y) ((__fp_unordered_compare (y, x) \
& 0x4500) == 0)
#define isgreaterequal(x, y) ((__fp_unordered_compare (x, y) \
& FP_INFINITE) == 0)
#define islessequal(x, y) ((__fp_unordered_compare(y, x) \
& FP_INFINITE) == 0)
#define islessgreater(x, y) ((__fp_unordered_compare(x, y) \
& FP_SUBNORMAL) == 0)
#define isunordered(x, y) ((__fp_unordered_compare(x, y) \
& 0x4500) == 0x4500)
#endif
#endif //0
#endif /* __STDC_VERSION__ >= 199901L */
#endif /* __NO_ISOCEXT */
#ifdef __cplusplus
}
extern "C++" {
template<class _Ty> inline _Ty _Pow_int(_Ty _X,int _Y) {
unsigned int _N;
if(_Y >= 0) _N = (unsigned int)_Y;
else _N = (unsigned int)(-_Y);
for(_Ty _Z = _Ty(1);;_X *= _X) {
if((_N & 1)!=0) _Z *= _X;
if((_N >>= 1)==0) return (_Y < 0 ? _Ty(1) / _Z : _Z);
}
}
}
#endif
#pragma pack(pop)
/* 7.12.14 */
/*
* With these functions, comparisons involving quiet NaNs set the FP
* condition code to "unordered". The IEEE floating-point spec
* dictates that the result of floating-point comparisons should be
* false whenever a NaN is involved, with the exception of the != op,
* which always returns true: yes, (NaN != NaN) is true).
*/
/* Mini libm (inline __fpclassify*, __signbit* and variants) */
/* TCC uses 8 bytes for double and long double, so effectively the l variants
* are never used. For now, they just run the normal (double) variant.
*/
/*
* most of the code in this file is taken from MUSL rs-1.0 (MIT license)
* - musl-libc: http://git.musl-libc.org/cgit/musl/tree/src/math?h=rs-1.0
* - License: http://git.musl-libc.org/cgit/musl/tree/COPYRIGHT?h=rs-1.0
*/
/*******************************************************************************
Start of code based on MUSL
*******************************************************************************/
/*
musl as a whole is licensed under the following standard MIT license:
----------------------------------------------------------------------
Copyright © 2005-2014 Rich Felker, et al.
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.
----------------------------------------------------------------------
*/
/* fpclassify */
__CRT_INLINE int __cdecl __fpclassify (double x) {
union {double f; uint64_t i;} u = {x};
int e = u.i>>52 & 0x7ff;
if (!e) return u.i<<1 ? FP_SUBNORMAL : FP_ZERO;
if (e==0x7ff) return u.i<<12 ? FP_NAN : FP_INFINITE;
return FP_NORMAL;
}
__CRT_INLINE int __cdecl __fpclassifyf (float x) {
union {float f; uint32_t i;} u = {x};
int e = u.i>>23 & 0xff;
if (!e) return u.i<<1 ? FP_SUBNORMAL : FP_ZERO;
if (e==0xff) return u.i<<9 ? FP_NAN : FP_INFINITE;
return FP_NORMAL;
}
__CRT_INLINE int __cdecl __fpclassifyl (long double x) {
return __fpclassify(x);
}
/* signbit */
__CRT_INLINE int __cdecl __signbit (double x) {
union {double d; uint64_t i;} y = { x };
return y.i>>63;
}
__CRT_INLINE int __cdecl __signbitf (float x) {
union {float f; uint32_t i; } y = { x };
return y.i>>31;
}
__CRT_INLINE int __cdecl __signbitl (long double x) {
return __signbit(x);
}
/* fmin*, fmax* */
#define TCCFP_FMIN_EVAL (isnan(x) ? y : \
isnan(y) ? x : \
(signbit(x) != signbit(y)) ? (signbit(x) ? x : y) : \
x < y ? x : y)
__CRT_INLINE double __cdecl fmin (double x, double y) {
return TCCFP_FMIN_EVAL;
}
__CRT_INLINE float __cdecl fminf (float x, float y) {
return TCCFP_FMIN_EVAL;
}
__CRT_INLINE long double __cdecl fminl (long double x, long double y) {
return TCCFP_FMIN_EVAL;
}
#define TCCFP_FMAX_EVAL (isnan(x) ? y : \
isnan(y) ? x : \
(signbit(x) != signbit(y)) ? (signbit(x) ? y : x) : \
x < y ? y : x)
__CRT_INLINE double __cdecl fmax (double x, double y) {
return TCCFP_FMAX_EVAL;
}
__CRT_INLINE float __cdecl fmaxf (float x, float y) {
return TCCFP_FMAX_EVAL;
}
__CRT_INLINE long double __cdecl fmaxl (long double x, long double y) {
return TCCFP_FMAX_EVAL;
}
/* *round* */
#define TCCFP_FORCE_EVAL(x) do { \
if (sizeof(x) == sizeof(float)) { \
volatile float __x; \
__x = (x); \
} else if (sizeof(x) == sizeof(double)) { \
volatile double __x; \
__x = (x); \
} else { \
volatile long double __x; \
__x = (x); \
} \
} while(0)
__CRT_INLINE double __cdecl round (double x) {
union {double f; uint64_t i;} u = {x};
int e = u.i >> 52 & 0x7ff;
double y;
if (e >= 0x3ff+52)
return x;
if (u.i >> 63)
x = -x;
if (e < 0x3ff-1) {
/* raise inexact if x!=0 */
TCCFP_FORCE_EVAL(x + 0x1p52);
return 0*u.f;
}
y = (double)(x + 0x1p52) - 0x1p52 - x;
if (y > 0.5)
y = y + x - 1;
else if (y <= -0.5)
y = y + x + 1;
else
y = y + x;
if (u.i >> 63)
y = -y;
return y;
}
__CRT_INLINE long __cdecl lround (double x) {
return round(x);
}
__CRT_INLINE long long __cdecl llround (double x) {
return round(x);
}
__CRT_INLINE float __cdecl roundf (float x) {
return round(x);
}
__CRT_INLINE long __cdecl lroundf (float x) {
return round(x);
}
__CRT_INLINE long long __cdecl llroundf (float x) {
return round(x);
}
__CRT_INLINE long double __cdecl roundl (long double x) {
return round(x);
}
__CRT_INLINE long __cdecl lroundl (long double x) {
return round(x);
}
__CRT_INLINE long long __cdecl llroundl (long double x) {
return round(x);
}
#endif /* End _MATH_H_ */

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,245 @@
#include <stdio.h>
#include "symbol_enumerator.h"
#if defined( WIN32 ) || defined( WINDOWS ) || defined( USE_WINDOWS ) || defined( _WIN32 )
#include <windows.h>
typedef struct _SYMBOL_INFO {
ULONG SizeOfStruct;
ULONG TypeIndex;
ULONG64 Reserved[2];
ULONG Index;
ULONG Size;
ULONG64 ModBase;
ULONG Flags;
ULONG64 Value;
ULONG64 Address;
ULONG Register;
ULONG Scope;
ULONG Tag;
ULONG NameLen;
ULONG MaxNameLen;
TCHAR Name[1];
} SYMBOL_INFO, *PSYMBOL_INFO;
typedef struct _IMAGEHLP_STACK_FRAME {
ULONG64 InstructionOffset;
ULONG64 ReturnOffset;
ULONG64 FrameOffset;
ULONG64 StackOffset;
ULONG64 BackingStoreOffset;
ULONG64 FuncTableEntry;
ULONG64 Params[4];
ULONG64 Reserved[5];
BOOL Virtual;
ULONG Reserved2;
} IMAGEHLP_STACK_FRAME, *PIMAGEHLP_STACK_FRAME;
typedef BOOL (*PSYM_ENUMERATESYMBOLS_CALLBACK)(
PSYMBOL_INFO pSymInfo,
ULONG SymbolSize,
PVOID UserContext
);
BOOL WINAPI SymEnumSymbols(
HANDLE hProcess,
ULONG64 BaseOfDll,
PCTSTR Mask,
PSYM_ENUMERATESYMBOLS_CALLBACK EnumSymbolsCallback,
const PVOID UserContext
);
BOOL WINAPI SymInitialize(
HANDLE hProcess,
PCTSTR UserSearchPath,
BOOL fInvadeProcess
);
BOOL WINAPI SymCleanup(
HANDLE hProcess
);
BOOL CALLBACK __cdecl mycb(
PSYMBOL_INFO pSymInfo,
ULONG SymbolSize,
PVOID UserContext
){
SymEnumeratorCallback cb = (SymEnumeratorCallback)UserContext;
return !cb( "", &pSymInfo->Name[0], (void*)pSymInfo->Address, (long) pSymInfo->Size );
}
int EnumerateSymbols( SymEnumeratorCallback cb )
{
HANDLE proc = GetCurrentProcess();
if( !SymInitialize( proc, 0, 1 ) ) return -1;
if( !SymEnumSymbols( proc, 0, "*!*", &mycb, (void*)cb ) )
{
SymCleanup(proc);
return -2;
}
SymCleanup(proc);
return 0;
}
#else
#include <stdio.h>
#include <dlfcn.h>
#include <stdint.h>
#include <limits.h>
#include <string.h>
#ifndef __GNUC__
#define __int128_t long long long
#endif
#include <link.h>
#include <elf.h>
#define UINTS_PER_WORD (__WORDSIZE / (CHAR_BIT * sizeof (unsigned int)))
struct dl_phdr_info {
ElfW(Addr) dlpi_addr; /* Base address of object */
const char *dlpi_name; /* (Null-terminated) name of
object */
const ElfW(Phdr) *dlpi_phdr; /* Pointer to array of
ELF program headers
for this object */
ElfW(Half) dlpi_phnum; /* # of items in dlpi_phdr */
};
void dl_iterate_phdr( void*, void*);
static ElfW(Word) gnu_hashtab_symbol_count(const unsigned int *const table)
{
const unsigned int *const bucket = table + 4 + table[2] * (unsigned int)(UINTS_PER_WORD);
unsigned int b = table[0];
unsigned int max = 0U;
while (b-->0U)
if (bucket[b] > max)
max = bucket[b];
return (ElfW(Word))max;
}
static static void *dynamic_pointer(const ElfW(Addr) addr,
const ElfW(Addr) base, const ElfW(Phdr) *const header, const ElfW(Half) headers)
{
if (addr) {
ElfW(Half) h;
for (h = 0; h < headers; h++)
if (header[h].p_type == PT_LOAD)
if (addr >= base + header[h].p_vaddr &&
addr < base + header[h].p_vaddr + header[h].p_memsz)
return (void *)addr;
}
return NULL;
}
//Mostly based off of http://stackoverflow.com/questions/29903049/get-names-and-addresses-of-exported-functions-from-in-linux
static int callback(struct dl_phdr_info *info,
size_t size, void *data)
{
SymEnumeratorCallback cb = (SymEnumeratorCallback)data;
const ElfW(Addr) base = info->dlpi_addr;
const ElfW(Phdr) *const header = info->dlpi_phdr;
const ElfW(Half) headers = info->dlpi_phnum;
const char *libpath, *libname;
ElfW(Half) h;
if (info->dlpi_name && info->dlpi_name[0])
libpath = info->dlpi_name;
else
libpath = "";
libname = strrchr(libpath, '/');
if (libname && libname[0] == '/' && libname[1])
libname++;
else
libname = libpath;
for (h = 0; h < headers; h++)
{
if (header[h].p_type == PT_DYNAMIC)
{
const ElfW(Dyn) *entry = (const ElfW(Dyn) *)(base + header[h].p_vaddr);
const ElfW(Word) *hashtab;
const ElfW(Sym) *symtab = NULL;
const char *strtab = NULL;
ElfW(Word) symbol_count = 0;
for (; entry->d_tag != DT_NULL; entry++)
{
switch (entry->d_tag)
{
case DT_HASH:
hashtab = dynamic_pointer(entry->d_un.d_ptr, base, header, headers);
if (hashtab)
symbol_count = hashtab[1];
break;
case DT_GNU_HASH:
hashtab = dynamic_pointer(entry->d_un.d_ptr, base, header, headers);
if (hashtab)
{
ElfW(Word) count = gnu_hashtab_symbol_count(hashtab);
if (count > symbol_count)
symbol_count = count;
}
break;
case DT_STRTAB:
strtab = dynamic_pointer(entry->d_un.d_ptr, base, header, headers);
break;
case DT_SYMTAB:
symtab = dynamic_pointer(entry->d_un.d_ptr, base, header, headers);
break;
}
}
if (symtab && strtab && symbol_count > 0) {
ElfW(Word) s;
for (s = 0; s < symbol_count; s++) {
const char *name;
void *const ptr = dynamic_pointer(base + symtab[s].st_value, base, header, headers);
int result;
if (!ptr)
continue;
if (symtab[s].st_name)
name = strtab + symtab[s].st_name;
else
name = "";
result = cb( libpath, name, ptr, symtab[s].st_size );
if( result ) return result; //Bail early.
}
}
}
}
return 0;
}
int EnumerateSymbols( SymEnumeratorCallback cb )
{
dl_iterate_phdr( callback, cb );
}
#endif

View file

@ -0,0 +1,12 @@
#ifndef _SYMBOL_ENUMERATOR_H
#define _SYMBOL_ENUMERATOR_H
//Enumerates all symbols in the currently loaded excutable.
//Don't forget to compile with -rdynamic!
//Return 0 to continue search. 1 to stop.
typedef int (*SymEnumeratorCallback)( const char * path, const char * name, void * location, long size );
int EnumerateSymbols( SymEnumeratorCallback cb );
#endif

View file

@ -0,0 +1,80 @@
#include <_mingw.h>
#define REMATH(x) double __cdecl x( double f ); float x##f(float v) { return x(v); }
int SymnumCheck( const char * path, const char * name, void * location, long size )
{
if( strncmp( name, "REGISTER", 8 ) == 0 )
{
typedef void (*sf)();
sf fn = (sf)location;
fn();
}
return 0;
}
void ManuallyRegisterDevices()
{
EnumerateSymbols( SymnumCheck );
}
REMATH( acos );
REMATH( cos );
REMATH( sin );
REMATH( sqrt );
REMATH( asin );
REMATH( exp );
REMATH( fmod );
REMATH( pow );
double __cdecl strtod (const char* str, char** endptr);
float strtof( const char* str, char** endptr)
{
return strtod( str, endptr );
}
double __cdecl atan2(double a, double b);
float atan2f(float a, float b)
{
return atan2( a, b );
}
//From http://stackoverflow.com/questions/40159892/using-asprintf-on-windows
int __cdecl vsprintf_s(
char *buffer,
size_t numberOfElements,
const char *format,
va_list argptr
);
int asprintf(char **strp, const char *fmt, ...) {
va_list ap;
va_start(ap, fmt);
int r = vasprintf(strp, fmt, ap);
va_end(ap);
return r;
}
int vasprintf(char **strp, const char *fmt, va_list ap) {
// _vscprintf tells you how big the buffer needs to be
int len = _vscprintf(fmt, ap);
if (len == -1) {
return -1;
}
size_t size = (size_t)len + 1;
char *str = (char*)malloc(size);
if (!str) {
return -1;
}
// _vsprintf_s is the "secure" version of vsprintf
int r = vsprintf_s(str, len + 1, fmt, ap);
if (r == -1) {
free(str);
return -1;
}
*strp = str;
return r;
}

File diff suppressed because it is too large Load diff

View file

@ -12,52 +12,56 @@
#define memcpy ets_memcpy
#define memset ets_memset
extern uint8_t gDFTIIR; //=6
#define DFTIIR gDFTIIR
extern uint8_t gFUZZ_IIR_BITS; //=1
#define FUZZ_IIR_BITS gFUZZ_IIR_BITS
#define ROOT_NOTE_OFFSET CCS.gROOT_NOTE_OFFSET
#define DFTIIR CCS.gDFTIIR
#define FUZZ_IIR_BITS CCS.gFUZZ_IIR_BITS
#define MAXNOTES 12 //MAXNOTES cannot be changed dynamically.
extern uint8_t gFILTER_BLUR_PASSES; //=2
#define FILTER_BLUR_PASSES gFILTER_BLUR_PASSES
extern uint8_t gSEMIBITSPERBIN; //=3
#define SEMIBITSPERBIN gSEMIBITSPERBIN
extern uint8_t gMAX_JUMP_DISTANCE; //=4
#define MAX_JUMP_DISTANCE gMAX_JUMP_DISTANCE
extern uint8_t gMAX_COMBINE_DISTANCE; //=7
#define MAX_COMBINE_DISTANCE gMAX_COMBINE_DISTANCE
extern uint8_t gAMP_1_IIR_BITS; //=4
#define AMP_1_IIR_BITS gAMP_1_IIR_BITS
extern uint8_t gAMP_2_IIR_BITS; //=2
#define AMP_2_IIR_BITS gAMP_2_IIR_BITS
extern uint8_t gMIN_AMP_FOR_NOTE; //=80
#define MIN_AMP_FOR_NOTE gMIN_AMP_FOR_NOTE
extern uint8_t gMINIMUM_AMP_FOR_NOTE_TO_DISAPPEAR; //=64
#define MINIMUM_AMP_FOR_NOTE_TO_DISAPPEAR gMINIMUM_AMP_FOR_NOTE_TO_DISAPPEAR
extern uint8_t gNOTE_FINAL_AMP; //=12
#define NOTE_FINAL_AMP gNOTE_FINAL_AMP
extern uint8_t gNERF_NOTE_PORP; //=15
#define NERF_NOTE_PORP gNERF_NOTE_PORP
extern uint8_t gUSE_NUM_LIN_LEDS; // = NUM_LIN_LEDS
#define USE_NUM_LIN_LEDS gUSE_NUM_LIN_LEDS
#define FILTER_BLUR_PASSES CCS.gFILTER_BLUR_PASSES
#define SEMIBITSPERBIN CCS.gSEMIBITSPERBIN
#define MAX_JUMP_DISTANCE CCS.gMAX_JUMP_DISTANCE
#define MAX_COMBINE_DISTANCE CCS.gMAX_COMBINE_DISTANCE
#define AMP_1_IIR_BITS CCS.gAMP_1_IIR_BITS
#define AMP_2_IIR_BITS CCS.gAMP_2_IIR_BITS
#define MIN_AMP_FOR_NOTE CCS.gMIN_AMP_FOR_NOTE
#define MINIMUM_AMP_FOR_NOTE_TO_DISAPPEAR CCS.gMINIMUM_AMP_FOR_NOTE_TO_DISAPPEAR
#define NOTE_FINAL_AMP CCS.gNOTE_FINAL_AMP
#define NERF_NOTE_PORP CCS.gNERF_NOTE_PORP
#define USE_NUM_LIN_LEDS CCS.gUSE_NUM_LIN_LEDS
#define COLORCHORD_OUTPUT_DRIVER CCS.gCOLORCHORD_OUTPUT_DRIVER
#define COLORCHORD_ACTIVE CCS.gCOLORCHORD_ACTIVE
#define INITIAL_AMP CCS.gINITIAL_AMP
//We are not enabling these for the ESP8266 port.
#define LIN_WRAPAROUND 0
#define SORT_NOTES 0
struct CCSettings
{
uint8_t gSETTINGS_KEY;
uint8_t gROOT_NOTE_OFFSET; //Set to define what the root note is. 0 = A.
uint8_t gDFTIIR; //=6
uint8_t gFUZZ_IIR_BITS; //=1
uint8_t gFILTER_BLUR_PASSES; //=2
uint8_t gSEMIBITSPERBIN; //=3
uint8_t gMAX_JUMP_DISTANCE; //=4
uint8_t gMAX_COMBINE_DISTANCE; //=7
uint8_t gAMP_1_IIR_BITS; //=4
uint8_t gAMP_2_IIR_BITS; //=2
uint8_t gMIN_AMP_FOR_NOTE; //=80
uint8_t gMINIMUM_AMP_FOR_NOTE_TO_DISAPPEAR; //=64
uint8_t gNOTE_FINAL_AMP; //=12
uint8_t gNERF_NOTE_PORP; //=15
uint8_t gUSE_NUM_LIN_LEDS; // = NUM_LIN_LEDS
uint8_t gCOLORCHORD_ACTIVE;
uint8_t gCOLORCHORD_OUTPUT_DRIVER;
uint8_t gINITIAL_AMP;
};
extern struct CCSettings CCS;
#endif

@ -1 +1 @@
Subproject commit 113e0d1a182cd138510f748abf2854c0e84cfa23
Subproject commit 248dcac4022bf1e3d3574f2f49626c99d794dd06

Binary file not shown.

Binary file not shown.

View file

@ -12,12 +12,17 @@ PAGE_OFFSET = 65536 # 1048576
#SDK_DEFAULT = $(HOME)/esp8266/esp-open-sdk
ESP_GCC_VERS = 4.8.5
SDK = $(HOME)/esp8266/esp_iot_sdk_v1.5.2
#SDK = $(HOME)/esp8266/esp_iot_sdk_v1.5.2
PAGE_SCRIPTS = main.js
FWBURNFLAGS = -b 1000000
FWBURNFLAGS = -b 2000000
OPTS += -DICACHE_FLASH
OPTS += -DDISABLE_CHARRX #Saves about 48 bytes.
OPTS += -DQUIET_REFLASH #Saves about 128 bytes.
OPTS += -DWS2812_FOUR_SAMPLE #Saves about 224 bytes.
#OPTS += -DWS2812_THREE_SAMPLE
#OPTS += -DVERIFY_FLASH_WRITE
#OPTS += -DDEBUG
#OPTS += -DFREQ=12500

View file

@ -11,51 +11,51 @@ extern volatile uint8_t sounddata[];
extern volatile uint16_t soundhead;
#define CONFIGURABLES 17 //(plus1)
#define CONFIGURABLES 18 //(plus1)
extern uint8_t RootNoteOffset; //Set to define what the root note is. 0 = A.
uint8_t gDFTIIR = 6;
uint8_t gFUZZ_IIR_BITS = 1;
uint8_t gFILTER_BLUR_PASSES = 2;
uint8_t gSEMIBITSPERBIN = 3;
uint8_t gMAX_JUMP_DISTANCE = 4;
uint8_t gMAX_COMBINE_DISTANCE = 7;
uint8_t gAMP_1_IIR_BITS = 4;
uint8_t gAMP_2_IIR_BITS = 2;
uint8_t gMIN_AMP_FOR_NOTE = 80;
uint8_t gMINIMUM_AMP_FOR_NOTE_TO_DISAPPEAR = 64;
uint8_t gNOTE_FINAL_AMP = 12;
uint8_t gNERF_NOTE_PORP = 15;
uint8_t gUSE_NUM_LIN_LEDS = NUM_LIN_LEDS;
uint8_t gCOLORCHORD_ACTIVE = 1;
uint8_t gCOLORCHORD_OUTPUT_DRIVER = 0;
struct SaveLoad
{
uint8_t configs[CONFIGURABLES];
uint8_t SaveLoadKey; //Must be 0xaa to be valid.
} settings;
uint8_t gConfigDefaults[CONFIGURABLES] = { 0, 6, 1, 2, 3, 4, 7, 4, 2, 80, 64, 12, 15, NUM_LIN_LEDS, 1, 0, 0 };
struct CCSettings CCS;
uint8_t * gConfigurables[CONFIGURABLES] = { &RootNoteOffset, &gDFTIIR, &gFUZZ_IIR_BITS, &gFILTER_BLUR_PASSES,
&gSEMIBITSPERBIN, &gMAX_JUMP_DISTANCE, &gMAX_COMBINE_DISTANCE, &gAMP_1_IIR_BITS,
&gAMP_2_IIR_BITS, &gMIN_AMP_FOR_NOTE, &gMINIMUM_AMP_FOR_NOTE_TO_DISAPPEAR, &gNOTE_FINAL_AMP,
&gNERF_NOTE_PORP, &gUSE_NUM_LIN_LEDS, &gCOLORCHORD_ACTIVE, &gCOLORCHORD_OUTPUT_DRIVER, 0 };
uint8_t gConfigDefaults[CONFIGURABLES] = { 0, 6, 1, 2, 3, 4, 7, 4, 2, 80, 64, 12, 15, NUM_LIN_LEDS, 1, 0, 16, 0 };
uint8_t * gConfigurables[CONFIGURABLES] = { &CCS.gROOT_NOTE_OFFSET, &CCS.gDFTIIR, &CCS.gFUZZ_IIR_BITS, &CCS.gFILTER_BLUR_PASSES,
&CCS.gSEMIBITSPERBIN, &CCS.gMAX_JUMP_DISTANCE, &CCS.gMAX_COMBINE_DISTANCE, &CCS.gAMP_1_IIR_BITS,
&CCS.gAMP_2_IIR_BITS, &CCS.gMIN_AMP_FOR_NOTE, &CCS.gMINIMUM_AMP_FOR_NOTE_TO_DISAPPEAR, &CCS.gNOTE_FINAL_AMP,
&CCS.gNERF_NOTE_PORP, &CCS.gUSE_NUM_LIN_LEDS, &CCS.gCOLORCHORD_ACTIVE, &CCS.gCOLORCHORD_OUTPUT_DRIVER, &CCS.gINITIAL_AMP, 0 };
char * gConfigurableNames[CONFIGURABLES] = { "gROOT_NOTE_OFFSET", "gDFTIIR", "gFUZZ_IIR_BITS", "gFILTER_BLUR_PASSES",
"gSEMIBITSPERBIN", "gMAX_JUMP_DISTANCE", "gMAX_COMBINE_DISTANCE", "gAMP_1_IIR_BITS",
"gAMP_2_IIR_BITS", "gMIN_AMP_FOR_NOTE", "gMINIMUM_AMP_FOR_NOTE_TO_DISAPPEAR", "gNOTE_FINAL_AMP",
"gNERF_NOTE_PORP", "gUSE_NUM_LIN_LEDS", "gCOLORCHORD_ACTIVE", "gCOLORCHORD_OUTPUT_DRIVER", 0 };
"gNERF_NOTE_PORP", "gUSE_NUM_LIN_LEDS", "gCOLORCHORD_ACTIVE", "gCOLORCHORD_OUTPUT_DRIVER", "gINITIAL_AMP", 0 };
void ICACHE_FLASH_ATTR CustomStart( )
{
int i;
spi_flash_read( 0x3D000, (uint32*)&settings, sizeof( settings ) );
for( i = 0; i < CONFIGURABLES; i++ )
if( settings.SaveLoadKey == 0xaa )
{
if( gConfigurables[i] )
for( i = 0; i < CONFIGURABLES; i++ )
{
*gConfigurables[i] = settings.configs[i];
if( gConfigurables[i] )
{
*gConfigurables[i] = settings.configs[i];
}
}
}
else
{
for( i = 0; i < CONFIGURABLES; i++ )
{
if( gConfigurables[i] )
{
*gConfigurables[i] = gConfigDefaults[i];
}
}
}
}
@ -105,8 +105,8 @@ int ICACHE_FLASH_ATTR CustomCommand(char * buffer, int retsize, char *pusrdata,
case 'l': case 'L': //LEDs
{
int i, it = 0;
buffend += ets_sprintf( buffend, "CL\t%d\t", gUSE_NUM_LIN_LEDS );
uint16_t toledsvals = gUSE_NUM_LIN_LEDS*3;
buffend += ets_sprintf( buffend, "CL\t%d\t", USE_NUM_LIN_LEDS );
uint16_t toledsvals = USE_NUM_LIN_LEDS*3;
if( toledsvals > 600 ) toledsvals = 600;
for( i = 0; i < toledsvals; i++ )
{
@ -198,6 +198,7 @@ int ICACHE_FLASH_ATTR CustomCommand(char * buffer, int retsize, char *pusrdata,
if( gConfigurables[i] )
settings.configs[i] = *gConfigurables[i];
}
settings.SaveLoadKey = 0xAA;
EnterCritical();
ets_intr_lock();

View file

@ -15,9 +15,9 @@
#include "ccconfig.h"
#include <embeddednf.h>
#include <embeddedout.h>
#include <commonservices.h>
#include "ets_sys.h"
#include "gpio.h"
//#define PROFILE
#define PORT 7777
@ -28,6 +28,7 @@
#define procTaskPrio 0
#define procTaskQueueLen 1
struct CCSettings CCS;
static volatile os_timer_t some_timer;
static struct espconn *pUdpServer;
@ -37,27 +38,26 @@ void ExitCritical();
extern volatile uint8_t sounddata[HPABUFFSIZE];
extern volatile uint16_t soundhead;
uint16_t soundtail;
extern uint8_t gCOLORCHORD_ACTIVE;
static uint8_t hpa_running = 0;
static uint8_t hpa_running = 0;
static uint8_t hpa_is_paused_for_wifi;
void ICACHE_FLASH_ATTR CustomStart( );
void ICACHE_FLASH_ATTR user_rf_pre_init()
{
}
extern uint8_t gCOLORCHORD_OUTPUT_DRIVER;
//Call this once we've stacked together one full colorchord frame.
static void NewFrame()
{
if( !gCOLORCHORD_ACTIVE ) return;
if( !COLORCHORD_ACTIVE ) return;
//uint8_t led_outs[NUM_LIN_LEDS*3];
int i;
HandleFrameInfo();
switch( gCOLORCHORD_OUTPUT_DRIVER )
switch( COLORCHORD_OUTPUT_DRIVER )
{
case 0:
UpdateLinearLEDs();
@ -72,56 +72,22 @@ static void NewFrame()
}
os_event_t procTaskQueue[procTaskQueueLen];
static uint8_t printed_ip = 0;
uint32_t samp_iir = 0;
int wf = 0;
//Tasks that happen all the time.
static void ICACHE_FLASH_ATTR HandleIPStuff()
{
//Idle Event.
struct station_config wcfg;
char stret[256];
char *stt = &stret[0];
struct ip_info ipi;
int stat = wifi_station_get_connect_status();
//printf( "STAT: %d %d\n", stat, wifi_get_opmode() );
if( stat == STATION_WRONG_PASSWORD || stat == STATION_NO_AP_FOUND || stat == STATION_CONNECT_FAIL )
{
wifi_set_opmode_current( 2 );
stt += ets_sprintf( stt, "Connection failed: %d\n", stat );
uart0_sendStr(stret);
}
if( stat == STATION_GOT_IP && !printed_ip )
{
wifi_station_get_config( &wcfg );
wifi_get_ip_info(0, &ipi);
stt += ets_sprintf( stt, "STAT: %d\n", stat );
stt += ets_sprintf( stt, "IP: %d.%d.%d.%d\n", (ipi.ip.addr>>0)&0xff,(ipi.ip.addr>>8)&0xff,(ipi.ip.addr>>16)&0xff,(ipi.ip.addr>>24)&0xff );
stt += ets_sprintf( stt, "NM: %d.%d.%d.%d\n", (ipi.netmask.addr>>0)&0xff,(ipi.netmask.addr>>8)&0xff,(ipi.netmask.addr>>16)&0xff,(ipi.netmask.addr>>24)&0xff );
stt += ets_sprintf( stt, "GW: %d.%d.%d.%d\n", (ipi.gw.addr>>0)&0xff,(ipi.gw.addr>>8)&0xff,(ipi.gw.addr>>16)&0xff,(ipi.gw.addr>>24)&0xff );
stt += ets_sprintf( stt, "WCFG: /%s/%s/\n", wcfg.ssid, wcfg.password );
uart0_sendStr(stret);
printed_ip = 1;
}
}
static void procTask(os_event_t *events)
{
system_os_post(procTaskPrio, 0, 0 );
if( gCOLORCHORD_ACTIVE && !hpa_running )
if( COLORCHORD_ACTIVE && !hpa_running )
{
ExitCritical();
hpa_running = 1;
}
if( !gCOLORCHORD_ACTIVE && hpa_running )
if( !COLORCHORD_ACTIVE && hpa_running )
{
EnterCritical();
hpa_running = 0;
@ -133,9 +99,11 @@ static void procTask(os_event_t *events)
#endif
while( soundtail != soundhead )
{
int16_t samp = sounddata[soundtail];
int32_t samp = sounddata[soundtail];
samp_iir = samp_iir - (samp_iir>>10) + samp;
PushSample32( (samp - (samp_iir>>10))*16 );
samp = (samp - (samp_iir>>10))*16;
samp = (samp * CCS.gINITIAL_AMP) >> 4;
PushSample32( samp );
soundtail = (soundtail+1)&(HPABUFFSIZE-1);
wf++;
@ -152,7 +120,6 @@ static void procTask(os_event_t *events)
if( events->sig == 0 && events->par == 0 )
{
CSTick( 0 );
HandleIPStuff();
}
}
@ -161,6 +128,13 @@ static void procTask(os_event_t *events)
static void ICACHE_FLASH_ATTR myTimer(void *arg)
{
CSTick( 1 );
if( hpa_is_paused_for_wifi && printed_ip )
{
StartHPATimer(); //Init the high speed ADC timer.
hpa_running = 1;
hpa_is_paused_for_wifi = 0; // only need to do once prevents unstable ADC
}
// uart0_sendStr(".");
// printf( "%d/%d\n",soundtail,soundhead );
// printf( "%d/%d\n",soundtail,soundhead );
@ -238,11 +212,25 @@ void ICACHE_FLASH_ATTR user_init(void)
InitColorChord(); //Init colorchord
StartHPATimer(); //Init the high speed ADC timer.
hpa_running = 1;
//Tricky: If we are in station mode, wait for that to get resolved before enabling the high speed timer.
if( wifi_get_opmode() == 1 )
{
hpa_is_paused_for_wifi = 1;
}
else
{
StartHPATimer(); //Init the high speed ADC timer.
hpa_running = 1;
}
ws2812_init();
// Attempt to make ADC more stable
// https://github.com/esp8266/Arduino/issues/2070
// see peripherals https://espressif.com/en/support/explore/faq
//wifi_set_sleep_type(NONE_SLEEP_T); // on its own stopped wifi working
//wifi_fpm_set_sleep_type(NONE_SLEEP_T); // with this seemed no difference
system_os_post(procTaskPrio, 0, 0 );
}

View file

@ -23,7 +23,8 @@
//4 takes up more RAM per LED than 3.
//3 has slightly more restrictve timing requirements.
//4 has more DMA load when running.
#define WS2812_THREE_SAMPLE
//#define WS2812_THREE_SAMPLE
//#define WS2812_FOUR_SAMPLE
void ICACHE_FLASH_ATTR ws2812_init();

BIN
embedded8266/web/page.mpfs Normal file

Binary file not shown.

View file

@ -6,7 +6,7 @@ var output;
var websocket;
var commsup = 0;
var mpfs_start_at = 1048576;
var mpfs_start_at = 65536; //1048576; NOTE: If you select 1048576, it will override the 65536 sector, but has much more room.
var flash_scratchpad_at = 524288;
var flash_blocksize = 65536;
var flash_sendsize = 256;
@ -44,10 +44,12 @@ function QueueOperation( command, callback )
workqueue.push( vp );
}
did_init = false;
function init()
{
var GPIOlines = '';
if( did_init ) return;
did_init = true;
GPIOlines = '';
for(var i=0; i<16; ++i)
GPIOlines += "<td align=center>"+ i
+ "<input type=button id=ButtonGPIO"+ i +" value=0 onclick=\"TwiddleGPIO("+ i +");\">"
@ -56,10 +58,11 @@ function init()
$('#MainMenu > tbody:first-child').before( "\
<tr><td width=1> \
<input type=submit onclick=\"ShowHideEvent( 'SystemStatus' );\" value='System Status' id=SystemStatusClicker></td><td> \
<input type=submit onclick=\"ShowHideEvent( 'SystemStatus' ); SystemInfoTick();\" value='System Status' id=SystemStatusClicker></td><td> \
<div id=SystemStatus class='collapsible'> \
<table width=100% border=1><tr><td> \
<div id=output> \n </td></tr></table></div></td></tr>" );
<div id=output></div><div id=systemsettings></div> \n </td></tr></table></div></td></tr>"
);
$('#MainMenu > tbody:last-child').after( "\
<tr><td width=1> \
@ -118,16 +121,19 @@ function init()
$("#custom_command_response").val( "" );
//Preclude drag and drop on rest of document in event user misses firmware boxes.
var donothing = function(e) {e.stopPropagation();e.preventDefault();};
donothing = function(e) {e.stopPropagation();e.preventDefault();};
$(document).on('drop', donothing );
$(document).on('dragover', donothing );
$(document).on('dragenter', donothing );
output = document.getElementById("output");
Ticker();
KickWifiTicker();
GPIODataTickerStart();
InitSystemTicker();
console.log( "Load complete.\n" );
Ticker();
}
window.addEventListener("load", init, false);
@ -141,6 +147,7 @@ function StartWebSocket()
workqueue = [];
lastitem = null;
websocket = new WebSocket(wsUri);
websocket.binaryType = 'arraybuffer';
websocket.onopen = function(evt) { onOpen(evt) };
websocket.onclose = function(evt) { onClose(evt) };
websocket.onmessage = function(evt) { onMessage(evt) };
@ -161,7 +168,8 @@ function onClose(evt)
var msg = 0;
var tickmessage = 0;
var lasthz = 0;
var time_since_hz = 0;
var time_since_hz = 10; //Make it realize it was disconnected to begin with.
function Ticker()
{
setTimeout( Ticker, 1000 );
@ -203,17 +211,24 @@ function onMessage(evt)
}
var rawdat = new Uint8Array(evt.data)
var stringdata = String.fromCharCode.apply(null, rawdat);
if( lastitem )
{
if( lastitem.callback )
{
lastitem.callback( lastitem, evt.data );
lastitem.callback( lastitem, stringdata, rawdat );
lastitem = null;
}
}
else
{
output.innerHTML = "<p>Messages: " + msg + "</p><p>RSSI: " + evt.data.substr(2) + "</p>";
if( stringdata.length > 2 )
{
var wxresp = stringdata.substr(2).split("\t");
output.innerHTML = "<p>Messages: " + msg + "</p><p>RSSI: " + wxresp[0] + " / IP: " + ((wxresp.length>1)?HexToIP( wxresp[1] ):"") + "</p>";
}
}
@ -278,27 +293,27 @@ function IssueCustomCommand()
function MakeDragDrop( divname, callback )
{
var obj = $("#" + divname);
obj.on('dragenter', function (e)
obj.on('dragenter', function (e)
{
e.stopPropagation();
e.preventDefault();
$(this).css('border', '2px solid #0B85A1');
});
obj.on('dragover', function (e)
obj.on('dragover', function (e)
{
e.stopPropagation();
e.preventDefault();
});
obj.on('dragend', function (e)
obj.on('dragend', function (e)
{
e.stopPropagation();
e.preventDefault();
$(this).css('border', '2px dotted #0B85A1');
});
obj.on('drop', function (e)
obj.on('drop', function (e)
{
$(this).css('border', '2px dotted #0B85A1');
e.preventDefault();
@ -318,9 +333,108 @@ function MakeDragDrop( divname, callback )
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
///Below here are mostly just events...
var did_wifi_get_config = false;
var is_data_ticker_running = false;
var is_waiting_on_stations = false;
var sysset = null;
var snchanged = false;
var sdchanged = false;
var lastpeerdata = "";
function CallbackForPeers(req,data)
{
if( data == lastpeerdata ) return;
lastpeerdata = data;
var lines = data.split( "\n" );
var searchcount = 0;
if( lines.length > 0 )
{
var line1 = lines[0].split( "\t" );
if( line1.length > 1 ) searchcount = Number( line1[1] );
}
var htm = "<TABLE BORDER=1 STYLE='width:150'><TR><TH>Address</TH><TH>Service</TH><TH>Name</TH><TH>Description</TH></TR>";
for( var i = 1; i < lines.length; i++ )
{
var elems = lines[i].split( "\t" );
if( elems.length < 4 ) continue;
IP = HexToIP( elems[0] );
htm += "<TR><TD><A HREF=http://" + IP + ">" + IP + "</A></TD><TD>" + elems[1] + "</TD><TD>" + elems[2] + "</TD><TD>" + elems[3] + "</TD></TR>";
}
htm += "</TABLE>";
if( searchcount == 0 )
{
htm += "<INPUT TYPE=SUBMIT VALUE=\"Initiate Search\" ONCLICK='QueueOperation(\"BS\");'>";
}
$("#peers").html( htm );
}
function SysTickBack(req,data)
{
var params = data.split( "\t" );
if( !snchanged )
{
$("#SystemName").prop( "value", params[3] );
$("#SystemName").removeClass( "unsaved-input");
}
if( !sdchanged )
{
$("#SystemDescription").prop( "value", params[4] );
$("#SystemDescription").removeClass( "unsaved-input");
}
$("#ServiceName").html( params[5] );
$("#FreeHeap").html( params[6] );
QueueOperation( "BL", CallbackForPeers );
}
function SystemInfoTick()
{
if( IsTabOpen('SystemStatus') )
{
QueueOperation( "I", SysTickBack );
setTimeout( SystemInfoTick, 500 );
}
else
{
//Stop.
}
}
function SystemChangesReset()
{
snchanged = false;
sdchanged = false;
}
function SystemUncommittedChanges()
{
if( sdchanged || snchanged ) return true;
else return false;
}
function InitSystemTicker()
{
sysset = document.getElementById( "systemsettings" );
SystemInfoTick();
sysset.innerHTML = "<TABLE style='width:150'><TR><TD>System Name:</TD><TD><INPUT TYPE=TEXT ID='SystemName' maxlength=10></TD><TD><INPUT TYPE=SUBMIT VALUE=Change ONCLICK='QueueOperation(\"IN\" + document.getElementById(\"SystemName\").value ); snchanged = false;'></TD></TR>\
<TR><TD NOWRAP>System Description:</TD><TD><INPUT TYPE=TEXT ID='SystemDescription' maxlength=16></TD><TD><INPUT TYPE=SUBMIT VALUE=Change ONCLICK='QueueOperation(\"ID\" + document.getElementById(\"SystemDescription\").value ); sdchanged = false;'></TD></TR><TR><TD>Service Name:</TD><TD><DIV ID=\"ServiceName\"></DIV></TD></TR><TR><TD>Free Heap:</TD><TD><DIV ID=\"FreeHeap\"></DIV></TD></TR></TABLE>\
<INPUT TYPE=SUBMIT VALUE=\"Reset To Current\" ONCLICK='SystemChangesReset();'>\
<INPUT TYPE=SUBMIT VALUE=Save ONCLICK='if( SystemUncommittedChanges() ) { IssueSystemMessage( \"Cannot save. Uncommitted changes.\"); return; } QueueOperation(\"IS\", function() { IssueSystemMessage( \"Saving\" ); } ); SystemChangesReset(); '>\
<INPUT TYPE=SUBMIT VALUE=\"Revert From Saved\" ONCLICK='QueueOperation(\"IL\", function() { IssueSystemMessage( \"Reverting.\" ); } ); SystemChangesReset();'>\
<INPUT TYPE=SUBMIT VALUE=\"Revert To Factory\" ONCLICK='if( confirm( \"Are you sure you want to revert to factory settings?\" ) ) QueueOperation(\"IR\"); SystemChangesReset();'>\
<INPUT TYPE=SUBMIT VALUE=Reboot ONCLICK='QueueOperation(\"IB\");'>\
<P>Search for others:</P>\
<DIV id=peers></DIV>";
$("#SystemName").on("input propertychange paste",function(){snchanged = true; $("#SystemName").addClass( "unsaved-input"); });
$("#SystemDescription").on("input propertychange paste",function(){sdchanged = true;$("#SystemDescription").addClass( "unsaved-input"); });
}
did_wifi_get_config = false;
is_data_ticker_running = false;
is_waiting_on_stations = false;
function ScanForWifi()
{
@ -378,7 +492,7 @@ function WifiDataTicker()
QueueOperation( "WI", function(req,data)
{
var params = data.split( "\t" );
var opmode = Number( params[0].substr(2) );
document.wifisection.wifitype.value = opmode;
document.wifisection.wificurname.value = params[1];
@ -394,6 +508,7 @@ function WifiDataTicker()
QueueOperation( "WR", function(req,data) {
var lines = data.split( "\n" );
var innerhtml;
if( data[0] == '!' ) return; //If no APs, don't deal with list.
if( lines.length < 3 )
{
@ -425,7 +540,7 @@ function WifiDataTicker()
innerhtml += "</TABLE>";
document.getElementById("WifiStations").innerHTML = innerhtml;
} );
setTimeout( WifiDataTicker, 12000 );
setTimeout( WifiDataTicker, 500 );
}
else
{
@ -435,7 +550,7 @@ function WifiDataTicker()
function ChangeWifiConfig()
{
var st = "W";
st += document.wifisection.wifitype.value;
st += "\t" + document.wifisection.wificurname.value;
@ -549,7 +664,7 @@ function SystemPushImageProgress( is_ok, comment, pushop )
pushop.ctx.file1md5 = faultylabs.MD5( pushop.paddata ).toLowerCase();
var reader = new FileReader();
reader.onload = function(e) {
reader.onload = function(e) {
$("#innersystemflashtext").html( "Pusing second half..." );
PushImageTo( e.target.result, flash_scratchpad_at + 0x40000, SystemPushImageProgress, pushop.ctx );
}
@ -567,7 +682,7 @@ function SystemPushImageProgress( is_ok, comment, pushop )
var stf = "FM" + flash_scratchpad_at + "\t0\t" + f1s + "\t" + f1m + "\t" + (flash_scratchpad_at+0x40000) + "\t" + 0x40000 + "\t" + f2s + "\t" + f2m + "\n";
var fun = function( fsrd, flashresponse ) { $("#innerflashtext").html( (flashresponse[0] == '!')?"Flashing failed.":"Flash success." ) };
QueueOperation( stf, fun);
QueueOperation( stf, fun);
}
return false;
@ -578,7 +693,7 @@ function SystemPushImageProgress( is_ok, comment, pushop )
function WebPagePushImageFunction( ok, comment, pushop )
{
{
if( pushop.place == pushop.padlen )
{
$("#innersystemflashtext").html("Push complete. Reload page.");
@ -589,7 +704,7 @@ function WebPagePushImageFunction( ok, comment, pushop )
}
return true;
}
}
function DragDropSystemFiles( file )
{
@ -607,7 +722,7 @@ function DragDropSystemFiles( file )
var reader = new FileReader();
reader.onload = function(e) {
reader.onload = function(e) {
PushImageTo( e.target.result, mpfs_start_at, WebPagePushImageFunction );
}
@ -620,18 +735,19 @@ function DragDropSystemFiles( file )
for( var i = 0; i < file.length; i++ )
{
if( file[i].name.substr( 0, 7 ) == "0x00000" ) file1 = file[i];
if( file[i].name.substr( 0, 7 ) == "0x40000" ) file2 = file[i];
console.log( "Found: " + file[i].name );
if( file[i].name.substr( 0, 17 ) == "image.elf-0x00000" ) file1 = file[i];
if( file[i].name.substr( 0, 17 ) == "image.elf-0x40000" ) file2 = file[i];
}
if( !file1 )
{
$("#innersystemflashtext").html( "Could not find a 0x00000... file." ); return;
$("#innersystemflashtext").html( "Could not find a image.elf-0x00000... file." ); return;
}
if( !file2 )
{
$("#innersystemflashtext").html( "Could not find a 0x40000... file." ); return;
$("#innersystemflashtext").html( "Could not find a image.elf-0x40000... file." ); return;
}
if( file1.size > 65536 )
@ -650,7 +766,7 @@ function DragDropSystemFiles( file )
var reader = new FileReader();
reader.onload = function(e) {
reader.onload = function(e) {
var ctx = new Object();
ctx.file1 = file1;
ctx.file2 = file2;
@ -682,6 +798,15 @@ function tohex8( c )
}
function HexToIP( hexstr )
{
if( !hexstr ) return "";
return parseInt( hexstr.substr( 6, 2 ), 16 ) + "." +
parseInt( hexstr.substr( 4, 2 ), 16 ) + "." +
parseInt( hexstr.substr( 2, 2 ), 16 ) + "." +
parseInt( hexstr.substr( 0, 2 ), 16 );
}
function ContinueSystemFlash( fsrd, flashresponse, pushop )
{
if( flashresponse[0] == '!' )

View file

@ -7,7 +7,7 @@ LDFLAGS:= -s -Wl,--relax -Wl,-Map=test.map -Wl,--gc-sections -ffunction-section
embeddedcc : ../embeddedcommon/embeddednf.c ../embeddedcommon/DFT32.c embeddedcc.c ../embeddedcommon/embeddedout.c
gcc -o $@ $^ $(CFLAGS) $(LDFLAGS) -m32
gcc -o $@ $^ $(CFLAGS) $(LDFLAGS)
dummy_leds : dummy_leds.c
gcc -o $@ $^ -lX11 -lpthread $(CFLAGS) $(LDFLAGS)

View file

@ -11,6 +11,7 @@
#include <string.h>
#include <netinet/in.h>
#include <stdio.h>
#include <stdlib.h> // Added by [olel] for atoi
#include "embeddedout.h"
struct sockaddr_in servaddr;
@ -64,7 +65,7 @@ int main( int argc, char ** argv )
connect( sock, (struct sockaddr *)&servaddr, sizeof(servaddr) );
Init();
InitColorChord(); // Changed by [olel] cause this was changed in embeddednf
while( ( ci = getchar() ) != EOF )
{