Skip to content

Commit 5bfbb09

Browse files
markshannonntoll
authored andcommitted
SAM: Delete dead code and linux/windows specific code. Rename main to avoid symbol clash.
1 parent 0fc6eb9 commit 5bfbb09

File tree

2 files changed

+8
-164
lines changed

2 files changed

+8
-164
lines changed

source/lib/sam/main.c

Lines changed: 1 addition & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -7,45 +7,6 @@
77
#include "sam.h"
88
#include "debug.h"
99

10-
#ifdef USESDL
11-
#include <SDL.h>
12-
#include <SDL_audio.h>
13-
#endif
14-
15-
void WriteWav(char* filename, char* buffer, int bufferlength)
16-
{
17-
FILE *file = fopen(filename, "wb");
18-
if (file == NULL) return;
19-
//RIFF header
20-
fwrite("RIFF", 4, 1,file);
21-
unsigned int filesize=bufferlength + 12 + 16 + 8 - 8;
22-
fwrite(&filesize, 4, 1, file);
23-
fwrite("WAVE", 4, 1, file);
24-
25-
//format chunk
26-
fwrite("fmt ", 4, 1, file);
27-
unsigned int fmtlength = 16;
28-
fwrite(&fmtlength, 4, 1, file);
29-
unsigned short int format=1; //PCM
30-
fwrite(&format, 2, 1, file);
31-
unsigned short int channels=1;
32-
fwrite(&channels, 2, 1, file);
33-
unsigned int samplerate = 22050;
34-
fwrite(&samplerate, 4, 1, file);
35-
fwrite(&samplerate, 4, 1, file); // bytes/second
36-
unsigned short int blockalign = 1;
37-
fwrite(&blockalign, 2, 1, file);
38-
unsigned short int bitspersample=8;
39-
fwrite(&bitspersample, 2, 1, file);
40-
41-
//data chunk
42-
fwrite("data", 4, 1, file);
43-
fwrite(&bufferlength, 4, 1, file);
44-
fwrite(buffer, bufferlength, 1, file);
45-
46-
fclose(file);
47-
}
48-
4910
void PrintUsage()
5011
{
5112
printf("usage: sam [options] Word1 Word2 ....\n");
@@ -92,63 +53,9 @@ void PrintUsage()
9253
printf("Q kitt-en (glottal stop) /H a(h)ead \n");
9354
}
9455

95-
#ifdef USESDL
96-
97-
int pos = 0;
98-
void MixAudio(void *unused, Uint8 *stream, int len)
99-
{
100-
int bufferpos = GetBufferLength();
101-
char *buffer = GetBuffer();
102-
int i;
103-
if (pos >= bufferpos) return;
104-
if ((bufferpos-pos) < len) len = (bufferpos-pos);
105-
for(i=0; i<len; i++)
106-
{
107-
stream[i] = buffer[pos];
108-
pos++;
109-
}
110-
}
111-
112-
113-
void OutputSound()
114-
{
115-
int bufferpos = GetBufferLength();
116-
bufferpos /= 50;
117-
SDL_AudioSpec fmt;
118-
119-
fmt.freq = 22050;
120-
fmt.format = AUDIO_U8;
121-
fmt.channels = 1;
122-
fmt.samples = 2048;
123-
fmt.callback = MixAudio;
124-
fmt.userdata = NULL;
125-
126-
/* Open the audio device and start playing sound! */
127-
if ( SDL_OpenAudio(&fmt, NULL) < 0 )
128-
{
129-
printf("Unable to open audio: %s\n", SDL_GetError());
130-
exit(1);
131-
}
132-
SDL_PauseAudio(0);
133-
//SDL_Delay((bufferpos)/7);
134-
135-
while (pos < bufferpos)
136-
{
137-
SDL_Delay(100);
138-
}
139-
140-
SDL_CloseAudio();
141-
}
142-
143-
#else
144-
145-
void OutputSound() {}
146-
147-
#endif
148-
14956
int debug = 0;
15057

151-
int main(int argc, char **argv)
58+
int sam_main(int argc, char **argv)
15259
{
15360
int i;
15461
int phonetic = 0;
@@ -236,28 +143,13 @@ int main(int argc, char **argv)
236143
printf("phonetic input: %s\n", input);
237144
} else strncat(input, "\x9b", 256);
238145

239-
#ifdef USESDL
240-
if ( SDL_Init(SDL_INIT_AUDIO) < 0 )
241-
{
242-
printf("Unable to init SDL: %s\n", SDL_GetError());
243-
exit(1);
244-
}
245-
atexit(SDL_Quit);
246-
#endif
247-
248146
SetInput(input);
249147
if (!SAMMain())
250148
{
251149
PrintUsage();
252150
return 1;
253151
}
254152

255-
if (wavfilename != NULL)
256-
WriteWav(wavfilename, GetBuffer(), GetBufferLength()/50);
257-
else
258-
OutputSound();
259-
260-
261153
return 0;
262154

263155
}

source/lib/sam/render.c

Lines changed: 7 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,11 @@ unsigned char trans(unsigned char mem39212, unsigned char mem39213);
5151
extern int bufferpos;
5252
extern char *buffer;
5353

54-
54+
/** Scaling c64 rate to sample rate */
55+
// Rate for 22.05kHz
56+
// #define SCALE_RATE(x) (((x)*1310)>>16)
57+
// Rate for 7.8125KHz
58+
#define SCALE_RATE(x) (((x)*464)>>16)
5559

5660
//timetable for more accurate c64 simulation
5761
int timetable[5][5] =
@@ -71,7 +75,7 @@ void Output(int index, unsigned char A)
7175
oldtimetableindex = index;
7276
// write a little bit in advance
7377
for(k=0; k<5; k++)
74-
buffer[bufferpos/50 + k] = (A & 15)*16;
78+
buffer[SCALE_RATE(bufferpos) + k] = (A & 15)*16;
7579
}
7680

7781

@@ -869,59 +873,7 @@ if (debug)
869873
// the sample for the phoneme.
870874
RenderSample(&mem66);
871875
goto pos48159;
872-
} //while
873-
874-
875-
// The following code is never reached. It's left over from when
876-
// the voiced sample code was part of this loop, instead of part
877-
// of RenderSample();
878-
879-
//pos48315:
880-
int tempA;
881-
phase1 = A ^ 255;
882-
Y = mem66;
883-
do
884-
{
885-
//pos48321:
886-
887-
mem56 = 8;
888-
A = Read(mem47, Y);
889-
890-
//pos48327:
891-
do
892-
{
893-
//48327: ASL A
894-
//48328: BCC 48337
895-
tempA = A;
896-
A = A << 1;
897-
if ((tempA & 128) != 0)
898-
{
899-
X = 26;
900-
// mem[54296] = X;
901-
bufferpos += 150;
902-
buffer[bufferpos/50] = (X & 15)*16;
903-
} else
904-
{
905-
//mem[54296] = 6;
906-
X=6;
907-
bufferpos += 150;
908-
buffer[bufferpos/50] = (X & 15)*16;
909-
}
910-
911-
for(X = wait2; X>0; X--); //wait
912-
mem56--;
913-
} while(mem56 != 0);
914-
915-
Y++;
916-
phase1++;
917-
918-
} while (phase1 != 0);
919-
// if (phase1 != 0) goto pos48321;
920-
A = 1;
921-
mem44 = 1;
922-
mem66 = Y;
923-
Y = mem49;
924-
return;
876+
}
925877
}
926878

927879

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy