TempleOSCD_140715.ISO

This commit is contained in:
Terry A. Davis authored and minexew committed 2018-09-08 21:46:09 +02:00
1 parent 7ef616a20e
commit 64f679eeb9
1095 files changed
+24814 -221011

No files matched your search

+11 -15
View File
@@ -1,6 +1,6 @@
#help_index "Snd/Math;Math"
public F64 Saw(F64 t,F64 period)
{ //0.0 - 1.0 think "(Sin+1)/2"
{//Sawtooth. 0.0 - 1.0 think "(Sin+1)/2"
if (period) {
if (t>=0.0)
return t%period/period;
@@ -11,7 +11,7 @@ public F64 Saw(F64 t,F64 period)
}
public F64 FullSaw(F64 t,F64 period)
{ //1.0 - -1.0 think "Sin"
{//Plus&Minus Sawtooth. 1.0 - -1.0 think "Sin"
if (period) {
if (t>=0.0)
return 2.0*(t%period/period)-1.0;
@@ -22,7 +22,7 @@ public F64 FullSaw(F64 t,F64 period)
}
public F64 Caw(F64 t,F64 period)
{ //1.0 - 0.0 think "(Cos+1)/2"
{//Cawtooth. 1.0 - 0.0 think "(Cos+1)/2"
if (period) {
if (t>=0.0)
return 1.0-t%period/period;
@@ -33,7 +33,7 @@ public F64 Caw(F64 t,F64 period)
}
public F64 FullCaw(F64 t,F64 period)
{ //1.0 - -1.0 think "Cos"
{//Plus&Minus Cawtooth. 1.0 - -1.0 think "Cos"
if (period) {
if (t>=0.0)
return -2.0*(t%period/period)+1.0;
@@ -44,7 +44,7 @@ public F64 FullCaw(F64 t,F64 period)
}
public F64 Tri(F64 t,F64 period)
{ //0.0 - 1.0 - 0.0
{//Triangle waveform. 0.0 - 1.0 - 0.0
if (period) {
t=2.0*(Abs(t)%period)/period;
if (t<=1.0)
@@ -55,9 +55,8 @@ public F64 Tri(F64 t,F64 period)
return 0.0;
}
public F64 FullTri(F64 t,F64 period)
{ //0.0 - 1.0 - 0.0 - -1.0 -0.0
{//Plus&Minus Triangle waveform. 0.0 - 1.0 - 0.0 - -1.0 -0.0
if (period) {
t=4.0*(t%period)/period;
if (t<=-1.0) {
@@ -79,14 +78,13 @@ public F64 FullTri(F64 t,F64 period)
#help_index "Snd/Math"
public F64 Note2Freq(I64 note,I64 octave=3)
{
{//Note number in octave to freq.
return 440.0*2.0`(octave-3+note/12.0);
}
F64 SinPhaseCont(F64 last_y,F64 last_dydt,
F64 current_amp,F64 phase_offset)
{
{//Next sample of sin waveform.
F64 phase;
phase=last_y/current_amp;
if (phase>1.0) phase=1.0;
@@ -100,7 +98,7 @@ F64 SinPhaseCont(F64 last_y,F64 last_dydt,
public CSndWaveCtrl *SndWaveCtrlNew(I64 sample_rate=8000,I64 sample_bits=24,
I64 channels=2,CTask *mem_task=NULL)
{
{//MAlloc ctrl struct for generating waveforms.
CSndWaveCtrl *swc=CAlloc(sizeof(CSndWaveCtrl),mem_task);
swc->freq_multiplier=1.0;
swc->amp_multiplier=1.0;
@@ -112,7 +110,7 @@ public CSndWaveCtrl *SndWaveCtrlNew(I64 sample_rate=8000,I64 sample_bits=24,
}
public U0 SndWaveCtrlDel(CSndWaveCtrl *swc)
{
{//Free waveform ctrl.
Free(swc);
}
@@ -126,7 +124,7 @@ public U0 SndWaveCtrlDel(CSndWaveCtrl *swc)
public U0 SndWaveAddBuf(CSndWaveCtrl *swc,U8 *buf,I64 num_samples,
F64 _freq,I64 _waveform=WF_SQUARE,F64 _amp=1.0,F64 _left=1.0, F64 _right=1.0)
{
{//Add waveform to buffer.
//num_samples is multiplied by channels to get buf_len.
//left,right range from 0.0-1.0
//Supports 16,24 and 32 bits
@@ -230,5 +228,3 @@ public U0 SndWaveAddBuf(CSndWaveCtrl *swc,U8 *buf,I64 num_samples,
swc->phase=phase;
}
}
#help_index "Snd"
+61 -61
View File
@@ -1,26 +1,31 @@
#help_index "Snd/Music"
U8 *cur_song=NULL;
CTask *cur_song_task=NULL;
I64 music_octave;
F64 music_note_len;
U8 music_note_map[7]={0,2,3,5,7,8,10};
I64 music_mute=0;
I64 music_meter_top,music_meter_bottom;
public F64 music_tempo,music_stacatto_factor;
//This is if you wish to sync with a
//note in a Play() string. 0 is the start
public I64 music_play_note_num=0;
public class CMusicGlbls
{
U8 *cur_song;
CTask *cur_song_task;
I64 octave;
F64 note_len;
U8 note_map[7];
Bool mute;
I64 meter_top,meter_bottom;
F64 tempo,stacatto_factor;
//If you wish to sync with a
//note in a Play() string. 0 is the start
I64 play_note_num;
F64 tM_correction,last_Beat,last_tM;
} music={NULL,NULL,3,1.0,{0,2,3,5,7,8,10},FALSE,4,4,2.5,0.9,0,0,0,0};
#help_index "Snd/Music;Time/Seconds"
F64 music_tM_correction=0,music_last_Beat=0,music_last_tM=0;
public F64 tM()
{
return (sys_jiffies+music_tM_correction)/JIFFY_FREQ;
{//Time in seconds synchronized to music subsystem.
return (cnts.jiffies+music.tM_correction)/JIFFY_FREQ;
}
public F64 Beat()
{ //Time in music beats
{//Time in music beats.
F64 result,cur_tM;
PUSHFD
CLI
@@ -28,11 +33,11 @@ public F64 Beat()
while (LBts(&sys_semas[SYS_SEMA_TMBEAT],0))
PAUSE
cur_tM=tM;
result=music_last_Beat;
if (music_tempo)
result+=(cur_tM-music_last_tM)*music_tempo;
music_last_tM=cur_tM;
music_last_Beat=result;
result=music.last_Beat;
if (music.tempo)
result+=(cur_tM-music.last_tM)*music.tempo;
music.last_tM=cur_tM;
music.last_Beat=result;
LBtr(&sys_semas[SYS_SEMA_TMBEAT],0);
POPFD
return result;
@@ -44,7 +49,7 @@ U8 *MusicSetOctave(U8 *st)
I64 ch;
ch=*st++;
while ('0'<=ch<='9') {
music_octave=ch-'0';
music.octave=ch-'0';
ch=*st++;
}
return --st;
@@ -57,13 +62,13 @@ U8 *MusicSetMeter(U8 *st)
while (ch=='M') {
ch=*st++;
if ('0'<=ch<='9') {
music_meter_top=ch-'0';
music.meter_top=ch-'0';
ch=*st++;
}
if (ch=='/')
ch=*st++;
if ('0'<=ch<='9') {
music_meter_bottom=ch-'0';
music.meter_bottom=ch-'0';
ch=*st++;
}
}
@@ -75,13 +80,13 @@ U8 *MusicSetNoteLen(U8 *st)
Bool cont=TRUE;
do {
switch (*st++) {
case 'w': music_note_len=4.0; break;
case 'h': music_note_len=2.0; break;
case 'q': music_note_len=1.0; break;
case 'e': music_note_len=0.5; break;
case 's': music_note_len=0.25; break;
case 't': music_note_len=2.0*music_note_len/3.0; break;
case '.': music_note_len=1.5*music_note_len; break;
case 'w': music.note_len=4.0; break;
case 'h': music.note_len=2.0; break;
case 'q': music.note_len=1.0; break;
case 'e': music.note_len=0.5; break;
case 's': music.note_len=0.25; break;
case 't': music.note_len=2.0*music.note_len/3.0; break;
case '.': music.note_len=1.5*music.note_len; break;
default:
st--;
cont=FALSE;
@@ -91,8 +96,7 @@ U8 *MusicSetNoteLen(U8 *st)
}
public U0 Play(U8 *st,U8 *words=NULL)
/*
Notes are entered with a capital letter.
{/* Notes are entered with a capital letter.
Octaves are entered with a digit and
stay set until changed.
@@ -108,30 +112,27 @@ public U0 Play(U8 *st,U8 *words=NULL)
'(' tie, placed before the note to be extended
$LK,"music_meter_top",A="MN:music_meter_top"$,$LK,"music_meter_bottom",A="MN:music_meter_bottom"$ is set with
$LK,"music.meter_top",A="MN:CMusicGlbls"$,$LK,"music.meter_bottom",A="MN:CMusicGlbls"$ is set with
"M3/4"
"M4/4"
etc.
Sharp and flat are done with '#' or 'b'.
The var music_stacatto_factor can
The var music.stacatto_factor can
be set to a range from 0.0 to 1.0.
The var music_tempo is quarter-notes
The var music.tempo is quarter-notes
per second. It defaults to
2.5 and gets faster when bigger.
*/
{
U8 *word,*last_st;
I64 note,i=0,timeout_val,timeout_val2;
Bool tie,old_preempt=Preempt(OFF);
F64 f,d,on_jiffies,off_jiffies;
music_play_note_num=0;
music.play_note_num=0;
while (*st) {
timeout_val=sys_jiffies;
timeout_val=cnts.jiffies;
tie=FALSE;
do {
@@ -149,7 +150,7 @@ public U0 Play(U8 *st,U8 *words=NULL)
if (!*st) break;
note=*st++-'A';
if (note<7) {
note=music_note_map[note];
note=music.note_map[note];
if (*st=='b') {
note--;
st++;
@@ -157,54 +158,54 @@ public U0 Play(U8 *st,U8 *words=NULL)
note++;
st++;
}
f=Note2Freq(note,music_octave);
f=Note2Freq(note,music.octave);
} else
f=0;
if (words && (word=LstSub(i++,words)) && StrCmp(word," "))
"%s",word;
d=JIFFY_FREQ*music_note_len/music_tempo;
d=JIFFY_FREQ*music.note_len/music.tempo;
if (tie) {
on_jiffies =d;
off_jiffies =0;
} else {
on_jiffies =d*music_stacatto_factor;
off_jiffies =d*(1.0-music_stacatto_factor);
on_jiffies =d*music.stacatto_factor;
off_jiffies =d*(1.0-music.stacatto_factor);
}
timeout_val+=on_jiffies;
timeout_val2=timeout_val+off_jiffies;
if (!music_mute)
if (!music.mute)
Snd(f);
SleepUntil(timeout_val);
music_tM_correction+=on_jiffies-ToI64(on_jiffies);
music.tM_correction+=on_jiffies-ToI64(on_jiffies);
if (!music_mute)
if (!music.mute)
Snd(0);
SleepUntil(timeout_val2);
music_tM_correction+=off_jiffies-ToI64(off_jiffies);
music.tM_correction+=off_jiffies-ToI64(off_jiffies);
music_play_note_num++;
music.play_note_num++;
}
Preempt(old_preempt);
}
U0 MusicSettingsRst()
{
music_play_note_num=0;
music_stacatto_factor=0.9;
music_tempo=2.5;
music_octave=3;
music_note_len=1.0;
music_meter_top=4;
music_meter_bottom=4;
music.play_note_num=0;
music.stacatto_factor=0.9;
music.tempo=2.5;
music.octave=3;
music.note_len=1.0;
music.meter_top=4;
music.meter_bottom=4;
PUSHFD
CLI
if (mp_cnt>1)
while (LBts(&sys_semas[SYS_SEMA_TMBEAT],0))
PAUSE
music_last_tM=tM;
music_last_Beat=0.0;
music.last_tM=tM;
music.last_Beat=0.0;
LBtr(&sys_semas[SYS_SEMA_TMBEAT],0);
POPFD
}
@@ -216,6 +217,5 @@ U0 CurSongTask()
Preempt(ON);
Fs->task_end_cb=&SndTaskEndCB;
while (TRUE)
Play(cur_song);
Play(music.cur_song);
}
#help_index "Snd"
+1 -3
View File
@@ -8,8 +8,7 @@ class CSndWaveCtrl
};
public U0 SndTaskEndCB()
//This will turn-off snd when a task gets killed.
{
{//Will turn-off snd when a task gets killed.
Snd(0);
Exit;
}
@@ -18,4 +17,3 @@ public U0 SndTaskEndCB()
#include "Music"
#include "SndEffects"
#include "SndFile"
#help_index ""
+9 -7
View File
@@ -1,3 +1,5 @@
#help_index "Snd"
#define SE_NOISE 0
#define SE_SWEEP 1
@@ -10,7 +12,7 @@ class CSoundEffectFrame
U0 SoundEffectEndTaskCB()
{
Free(FramePtr("CSoundEffectFrame"));
music_mute--;
music.mute--;
SndTaskEndCB;
}
@@ -26,7 +28,7 @@ U0 SoundEffectTask(CSoundEffectFrame *ns)
while (tS<timeout)
if (f=RandU16%i+ns->freq1) {
Snd(f);
Sleep(MaxI64(3000/f,1));
Sleep(ClampI64(3000/f,1,50));
} else
break;
break;
@@ -35,7 +37,7 @@ U0 SoundEffectTask(CSoundEffectFrame *ns)
t=(tS-t0)/ns->duration;
if (f=(1.0-t)*ns->freq1+t*ns->freq2) {
Snd(f);
Sleep(MaxI64(3000/f,1));
Sleep(ClampI64(3000/f,1,50));
} else
break;
}
@@ -44,7 +46,7 @@ U0 SoundEffectTask(CSoundEffectFrame *ns)
}
public CTask *Noise(I64 mS,F64 min_freq,F64 max_freq)
{
{//Make white noise for given number of mS.
CSoundEffectFrame *ns;
if (mS>0) {
ns=MAlloc(sizeof(CSoundEffectFrame));
@@ -52,14 +54,14 @@ public CTask *Noise(I64 mS,F64 min_freq,F64 max_freq)
ns->duration=mS/1000.0;
ns->freq1=min_freq;
ns->freq2=max_freq;
music_mute++;
music.mute++;
return Spawn(&SoundEffectTask,ns,"Noise",,Fs);
} else
return NULL;
}
public CTask *Sweep(I64 mS,F64 freq1,F64 freq2)
{
{//Sweep through freq range in given number of mS.
CSoundEffectFrame *ns;
if (mS>0) {
ns=MAlloc(sizeof(CSoundEffectFrame));
@@ -67,7 +69,7 @@ public CTask *Sweep(I64 mS,F64 freq1,F64 freq2)
ns->duration=mS/1000.0;
ns->freq1=freq1;
ns->freq2=freq2;
music_mute++;
music.mute++;
return Spawn(&SoundEffectTask,ns,"Noise",,Fs);
} else
return NULL;
+14 -19
View File
@@ -2,7 +2,7 @@
#define SNDFILE_SAMPLE_RATE 8000
//Header for a ".SND" file
class CFileSND
{ //big endian
{//big endian
U32 signature; //0x646e732e
U32 offset; //24
U32 data_size;
@@ -12,19 +12,16 @@ class CFileSND
I16 body[1];
};
//This is a windows media constraint.
//Windows media constraint.
//#define MAX_SND_FILE_DATA 0x0007FF00
#define MAX_SND_FILE_DATA 0x7FFFFF00
public I64 SndFileCreate(U8 *base_filename,F64 normalized_vol=1.0,F64 averaging=0.0,I64 waveform=WF_SQUARE,
F64 reverb_delay=0,F64 reverb_intensity=0)
//Use "snd_record" flag to start or stop
//recording, then call this routine.
{//Use "snd.record" flag to start or stop recording, then call this routine.
//Averaging should be a num from 0.0 to 0.999.
//Vol should be from 0.0 to 1.0.
//Set reverb_delay to like 0.3 sec and reverb_intensity to like 0.4.
{
I64 i,k,cnt,cnt2,level,file_num;
F64 avg,dt;
CFileSND *s;
@@ -32,12 +29,12 @@ public I64 SndFileCreate(U8 *base_filename,F64 normalized_vol=1.0,F64 averaging=
CSndData *d,*d1;
U8 *name,*name2;
snd_record=FALSE;
snd.record=FALSE;
dt=snd_record_root.last->time_stamp-snd_record_root.next->time_stamp;
dt=snd.record_root.last->time-snd.record_root.next->time;
if (!dt) return 0;
cnt=dt*SNDFILE_SAMPLE_RATE;
cnt++; //terminator
cnt++; //Terminator
name=StrNew(base_filename);
FileExtRem(name);
@@ -49,11 +46,11 @@ public I64 SndFileCreate(U8 *base_filename,F64 normalized_vol=1.0,F64 averaging=
s->sample_rate=EndianU32(SNDFILE_SAMPLE_RATE);
s->channels=EndianU32(1);
d=snd_record_root.next;
d=snd.record_root.next;
k=0;
while (d->next!=&snd_record_root) {
while (d->next!=&snd.record_root) {
d1=d->next;
dt=d1->time_stamp-d->time_stamp;
dt=d1->time-d->time;
cnt2=dt*SNDFILE_SAMPLE_RATE;
SndWaveAddBuf(swc,&s->body[k],cnt2,d->freq,waveform,normalized_vol);
k+=cnt2;
@@ -69,14 +66,14 @@ public I64 SndFileCreate(U8 *base_filename,F64 normalized_vol=1.0,F64 averaging=
s->body[i]=avg=LowPass1(averaging,avg,s->body[i],1.0);
}
//reverb
//Reverb
if (reverb_intensity) {
if (dt=reverb_delay*SNDFILE_SAMPLE_RATE)
for (i=dt;i<cnt;i++)
s->body[i]+=reverb_intensity*s->body[i-dt];
}
//Get rid of D.C. component
//Get rid of D.C. component
for (k=0;k<3;k++) {
level=0;
for (i=0;i<cnt-1;i++)
@@ -91,8 +88,8 @@ public I64 SndFileCreate(U8 *base_filename,F64 normalized_vol=1.0,F64 averaging=
s->body[cnt-1]=0;
d=snd_record_root.next;
while (d!=&snd_record_root) {
d=snd.record_root.next;
while (d!=&snd.record_root) {
d1=d->next;
QueRem(d);
Free(d);
@@ -108,7 +105,7 @@ public I64 SndFileCreate(U8 *base_filename,F64 normalized_vol=1.0,F64 averaging=
i=MAX_SND_FILE_DATA;
s->data_size=EndianU32(i*sizeof(I16));
MemCpy(s->body,&s->body[file_num*MAX_SND_FILE_DATA],i*sizeof(I16));
SPrint(name2,"%s%03d.SND",name,file_num++);
StrPrint(name2,"%s%03d.SND",name,file_num++);
FileWrite(name2,s,offset(CFileSND.body)+i*sizeof(I16));
cnt2-=i;
}
@@ -119,5 +116,3 @@ public I64 SndFileCreate(U8 *base_filename,F64 normalized_vol=1.0,F64 averaging=
SndWaveCtrlDel(swc);
return cnt;
}
#help_index ""