Index: apps/plugins/midi/midiutil.c
===================================================================
--- apps/plugins/midi/midiutil.c (Revision 30427)
+++ apps/plugins/midi/midiutil.c (Arbeitskopie)
@@ -28,12 +28,12 @@
int chPBDepth[16] IBSS_ATTR; /* Channel pitch bend depth */
int chPBNoteOffset[16] IBSS_ATTR; /* Pre-computed whole semitone offset */
int chPBFractBend[16] IBSS_ATTR; /* Fractional bend applied to delta */
-unsigned char chLastCtrlMSB[16]; /* MIDI regs, used for Controller 6. */
-unsigned char chLastCtrlLSB[16]; /* The non-registered ones are ignored */
+unsigned char chLastCtrlMSB[16] IBSS_ATTR; /* MIDI regs, used for Controller 6. */
+unsigned char chLastCtrlLSB[16] IBSS_ATTR; /* The non-registered ones are ignored */

struct GPatch * gusload(char *);
-struct GPatch * patchSet[128];
-struct GPatch * drumSet[128];
+struct GPatch * patchSet[128] IBSS_ATTR;
+struct GPatch * drumSet[128] IBSS_ATTR;

struct SynthObject voices[MAX_VOICES] IBSS_ATTR;

Index: apps/plugins/midi/guspat.c
===================================================================
--- apps/plugins/midi/guspat.c (Revision 30427)
+++ apps/plugins/midi/guspat.c (Arbeitskopie)
@@ -23,7 +23,7 @@
#include "midiutil.h"

/* This came from one of the Gravis documents */
-const uint32_t gustable[]=
+const uint32_t gustable[] ICONST_ATTR =
{
8175, 8661, 9177, 9722, 10300, 10913, 11562, 12249, 12978, 13750, 14567, 15433,
16351, 17323, 18354, 19445, 20601, 21826, 23124, 24499, 25956, 27500, 29135, 30867,
Index: apps/plugins/midi/midiutil.h
===================================================================
--- apps/plugins/midi/midiutil.h (Revision 30427)
+++ apps/plugins/midi/midiutil.h (Arbeitskopie)
@@ -26,30 +26,21 @@
#define BUF_SIZE 16384 /* 64 kB output buffers */
#define NBUF 2

+#define SAMPLE_RATE SAMPR_44 /* Always use 44.1 kHz to avoid aliasing effects */
+
#ifndef SIMULATOR

-#if (HW_SAMPR_CAPS & SAMPR_CAP_22) /* use 22050Hz if we can */
-#define SAMPLE_RATE SAMPR_22 /* 22050 */
-#else
-#define SAMPLE_RATE SAMPR_44 /* 44100 */
-#endif
+ #if (CONFIG_PLATFORM & PLATFORM_HOSTED)
+ #define MAX_VOICES 48
+ #else
+ #define MAX_VOICES 24 /* Note: 24 midi channels is the minimum general midi spec implementation */
+ #endif

-/* Some of the pp based targets can't handle too many voices
- mainly because they have to use 44100Hz sample rate, this could be
- improved to increase MAX_VOICES for targets that can do 22kHz */
-#ifdef CPU_PP
-#define MAX_VOICES 16
-#elif (CONFIG_PLATFORM & PLATFORM_HOSTED)
-#define MAX_VOICES 48
#else
-#define MAX_VOICES 24 /* Note: 24 midi channels is the minimum general midi spec implementation */
-#endif /* CPU_PP */
+
+ /* In sumulator we can afford to use more voices */
+ #define MAX_VOICES 48

-#else /* Simulator requires 44100Hz, and we can afford to use more voices */
-
-#define SAMPLE_RATE SAMPR_44
-#define MAX_VOICES 48
-
#endif

#define BYTE unsigned char
@@ -160,8 +151,8 @@
extern int chPat[16]; /* Channel patch */
extern int chPW[16]; /* Channel pitch wheel, MSB only */
extern int chPBDepth[16]; /* Channel pitch bend depth (Controller 6 */
-extern int chPBNoteOffset[16] IBSS_ATTR; /* Pre-computed whole semitone offset */
-extern int chPBFractBend[16] IBSS_ATTR; /* Fractional bend applied to delta */
+extern int chPBNoteOffset[16]; /* Pre-computed whole semitone offset */
+extern int chPBFractBend[16]; /* Fractional bend applied to delta */
extern unsigned char chLastCtrlMSB[16]; /* MIDI regs, used for Controller 6. */
extern unsigned char chLastCtrlLSB[16]; /* The non-registered ones are ignored */

Index: apps/plugins/midi/synth.c
===================================================================
--- apps/plugins/midi/synth.c (Revision 30427)
+++ apps/plugins/midi/synth.c (Arbeitskopie)
@@ -260,6 +260,21 @@
so->curOffset = 0;
}

+static inline void panSample(int32_t * out, int pan, int s1)
+{
+ if(LIKELY(pan == 64))
+ {
+ /* s2 = s1 = s1 * 64 */
+ *(out) += ((s1 << 16) & 0xFFFF0000) | ((s1) &0xFFFF);
+ }
+ else
+ {
+ int s2 = s1 * pan;
+ s1 = (s1 << 7) -s2;
+ *(out) += ((s1 << 9) & 0xFFFF0000) | ((s2 >> 7) &0xFFFF);
+ }
+}
+
static inline void synthVoice(struct SynthObject * so, int32_t * out, unsigned int samples)
{
struct GWaveform * wf;
@@ -299,9 +314,7 @@
so->isUsed = false;

s1 = so->decay;
- s2 = s1 * pan;
- s1 = (s1 << 7) -s2;
- *(out++) += ((s1 << 9) & 0xFFFF0000) | ((s2 >> 7) &0xFFFF);
+ panSample(out++, pan, s1);
continue;
}
} else /* OK to advance voice */
@@ -430,9 +443,7 @@
so->decay = 1; /* stupid junk.. */
}

- s2 = s1 * pan;
- s1 = (s1 << 7) - s2;
- *(out++) += ((s1 << 9) & 0xFFFF0000) | ((s2 >> 7) &0xFFFF);
+ panSample(out++, pan, s1);
}

/* store these again */
@@ -445,21 +456,22 @@
/* buffer to hold all the samples for the current tick, this is a hack
neccesary for coldfire targets as pcm_play_data uses the dma which cannot
access iram */
-int32_t samp_buf[512] IBSS_ATTR;
+#define SAMP_BUF_SIZE 1024
+static int32_t samp_buf[SAMP_BUF_SIZE] IBSS_ATTR;

/* synth num_samples samples and write them to the */
/* buffer pointed to by buf_ptr */
void synthSamples(int32_t *buf_ptr, unsigned int num_samples) ICODE_ATTR;
void synthSamples(int32_t *buf_ptr, unsigned int num_samples)
{
- if (UNLIKELY(num_samples > 512))
+ if (UNLIKELY(num_samples > SAMP_BUF_SIZE))
DEBUGF("num_samples is too big!\n");
else
{
int i;
struct SynthObject *voicept;

- rb->memset(samp_buf, 0, num_samples*4);
+ rb->memset(samp_buf, 0, num_samples*sizeof(int32_t));

for(i=0; i < MAX_VOICES; i++)
{
@@ -470,7 +482,7 @@
}
}

- rb->memcpy(buf_ptr, samp_buf, num_samples*4);
+ rb->memcpy(buf_ptr, samp_buf, num_samples*sizeof(int32_t));
}

/* TODO: Automatic Gain Control, anyone? */
Index: apps/plugins/midi/sequencer.c
===================================================================
--- apps/plugins/midi/sequencer.c (Revision 30427)
+++ apps/plugins/midi/sequencer.c (Arbeitskopie)
@@ -33,7 +33,7 @@
* I doubt anyone has made their own custom rockbox patchset
* (if you have, please send a copy my way :) )
*/
-static const unsigned char patchScale[]=
+static const unsigned char patchScale[] ICONST_ATTR =
{
125,115,115,100,100,80,115,100,100,100,100,80,100,100,100,100,
100,100,100,100,60,100,100,100,150,155,145,100,125,86,125,85,