Skip to content

Commit

Permalink
added WM_MO_ROUNDTEMPO option to test some issues, also made sure WHO…
Browse files Browse the repository at this point in the history
…LE/ROUNDTEMPO occured with first tempo setting, and added accumilated delta to devtest

git-svn-id: svn://svn.code.sf.net/p/wildmidi/svn/trunk@146 c49d981e-1564-41db-a9da-c6d570d03c1e
  • Loading branch information
Chris Ison committed Nov 19, 2011
1 parent 0ef7cc9 commit dd7b154
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 14 deletions.
2 changes: 1 addition & 1 deletion include/wildmidi_lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#define WM_MO_ENHANCED_RESAMPLING 0x0002
#define WM_MO_REVERB 0x0004
#define WM_MO_WHOLETEMPO 0x8000

#define WM_MO_ROUNDTEMPO 0xA000
#define WM_GS_VERSION 0x0001

struct _WM_Info {
Expand Down
51 changes: 40 additions & 11 deletions src/DevTest.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,14 +174,20 @@ test_midi(unsigned char * midi_data, unsigned long int midi_size, unsigned int v
unsigned int track_size;
unsigned char *next_track;
unsigned char event;
unsigned int delta;
unsigned int delta;
unsigned long int delta_accum;
unsigned int meta_length;
unsigned int no_tracks;
unsigned int i;
unsigned int divisions = 96;
unsigned char running_event;
unsigned char *sysex_store = NULL;
unsigned long int sysex_store_ofs = 0;
unsigned long int tempo = 500000;
float beats_per_minute = 0.0;
float microseconds_per_pulse = 0.0;
float pulses_per_second = 0.0;
float samples_per_delta_f = 0.0;

if (strncmp((char *) midi_data,"RIFF",4) == 0)
{
Expand Down Expand Up @@ -256,14 +262,24 @@ test_midi(unsigned char * midi_data, unsigned long int midi_size, unsigned int v
divisions = *midi_data++ << 8;
divisions |= *midi_data++;
midi_size -= 2;
if (verbose) printf("Divisions: %i\n", divisions);
if (verbose)
{
printf("Divisions: %i\n", divisions);

if (divisions & 0x00008000)
{
printf("Division Type Not Supported\n");
return -1;
if (divisions & 0x00008000)
{
printf("Division Type Not Supported\n");
return -1;
}

//Slow but needed for accuracy
beats_per_minute = 60000000.0 / (float)tempo;
microseconds_per_pulse = (float)tempo / (float)divisions;
pulses_per_second = 1000000.0 / microseconds_per_pulse;
samples_per_delta_f = 44100.0 / pulses_per_second;
if (verbose) printf("BPM: %f, SPD @ 44100: %f\n", beats_per_minute, samples_per_delta_f);

}

for (i = 0; i < no_tracks; i++)
{
if (midi_size < 8)
Expand Down Expand Up @@ -300,7 +316,8 @@ test_midi(unsigned char * midi_data, unsigned long int midi_size, unsigned int v
return -1;
}

next_track = midi_data + track_size;
next_track = midi_data + track_size;
delta_accum = 0;
while (midi_data < next_track) {
delta = 0;
while (*midi_data > 0x7F) {
Expand All @@ -318,8 +335,13 @@ test_midi(unsigned char * midi_data, unsigned long int midi_size, unsigned int v
printf ("Corrupt Midi, Missing or Corrupt Track Data\n");
return -1;
}
midi_size--;
if (verbose) printf("Delta: %i\n", delta);
midi_size--;
delta_accum += delta;
// tempo microseconds per quarter note
// divisions pulses per quarter note
//if (verbose) printf("Est Seconds: %f\n",(((float)tempo/(float)divisions*(float)delta_accum)/1000000.0));
if (verbose) printf("Delta: %i, Accumilated Delta: %i\n", delta, delta_accum);


if (*midi_data < 0x80) {
if (running_event == 0) {
Expand Down Expand Up @@ -532,7 +554,14 @@ test_midi(unsigned char * midi_data, unsigned long int midi_size, unsigned int v
if (midi_data[1] != 0x03) {
printf ("Corrupt Midi, Bad Tempo\n");
return -1;
}
}
tempo = (midi_data[2] << 16) | (midi_data[3] << 8) | midi_data[4];
beats_per_minute = 60000000.0 / (float)tempo;
microseconds_per_pulse = (float)tempo / (float)divisions;
pulses_per_second = 1000000.0 / microseconds_per_pulse;
samples_per_delta_f = 44100.0 / pulses_per_second;
if (verbose) printf("BPM: %f, SPD @ 44100: %f\n", beats_per_minute, samples_per_delta_f);

} else {
if (verbose) printf ("Meta Event: Unsupported (%i)\n", *midi_data);
}
Expand Down
7 changes: 6 additions & 1 deletion src/wildmidi.c
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,7 @@ static struct option const long_options[] = {
{"enhanced_resample",0,0,'e'},
{"auddev",1,0,'d'},
{"wholetempo",0,0,'w'},
{"roundtempo",0,0,'n'},
{NULL,0,NULL,0}
};

Expand All @@ -723,6 +724,7 @@ do_help (void) {
#endif
printf("MIDI Options\r\n");
printf(" -w --wholetempo round down tempo to whole number\r\n");
printf(" -n --roundtempo round tempo to nearest whole number\r\n");
printf("Software Wavetable Options\r\n");
printf(" -o W --wavout=W Saves the output to W in wav format\r\n");
printf(" at 44100Hz 16 bit stereo\r\n");
Expand Down Expand Up @@ -818,7 +820,7 @@ main (int argc, char **argv) {

do_version();
while (1) {
i = getopt_long (argc, argv, "vho:lr:c:m:btk:p:ed:i:w", long_options, &option_index);
i = getopt_long (argc, argv, "vho:lr:c:m:btk:p:ed:i:wn", long_options, &option_index);
if (i == -1)
break;
switch (i) {
Expand Down Expand Up @@ -868,6 +870,9 @@ main (int argc, char **argv) {
break;
case 'w': // whole number tempo
mixer_options |= WM_MO_WHOLETEMPO;
break;
case 'n': // whole number tempo
mixer_options |= WM_MO_ROUNDTEMPO;
break;
default:
printf ("Unknown Option -%o ??\r\n", i);
Expand Down
14 changes: 13 additions & 1 deletion src/wildmidi_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -2304,6 +2304,15 @@ WM_ParseNewMidi (unsigned char *midi_data, unsigned int midi_size)
return NULL;
}

if (WM_MixerOptions && WM_MO_WHOLETEMPO)
{
float bpm_f = 60000000.0 / (float)tempo;
tempo = 60000000 / (unsigned long int)bpm_f;
} else if (WM_MixerOptions && WM_MO_ROUNDTEMPO)
{
float bpm_fr = 60000000.0 / (float)tempo + 0.5;
tempo = 60000000 / (unsigned long int)bpm_fr;
}
{
//Slow but needed for accuracy
microseconds_per_pulse = (float)tempo / (float)divisions;
Expand Down Expand Up @@ -2404,7 +2413,6 @@ WM_ParseNewMidi (unsigned char *midi_data, unsigned int midi_size)
continue;
}
}

do {
if (*tracks[i] > 0x7F)
{
Expand Down Expand Up @@ -2538,6 +2546,10 @@ WM_ParseNewMidi (unsigned char *midi_data, unsigned int midi_size)
{
float bpm_f = 60000000.0 / (float)tempo;
tempo = 60000000 / (unsigned long int)bpm_f;
} else if (WM_MixerOptions && WM_MO_ROUNDTEMPO)
{
float bpm_fr = 60000000.0 / (float)tempo + 0.5;
tempo = 60000000 / (unsigned long int)bpm_fr;
}
{
//Slow but needed for accuracy
Expand Down

0 comments on commit dd7b154

Please sign in to comment.