diff --git a/lib/include/rtbuf/glfw3.h b/lib/include/rtbuf/glfw3.h
index ddb1f81..a2199bc 100644
--- a/lib/include/rtbuf/glfw3.h
+++ b/lib/include/rtbuf/glfw3.h
@@ -20,13 +20,11 @@
#include <rtbuf/rtbuf.h>
#include <rtbuf/music.h>
-#pragma pack(push,1)
typedef struct rtbuf_glfw3_keyboard_data {
s_rtbuf_music_notes notes;
GLFWwindow *window;
unsigned int octave;
} s_rtbuf_glfw3_keyboard_data;
-#pragma pack(pop)
enum {
RTBUF_GLFW3_OSCILLOSCOPE_IN_BLACK,
@@ -36,10 +34,8 @@ enum {
RTBUF_GLFW3_OSCILLOSCOPE_INS
};
-#pragma pack(push,1)
typedef struct rtbuf_glfw3_oscilloscope_data {
GLFWwindow *window;
} s_rtbuf_glfw3_oscilloscope_data;
-#pragma pack(pop)
#endif
diff --git a/lib/include/rtbuf/music.h b/lib/include/rtbuf/music.h
index 91604c3..c370e37 100644
--- a/lib/include/rtbuf/music.h
+++ b/lib/include/rtbuf/music.h
@@ -26,14 +26,12 @@
#define RTBUF_MUSIC_NOTE_SIZE RTBUF_SIGNAL_SAMPLE_SIZE
#define RTBUF_MUSIC_NOTE_TYPE "music_note"
-#pragma pack(push,1)
typedef struct rtbuf_music_note {
t_rtbuf_signal_sample velocity; /* between 0.0 and 1.0 */
t_rtbuf_signal_sample freq; /* above 0.0 */
t_rtbuf_signal_sample start; /* time since start */
t_rtbuf_signal_sample stop; /* time since stop, or -1.0 */
} s_rtbuf_music_note;
-#pragma pack(pop)
#define RTBUF_MUSIC_NOTE_IN(note) \
{ note "velocity", RTBUF_SIGNAL_SAMPLE_TYPE, 1.0, 0.0, 1.0 }, \
@@ -69,12 +67,10 @@ enum {
#define RTBUF_MUSIC_NOTE_MAX 32
-#pragma pack(push,1)
typedef struct rtbuf_music_notes {
unsigned int note_n;
s_rtbuf_music_note note[RTBUF_MUSIC_NOTE_MAX];
} s_rtbuf_music_notes;
-#pragma pack(pop)
#define RTBUF_MUSIC_NOTES_SIZE sizeof(unsigned int)
#define RTBUF_MUSIC_NOTES_TYPE "music_notes"
diff --git a/lib/include/rtbuf/portaudio.h b/lib/include/rtbuf/portaudio.h
index 35dd846..74a7a61 100644
--- a/lib/include/rtbuf/portaudio.h
+++ b/lib/include/rtbuf/portaudio.h
@@ -32,12 +32,10 @@ enum {
typedef short t_rtbuf_portaudio_sample;
typedef t_rtbuf_portaudio_sample t_rtbuf_portaudio_samples[RTBUF_PORTAUDIO_SAMPLES];
-#pragma pack(push,1)
typedef struct rtbuf_portaudio_input_data {
t_rtbuf_signal signal[RTBUF_PORTAUDIO_CHANNELS];
t_rtbuf_portaudio_samples samples;
} s_rtbuf_portaudio_input_data;
-#pragma pack(pop)
int rtbuf_portaudio_input (s_rtbuf *rtb);
int rtbuf_portaudio_input_start (s_rtbuf *rtb);
@@ -47,12 +45,10 @@ typedef struct rtbuf_portaudio_output_reserved {
PaStream *stream;
} s_rtbuf_portaudio_output_reserved;
-#pragma pack(push,1)
typedef struct rtbuf_portaudio_output_data {
t_rtbuf_portaudio_samples samples;
s_rtbuf_portaudio_output_reserved reserved;
} s_rtbuf_portaudio_output_data;
-#pragma pack(pop)
#define RTBUF_PORTAUDIO_OUTPUT_RESERVED_SIZE \
sizeof(s_rtbuf_portaudio_output_reserved)
diff --git a/lib/include/rtbuf/reverb.h b/lib/include/rtbuf/reverb.h
index 7e7fad1..a2f9f1f 100644
--- a/lib/include/rtbuf/reverb.h
+++ b/lib/include/rtbuf/reverb.h
@@ -25,7 +25,6 @@
#define RTBUF_REVERB_FDN4_DELAY_SAMPLES_MAX \
RTBUF_SIGNAL_SAMPLERATE
-#pragma pack(push,1)
typedef struct rtbuf_reverb_fdn4_data {
t_rtbuf_signal signal;
t_rtbuf_signal_sample d0[RTBUF_REVERB_FDN4_DELAY_SAMPLES_MAX];
@@ -34,7 +33,6 @@ typedef struct rtbuf_reverb_fdn4_data {
t_rtbuf_signal_sample d3[RTBUF_REVERB_FDN4_DELAY_SAMPLES_MAX];
unsigned int pos;
} s_rtbuf_reverb_fdn4_data;
-#pragma pack(pop)
enum {
RTBUF_REVERB_FDN4_IN_SIGNAL = 0,
diff --git a/lib/include/rtbuf/signal.h b/lib/include/rtbuf/signal.h
index 784cb3a..cf2986b 100644
--- a/lib/include/rtbuf/signal.h
+++ b/lib/include/rtbuf/signal.h
@@ -61,7 +61,6 @@ const double g_rtbuf_signal_default_frequency;
/* butterworth bandpass filter, second order */
-#pragma pack(push,1)
typedef struct rtbuf_signal_bandpass2_data {
t_rtbuf_signal signal;
t_rtbuf_signal_sample x1;
@@ -73,7 +72,6 @@ typedef struct rtbuf_signal_bandpass2_data {
t_rtbuf_signal_sample y3;
t_rtbuf_signal_sample y4;
} s_rtbuf_signal_bandpass2_data;
-#pragma pack(pop)
enum {
RTBUF_SIGNAL_BANDPASS_IN_SIGNAL = 0,
@@ -91,13 +89,11 @@ int rtbuf_signal_bandpass2_start (s_rtbuf *rtb);
#define RTBUF_SIGNAL_DELAY_SAMPLES_MAX (RTBUF_SIGNAL_DELAY_MAX * \
RTBUF_SIGNAL_SAMPLERATE)
-#pragma pack(push,1)
typedef struct rtbuf_signal_delay_data {
t_rtbuf_signal signal;
t_rtbuf_signal_sample in[RTBUF_SIGNAL_DELAY_SAMPLES_MAX];
unsigned int pos;
} s_rtbuf_signal_delay_data;
-#pragma pack(pop)
enum {
RTBUF_SIGNAL_DELAY_IN_SIGNAL = 0,
@@ -111,7 +107,6 @@ int rtbuf_signal_delay_start (s_rtbuf *rtb);
/* butterworth second order 10 band equalizer */
-#pragma pack(push,1)
typedef struct rtbuf_signal_equalizer10_data {
t_rtbuf_signal signal;
t_rtbuf_signal signal32;
@@ -169,7 +164,6 @@ typedef struct rtbuf_signal_equalizer10_data {
t_rtbuf_signal_sample y9_3;
t_rtbuf_signal_sample y9_4;
} s_rtbuf_signal_equalizer10_data;
-#pragma pack(pop)
enum {
RTBUF_SIGNAL_EQUALIZER10_IN_SIGNAL = 0,
@@ -195,7 +189,6 @@ int rtbuf_signal_equalizer10_start (s_rtbuf *rtb);
#define RTBUF_SIGNAL_FLANGER_SAMPLES_MAX (RTBUF_SIGNAL_FLANGER_MAX * \
RTBUF_SIGNAL_SAMPLERATE)
-#pragma pack(push,1)
typedef struct rtbuf_signal_flanger_data {
t_rtbuf_signal signal;
double phase;
@@ -203,7 +196,6 @@ typedef struct rtbuf_signal_flanger_data {
unsigned int pos;
unsigned int ds;
} s_rtbuf_signal_flanger_data;
-#pragma pack(pop)
enum {
RTBUF_SIGNAL_FLANGER_IN_SIGNAL = 0,
@@ -219,13 +211,11 @@ int rtbuf_signal_flanger_start (s_rtbuf *rtb);
/* butterworth hipass filter, first order */
-#pragma pack(push,1)
typedef struct rtbuf_signal_hipass_data {
t_rtbuf_signal signal;
t_rtbuf_signal_sample x1;
t_rtbuf_signal_sample y1;
} s_rtbuf_signal_hipass_data;
-#pragma pack(pop)
enum {
RTBUF_SIGNAL_HIPASS_IN_SIGNAL = 0,
@@ -238,7 +228,6 @@ int rtbuf_signal_hipass_start (s_rtbuf *rtb);
/* butterworth hipass filter, second order */
-#pragma pack(push,1)
typedef struct rtbuf_signal_hipass2_data {
t_rtbuf_signal signal;
t_rtbuf_signal_sample x1;
@@ -246,14 +235,12 @@ typedef struct rtbuf_signal_hipass2_data {
t_rtbuf_signal_sample y1;
t_rtbuf_signal_sample y2;
} s_rtbuf_signal_hipass2_data;
-#pragma pack(pop)
int rtbuf_signal_hipass2 (s_rtbuf *rtb);
int rtbuf_signal_hipass2_start (s_rtbuf *rtb);
/* butterworth hipass filter, third order */
-#pragma pack(push,1)
typedef struct rtbuf_signal_hipass3_data {
t_rtbuf_signal signal;
t_rtbuf_signal_sample x1;
@@ -263,14 +250,12 @@ typedef struct rtbuf_signal_hipass3_data {
t_rtbuf_signal_sample y2;
t_rtbuf_signal_sample y3;
} s_rtbuf_signal_hipass3_data;
-#pragma pack(pop)
int rtbuf_signal_hipass3 (s_rtbuf *rtb);
int rtbuf_signal_hipass3_start (s_rtbuf *rtb);
/* butterworth hipass filter, fourth order */
-#pragma pack(push,1)
typedef struct rtbuf_signal_hipass4_data {
t_rtbuf_signal signal;
t_rtbuf_signal_sample x1;
@@ -282,14 +267,12 @@ typedef struct rtbuf_signal_hipass4_data {
t_rtbuf_signal_sample y3;
t_rtbuf_signal_sample y4;
} s_rtbuf_signal_hipass4_data;
-#pragma pack(pop)
int rtbuf_signal_hipass4 (s_rtbuf *rtb);
int rtbuf_signal_hipass4_start (s_rtbuf *rtb);
/* butterworth hipass filter, fifth order */
-#pragma pack(push,1)
typedef struct rtbuf_signal_hipass5_data {
t_rtbuf_signal signal;
t_rtbuf_signal_sample x1;
@@ -303,20 +286,17 @@ typedef struct rtbuf_signal_hipass5_data {
t_rtbuf_signal_sample y4;
t_rtbuf_signal_sample y5;
} s_rtbuf_signal_hipass5_data;
-#pragma pack(pop)
int rtbuf_signal_hipass5 (s_rtbuf *rtb);
int rtbuf_signal_hipass5_start (s_rtbuf *rtb);
/* butterworth lowpass filter, first order */
-#pragma pack(push,1)
typedef struct rtbuf_signal_lowpass_data {
t_rtbuf_signal signal;
t_rtbuf_signal_sample x1;
t_rtbuf_signal_sample y1;
} s_rtbuf_signal_lowpass_data;
-#pragma pack(pop)
enum {
RTBUF_SIGNAL_LOWPASS_IN_SIGNAL = 0,
@@ -329,7 +309,6 @@ int rtbuf_signal_lowpass_start (s_rtbuf *rtb);
/* butterworth lowpass filter, second order */
-#pragma pack(push,1)
typedef struct rtbuf_signal_lowpass2_data {
t_rtbuf_signal signal;
t_rtbuf_signal_sample x1;
@@ -337,14 +316,12 @@ typedef struct rtbuf_signal_lowpass2_data {
t_rtbuf_signal_sample y1;
t_rtbuf_signal_sample y2;
} s_rtbuf_signal_lowpass2_data;
-#pragma pack(pop)
int rtbuf_signal_lowpass2 (s_rtbuf *rtb);
int rtbuf_signal_lowpass2_start (s_rtbuf *rtb);
/* butterworth lowpass filter, third order */
-#pragma pack(push,1)
typedef struct rtbuf_signal_lowpass3_data {
t_rtbuf_signal signal;
t_rtbuf_signal_sample x1;
@@ -354,14 +331,12 @@ typedef struct rtbuf_signal_lowpass3_data {
t_rtbuf_signal_sample y2;
t_rtbuf_signal_sample y3;
} s_rtbuf_signal_lowpass3_data;
-#pragma pack(pop)
int rtbuf_signal_lowpass3 (s_rtbuf *rtb);
int rtbuf_signal_lowpass3_start (s_rtbuf *rtb);
/* butterworth lowpass filter, fourth order */
-#pragma pack(push,1)
typedef struct rtbuf_signal_lowpass4_data {
t_rtbuf_signal signal;
t_rtbuf_signal_sample x1;
@@ -373,14 +348,12 @@ typedef struct rtbuf_signal_lowpass4_data {
t_rtbuf_signal_sample y3;
t_rtbuf_signal_sample y4;
} s_rtbuf_signal_lowpass4_data;
-#pragma pack(pop)
int rtbuf_signal_lowpass4 (s_rtbuf *rtb);
int rtbuf_signal_lowpass4_start (s_rtbuf *rtb);
/* butterworth lowpass filter, fifth order */
-#pragma pack(push,1)
typedef struct rtbuf_signal_lowpass5_data {
t_rtbuf_signal signal;
t_rtbuf_signal_sample x1;
@@ -394,19 +367,16 @@ typedef struct rtbuf_signal_lowpass5_data {
t_rtbuf_signal_sample y4;
t_rtbuf_signal_sample y5;
} s_rtbuf_signal_lowpass5_data;
-#pragma pack(pop)
int rtbuf_signal_lowpass5 (s_rtbuf *rtb);
int rtbuf_signal_lowpass5_start (s_rtbuf *rtb);
/* sawtooth */
-#pragma pack(push,1)
typedef struct rtbuf_signal_sawtooth_data {
t_rtbuf_signal signal;
double phase;
} s_rtbuf_signal_sawtooth_data;
-#pragma pack(pop)
enum {
RTBUF_SIGNAL_SAWTOOTH_IN_FREQUENCY = 0,
@@ -419,12 +389,10 @@ int rtbuf_signal_sawtooth_start (s_rtbuf *rtb);
/* sinus */
-#pragma pack(push,1)
typedef struct rtbuf_signal_sinus_data {
t_rtbuf_signal signal;
double phase;
} s_rtbuf_signal_sinus_data;
-#pragma pack(pop)
enum {
RTBUF_SIGNAL_SINUS_IN_FREQUENCY = 0,
@@ -444,23 +412,14 @@ enum {
RTBUF_SIGNAL_SQUARE_IN_N
};
-#pragma pack(push,1)
typedef struct rtbuf_signal_square_data {
t_rtbuf_signal signal;
double phase;
} s_rtbuf_signal_square_data;
-#pragma pack(pop)
int rtbuf_signal_square (s_rtbuf *rtb);
int rtbuf_signal_square_start (s_rtbuf *rtb);
const double sqrt2_2;
-#ifndef M_SQRT2
-#define M_SQRT2 1.41421356237309504880
-#endif
-#ifndef M_PI
-#define M_PI 3.14159265358979323846
-#endif
-
#endif /* RTBUF_SIGNAL_H */
diff --git a/lib/include/rtbuf/synth.h b/lib/include/rtbuf/synth.h
index 2a8616a..1d6147e 100644
--- a/lib/include/rtbuf/synth.h
+++ b/lib/include/rtbuf/synth.h
@@ -39,12 +39,10 @@ enum {
RTBUF_SYNTH_ENVELOPE_STATE_ENDED
};
-#pragma pack(push,1)
typedef struct rtbuf_synth_adsr_data {
t_rtbuf_signal signal;
int state;
} s_rtbuf_synth_adsr_data;
-#pragma pack(pop)
int rtbuf_synth_adsr (s_rtbuf *rtb);
int rtbuf_synth_adsr_start (s_rtbuf *rtb);
@@ -65,13 +63,11 @@ enum {
#define RTBUF_SYNTH_SYNTH_IN_NOTE_OSCILLATOR(i) \
(RTBUF_SYNTH_SYNTH_IN_NOTE_0_OSCILLATOR + 2 * i)
-#pragma pack(push,1)
typedef struct rtbuf_synth_synth_data
{
t_rtbuf_signal signal;
unsigned int note_n;
} s_rtbuf_synth_synth_data;
-#pragma pack(pop)
int rtbuf_synth_synth (s_rtbuf *rtb);
int rtbuf_synth_synth_start (s_rtbuf *rtb);
diff --git a/librtbuf/rtbuf_lib.c b/librtbuf/rtbuf_lib.c
index bc9f3a9..3288b90 100644
--- a/librtbuf/rtbuf_lib.c
+++ b/librtbuf/rtbuf_lib.c
@@ -201,6 +201,20 @@ void rtbuf_lib_proc_in_init_proc (s_rtbuf_proc *proc,
proc->in_n = i;
}
+unsigned int add_padding (unsigned int offset, unsigned int size)
+{
+ unsigned int align = 1;
+ if (size == 2)
+ align = 2;
+ else if (size == 4)
+ align = 4;
+ else if (size == 8)
+ align = 8;
+ else if (size == 16)
+ align = 16;
+ return (offset + align - 1) / align * align;
+}
+
void rtbuf_lib_proc_out_init_proc (s_rtbuf_proc *proc,
s_rtbuf_lib_proc_out *out)
{
@@ -210,15 +224,19 @@ void rtbuf_lib_proc_out_init_proc (s_rtbuf_proc *proc,
unsigned int offset = 0;
while (out->name && i < RTBUF_PROC_OUT_MAX) {
s_rtbuf_proc_out *o = &proc->out[i];
+ size_t size;
o->name = symbol_intern(out->name);
o->type = rtbuf_type(out->type);
assert(o->type);
+ size = (o->type->t.bits + 7) / 8;
+ offset = add_padding(offset, size);
o->offset = offset;
- offset += (o->type->t.bits + 7) / 8;
+ offset += size;
out++;
i++;
}
assert(i < RTBUF_PROC_OUT_MAX);
+ offset = add_padding(offset, 8);
proc->out_bytes = offset;
proc->type.bits = offset * 8;
proc->type.type = DATA_TYPE_BITS;
diff --git a/librtbuf/rtbuf_type.c b/librtbuf/rtbuf_type.c
index c00904a..8bfb46c 100644
--- a/librtbuf/rtbuf_type.c
+++ b/librtbuf/rtbuf_type.c
@@ -106,7 +106,7 @@ s_rtbuf_type * rtbuf_type_parse_array (const char *name)
return 0;
buf[rb] = 0;
size = atoi(&buf[lb + 1]);
- return rtbuf_type_new(name, element_type->t.bits / 8 * size);
+ return rtbuf_type_new(name, (element_type->t.bits + 7) / 8 * size);
}
return 0;
}