From: slack Date: Wed, 10 Jun 2009 16:57:13 +0000 (+0200) Subject: Switched from SDL typedefs to own, in order to avoid including the whole SDL.h everywhere X-Git-Url: http://slack.codemaniacs.com/git/?a=commitdiff_plain;h=a7a9805e9f1236f566dc18d97f071976354afec9;p=lolailo.git Switched from SDL typedefs to own, in order to avoid including the whole SDL.h everywhere --- diff --git a/mainwindow.cpp b/mainwindow.cpp index 0e168c1..35560da 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -10,7 +10,8 @@ MainWindow::MainWindow(QWidget *parent):QMainWindow(parent) tracker = new TrackerWindow(centralWindow); topLayout->addWidget(tracker); - + + resize(600,600); } MainWindow::~MainWindow() diff --git a/play.cpp b/play.cpp index 0bfae32..70e3229 100644 --- a/play.cpp +++ b/play.cpp @@ -1,8 +1,9 @@ #include "play.h" #include +#include -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 8d72d4c..3a04598 100644 --- a/play.h +++ b/play.h @@ -1,12 +1,12 @@ #ifndef PLAY_H #define PLAY_H -#include +#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 index 0000000..eb6508c --- /dev/null +++ b/sizedtypes.h @@ -0,0 +1,154 @@ +#ifndef SIZED_TYPES_H +#define SIZED_TYPES_H + +#include + + +// 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 1c27c97..fa4a42c 100644 --- a/synth.h +++ b/synth.h @@ -1,35 +1,38 @@ #ifndef SYNTH_H #define SYNTH_H -#include +#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];