mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-10-14 10:37:38 -04:00
Code cleanup, fix warnings, error checking, add midi2wav to viewers.config
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@6304 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
19631f4552
commit
5811214b0c
8 changed files with 114 additions and 57 deletions
|
@ -94,6 +94,14 @@ struct GPatch * gusload(char * filename)
|
||||||
|
|
||||||
int file = rb->open(filename, O_RDONLY);
|
int file = rb->open(filename, O_RDONLY);
|
||||||
|
|
||||||
|
if(file == -1)
|
||||||
|
{
|
||||||
|
char message[50];
|
||||||
|
snprintf(message, 50, "Error opening %s", filename);
|
||||||
|
rb->splash(HZ*2, true, message);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
gp->header=readData(file, 12);
|
gp->header=readData(file, 12);
|
||||||
gp->gravisid=readData(file, 10);
|
gp->gravisid=readData(file, 10);
|
||||||
gp->desc=readData(file, 60);
|
gp->desc=readData(file, 60);
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
//This came from one of the Gravis documents
|
//This came from one of the Gravis documents
|
||||||
const static unsigned int gustable[]=
|
static const unsigned int gustable[]=
|
||||||
{
|
{
|
||||||
8175, 8661, 9177, 9722, 10300, 10913, 11562, 12249, 12978, 13750, 14567, 15433,
|
8175, 8661, 9177, 9722, 10300, 10913, 11562, 12249, 12978, 13750, 14567, 15433,
|
||||||
16351, 17323, 18354, 19445, 20601, 21826, 23124, 24499, 25956, 27500, 29135, 30867,
|
16351, 17323, 18354, 19445, 20601, 21826, 23124, 24499, 25956, 27500, 29135, 30867,
|
||||||
|
|
|
@ -185,7 +185,6 @@ struct Track * readTrack(int file)
|
||||||
trk->pos = 0;
|
trk->pos = 0;
|
||||||
trk->delta = 0;
|
trk->delta = 0;
|
||||||
|
|
||||||
int len=0;
|
|
||||||
int numEvents=0;
|
int numEvents=0;
|
||||||
|
|
||||||
int pos = rb->lseek(file, 0, SEEK_CUR);
|
int pos = rb->lseek(file, 0, SEEK_CUR);
|
||||||
|
@ -269,6 +268,8 @@ int readVarData(int file)
|
||||||
return(value);
|
return(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
//This function should not be needed because we
|
//This function should not be needed because we
|
||||||
//can just release the whole memory buffer at once
|
//can just release the whole memory buffer at once
|
||||||
void unloadFile(struct MIDIfile * mf)
|
void unloadFile(struct MIDIfile * mf)
|
||||||
|
@ -296,10 +297,10 @@ void unloadFile(struct MIDIfile * mf)
|
||||||
}
|
}
|
||||||
free(mf); //Unload the main struct
|
free(mf); //Unload the main struct
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
void bail(const char * err)
|
void bail(const char * err)
|
||||||
{
|
{
|
||||||
printf("\nERROR: %s\n", err);
|
rb->splash(HZ*3, true, err);
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,16 +40,18 @@
|
||||||
#define CTRL_PANNING 10
|
#define CTRL_PANNING 10
|
||||||
#define CHANNEL 1
|
#define CHANNEL 1
|
||||||
|
|
||||||
|
//Most of these are deprecated.. rampdown is used, maybe one other one too
|
||||||
#define STATE_ATTACK 1
|
#define STATE_ATTACK 1
|
||||||
#define STATE_DECAY 2
|
#define STATE_DECAY 2
|
||||||
#define STATE_SUSTAIN 3
|
#define STATE_SUSTAIN 3
|
||||||
#define STATE_RELEASE 4
|
#define STATE_RELEASE 4
|
||||||
#define STATE_RAMPDOWN 5
|
#define STATE_RAMPDOWN 5
|
||||||
|
|
||||||
|
//Loop states
|
||||||
#define STATE_LOOPING 7
|
#define STATE_LOOPING 7
|
||||||
#define STATE_NONLOOPING 8
|
#define STATE_NONLOOPING 8
|
||||||
|
|
||||||
|
//Various bits in the GUS mode byte
|
||||||
#define LOOP_ENABLED 4
|
#define LOOP_ENABLED 4
|
||||||
#define LOOP_PINGPONG 8
|
#define LOOP_PINGPONG 8
|
||||||
#define LOOP_REVERSE 16
|
#define LOOP_REVERSE 16
|
||||||
|
@ -65,7 +67,8 @@ unsigned char chVol[16]; //Channel volume
|
||||||
unsigned char chPanLeft[16]; //Channel panning
|
unsigned char chPanLeft[16]; //Channel panning
|
||||||
unsigned char chPanRight[16];
|
unsigned char chPanRight[16];
|
||||||
unsigned char chPat[16]; //Channel patch
|
unsigned char chPat[16]; //Channel patch
|
||||||
unsigned char chPW[16]; //Channel pitch wheel, MSB
|
unsigned char chPW[16]; //Channel pitch wheel, MSB only
|
||||||
|
|
||||||
|
|
||||||
struct GPatch * gusload(char *);
|
struct GPatch * gusload(char *);
|
||||||
struct GPatch * patchSet[128];
|
struct GPatch * patchSet[128];
|
||||||
|
@ -118,8 +121,19 @@ struct MIDIfile
|
||||||
int numPatches;
|
int numPatches;
|
||||||
};
|
};
|
||||||
|
|
||||||
void *my_malloc(int size);
|
|
||||||
|
|
||||||
|
|
||||||
|
void sendEvent(struct Event * ev);
|
||||||
|
int tick(struct MIDIfile * mf);
|
||||||
|
inline void setPoint(struct SynthObject * so, int pt);
|
||||||
|
struct Event * getEvent(struct Track * tr, int evNum);
|
||||||
|
int readTwoBytes(int file);
|
||||||
|
int readFourBytes(int file);
|
||||||
|
int readVarData(int file);
|
||||||
|
int midimain(void * filename);
|
||||||
|
|
||||||
|
|
||||||
|
//Rick's code
|
||||||
void *alloc(int size)
|
void *alloc(int size)
|
||||||
{
|
{
|
||||||
static char *offset = NULL;
|
static char *offset = NULL;
|
||||||
|
@ -143,7 +157,7 @@ void *alloc(int size)
|
||||||
totalSize -= size + 4;
|
totalSize -= size + 4;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
void *ralloc(char *offset, int len)
|
void *ralloc(char *offset, int len)
|
||||||
{
|
{
|
||||||
int size;
|
int size;
|
||||||
|
@ -175,18 +189,13 @@ void *ralloc(char *offset, int len)
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
void * allocate(int size)
|
void * allocate(int size)
|
||||||
{
|
{
|
||||||
return alloc(size);
|
return alloc(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
void sendEvent(struct Event * ev);
|
|
||||||
int tick(struct MIDIfile * mf);
|
|
||||||
inline void setPoint(struct SynthObject * so, int pt);
|
|
||||||
struct Event * getEvent(struct Track * tr, int evNum);
|
|
||||||
|
|
||||||
unsigned char readChar(int file)
|
unsigned char readChar(int file)
|
||||||
{
|
{
|
||||||
char buf[2];
|
char buf[2];
|
||||||
|
@ -211,11 +220,9 @@ int eof(int fd)
|
||||||
return size+1 == rb->lseek(fd, 0, SEEK_CUR);
|
return size+1 == rb->lseek(fd, 0, SEEK_CUR);
|
||||||
}
|
}
|
||||||
|
|
||||||
void printf(char *fmt, ...) {}
|
void printf(char *fmt, ...) {fmt=fmt; }
|
||||||
|
|
||||||
//#define my_malloc(a) malloc(a)
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
void *audio_bufferbase;
|
void *audio_bufferbase;
|
||||||
void *audio_bufferpointer;
|
void *audio_bufferpointer;
|
||||||
unsigned int audio_buffer_free;
|
unsigned int audio_buffer_free;
|
||||||
|
@ -252,11 +259,8 @@ void setmallocpos(void *pointer)
|
||||||
audio_bufferpointer = pointer;
|
audio_bufferpointer = pointer;
|
||||||
audio_buffer_free = audio_bufferpointer - audio_bufferbase;
|
audio_buffer_free = audio_bufferpointer - audio_bufferbase;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
void exit(int code)
|
void exit(int code)
|
||||||
{
|
{
|
||||||
}
|
code = code; //Stub function, kill warning for now
|
||||||
|
|
||||||
void free(void * ptr)
|
|
||||||
{
|
|
||||||
}
|
}
|
|
@ -242,7 +242,7 @@ void sendEvent(struct Event * ev)
|
||||||
int tick(struct MIDIfile * mf)
|
int tick(struct MIDIfile * mf)
|
||||||
{
|
{
|
||||||
if(mf==NULL)
|
if(mf==NULL)
|
||||||
return;
|
return 0;
|
||||||
|
|
||||||
int a=0;
|
int a=0;
|
||||||
int tracksAdv=0;
|
int tracksAdv=0;
|
||||||
|
|
|
@ -49,7 +49,7 @@ void readTextBlock(int file, char * buf)
|
||||||
|
|
||||||
//Filename is the name of the config file
|
//Filename is the name of the config file
|
||||||
//The MIDI file should have been loaded at this point
|
//The MIDI file should have been loaded at this point
|
||||||
void initSynth(struct MIDIfile * mf, char * filename, char * drumConfig)
|
int initSynth(struct MIDIfile * mf, char * filename, char * drumConfig)
|
||||||
{
|
{
|
||||||
char patchUsed[128];
|
char patchUsed[128];
|
||||||
char drumUsed[128];
|
char drumUsed[128];
|
||||||
|
@ -92,8 +92,8 @@ void initSynth(struct MIDIfile * mf, char * filename, char * drumConfig)
|
||||||
if(mf->tracks[a] == NULL)
|
if(mf->tracks[a] == NULL)
|
||||||
{
|
{
|
||||||
printf("\nNULL TRACK !!!");
|
printf("\nNULL TRACK !!!");
|
||||||
exit(1);
|
rb->splash(HZ*2, true, "Null Track in loader.");
|
||||||
return;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(ts=0; ts<mf->tracks[a]->numEvents; ts++)
|
for(ts=0; ts<mf->tracks[a]->numEvents; ts++)
|
||||||
|
@ -112,29 +112,43 @@ void initSynth(struct MIDIfile * mf, char * filename, char * drumConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
int file = rb->open(filename, O_RDONLY);
|
int file = rb->open(filename, O_RDONLY);
|
||||||
|
if(file == -1)
|
||||||
|
{
|
||||||
|
rb->splash(HZ*2, true, "Bad patch config.\nDid you install the patchset?");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
char name[30];
|
char name[40];
|
||||||
char fn[30];
|
char fn[40];
|
||||||
|
|
||||||
//Scan our config file and load the right patches as needed
|
//Scan our config file and load the right patches as needed
|
||||||
int c = 0;
|
int c = 0;
|
||||||
rb->snprintf(name, 30, "");
|
rb->snprintf(name, 40, "");
|
||||||
for(a=0; a<128; a++)
|
for(a=0; a<128; a++)
|
||||||
{
|
{
|
||||||
while(readChar(file)!=' ' && !eof(file));
|
while(readChar(file)!=' ' && !eof(file));
|
||||||
readTextBlock(file, name);
|
readTextBlock(file, name);
|
||||||
|
|
||||||
rb->snprintf(fn, 30, "/patchset/%s.pat", name);
|
rb->snprintf(fn, 40, "/.rockbox/patchset/%s.pat", name);
|
||||||
printf("\nLOADING: <%s> ", fn);
|
printf("\nLOADING: <%s> ", fn);
|
||||||
|
|
||||||
if(patchUsed[a]==1)
|
if(patchUsed[a]==1)
|
||||||
patchSet[a]=gusload(fn);
|
patchSet[a]=gusload(fn);
|
||||||
|
|
||||||
|
// if(patchSet[a] == NULL)
|
||||||
|
// return -1;
|
||||||
|
|
||||||
while((c != '\n'))
|
while((c != '\n'))
|
||||||
c = readChar(file);
|
c = readChar(file);
|
||||||
}
|
}
|
||||||
rb->close(file);
|
rb->close(file);
|
||||||
|
|
||||||
file = rb->open(drumConfig, O_RDONLY);
|
file = rb->open(drumConfig, O_RDONLY);
|
||||||
|
if(file == -1)
|
||||||
|
{
|
||||||
|
rb->splash(HZ*2, true, "Bad drum config.\nDid you install the patchset?");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
//Scan our config file and load the drum data
|
//Scan our config file and load the drum data
|
||||||
int idx=0;
|
int idx=0;
|
||||||
|
@ -143,7 +157,7 @@ void initSynth(struct MIDIfile * mf, char * filename, char * drumConfig)
|
||||||
{
|
{
|
||||||
readTextBlock(file, number);
|
readTextBlock(file, number);
|
||||||
readTextBlock(file, name);
|
readTextBlock(file, name);
|
||||||
rb->snprintf(fn, 30, "/patchset/%s.pat", name);
|
rb->snprintf(fn, 40, "/.rockbox/patchset/%s.pat", name);
|
||||||
|
|
||||||
idx = rb->atoi(number);
|
idx = rb->atoi(number);
|
||||||
if(idx == 0)
|
if(idx == 0)
|
||||||
|
@ -151,13 +165,15 @@ void initSynth(struct MIDIfile * mf, char * filename, char * drumConfig)
|
||||||
|
|
||||||
if(drumUsed[idx]==1)
|
if(drumUsed[idx]==1)
|
||||||
drumSet[idx]=gusload(fn);
|
drumSet[idx]=gusload(fn);
|
||||||
|
|
||||||
|
// if(drumSet[idx] == NULL)
|
||||||
|
// return -1;
|
||||||
|
|
||||||
while((c != '\n') && (c != 255) && (!eof(file)))
|
while((c != '\n') && (c != 255) && (!eof(file)))
|
||||||
{
|
|
||||||
printf("loop");
|
|
||||||
c = readChar(file);
|
c = readChar(file);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
rb->close(file);
|
rb->close(file);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -19,13 +19,17 @@
|
||||||
#define SAMPLE_RATE 48000
|
#define SAMPLE_RATE 48000
|
||||||
#define MAX_VOICES 100
|
#define MAX_VOICES 100
|
||||||
|
|
||||||
/* This is for writing to the DSP directly from the Simulator
|
/*
|
||||||
|
#if defined(SIMULATOR)
|
||||||
|
// This is for writing to the DSP directly from the Simulator
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <linux/soundcard.h>
|
#include <linux/soundcard.h>
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
|
#endif
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "../../plugin.h"
|
#include "../../plugin.h"
|
||||||
#include "midi/midiutil.c"
|
#include "midi/midiutil.c"
|
||||||
#include "midi/guspat.h"
|
#include "midi/guspat.h"
|
||||||
|
@ -47,23 +51,56 @@ struct plugin_api * rb;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
|
enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
|
||||||
{
|
{
|
||||||
|
TEST_PLUGIN_API(api);
|
||||||
|
rb = api;
|
||||||
TEST_PLUGIN_API(api);
|
TEST_PLUGIN_API(api);
|
||||||
(void)parameter;
|
(void)parameter;
|
||||||
rb = api;
|
rb = api;
|
||||||
rb->splash(HZ*2, true, "MIDI");
|
|
||||||
midimain();
|
if(parameter == NULL)
|
||||||
rb->splash(HZ*2, true, "FINISHED PLAYING");
|
{
|
||||||
|
rb->splash(HZ*2, true, " Play .MID file ");
|
||||||
|
return PLUGIN_OK;
|
||||||
|
}
|
||||||
|
rb->splash(HZ, true, parameter);
|
||||||
|
if(midimain(parameter) == -1)
|
||||||
|
{
|
||||||
|
return PLUGIN_ERROR;
|
||||||
|
}
|
||||||
|
rb->splash(HZ*3, true, "FINISHED PLAYING");
|
||||||
return PLUGIN_OK;
|
return PLUGIN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int midimain()
|
int midimain(void * filename)
|
||||||
{
|
{
|
||||||
rb->splash(HZ*2, true, "OPENED DSP");
|
|
||||||
|
printf("\nHello.\n");
|
||||||
|
|
||||||
|
rb->splash(HZ/5, true, "LOADING MIDI");
|
||||||
|
|
||||||
|
struct MIDIfile * mf = loadFile(filename);
|
||||||
|
long bpm, nsmp, l;
|
||||||
|
|
||||||
|
int bp=0;
|
||||||
|
|
||||||
|
rb->splash(HZ/5, true, "LOADING PATCHES");
|
||||||
|
if (initSynth(mf, "/.rockbox/patchset/patchset.cfg", "/.rockbox/patchset/drums.cfg") == -1)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
fd=rb->open("/dsp.raw", O_WRONLY|O_CREAT);
|
fd=rb->open("/dsp.raw", O_WRONLY|O_CREAT);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
//This lets you hear the music through the sound card if you are on Simulator
|
||||||
|
//Make a symlink, archos/dsp.raw and make it point to /dev/dsp or whatever
|
||||||
|
//your sound device is.
|
||||||
|
|
||||||
|
#if defined(SIMULATOR)
|
||||||
int arg, status;
|
int arg, status;
|
||||||
int bit, samp, ch;
|
int bit, samp, ch;
|
||||||
|
|
||||||
|
@ -82,24 +119,14 @@ int midimain()
|
||||||
status = ioctl(fd, SOUND_PCM_WRITE_RATE, &arg);
|
status = ioctl(fd, SOUND_PCM_WRITE_RATE, &arg);
|
||||||
status = ioctl(fd, SOUND_PCM_READ_RATE, &arg);
|
status = ioctl(fd, SOUND_PCM_READ_RATE, &arg);
|
||||||
samp=arg;
|
samp=arg;
|
||||||
|
#endif
|
||||||
*/
|
*/
|
||||||
|
|
||||||
printf("\nHello.\n");
|
|
||||||
// initSound(); //Open the computer's sound card
|
|
||||||
int a=0;
|
|
||||||
|
|
||||||
rb->splash(HZ*2, true, "LOADING MIDI");
|
rb->splash(HZ/5, true, " START PLAYING ");
|
||||||
|
|
||||||
struct MIDIfile * mf = loadFile("/test.mid");
|
|
||||||
|
|
||||||
rb->splash(HZ*2, true, "LOADED MIDI");
|
|
||||||
long bpm, nsmp, l;
|
|
||||||
|
|
||||||
int bp=0;
|
|
||||||
|
|
||||||
rb->splash(HZ*2, true, "LOADING PATCHES");
|
|
||||||
initSynth(mf, "/iriver2.cfg", "/drums.cfg"); //Initialize the MIDI syntehsizer
|
|
||||||
rb->splash(HZ*2, true, "START PLAYING");
|
|
||||||
|
|
||||||
signed char buf[3000];
|
signed char buf[3000];
|
||||||
|
|
||||||
|
|
|
@ -17,3 +17,4 @@ ogg,vorbis2wav.rock, 00 00 00 00 00 00
|
||||||
wv,wv2wav.rock, 00 00 00 00 00 00
|
wv,wv2wav.rock, 00 00 00 00 00 00
|
||||||
m3u,iriverify.rock,00 00 00 00 00 00
|
m3u,iriverify.rock,00 00 00 00 00 00
|
||||||
mpc,mpc2wav.rock, 00 00 00 00 00 00
|
mpc,mpc2wav.rock, 00 00 00 00 00 00
|
||||||
|
mid,midi2wav.rock, 01 20 30 40 50 60
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue