Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Remove dependency on libmath

  • Loading branch information...
commit c01bb2f94495072abc73fd2ac609a7bb7842aba5 1 parent 0ab45bf
@sbourdeauducq sbourdeauducq authored
Showing with 126 additions and 7 deletions.
  1. +3 −6 src/Makefile
  2. +115 −0 src/sincos.c
  3. +7 −0 src/sincos.h
  4. +1 −1  src/tests_audio.c
View
9 src/Makefile
@@ -7,9 +7,9 @@ OBJECTS = crt0.o $(COBJS)
SEGMENTS= -j .text -j .data -j .rodata
LDFLAGS+= -T linker.ld -N
-LDFLAGS+= -L$(MMDIR)/software/libbase -L$(MMDIR)/software/libmath -L$(MMDIR)/software/libnet -L$(MMDIR)/software/libhal
-LDLIBS= -lbase -lmath -lnet -lhal
-LIBS=$(MMDIR)/software/libbase/libbase.a $(MMDIR)/software/libmath/libmath.a \
+LDFLAGS+= -L$(MMDIR)/software/libbase -L$(MMDIR)/software/libnet -L$(MMDIR)/software/libhal
+LDLIBS= -lbase -lnet -lhal
+LIBS=$(MMDIR)/software/libbase/libbase.a \
$(MMDIR)/software/libnet/libnet.a $(MMDIR)/software/libhal/libhal.a
CFLAGS+= -DVERSION='"$(GIT_VERSION)$(GIT_STATUS)"'
@@ -43,9 +43,6 @@ $(MMDIR)/software/libhal/libhal.a:
$(MMDIR)/software/libnet/libnet.a:
make -C $(MMDIR)/software/libnet/
-$(MMDIR)/software/libmath/libmath.a:
- make -C $(MMDIR)/software/libmath/
-
.PHONY: clean depend load boot.crc.bin $(LIBS)
boot.crc.bin: boot.bin
View
115 src/sincos.c
@@ -0,0 +1,115 @@
+/*
+ Copyright (C) 2001, 2002 Jesus Calvino-Fraga, jesusc@ieee.org
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+
+union float_long
+{
+ float f;
+ long l;
+};
+
+#define HALF_PI 1.5707963268
+#define iPI 0.3183098862
+#define EPS2 59.6046E-9
+
+/* fabsf: Returns the absolute value of a 32-bit float. */
+static float fabsf(const float x)
+{
+ union float_long fl;
+
+ fl.f = x;
+ fl.l &= 0x7fffffff;
+ return fl.f;
+}
+
+/*
+ sincosf: Computes sin or cos of a 32-bit float as outlined in
+ [1] William James Cody and W. M. Waite. _Software manual for the
+ elementary functions_, Englewood Cliffs, N.J.:Prentice-Hall, 1980.
+*/
+#define r1 (-0.1666665668E+0)
+#define r2 (0.8333025139E-2)
+#define r3 (-0.1980741872E-3)
+#define r4 (0.2601903036E-5)
+
+/* PI=C1+C2 */
+#define C1 3.140625
+#define C2 9.676535897E-4
+
+/*A reasonable value for YMAX is the int part of PI*B**(t/2)=3.1416*2**(12)*/
+#define YMAX 12867.0
+
+static float sincosf(float x, int iscos)
+{
+ float y, f, r, g, XN;
+ int N;
+ char sign;
+
+ if(iscos)
+ {
+ y=fabsf(x)+HALF_PI;
+ sign=0;
+ }
+ else
+ {
+ if(x<0.0)
+ { y=-x; sign=1; }
+ else
+ { y=x; sign=0; }
+ }
+
+ if(y>YMAX)
+ {
+ //errno=ERANGE;
+ return 0.0;
+ }
+
+ /*Round y/PI to the nearest integer*/
+ N=((y*iPI)+0.5); /*y is positive*/
+
+ /*If N is odd change sign*/
+ if(N&1) sign=!sign;
+
+ XN=N;
+ /*Cosine required? (is done here to keep accuracy)*/
+ if(iscos) XN-=0.5;
+
+ y=fabsf(x);
+ r=(int)y;
+ g=y-r;
+ f=((r-XN*C1)+g)-XN*C2;
+
+ g=f*f;
+ if(g>EPS2) //Used to be if(fabsf(f)>EPS)
+ {
+ r=(((r4*g+r3)*g+r2)*g+r1)*g;
+ f+=f*r;
+ }
+ return (sign?-f:f);
+}
+
+float sinf(float x)
+{
+ if (x==0.0) return 0.0;
+ return sincosf(x, 0);
+}
+
+float cosf(float x)
+{
+ if (x==0.0) return 1.0;
+ return sincosf(x, 1);
+}
View
7 src/sincos.h
@@ -0,0 +1,7 @@
+#ifndef __SINCOS_H
+#define __SINCOS_H
+
+float sinf(float x);
+float cosf(float x);
+
+#endif /* __SINCOS_H */
View
2  src/tests_audio.c
@@ -19,8 +19,8 @@
#include <hw/ac97.h>
#include <irq.h>
#include <stdio.h>
-#include <math.h>
#include <console.h>
+#include "sincos.h"
#include "testdefs.h"
static unsigned int snd_ac97_read(unsigned int addr)
Please sign in to comment.
Something went wrong with that request. Please try again.