More work on PDBox by Wincent Balin. The PDBox plug-in is now working with the pdpod_...
[kugel-rb.git] / apps / plugins / pdbox / pdbox.h
blobe7587927dc206510575b0fcbf8072e4db2d84795
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2009 Wincent Balin
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 #ifndef PDBOX_H
23 #define PDBOX_H
25 /* Use dbestfit. */
26 #include "bmalloc.h"
27 #include "dmalloc.h"
29 /* Pure Data */
30 #include "m_pd.h"
33 /* dbestfit declarations. */
35 /* Minimal memory size. */
36 #define MIN_MEM_SIZE (4 * 1024 * 1024)
39 /* Audio declarations. */
40 #define PD_SAMPLERATE 22050
41 #define PD_SAMPLES_PER_HZ ((PD_SAMPLERATE / HZ) + \
42 (PD_SAMPLERATE % HZ > 0 ? 1 : 0))
43 #define PD_OUT_CHANNELS 2
45 /* Audio buffer part. Contains data for one HZ period. */
46 #ifdef SIMULATOR
47 #define AUDIOBUFSIZE (PD_SAMPLES_PER_HZ * PD_OUT_CHANNELS * 4)
48 #else
49 #define AUDIOBUFSIZE (PD_SAMPLES_PER_HZ * PD_OUT_CHANNELS)
50 #endif
51 struct audio_buffer
53 int16_t data[AUDIOBUFSIZE];
54 unsigned int fill;
58 /* Additional functions. */
59 char *rb_strncat(char *s, const char *t, size_t n);
60 double rb_strtod(const char*, char**);
61 double rb_atof(const char*);
62 void rb_ftoan(float, char*, int);
63 float rb_floor(float);
64 long rb_atol(const char* s);
65 float rb_sin(float rad);
66 float rb_cos(float rad);
67 int rb_fscanf_f(int fd, float* f);
68 int rb_fprintf_f(int fd, float f);
69 float rb_log10(float);
70 float rb_log(float);
71 float rb_exp(float);
72 float rb_pow(float, float);
73 float rb_sqrt(float);
74 float rb_fabs(float);
75 float rb_atan(float);
76 float rb_atan2(float, float);
77 float rb_sinh(float);
78 float rb_tan(float);
79 typedef struct
81 int quot;
82 int rem;
84 div_t;
85 div_t div(int x, int y);
86 void sys_findlibdir(const char* filename);
87 int sys_startgui(const char *guidir);
90 /* Network declarations. */
92 /* Maximal size of the datagram. */
93 #define MAX_DATAGRAM_SIZE 255
95 /* This structure replaces a UDP datagram. */
96 struct datagram
98 bool used;
99 uint8_t size;
100 char data[MAX_DATAGRAM_SIZE];
103 /* Prototypes of network functions. */
104 void net_init(void);
105 void net_destroy(void);
106 bool send_datagram(struct event_queue* route, int port,
107 char* data, size_t size);
108 bool receive_datagram(struct event_queue* route, int port,
109 struct datagram* buffer);
111 /* Network message queues. */
112 extern struct event_queue gui_to_core;
113 extern struct event_queue core_to_gui;
115 /* UDP ports of the original software. */
116 #define PD_CORE_PORT 3333
117 #define PD_GUI_PORT 3334
119 /* Convinience macros. */
120 #define SEND_TO_CORE(data) \
121 send_datagram(&gui_to_core, PD_CORE_PORT, data, strlen(data))
122 #define RECEIVE_TO_CORE(buffer) \
123 receive_datagram(&gui_to_core, PD_CORE_PORT, buffer)
124 #define SEND_FROM_CORE(data) \
125 send_datagram(&core_to_gui, PD_GUI_PORT, data, strlen(data))
126 #define RECEIVE_FROM_CORE(buffer) \
127 receive_datagram(&core_to_gui, PD_GUI_PORT, buffer)
129 /* PD core message callback. */
130 void rockbox_receive_callback(struct datagram* dg);
133 /* Pure Data declarations. */
135 /* Pure Data function prototypes. */
136 void pd_init(void);
139 /* Redefinitons of ANSI C functions. */
140 #include "lib/wrappers.h"
142 #define strncmp rb->strncmp
143 #define atoi rb->atoi
144 #define write rb->write
146 #define strncat rb_strncat
147 #define floor rb_floor
148 #define atof rb_atof
149 #define atol rb_atol
150 #define ftoan rb_ftoan
151 #define sin rb_sin
152 #define cos rb_cos
153 #define log10 rb_log10
154 #define log rb_log
155 #define exp rb_exp
156 #define pow rb_pow
157 #define sqrt rb_sqrt
158 #define fabs rb_fabs
159 #define atan rb_atan
160 #define atan2 rb_atan2
161 #define sinh rb_sinh
162 #define tan rb_tan
164 #endif