asoft_sound: can now generate BASIC program to play sounds

also have a mostly debugged still_alive sound file
This commit is contained in:
Vince Weaver 2017-01-05 13:04:25 -05:00
parent 1f3d1aace4
commit f525fd321c
3 changed files with 314 additions and 4 deletions

View File

@ -1,14 +1,236 @@
#include <stdio.h> #include <stdio.h>
#include <string.h>
static int line=0;
static int get_freq(int note, int octave, int flat, int sharp) {
if (octave==0) {
switch(note) {
case 'A':
if (sharp) return 143;
if (flat) return 161;
return 152;
case 'B':
if (flat) return 143;
return 135;
case 'C':
if (sharp) return 241;
return 255;
case 'D':
if (sharp) return 214;
if (flat) return 241;
return 227;
case 'E':
if (flat) return 214;
return 202;
case 'F':
if (sharp) return 180;
return 191;
case 'G':
if (sharp) return 161;
if (flat) return 180;
return 170;
default: fprintf(stderr,"Unknown note %c Line %d\n",
note,line);
}
} else
if (octave==1) {
switch(note) {
case 'A':
if (sharp) return 72;
if (flat) return 81;
return 76;
case 'B':
if (flat) return 72;
return 68;
case 'C':
if (sharp) return 121;
return 128;
case 'D':
if (sharp) return 108;
if (flat) return 121;
return 114;
case 'E':
if (flat) return 108;
return 102;
case 'F':
if (sharp) return 91;
return 96;
case 'G':
if (sharp) return 81;
if (flat) return 91;
return 85;
default: fprintf(stderr,"Unknown note %c\n",note);
}
} else
if (octave==2) {
switch(note) {
case 'A':
if (sharp) return 36;
if (flat) return 40;
return 38;
case 'B':
if (flat) return 36;
return 34;
case 'C':
if (sharp) return 60;
return 64;
case 'D':
if (sharp) return 54;
if (flat) return 60;
return 57;
case 'E':
if (flat) return 54;
return 51;
case 'F':
if (sharp) return 45;
return 48;
case 'G':
if (sharp) return 40;
if (flat) return 45;
return 43;
default: fprintf(stderr,"Unknown note %c\n",note);
}
} else {
fprintf(stderr,"Unknown octave %d!\n",octave);
}
return 0;
}
static int get_duration(int length) {
int d=0;
if (length==2) {
d=216;
} else if (length==4) {
d=108;
} else if (length==8) {
d=54;
} else if (length==16) {
d=27;
} else if (length==3) {
d=162;
} else {
fprintf(stderr,"Unknown duration %d Line %d\n",length,line);
}
return d;
}
static int get_rest(int length) {
int rest=0;
switch(length) {
case 1: rest=128; break;
case 2: rest=64; break;
case 4: rest=32; break;
case 8: rest=16; break;
case 16: rest=8; break;
default: fprintf(stderr,"Unknown rest length %d Line %d!\n",
length,line);
}
return rest*5;
}
int main(int argc, char **argv) { int main(int argc, char **argv) {
char string[BUFSIZ]; char string[BUFSIZ];
char *result; char *result;
int basic_line=100;
int i;
int length=8,last_length=0,duration;
int rest_length,sharp,flat;
int octave=1;
int freq;
int note;
/* Routine from http://eightbitsoundandfury.ld8.org/programming.html */
printf("50 FOR L = 770 TO 790: READ V: POKE L,V: NEXT L\n");
printf("51 DATA 173,48,192,136,208,5,206,1,3,240,9\n");
printf("52 DATA 202,208,245,174,0,3,76,2,3,96\n");
printf("53 GOTO 100\n");
printf("90 POKE 768,F:POKE 769,D:CALL 770:RETURN\n");
while(1) { while(1) {
result=fgets(string,BUFSIZ,stdin); result=fgets(string,BUFSIZ,stdin);
line++;
if (result==NULL) break; if (result==NULL) break;
printf("%s",result);
if (string[0]=='\'') continue;
i=0;
while(1) {
if (string[i]=='\n') break;
if (string[i]=='\0') break;
if ((string[i]==' ') || (string[i]=='\t')) {
i++;
continue;
}
if (string[i]=='<') {
octave--;
}
else if (string[i]=='>') {
octave++;
}
else if (string[i]=='L') {
i++;
length=string[i]-'0';
if ((length==1) && (string[i+1]=='6')) {
length=16;
i++;
}
}
else if (string[i]=='R') {
i++;
rest_length=get_rest(string[i]-'0');
printf("%d FOR I=1 TO %d: NEXT I\n",
basic_line,rest_length);
basic_line++;
}
else if ((string[i]>='A') && (string[i]<='G')) {
sharp=0; flat=0;
note=string[i];
if (string[i+1]=='#') {
sharp=1;
i++;
}
if (string[i+1]=='-') {
flat=1;
i++;
}
printf("%d ",basic_line);
if (length!=last_length) {
duration=get_duration(length);
printf("D=%d:",duration);
last_length=length;
}
freq=get_freq(note,octave,flat,sharp);
printf("F=%d:GOSUB 90\n",freq);
basic_line++;
}
else {
fprintf(stderr,"Unknown char %c\n",string[i]);
}
i++;
}
} }
return 0; return 0;

View File

@ -1,7 +1,7 @@
DOS33 = ../dos33fs-utils/dos33 DOS33 = ../dos33fs-utils/dos33
TXT2BAS = ../asoft_basic-utils/tokenize_asoft TXT2BAS = ../asoft_basic-utils/tokenize_asoft
SHAPETABLE = ../hgr-utils/shape_table SHAPETABLE = ../hgr-utils/shape_table
SOUNDCONVERT = ../asoft_sound/asoft_sound
all: glados33.dsk all: glados33.dsk
@ -17,11 +17,19 @@ shape_test.bas: objects.shape
SHAPE_TEST.BAS: shape_test.bas SHAPE_TEST.BAS: shape_test.bas
$(TXT2BAS) < shape_test.bas > SHAPE_TEST.BAS $(TXT2BAS) < shape_test.bas > SHAPE_TEST.BAS
glados33.dsk: STILL_ALIVE.BAS OBJECTS.SHAPE SHAPE_TEST.BAS sound_test.bas: still_alive.notes
$(SOUNDCONVERT) < still_alive.notes > sound_test.bas
SOUND_TEST.BAS: sound_test.bas
$(TXT2BAS) < sound_test.bas > SOUND_TEST.BAS
glados33.dsk: STILL_ALIVE.BAS OBJECTS.SHAPE SHAPE_TEST.BAS SOUND_TEST.BAS
$(DOS33) -y glados33.dsk SAVE A STILL_ALIVE.BAS $(DOS33) -y glados33.dsk SAVE A STILL_ALIVE.BAS
$(DOS33) -y glados33.dsk SAVE B OBJECTS.SHAPE $(DOS33) -y glados33.dsk SAVE B OBJECTS.SHAPE
$(DOS33) -y glados33.dsk SAVE A SHAPE_TEST.BAS $(DOS33) -y glados33.dsk SAVE A SHAPE_TEST.BAS
$(DOS33) -y glados33.dsk SAVE A SOUND_TEST.BAS
clean: clean:
rm -f *~ *.BAS *.SHAPE *.lst rm -f *~ *.BAS *.SHAPE sound_test.bas shape_test.bas *.lst

View File

@ -0,0 +1,80 @@
' This was a triumph
L8 G F# E E F# R8 R4 R2 R4 R8
' I'm making a note here, HUGE SUCCESS
L8 < A > G F# E L4 E L8 F# R4 L4 D L8 E < L4 A > R8 R4 R4 R8
' It's hard to overstate my satisfaction
'L8 < A > L4 E L8 F# G L4 G L8 F# C# C# L3 D L4 E L8 < A A A > L4 F# R8 R2 R2
L8 < A > L4 E L8 F# L3 G L8 F# L4 C# L3 D L4 E L8 < A L4 A> L4 F# R8 R2 R2
' Aperture Science
L8 G F# E E F# R8 R4 R2 R4 R8
' we do what we must because we can.
L8 < A > G F# E E R4 F# D R4 E < L3 A > R8 R4 R2
' for the good of all of us except the ones who are dead.
L4 E L8 F# L3 G L8 E L3 C# L8 D E R8 < A > D E F E D C R4
' But there's no sense crying over every mistake
L8 < A B- > L4 C F L8 E D D C D C L4 C C
' you just keep on trying till you run out of cake
L8 <A B- > L4 C F L8 G F E D D E L4 F F
' and the Science gets done and you make a neat gun
L8 G A B- B- L4 A G L8 F G A A L4 G F
' for the people who are still alive.
L8 D C L8 D F F L4 E L8 E F# L3 F# R4 R2 R1 R1 R4 R8
' I'm not even angry
' Note 8-16 and dotted 8
L8 < A > G F# E E F# R4 R2 R2
' I'm being so sincere right now
L8 G F# E L3 E L8 F# L4 D E < A > R8 R4 R2
' even though you broke my heart and killed me.
L4 E L8 F# L3 G L4 E C# L8 D L3 E L8 < A L4 A > L8 F# R4 R2 R4 R8
' and tore me to pieces
L8 < A > G F# E E F# R8 R4 R2 R4 R8
' L8 C# B A G G A R8 R4 R2 R4 R8
' and threw every piece into a fire
L8 < A > G F# E E R4 F# D R4 E < L4 A > R8 R4 R2
' As they burned it hurt because
L4 E F# L3 G L4 E C# L8 D E R8
' I was so happy for you
L8 < A > D E F E D C R4
' Now these points of data make a beautiful line
L8 < A B- > L4 C F L8 E D D C D C L4 C C
' and we're out of beta, we're releasing on time.
L8 < A B- > L4 C F L8 G F E D D E L4 F F
' So I'm GLaD. I got burned. Think of all the things we learned
L8 G A B- B- L4 A G L8 F G A A G F L4 F
' for the people who are still alive
L8 D C D F F L4 E L8 E F# L3 F# R8 R2 R1 R1 R2
' Go ahead and leave me
L8 G L16 F# F# L8 E L4 E L8 F# R4 R2 R4 R8
' I think I'd prefer to stay inside
L8 < A > L8 G F# E E R4 L8 F# D R4 L8 E L4 < A > R8 R4 R2
' Maybe you'll find someone else to help you.
L4 E L8 F# L3 G L4 E C# L8 D L3 E L8 < A L4 A> L8 F# R4 R2 R2
' Maybe Black Mesa
L8 G F# E L4 E L8 F# R4 R2 R2
' THAT WAS A JOKE, HA HA, FAT CHANCE
L8 G F# E E R4 F# D R4 E < L4 A > R8 R4 R2
' Anyway this cake is great, it's so delicious and moist.
L4 E L8 F# L3 G L4 E C# L8 D E R8 < A > D E F E D C R4
' Look at me still talking when there's Science to do
L8 < A B- > L4 C F L8 E D D C D L4 C C
' When I look out there is makes me GLaD I'm not you.
L8 < A B- > L4 C F L8 G F E D D E L4 F F
' I've experiments to run. There is research to be done.
L8 G A B- B- A G L4 G L8 F G A A G F L4 F
' On the people who are still alive.
L8 D C D F F L4 E L8 E F# L3 F# R4 R4
' And believe me I am still alive.
L8 A A B A F# L4 D L8 E F# L3 F# R4 R8
' I'm doing science and I'm still alive.
L8 A A A B A F# L4 D L8 E F# L3 F# R4 R8
' I feel FANTASTIC and I'm still alive.
L8 A A A B A F# L4 D L8 E F# L3 F# R4 R4
' While you're dying I'll be still aliave
L8 A A B A F# L4 D L8 E F# L3 F# R4 R8
' And when you're dead I will be still alive
L8 A A A B A F# L4 D L8 E F# L3 F# R4 R8
' STILL ALIVE
L8 G A L3 A R4 R8
' STILL ALIVE
L8 G F# L3 F# R4 R2