Switched from SDL typedefs to own, in order to avoid including the whole SDL.h everywhere
authorslack <slack@codemaniacs.com>
Wed, 10 Jun 2009 16:57:13 +0000 (18:57 +0200)
committerslack <slack@codemaniacs.com>
Wed, 10 Jun 2009 16:59:49 +0000 (18:59 +0200)
mainwindow.cpp
play.cpp
play.h
sizedtypes.h [new file with mode: 0644]
synth.h

index 0e168c109a129acdee9a03387dce47996d9ecdf0..35560da34b2d9835d07a7c583c23bd638ecb16ad 100644 (file)
@@ -10,7 +10,8 @@ MainWindow::MainWindow(QWidget *parent):QMainWindow(parent)
     
     tracker = new TrackerWindow(centralWindow);
     topLayout->addWidget(tracker);
-        
+
+    resize(600,600);
 }
 
 MainWindow::~MainWindow()
index 0bfae3244a4a5bac01ccd9af6fac83e2d1b3458a..70e3229e285775fb1d83040c9b7f494259dcaadb 100644 (file)
--- a/play.cpp
+++ b/play.cpp
@@ -1,8 +1,9 @@
 #include "play.h"
 
 #include <cstdio>
+#include <cstring>
 
-void play(void *songdata, Uint8* stream, int len)
+void play(void *songdata, uint8* stream, int len)
 {
     memset(stream, 0, len);
     //printf("Sound callback\n");
diff --git a/play.h b/play.h
index 8d72d4c2a31ee6ecedd5407dec4ec4d398c8b102..3a0459813270fcd0e79bec65adb9aaeee3407114 100644 (file)
--- a/play.h
+++ b/play.h
@@ -1,12 +1,12 @@
 #ifndef PLAY_H
 #define PLAY_H
 
-#include <SDL/SDL.h>
+#include "sizedtypes.h"
 
 struct Song
 {
 };
 
-void play(void *songdata, Uint8 *stream, int len);
+void play(void *songdata, uint8 *stream, int len);
 
 #endif // PLAY_H
diff --git a/sizedtypes.h b/sizedtypes.h
new file mode 100644 (file)
index 0000000..eb6508c
--- /dev/null
@@ -0,0 +1,154 @@
+#ifndef SIZED_TYPES_H
+#define SIZED_TYPES_H
+
+#include <limits.h>
+
+
+// NOTE: sizeof(char) <= sizeof(short) <= sizeof(int) 
+//               <= sizeof(long) <= sizeof(long long)
+// char  >= 8 bit
+// short >= 16 bit
+// long  >= 32 bit 
+
+// Define SIZEOF_CHAR 
+#if UCHAR_MAX == 0xff
+#define SIZEOF_CHAR 1
+#elif UCHAR_MAX == 0xffff
+#define SIZEOF_CHAR 2
+#elif UCHAR_MAX == 0xfffffffful
+#define SIZEOF_CHAR 4
+#elif UCHAR_MAX == 0xfffffffffffffffful
+#define SIZEOF_CHAR 8
+#endif // SIZEOF_CHAR
+
+// Define SIZEOF_SHORT
+#if USHRT_MAX == 0xffff
+#define SIZEOF_SHORT 2
+#elif USHRT_MAX == 0xfffffffful
+#define SIZEOF_SHORT 4
+#elif USHRT_MAX == 0xfffffffffffffffful
+#define SIZEOF_SHORT 8
+#endif // SIZEOF_SHORT
+
+// Define SIZEOF_INT
+#if UINT_MAX == 0xffff
+#define SIZEOF_INT 2
+#elif UINT_MAX == 0xfffffffful
+#define SIZEOF_INT 4
+#elif UINT_MAX == 0xfffffffffffffffful
+#define SIZEOF_INT 8
+#endif // SIZEOF_INT
+
+// Define SIZEOF_LONG
+#if ULONG_MAX == 0xfffffffful
+#define SIZEOF_LONG 4
+#elif ULONG_MAX == 0xfffffffffffffffful
+#define SIZEOF_LONG 8
+#endif // SIZEOF_LONG
+
+// Define SIZEOF_LONG_LONG
+#ifdef ULLONG_MAX
+#if ULLONG_MAX == 0xffffffffull
+#define SIZEOF_LONG_LONG 4
+#elif ULLONG_MAX == 0xffffffffffffffffull
+#define SIZEOF_LONG_LONG 8
+#endif
+#endif // SIZEOF_LONG_LONG
+#define COMPILE_TIME_ASSERT(name, x)               \
+              typedef int SIZED_dummy_ ## name[(x) * 2 - 1]
+
+
+// Define 8-bit types
+#if SIZEOF_CHAR == 1
+typedef unsigned char uint8;
+typedef signed char    int8;
+COMPILE_TIME_ASSERT(uint8, 1==sizeof(uint8));
+COMPILE_TIME_ASSERT(int8, 1==sizeof(int8));
+#define HAVE_INT8
+#define HAVE_UINT8
+#endif // short y siguientes tienen minimo 16 bits
+
+// Define 16-bit types
+#if SIZEOF_SHORT == 2
+typedef unsigned short uint16;
+typedef signed short    int16;
+COMPILE_TIME_ASSERT(uint16, 2==sizeof(uint16));
+COMPILE_TIME_ASSERT(int16, 2==sizeof(int16));
+#define HAVE_INT16
+#define HAVE_UINT16
+#endif
+
+// Define 32-bit types
+#if SIZEOF_SHORT == 4
+typedef unsigned short uint32;
+typedef signed short    int32;
+COMPILE_TIME_ASSERT(uint32, 4==sizeof(uint32));
+COMPILE_TIME_ASSERT(int32, 4==sizeof(int32));
+#define HAVE_INT32
+#define HAVE_UINT32
+#elif SIZEOF_INT == 4
+typedef unsigned int   uint32;
+typedef signed int      int32;
+COMPILE_TIME_ASSERT(uint32, 4==sizeof(uint32));
+COMPILE_TIME_ASSERT(int32, 4==sizeof(int32));
+#define HAVE_INT32
+#define HAVE_UINT32
+#elif SIZEOF_LONG == 4
+typedef unsigned long  uint32;
+typedef signed long     int32;
+COMPILE_TIME_ASSERT(uint32, 4==sizeof(uint32));
+COMPILE_TIME_ASSERT(int32, 4==sizeof(int32));
+#define HAVE_INT32
+#define HAVE_UINT32
+#elif SIZEOF_LONG_LONG == 4
+typedef unsigned long long uint32;
+typedef signed long long int32;
+COMPILE_TIME_ASSERT(uint32, 4==sizeof(uint32));
+COMPILE_TIME_ASSERT(int32, 4==sizeof(int32));
+#define HAVE_INT32
+#define HAVE_UINT32
+#endif
+
+// Define 64-bit types
+#if SIZEOF_SHORT == 8
+typedef unsigned short uint64;
+typedef signed short    int64;
+COMPILE_TIME_ASSERT(uint64, 8==sizeof(uint64));
+COMPILE_TIME_ASSERT(int64, 8==sizeof(int64));
+#define HAVE_INT64
+#define HAVE_UINT64
+#elif SIZEOF_INT == 8
+typedef unsigned int   uint64;
+typedef signed int      int64;
+COMPILE_TIME_ASSERT(uint64, 8==sizeof(uint64));
+COMPILE_TIME_ASSERT(int64, 8==sizeof(int64));
+#define HAVE_INT64
+#define HAVE_UINT64
+#elif SIZEOF_LONG == 8
+typedef unsigned long  uint64;
+typedef signed long     int64;
+COMPILE_TIME_ASSERT(uint64, 8==sizeof(uint64));
+COMPILE_TIME_ASSERT(int64, 8==sizeof(int64));
+#define HAVE_INT64
+#define HAVE_UINT64
+#elif SIZEOF_LONG_LONG == 8
+typedef unsigned long long uint64;
+typedef signed long long    int64;
+COMPILE_TIME_ASSERT(uint64, 8==sizeof(uint64));
+COMPILE_TIME_ASSERT(int64, 8==sizeof(int64));
+#define HAVE_INT64
+#define HAVE_UINT64
+#endif
+
+#ifndef HAVE_INT64
+#warning "LLONG_MAX not defined. Trying with long long for 64 bit integers."
+typedef unsigned long long uint64;
+typedef signed long long    int64;
+COMPILE_TIME_ASSERT(uint64, 8==sizeof(uint64));
+COMPILE_TIME_ASSERT(int64, 8==sizeof(int64));
+#define HAVE_INT64
+#define HAVE_UINT64
+#endif
+
+#endif // SIZED_TYPES_H
diff --git a/synth.h b/synth.h
index 1c27c975bb2ff610f4ad0194d7e75a73e34dc3ec..fa4a42c946792e40d55c740df1c587f41541d7ed 100644 (file)
--- a/synth.h
+++ b/synth.h
@@ -1,35 +1,38 @@
 #ifndef SYNTH_H
 #define SYNTH_H
 
-#include <SDL/SDL.h>
+#include "sizedtypes.h"
 
 #define BUFFER_SIZE 1024
 #define MAX_OPS 30
 
 /*
-    An instrument is defined a FORTH-like stack of several operations between waveforms,
-    possibly with parameters. For example:
+    An instrument is defined a FORTH-like stack of several operations between
+    waveforms, possibly with parameters. For example:
 
-    square_osc(wet=100%, pulse_width=50%) -> LP_filter(cutoff=4000 Hz, Q=0.1) -> Delay (5ms)
+    square_osc(wet=100%, pulse_width=50%) -> 
+    LP_filter(cutoff=4000 Hz, Q=0.1) -> 
+    Delay (5ms)
 
-    These operations are encoded as sequences of bytes. The first byte in the sequence selects the
-    operation, and the corresponding function reads as many parameter bytes as it needs, updating
-    the pointer. Any non-existant operation ends the sequence.
+    These operations are encoded as sequences of bytes. The first byte in the
+    sequence selects the operation, and the corresponding function reads as many
+    parameter bytes as it needs, updating the pointer. Any non-existant
+    operation ends the sequence.
 */
 
 struct Voice
 {
         float pitch;
         float vol;
-        Uint8 *ins;  // instrument definition
+        uint8 *ins;  // instrument definition
 
         int pos;     // position in samples since the start
-        Uint8 active;   // { 0 ==> inactive, (not 0) ==> active }
+        uint8 active;   // { 0 ==> inactive, (not 0) ==> active }
 
         // data buffer to store, for example, previous inputs/outputs for filtering.
         // 50 bytes should be enough for everyone. Anyway, voices will be created
         // at bss, so they don't count for the file size :)
-        Uint8 status[50];
+        uint8 status[50];
 
         // buffers generated by wave operations
         float waves[MAX_OPS][BUFFER_SIZE];