|
無限音階(シェパードトーン)
音程が上がり続けるように聞こえる(かな?)
DIM FREQ(7)
MAT READ FREQ
!' ド レ ミ ファ ソ ラ シ
DATA 261.626,293.665,329.628,349.228,195.998,220,246.942 !'各音の周波数(Hz) ※ソ、ラ、シはオクターブ下
!'LET PATH$="C:\WINDOWS\TEMP\" !'作業用フォルダ、RAMディスクなど
LET CHANNEL=1 !'モノラル
LET SAMPLEBIT=16 !'ビット数(-32768~32767)
LET HEADERSIZE=16
LET WAVETYPE=1
LET SAMPLINGFREQ=22050 !'サンプリング周波数
LET SAMPLESIZE = SAMPLEBIT / 8 * CHANNEL
LET DATARATE = SAMPLESIZE * SAMPLINGFREQ
LET VOL=.5 !'音量
LET LEVEL=2^(SAMPLEBIT-1)*VOL
LET N=3 !'ドレミファ・・・の繰り返し回数
LET SECOND=.5 !'各音の継続時間(0.5秒)
LET PCMSIZE=INT(DATARATE*SECOND*7*N)
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);
FOR J=1 TO N
FOR I=1 TO 7
LET M=SAMPLINGFREQ*SECOND-1
FOR K=0 TO M
LET X=K/M
LET ENVELOPE=1-X^6
LET DAT=0
FOR L=1 TO 8
LET DAT=DAT+SIN(2^(L-3)*FREQ(I)*K/SAMPLINGFREQ*2*PI)/8
NEXT L
LET DAT=DAT*LEVEL*ENVELOPE
PRINT #1:MKI$(INT(DAT));
NEXT K
NEXT I
NEXT J
CLOSE #1
PLAYSOUND PATH$ & "無限音階.wav" !'再生
!'FILE DELETE PATH$ & "無限音階.wav"
END
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
|
|