Some fixes and cleanups (still doesn't work here).
git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@1757 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
@@ -17,6 +17,13 @@ endif
|
||||
CFLAGS += -DUSE_SDLAUDIO=1 $(shell fltk-config --cxxflags)
|
||||
LDFLAGS += $(shell fltk-config --ldflags)
|
||||
|
||||
CFLAGS += -W -Wall \
|
||||
-Wwrite-strings -Wimplicit -Wreturn-type -Wformat \
|
||||
-Wswitch -Wcomment -Wchar-subscripts \
|
||||
-Wparentheses -Wcast-align -Waggregate-return \
|
||||
-Winline
|
||||
# -Wcast-qual
|
||||
|
||||
# MacOS X apps need to have a resource fork applied, else the window
|
||||
# manager will refuse to manage them (which makes the app very
|
||||
# difficult to use) This rule should be ignored by all non-Mac
|
||||
|
||||
@@ -141,8 +141,6 @@ void fill_audio (void *u, Uint8 *stream, int len)
|
||||
void
|
||||
fill_audio (void *u, Uint8 *stream, int len)
|
||||
{
|
||||
Sint16 *b;
|
||||
int l, i;
|
||||
long amt_left;
|
||||
WAVESTRUCT *WaveData = (WAVESTRUCT *)u;
|
||||
|
||||
|
||||
+42
-34
@@ -31,9 +31,11 @@
|
||||
# include <io.h>
|
||||
# include <direct.h>
|
||||
# define MKDIR mkdir
|
||||
# define PATH_MAX _MAX_PATH
|
||||
#else
|
||||
# include <unistd.h>
|
||||
# define MKDIR(dir) mkdir((dir), 0777)
|
||||
# include <limits.h>
|
||||
#endif
|
||||
|
||||
#ifdef __linux__
|
||||
@@ -194,8 +196,6 @@ void StartPlayback ()
|
||||
}
|
||||
if (trackxtra->tracknum)
|
||||
{
|
||||
char *block;/* pointer to the block */
|
||||
unsigned long blockSize;/* holds the size of the block */
|
||||
char buf[80];
|
||||
AUDIOHDR audiohdr;
|
||||
trackxtra->paused = 0;
|
||||
@@ -264,7 +264,7 @@ void NextFrame ()
|
||||
StartPlayback();
|
||||
else {
|
||||
curtime = get_clock();
|
||||
printf ("Frame time: %d\n",curtime-trackxtra->time);
|
||||
printf ("Frame time: %lu\n",curtime-trackxtra->time);
|
||||
playing_clip = playing_clip->Next;
|
||||
playing_clip->time = curtime-trackxtra->time;
|
||||
synch->TextScreen->value(playing_clip->str);
|
||||
@@ -275,31 +275,33 @@ void NextFrame ()
|
||||
|
||||
}
|
||||
|
||||
void wrapstr (char *dst, char *src)
|
||||
void
|
||||
wrapstr (char *dst, const char *src)
|
||||
{
|
||||
int i,j,last=0;
|
||||
for (i = 0; i < strlen (src); i++) {
|
||||
size_t i,j,last=0;
|
||||
size_t src_len = strlen(src);
|
||||
for (i = 0; i < src_len; i++) {
|
||||
*dst++ = src[i];
|
||||
if (i == last) {
|
||||
if (i != 0) {
|
||||
if (i != 0)
|
||||
*dst++ = '\n';
|
||||
}
|
||||
last = strlen(src);
|
||||
for (j=i+1; j < strlen (src); j++) {
|
||||
|
||||
last = src_len;
|
||||
for (j=i+1; j < src_len; j++) {
|
||||
if (j -i > WRAP_LEN)
|
||||
break;
|
||||
if (src[j] == ' ') {
|
||||
if (src[j] == ' ')
|
||||
last = j;
|
||||
}
|
||||
}
|
||||
if (j == strlen (src))
|
||||
if (j == src_len)
|
||||
last = j;
|
||||
}
|
||||
}
|
||||
*dst = 0;
|
||||
}
|
||||
|
||||
void PauseFrame ()
|
||||
void
|
||||
PauseFrame ()
|
||||
{
|
||||
unsigned long curtime;
|
||||
if(trackxtra->paused)
|
||||
@@ -311,10 +313,11 @@ void PauseFrame ()
|
||||
trackxtra->paused = ! trackxtra->paused;
|
||||
}
|
||||
|
||||
void GetTracks (int value)
|
||||
void
|
||||
GetTracks (int value)
|
||||
{
|
||||
const char *race;
|
||||
char buf[80];
|
||||
char speechFileName[PATH_MAX];
|
||||
char str[MAX_LEN];
|
||||
int i = 0, read_data = 0;
|
||||
CLIPTXTDATA *curclip;
|
||||
@@ -323,15 +326,12 @@ void GetTracks (int value)
|
||||
race = races[value - 1];
|
||||
CleanUp();
|
||||
sprintf (path, "comm/%s", race);
|
||||
sprintf (buf, "%s/%s.txt",path, race);
|
||||
fh = fopen (buf, "r");
|
||||
sprintf (speechFileName, "%s/%s.txt", path, race);
|
||||
fh = fopen (speechFileName, "r");
|
||||
if (!fh) {
|
||||
char buf1[100];
|
||||
sprintf (buf1, "Could not find %s!",buf);
|
||||
fl_alert (buf1);
|
||||
fl_alert ("Could not find %s!", speechFileName);
|
||||
return;
|
||||
}
|
||||
char tmp[80];
|
||||
MKDIR ("timestamp");
|
||||
sprintf(savepath,"timestamp/%s",race);
|
||||
MKDIR (savepath);
|
||||
@@ -344,7 +344,8 @@ void GetTracks (int value)
|
||||
char *tmp;
|
||||
read_data = 0;
|
||||
tmp = strtok (str, "\t ");
|
||||
if ((tmp = strtok (NULL, "\t ")) != NULL)
|
||||
tmp = strtok (NULL, "\t ");
|
||||
if (tmp != NULL)
|
||||
{
|
||||
#ifdef SKIP_SINGLE_LINES
|
||||
if (i && racedata[i-1]->num_lines < 2) {
|
||||
@@ -353,7 +354,7 @@ void GetTracks (int value)
|
||||
}
|
||||
#endif
|
||||
if (i && ! racedata[i-1]->tracktime) {
|
||||
char buf[80];
|
||||
char buf[PATH_MAX];
|
||||
sprintf(buf,"%s/%s", path, racedata[i-1]->filename);
|
||||
racedata[i-1]->tracktime = get_ogg_runtime(buf);
|
||||
synch->TrackSelector->add (racedata[i-1]->filename);
|
||||
@@ -364,12 +365,13 @@ void GetTracks (int value)
|
||||
}
|
||||
i++;
|
||||
racedata[i-1] = new FILEDATA;
|
||||
strcpy (racedata[i-1]->filename, tmp);
|
||||
strncpy (racedata[i-1]->filename, tmp, PATH_MAX);
|
||||
racedata[i-1]->filename[PATH_MAX - 1] = '\0';
|
||||
curclip = NULL;
|
||||
read_data = 1;
|
||||
}
|
||||
}
|
||||
else if (read_data && strlen (str))
|
||||
else if (read_data && str[0] != '\0')
|
||||
{
|
||||
if (racedata[i-1]->clip == NULL) {
|
||||
racedata[i-1]->clip = new CLIPTXTDATA;
|
||||
@@ -393,7 +395,7 @@ void GetTracks (int value)
|
||||
}
|
||||
#endif
|
||||
if (i && ! racedata[i-1]->tracktime) {
|
||||
char buf[80];
|
||||
char buf[PATH_MAX];
|
||||
sprintf(buf,"%s/%s",path, racedata[i-1]->filename);
|
||||
racedata[i-1]->tracktime = get_ogg_runtime(buf);
|
||||
synch->TrackSelector->add (racedata[i-1]->filename);
|
||||
@@ -402,9 +404,8 @@ void GetTracks (int value)
|
||||
}
|
||||
|
||||
unsigned long
|
||||
get_ogg_runtime (char *filename) {
|
||||
get_ogg_runtime (const char *filename) {
|
||||
OggVorbis_File vf;
|
||||
vorbis_info *vi;
|
||||
FILE *fh;
|
||||
unsigned long runtime;
|
||||
double rt;
|
||||
@@ -420,12 +421,12 @@ get_ogg_runtime (char *filename) {
|
||||
printf("%s : %lu (%f)\n", filename, runtime, rt);
|
||||
return(runtime);
|
||||
}
|
||||
|
||||
int
|
||||
read_ogg (char *filename, AUDIOHDR *audiohdr) {
|
||||
read_ogg (const char *filename, AUDIOHDR *audiohdr) {
|
||||
OggVorbis_File vf;
|
||||
vorbis_info *vi;
|
||||
FILE *fh;
|
||||
char *wav;
|
||||
int current_section;
|
||||
|
||||
fh = fopen(filename, "rb");
|
||||
@@ -444,20 +445,23 @@ read_ogg (char *filename, AUDIOHDR *audiohdr) {
|
||||
{
|
||||
const unsigned int extra = 10000;
|
||||
unsigned int numsamples = extra + (unsigned int)ov_pcm_total(&vf,0);
|
||||
unsigned int numbytes = numsamples*vi->channels*2; // 16bit output wav
|
||||
unsigned int numbytes = numsamples * vi->channels * 2;
|
||||
// 16bit output wav
|
||||
char *wavptr;
|
||||
int eof = 0;
|
||||
unsigned long readbytes = 0;
|
||||
audiohdr->data = new char[numbytes];
|
||||
wavptr = audiohdr->data;
|
||||
while(!eof){
|
||||
long ret=ov_read(&vf,wavptr,numbytes-readbytes,0,2,1,¤t_section);
|
||||
long ret = ov_read(&vf, wavptr, numbytes - readbytes,
|
||||
0, 2, 1, ¤t_section);
|
||||
if (ret == 0) {
|
||||
eof = 1;
|
||||
} else if (ret > 0) {
|
||||
readbytes += ret;
|
||||
wavptr += ret;
|
||||
}
|
||||
// XXX - What if ret < 0 - SvdB
|
||||
}
|
||||
audiohdr->data_len = readbytes;
|
||||
}
|
||||
@@ -466,7 +470,8 @@ read_ogg (char *filename, AUDIOHDR *audiohdr) {
|
||||
return (0);
|
||||
}
|
||||
|
||||
unsigned long checksum(char *filename)
|
||||
unsigned long
|
||||
checksum(const char *filename)
|
||||
{
|
||||
int fh;
|
||||
unsigned long chk = 0, buf = 0;
|
||||
@@ -474,7 +479,10 @@ unsigned long checksum(char *filename)
|
||||
if (fh == -1)
|
||||
return 0;
|
||||
while (read(fh, &buf, sizeof(buf)) > 0)
|
||||
// XXX Not endianness-safe - SvdB
|
||||
chk = ((chk << 1) | (chk >> 31)) ^ buf;
|
||||
close(fh);
|
||||
return (chk);
|
||||
}
|
||||
|
||||
|
||||
|
||||
+4
-4
@@ -44,7 +44,7 @@ typedef struct CLIPTXTDATA {
|
||||
} CLIPTXTDATA;
|
||||
|
||||
typedef struct FILEDATA {
|
||||
char filename[20];
|
||||
char filename[PATH_MAX];
|
||||
int num_lines;
|
||||
long chksum;
|
||||
unsigned long tracktime;
|
||||
@@ -76,9 +76,9 @@ typedef struct XTRATRACKDATA {
|
||||
}
|
||||
} XTRATRACKDATA;
|
||||
|
||||
int read_ogg (char *filename, AUDIOHDR *audiohdr);
|
||||
unsigned long get_ogg_runtime (char *filename);
|
||||
unsigned long checksum(char *filename);
|
||||
int read_ogg (const char *filename, AUDIOHDR *audiohdr);
|
||||
unsigned long get_ogg_runtime (const char *filename);
|
||||
unsigned long checksum(const char *filename);
|
||||
|
||||
|
||||
unsigned long get_clock();
|
||||
|
||||
Reference in New Issue
Block a user