|
OPTION CHARACTER BYTE
LET CHANNEL=1 !'モノラル
LET SAMPLEBIT=16 !'ビット数
LET HEADERSIZE=16
LET WAVETYPE=1
!'LET PATH$="C:\WINDOWS\TEMP\" !'作業用フォルダ、RAMディスクなど
LET SAMPLINGFREQ=16000 !'サンプリング周波数
LET TEMPO=80 !'テンポ
DO
READ IF MISSING THEN EXIT DO:A$,T$
LET PLAYTIME=PLAYTIME+LENGTH(T$) !'演奏時間(秒)
LOOP
LET SAMPLESIZE = SAMPLEBIT / 8 * CHANNEL
LET DATARATE = SAMPLESIZE * SAMPLINGFREQ
LET VOL=.5 !'音量
LET LEVEL=2^(SAMPLEBIT-1)*VOL
LET PCMSIZE=INT(DATARATE*PLAYTIME)
LET WAVEFILESIZE = PCMSIZE + 36
OPEN #1:NAME PATH$ & "故郷.wav"
ERASE #1
PRINT #1:"RIFF";
PRINT #1:MKL$(WAVEFILESIZE);
PRINT #1:"WAVEfmt ";
PRINT #1:MKL$(HEADERSIZE);
PRINT #1:MKI$(WAVETYPE);
PRINT #1:MKI$(CHANNEL);
PRINT #1:MKL$(SAMPLINGFREQ);
PRINT #1:MKL$(DATARATE);
PRINT #1:MKI$(SAMPLESIZE);
PRINT #1:MKI$(SAMPLEBIT);
PRINT #1:"data";
PRINT #1:MKL$(PCMSIZE);
RESTORE
DO
READ IF MISSING THEN EXIT DO:A$,T$
LET FREQ=GETFREQ(A$)
LET M=SAMPLINGFREQ*LENGTH(T$)-1 !'※Mが整数であること(非整数になる場合、再生エラーとなる可能性あり)
FOR J=0 TO M
LET X=J/M
LET ENVELOPE=1-X^6
LET DAT=LEVEL*SIN(J*FREQ/SAMPLINGFREQ*2*PI)*ENVELOPE
PRINT #1:MKI$(INT(DAT));
NEXT J
LOOP
DATA C,4,C,4,C,4,D,4.,E,8,D,4,E,4,E,4,F,4,G,2,R,4
DATA F,4,G,4,A,4,E,4.,F,8,E,4,D,4,D,4,-B,4,C,2,R,4
DATA D,8,C,8,D,4,-G,4,C,8,D,8,E,4,E,4,F,8,E,8,F,4.,A,8
DATA G,8,F,8,E,4,R,4,G,4,G,4,G,4,C,4.,D,8,E,4,F,4,F,4,D,4,C,2,R,4
CLOSE #1
PLAYSOUND PATH$ & "故郷.wav" !'再生
!'FILE DELETE PATH$ & "故郷.wav"
FUNCTION LENGTH(T$)
SELECT CASE T$
CASE "2" !'2分音符
LET LENGTH=60/TEMPO*2
CASE "2." !'付点2分音符
LET LENGTH=60/TEMPO*2+60/TEMPO
CASE "4" !'4分音符
LET LENGTH=60/TEMPO
CASE "4." !'付点4分音符
LET LENGTH=60/TEMPO+60/TEMPO/2
CASE "8"
LET LENGTH=60/TEMPO/2
CASE "8."
LET LENGTH=60/TEMPO/2+60/TEMPO/4
CASE "16"
LET LENGTH=60/TEMPO/4
END SELECT
END FUNCTION
END
EXTERNAL FUNCTION GETFREQ(KEY$) !'音名 → 周波数(Hz)
RESTORE
DO
READ K$,FREQ
IF KEY$=K$ THEN
LET GETFREQ=FREQ
EXIT FUNCTION
END IF
LOOP
DATA -C,130.813,-D,146.832,-E,164.814,-F,174.614,-G,195.998,-A,220,-B,246.942
DATA C,261.626,D,293.665,E,329.628,F,349.228,G,391.996,A,440,B,493.884
DATA +C,523.251,+D,587.33,+E,659.255,+F,698.456,+G,783.991,+A,880,R,0
END FUNCTION
EXTERNAL FUNCTION MKI$(A)
OPTION CHARACTER BYTE
DECLARE STRING A$,B$
IF A<0 THEN LET A=A+65536
LET A$=CHR$(MOD(A,256))
LET B$=CHR$(INT(A/256))
LET MKI$=A$ & B$
END FUNCTION
EXTERNAL FUNCTION MKL$(A)
OPTION CHARACTER BYTE
DECLARE STRING A$,B$,C$,D$
IF A<0 THEN LET A=A+2^32
LET A$=CHR$(MOD(A,256))
LET B$=CHR$(MOD(INT(A/256),256))
LET C$=CHR$(MOD(INT(A/65536),256))
LET D$=CHR$(MOD(INT(A/16777216),256))
LET MKL$=A$ & B$ & C$ & D$
END FUNCTION
|
|