Commit e8f615a2 authored by dave griffiths's avatar dave griffiths
Browse files

more fluxa

parent fe7fc19f
...@@ -548,8 +548,3 @@ ...@@ -548,8 +548,3 @@
(disassemble c)) (disassemble c))
code) code)
;;----------------------------------------------------------------
;; immediate mode (everyone loves immediate mode)
(define immediate-cube (with-state (hint-none) (build-cube)))
(define (draw-cube) (draw-instance immediate-cube))
; lz/nz ; lz/nz
(synth-init) (synth-init 10 44100)
(define (make-lz md d stk w h mem) (define (make-lz md d stk w h mem)
(vector md d stk w h mem)) (vector md d stk w h mem))
...@@ -30,10 +30,10 @@ ...@@ -30,10 +30,10 @@
(define (lz-pop! lz) (define (lz-pop! lz)
(when (> (lz-d lz) 0) (when (> (lz-d lz) 0)
(set-lz-d! lz (- (lz-d lz) 1))) (set-lz-d! lz (- (lz-d lz) 1)))
(let ((tmp (car (lz-stk lz)))) (let ((tmp (car (lz-stk lz))))
(when (not (eq? (length (lz-stk lz)) 1)) (when (not (eqv? (length (lz-stk lz)) 1))
(set-lz-stk! lz (cdr (lz-stk lz)))) (set-lz-stk! lz (cdr (lz-stk lz))))
tmp)) tmp))
(define (lz-push! lz item) (define (lz-push! lz item)
...@@ -54,7 +54,7 @@ ...@@ -54,7 +54,7 @@
(lz-inc-pos lz) (lz-inc-pos lz)
(when (>= (car (lz-top lz)) 8) (when (>= (car (lz-top lz)) 8)
(cond (cond
((eq? (length (lz-stk lz)) 1) ((eqv? (length (lz-stk lz)) 1)
(set-lz-top! lz (list 0 0))) (set-lz-top! lz (list 0 0)))
(else (else
(lz-pop! lz)))) (lz-pop! lz))))
...@@ -66,7 +66,7 @@ ...@@ -66,7 +66,7 @@
(cond (cond
((char=? data #\ ) ((char=? data #\ )
(cond (cond
((eq? (length (lz-stk lz)) 1) ((eqv? (length (lz-stk lz)) 1)
(set-lz-top! lz (list 0 0))) (set-lz-top! lz (list 0 0)))
(else (else
(lz-pop! lz)))) (lz-pop! lz))))
...@@ -105,11 +105,11 @@ ...@@ -105,11 +105,11 @@
(define (t) (ntp-time)) (define (t) (ntp-time))
(define (build-nz lz sz tk) (define (build-nz lz sz tk)
(make-nz lz '(60) 0 sz (ntp-time-add (t) 1) tk 1.0)) (make-nz lz '(60) 0 sz (ntp-time-add (t) 5) tk 1.0))
(define (nz-pop! nz) (define (nz-pop! nz)
(let ((tmp (car (nz-vals nz)))) (let ((tmp (car (nz-vals nz))))
(when (not (eq? (length (nz-vals nz)) 1)) (when (not (eqv? (length (nz-vals nz)) 1))
(set-nz-vals! nz (cdr (nz-vals nz)))) (set-nz-vals! nz (cdr (nz-vals nz))))
tmp)) tmp))
...@@ -147,53 +147,79 @@ ...@@ -147,53 +147,79 @@
(define l (build-lz 9 8 3)) (define l (build-lz 9 8 3))
(lz-prog l 0 "cCBca-aa") ;(lz-prog l 0 "cCBca-aa")
(lz-prog l 1 "c-d-c<.d") ;(lz-prog l 1 "c-d-c<.d")
(lz-prog l 2 "b++b+ACd") ;(lz-prog l 2 "b++b+ACd")
;(lz-prog l 0 "ccddddcd") ;(lz-prog l 0 "aB")
;(lz-prog l 1 "->d-AC-A") ;(lz-prog l 1 "-d>-AC-A")
;(lz-prog l 2 "b+b--bAB") ;(lz-prog l 2 "b+b--bAB")
(define z (build-nz l (lz-prog l 0 " B C")
(list (lz-prog l 1 "abCcb")
(list (lz-prog l 2 "ccBdb")
(lambda (v) (mul (adsr 0 0.01 0.1 1) (sine (add (mul 20 (sine 4)) (note v)))))
(lambda (v) (mul (adsr 0 0.1 0 0) (mul 0.2 (add (saw (* 1.5 (note v)))
(saw (note v))))))
(lambda (v) (mul (adsr 0 0.1 0 0) (define ss
(moogbp (squ (add 10 (mul 1000 (pow (adsr 0 0.2 0 0) 10)))) (list
(* v 0.1) 0.1))) (list
(lambda (v) (mul (adsr 0 0.02 0 0) (moogbp (white 4) (* v 0.01) 0.45)))) (lambda (v) (mul (adsr 0 0.01 0.1 1) (sine (add (mul 20 (sine 4)) (note v)))))
(list (lambda (v) (mul (adsr 0 0.1 0 0) (mul 0.2 (add (saw (* 1.5 (note v)))
(lambda (v) (mul (adsr 0 0.03 0.1 1) (mooghp (saw (* (note v) 0.5)) (saw (note v))))))
(mul 0.2 (adsr 0.5 0 0 0)) 0.45))) (lambda (v) (mul (adsr 0 0.1 0 0)
(lambda (v) (mul (adsr 0 0.1 0.1 1) (mooglp (add (saw (* 1.5 (note v))) (saw (note v))) (moogbp (squ (add 10 (mul 1000 (pow (adsr 0 0.2 0 0) 10))))
(* v 0.12) 0.4))) (* v 0.1) 0.1)))
(lambda (v) (mul (adsr 0 0.1 0 0) (sine (add (lambda (v) (mul (adsr 0 0.02 0 0) (moogbp (white 4) (* v 0.01) 0.45))))
(fmod (* v 50) 300) (list
(mul 1000 (pow (adsr 0 0.2 0 0) 10)))))) (lambda (v) (mul (adsr 0 0.03 0.1 1) (mooghp (saw (* (note v) 0.5))
(lambda (v) (mul (adsr 0.04 0.02 0 0) (mooglp (white 4) (* v 0.01) 0.45)))) (mul 0.2 (adsr 0.5 0 0 0)) 0.45)))
(list (lambda (v) (mul (adsr 0 0.1 0.1 1) (mooglp (add (saw (* 1.5 (note v))) (saw (note v)))
(lambda (v) (mul (adsr 0 0.03 0.1 1) (crush (sine (* (note v) 0.5)) (* v 0.12) 0.4)))
0.1 0.3))) (lambda (v) (mul (adsr 0 0.1 0 0) (sine (add
(lambda (v) (mul (adsr 0 0.03 0.1 1) (mooglp (white (* 0.125 (note v))) (fmod (* v 50) 300)
(fmod (* v 0.04) 1) 0.4))) (mul 1000 (pow (adsr 0 0.2 0 0) 10))))))
(lambda (v) (mul (adsr 0 0.1 0.1 0.5) (lambda (v) (mul (adsr 0.04 0.02 0 0) (mooglp (white 4) (* v 0.01) 0.45))))
(add (list
(saw (add (/ (note v) 4) (mul 1000 (pow (adsr 0.3 0.1 0 0) 3)))) (lambda (v) (mul (adsr 0.5 0.03 0.1 1) (crush (sine (* (note v) 0.5))
(saw (add (+ 1 (/ (note v) 4)) (mul 1000 (pow (adsr 0.1 0.1 0 0) 3))))))) 0.1 0.3)))
(lambda (v) (mul (adsr 0 0.02 0 0) (mooglp (white 4) (* v 0.01) 0.45))))) (lambda (v) (mul (adsr 0 0.03 0.1 1) (mooglp (white (* 0.125 (note v)))
0.1)) (fmod (* v 0.04) 1) 0.4)))
(lambda (v) (mul (adsr 0 0.1 0.1 0.5)
(add
(saw (add (/ (note v) 4) (mul 1000 (pow (adsr 0.3 0.1 0 0) 3))))
(saw (add (+ 1 (/ (note v) 4)) (mul 1000 (pow (adsr 0.1 0.1 0 0) 3)))))))
(define (loop) (lambda (v) (mul (adsr 0 0.02 0 0) (mooglp (white 4) (* v 0.01) 0.45)))))
(nz-tick z) )
(sleep 100)
(loop)) (define ss2
(list
;(play-now (sine 400) 0) (list
(lambda (v) (moogbp (mul (adsr 0 0.2 0.1 0.1) (pink 100)) (adsr 0 0.01 0.1 1) 0.3))
(loop) (lambda (v) (mul (adsr 0 0.01 0 1) (white 20)))
(lambda (v) (mul (adsr 0 0.1 0.1 1) (pink 50)))
(lambda (v) (mul (adsr 0 0.1 0.1 1) (sine (mul (adsr 0 0.1 0 0) 150)))))
(list
(lambda (v) (mul (adsr 0 0.01 0.1 1) (white (+ 440 (* v 20)))))
(lambda (v) (mul (adsr 0 0.01 0.1 1) (white (+ 240 (* v 20)))))
(lambda (v) (mul (adsr 0 0.01 0.1 1) (white (+ 140 (* v 20)))))
(lambda (v) (mul (adsr 0 0.01 0.1 1) (white (mul (adsr 0 0.1 0 0) (+ 40 (* v 50)))))))
(list
(lambda (v) (mul (adsr 0 0.01 0.1 1) (saw (+ 440 (* v 20)))))
(lambda (v) (mul (adsr 0 0.01 0.1 1) (saw (+ 240 (* v 20)))))
(lambda (v) (mul (adsr 0 0.01 0.1 1) (saw (+ 140 (* v 20)))))
(lambda (v) (mul (adsr 0 0.01 0.1 1) (saw (mul (adsr 0 0.1 0 0) (+ 40 (* v 50)))))))
(list
(lambda (v) (mul (adsr 0 0.01 0.1 1) (pink (+ 440 (* v 20)))))
(lambda (v) (mul (adsr 0 0.01 0.1 1) (pink (+ 240 (* v 20)))))
(lambda (v) (mul (adsr 0 0.01 0.1 1) (pink (+ 140 (* v 20)))))
(lambda (v) (mul (adsr 0 0.01 0.1 1) (pink (mul (adsr 0 0.1 0 0) (+ 40 (* v 50)))))))
))
(define z (build-nz l ss 0.2))
(every-frame (nz-tick z))
...@@ -3,10 +3,9 @@ ...@@ -3,10 +3,9 @@
(define time (ntp-time-add (ntp-time) 2)) (define time (ntp-time-add (ntp-time) 2))
(define (loop time m) (define (loop time m)
(when (< m 10) (when (< m 20)
(display time)(newline)
(play time (mul (adsr 0 0.1 0.3 1) (saw (+ 400 (* m 20)))) 0) (play time (mul (adsr 0 0.1 0.3 1) (saw (+ 400 (* m 20)))) 0)
(loop (ntp-time-add time 0.3) (+ m 1)))) (loop (ntp-time-add time 0.1) (+ m 1))))
(loop time 0) (loop time 0)
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
using namespace std; using namespace std;
alsa_device::alsa_device() { alsa_device::alsa_device(unsigned int sr) {
int i; int i;
int err; int err;
short buf[128]; short buf[128];
...@@ -17,9 +17,7 @@ alsa_device::alsa_device() { ...@@ -17,9 +17,7 @@ alsa_device::alsa_device() {
if ((err = snd_pcm_set_params(playback_handle, if ((err = snd_pcm_set_params(playback_handle,
SND_PCM_FORMAT_S16_LE, SND_PCM_FORMAT_S16_LE,
SND_PCM_ACCESS_RW_INTERLEAVED, SND_PCM_ACCESS_RW_INTERLEAVED,
2, 2,sr,1,
48000,
1,
500000)) < 0) { /* 0.5sec */ 500000)) < 0) { /* 0.5sec */
printf("Playback open error: %s\n", snd_strerror(err)); printf("Playback open error: %s\n", snd_strerror(err));
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
...@@ -31,8 +29,7 @@ alsa_device::~alsa_device() { ...@@ -31,8 +29,7 @@ alsa_device::~alsa_device() {
snd_pcm_close (playback_handle); snd_pcm_close (playback_handle);
} }
#define AUDIO_BUFSIZE 4096 #define AUDIO_BUFSIZE 4096*2
void audio_loop(void *c) { void audio_loop(void *c) {
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
class alsa_device { class alsa_device {
public: public:
alsa_device(); alsa_device(unsigned int sr);
~alsa_device(); ~alsa_device();
void start_crank(Graph *g); void start_crank(Graph *g);
......
...@@ -194,7 +194,7 @@ void Graph::Process(unsigned int bufsize, Sample &left, Sample &right) ...@@ -194,7 +194,7 @@ void Graph::Process(unsigned int bufsize, Sample &left, Sample &right)
pthread_mutex_lock(m_Mutex); pthread_mutex_lock(m_Mutex);
{ {
Time LastTime = m_CurrentTime; Time LastTime = m_CurrentTime;
m_CurrentTime.IncBySample(bufsize,48000); m_CurrentTime.IncBySample(bufsize,m_SampleRate);
// first check the event queue // first check the event queue
Event e; Event e;
...@@ -226,8 +226,8 @@ void Graph::Process(unsigned int bufsize, Sample &left, Sample &right) ...@@ -226,8 +226,8 @@ void Graph::Process(unsigned int bufsize, Sample &left, Sample &right)
if (pan<0) leftpan=1-pan; if (pan<0) leftpan=1-pan;
else rightpan=1+pan; else rightpan=1+pan;
left.MulMix(m_NodeMap[i->first]->GetOutput(),0.1*leftpan); left.MulMix(m_NodeMap[i->first]->GetOutput(),0.5*leftpan);
right.MulMix(m_NodeMap[i->first]->GetOutput(),0.1*rightpan); right.MulMix(m_NodeMap[i->first]->GetOutput(),0.5*rightpan);
} }
} }
...@@ -258,10 +258,10 @@ void Graph::Play(unsigned int seconds, unsigned int fraction, unsigned int id, f ...@@ -258,10 +258,10 @@ void Graph::Play(unsigned int seconds, unsigned int fraction, unsigned int id, f
} }
} else { } else {
cerr<<"Event arrived too late ignoring: "<<m_CurrentTime.GetDifference(e.TimeStamp)<<endl; cerr<<"Event arrived too late ignoring: "<<m_CurrentTime.GetDifference(e.TimeStamp)<<endl;
m_CurrentTime.Print(); //m_CurrentTime.Print();
e.TimeStamp=m_CurrentTime; //e.TimeStamp=m_CurrentTime;
e.TimeStamp+=0.1; //e.TimeStamp+=0.1;
m_EventQueue.Add(e); //m_EventQueue.Add(e);
} }
pthread_mutex_unlock(m_Mutex); pthread_mutex_unlock(m_Mutex);
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
using namespace std; using namespace std;
#define DEFAULT_BUFSIZE 4096 #define DEFAULT_BUFSIZE 4096*2
/////////////////////////////////////////// ///////////////////////////////////////////
......
...@@ -224,7 +224,8 @@ int main(int argc, char *argv[]) ...@@ -224,7 +224,8 @@ int main(int argc, char *argv[])
appEval((char*)LoadFile(string(ASSETS_PATH)+"init.scm").c_str()); appEval((char*)LoadFile(string(ASSETS_PATH)+"init.scm").c_str());
if (window) appEval((char*)LoadFile(string(ASSETS_PATH)+"boot.scm").c_str()); appEval((char*)LoadFile(string(ASSETS_PATH)+"boot.scm").c_str());
if (window) appEval((char*)LoadFile(string(ASSETS_PATH)+"fluxus.scm").c_str());
appEval((char*)LoadFile(string(ASSETS_PATH)+"lib.scm").c_str()); appEval((char*)LoadFile(string(ASSETS_PATH)+"lib.scm").c_str());
appEval((char*)LoadFile(string(ASSETS_PATH)+"compiler.scm").c_str()); appEval((char*)LoadFile(string(ASSETS_PATH)+"compiler.scm").c_str());
appEval((char*)LoadFile(string(ASSETS_PATH)+"fluxa.scm").c_str()); appEval((char*)LoadFile(string(ASSETS_PATH)+"fluxa.scm").c_str());
...@@ -267,10 +268,21 @@ int main(int argc, char *argv[]) ...@@ -267,10 +268,21 @@ int main(int argc, char *argv[])
//usleep(5*1000); //usleep(5*1000);
if (window) DisplayCallback(); if (window) DisplayCallback();
else {
if (!pthread_mutex_trylock(render_mutex)) {
appEval("(frame-hook)");
pthread_mutex_unlock(render_mutex);
}
}
usleep(1000);
} }
#else #else
if (window) glutMainLoop(); if (window) glutMainLoop();
else while(true) { sleep(1); } else while(true)
{
appEval("(frame-hook)");
usleep(1000);
}
#endif #endif
return 0; return 0;
......
...@@ -206,7 +206,7 @@ ...@@ -206,7 +206,7 @@
_OP_DEF(opexe_6, "id-map-add", 2, 2, TST_NONE, OP_ID_MAP_ADD ) _OP_DEF(opexe_6, "id-map-add", 2, 2, TST_NONE, OP_ID_MAP_ADD )
_OP_DEF(opexe_6, "id-map-get", 1, 1, TST_NONE, OP_ID_MAP_GET ) _OP_DEF(opexe_6, "id-map-get", 1, 1, TST_NONE, OP_ID_MAP_GET )
_OP_DEF(opexe_6, "synth-init", 0, 0, 0, OP_SYNTH_INIT ) _OP_DEF(opexe_6, "synth-init", 2, 2, 0, OP_SYNTH_INIT )
_OP_DEF(opexe_6, "synth-create", 3, 3, 0, OP_SYNTH_CRT ) _OP_DEF(opexe_6, "synth-create", 3, 3, 0, OP_SYNTH_CRT )
_OP_DEF(opexe_6, "synth-connect", 3, 3, 0, OP_SYNTH_CON ) _OP_DEF(opexe_6, "synth-connect", 3, 3, 0, OP_SYNTH_CON )
_OP_DEF(opexe_6, "synth-play", 4, 4, 0, OP_SYNTH_PLY ) _OP_DEF(opexe_6, "synth-play", 4, 4, 0, OP_SYNTH_PLY )
......
...@@ -4541,8 +4541,8 @@ static pointer opexe_6(scheme *sc, enum scheme_opcodes op) { ...@@ -4541,8 +4541,8 @@ static pointer opexe_6(scheme *sc, enum scheme_opcodes op) {
//////////////////// fluxa ///////////////////////////////////////// //////////////////// fluxa /////////////////////////////////////////
case OP_SYNTH_INIT: { case OP_SYNTH_INIT: {
m_alsa_device = new alsa_device(); m_alsa_device = new alsa_device(ivalue(cadr(sc->args)));
m_audio_graph = new Graph(20,48000); m_audio_graph = new Graph(ivalue(car(sc->args)),ivalue(cadr(sc->args)));
m_alsa_device->start_crank(m_audio_graph); m_alsa_device->start_crank(m_audio_graph);
s_return(sc,sc->F); s_return(sc,sc->F);
} break; } break;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment