Commit 1ab91a76 authored by Dave Griffiths's avatar Dave Griffiths
Browse files

fluxa works

parent 51d24e01
......@@ -13,6 +13,7 @@ SRCS := src/main.cpp\
src/fluxa/GraphNode.cpp\
src/fluxa/Modules.cpp\
src/fluxa/ModuleNodes.cpp\
src/audio/alsa.cpp \
src/engine/obj_reader.cpp\
src/engine/engine.cpp\
src/engine/primitive.cpp\
......@@ -25,9 +26,9 @@ SRCS := src/main.cpp\
src/engine/jellyfish.cpp
# for the minute, go out and up to link to the vision lib
CCFLAGS = -ggdb -Wall -O3 -fpermissive -ffast-math -Wno-unused -DFLX_LINUX -Isrc -DASSETS_PATH=@prefix@/lib/jellyfish/
CCFLAGS = -ggdb -O3 -fpermissive -ffast-math -Wno-unused -DFLX_LINUX -Isrc -Wno-write-strings -DASSETS_PATH=@prefix@/lib/jellyfish/
LDFLAGS =
LIBS = -lglut -lGL -lpng -lpthread -ldl -llo -ljpeg
LIBS = -lglut -lGL -lpng -lpthread -ldl -llo -ljpeg -lasound
CC = @CXX@
OBJS := ${SRCS:.cpp=.o}
......@@ -49,11 +50,11 @@ ${OBJS}: %.o: %.cpp %.dep
${DEPS}: %.dep: %.cpp Makefile
${CC} ${CCFLAGS} -MM $< > $@
clean::
-rm -f *~ src/*.o ${TARGET}
clean:: cleandeps
-rm -f *~ src/*.o src/*/*.o ${TARGET}
cleandeps:: clean
-rm -f src/*.dep
cleandeps::
-rm -f src/*.dep src/*/*.dep
install:: ${TARGET}
-cp jellyfish @prefix@/bin/
......
(display "hello")(newline)
(synth-init)
(display "init done")(newline)
(synth-create 0 2 440.0)
(synth-play 0.0 0 0.0)
(display "done")(newline)
(define op_terminal 0) (define op_sine 1) (define op_saw 2) (define op_tri 3) (define op_squ 4)
(define op_white 5) (define op_pink 6) (define op_adsr 7) (define op_add 8) (define op_sub 9)
(define op_mul 10) (define op_div 11) (define op_pow 12) (define op_mooglp 13) (define op_moogbp 14)
(define op_mooghp 15) (define op_formant 16) (define op_sample 17) (define op_crush 18)
(define op_distort 19) (define op_clip 20) (define op_echo 21) (define op_ks 22) (define op_xfade 23)
(define op_sampnhold 24) (define op_tracknhold 25) (define op_pad 26) (define op_cryptodistort 27)
(define current-id 0)
(define (new-id)
(let ((ret (+ current-id 1)))
(set! current-id ret)
ret))
(define (node id) (list "node" id))
(define (node-id n) (cadr n))
(define (node? n)
(and (list? n) (not (null? n)) (equal? (car n) "node")))
(define (get-node-id v)
(cond ((node? v)
(node-id v))
(else
(let ((id (new-id)))
(synth-create id op_TERMINAL v)
id))))
(define (make-args id operands)
(let ((index -1))
(foldl
(lambda (a l)
(set! index (+ index 1))
(append l (list (list id index (get-node-id a)))))
'()
operands)))
(define (operator op operands)
(let ((id (new-id)))
(synth-create id op 0)
(map (lambda (l) (apply synth-connect l)) (make-args id operands))
(node id)))
(define (play-now node pan) (synth-play 0 (node-id node) pan))
(define (sine a) (operator op_sine (list a)))
(define (saw a) (operator op_saw (list a)))
(define (tri a) (operator op_tri (list a)))
(define (squ a) (operator op_squ (list a)))
(define (white a) (operator op_white (list a)))
(define (pink a) (operator op_pink (list a)))
(define (add a b) (operator op_add (list a b)))
(define (sub a b) (operator op_sub (list a b)))
(define (mul a b) (operator op_mul (list a b)))
(define (div a b) (operator op_div (list a b)))
(define (pow a b) (operator op_pow (list a b)))
(define (adsr a d s r) (operator op_adsr (list a d s r)))
(define (mooglp in c r) (operator op_mooglp (list in c r)))
(define (moogbp in c r) (operator op_moogbp (list in c r)))
(define (mooghp in c r) (operator op_mooghp (list in c r)))
(define (formant in c r) (operator op_formant (list in c r)))
(define (crush in freq bits) (operator op_crush (list in bits freq)))
(define (distort in amount) (operator op_distort (list in amount)))
(define (klip in amount) (operator op_clip (list in amount)))
(define (echo in delaytime feedback) (operator op_echo (list in delaytime feedback)))
(define (ks freq cutoff resonance) (operator op_ks (list freq cutoff resonance)))
(define (xfade s0 s1 mix) (operator op_xfade (list s0 s1 mix)))
(define (s&h sig cv) (operator op_sampnhold (list sig cv)))
(define (t&h sig cv) (operator op_tracknhold (list sig cv)))
(define (pad a g c r) (operator op_pad (list a g c r)))
(synth-init)
(play-now (mul
5
(echo
(mul (adsr 0 1 0 0)
(sine (add 40 (mul (sine 800)
(mul (sine 3) 1000)))))
0.1 0.9)) 0)(newline)
#include "alsa.h"
#include <pthread.h>
#include <iostream>
using namespace std;
alsa_device::alsa_device() {
int i;
int err;
short buf[128];
snd_pcm_hw_params_t *hw_params;
if ((err = snd_pcm_open (&playback_handle, "hw:0,0", SND_PCM_STREAM_PLAYBACK, 0)) < 0) {
fprintf (stderr, "cannot open audio device %s (%s)\n",
"hw:0,0",
snd_strerror (err));
exit (1);
}
if ((err = snd_pcm_hw_params_malloc (&hw_params)) < 0) {
fprintf (stderr, "cannot allocate hardware parameter structure (%s)\n",
snd_strerror (err));
exit (1);
}
if ((err = snd_pcm_hw_params_any (playback_handle, hw_params)) < 0) {
fprintf (stderr, "cannot initialize hardware parameter structure (%s)\n",
snd_strerror (err));
exit (1);
}
if ((err = snd_pcm_hw_params_set_access (playback_handle, hw_params, SND_PCM_ACCESS_RW_INTERLEAVED)) < 0) {
fprintf (stderr, "cannot set access type (%s)\n",
snd_strerror (err));
exit (1);
}
if ((err = snd_pcm_hw_params_set_format (playback_handle, hw_params, SND_PCM_FORMAT_S16_LE)) < 0) {
fprintf (stderr, "cannot set sample format (%s)\n",
snd_strerror (err));
exit (1);
}
/*
if ((err = snd_pcm_hw_params_set_rate_near (playback_handle, hw_params, 48000, 0)) < 0) {
fprintf (stderr, "cannot set sample rate (%s)\n",
snd_strerror (err));
exit (1);
if ((err = snd_pcm_open(&playback_handle, "hw:0,0", SND_PCM_STREAM_PLAYBACK, 0)) < 0) {
printf("Playback open error: %s\n", snd_strerror(err));
exit(EXIT_FAILURE);
}
if ((err = snd_pcm_set_params(playback_handle,
SND_PCM_FORMAT_S16_LE,
SND_PCM_ACCESS_RW_INTERLEAVED,
2,
48000,
1,
500000)) < 0) { /* 0.5sec */
printf("Playback open error: %s\n", snd_strerror(err));
exit(EXIT_FAILURE);
}
*/
if ((err = snd_pcm_hw_params_set_channels (playback_handle, hw_params, 2)) < 0) {
fprintf (stderr, "cannot set channel count (%s)\n",
snd_strerror (err));
exit (1);
}
if ((err = snd_pcm_hw_params (playback_handle, hw_params)) < 0) {
fprintf (stderr, "cannot set parameters (%s)\n",
snd_strerror (err));
exit (1);
}
snd_pcm_hw_params_free (hw_params);
if ((err = snd_pcm_prepare (playback_handle)) < 0) {
fprintf (stderr, "cannot prepare audio interface for use (%s)\n",
snd_strerror (err));
exit (1);
}
}
alsa_device::~alsa_device() {
snd_pcm_close (playback_handle);
}
void alsa_device::play(short* buf, size_t length) {
int err;
if ((err = snd_pcm_writei (playback_handle, buf, length)) != length) {
fprintf (stderr, "write to audio interface failed (%s)\n",
snd_strerror (err));
exit (1);
}
#define AUDIO_BUFSIZE 4096
void audio_loop(void *c) {
alsa_device *a=(alsa_device *)c;
Graph *g = a->m_graph;
Sample *left = new Sample(AUDIO_BUFSIZE);
Sample *right = new Sample(AUDIO_BUFSIZE);
short *data = new short(AUDIO_BUFSIZE*2);
do {
left->Zero();
right->Zero();
g->Process(AUDIO_BUFSIZE, *left, *right);
unsigned int pos=0;
for (unsigned int i=0; i<AUDIO_BUFSIZE*2; i+=2)
{
data[i]=(short)((*left)[pos++]*3276);
}
pos=0;
for (unsigned int i=1; i<AUDIO_BUFSIZE*2; i+=2)
{
data[i]=(short)((*right)[pos++]*3276);
}
a->play(AUDIO_BUFSIZE, data);
} while(1);
}
void alsa_device::start_crank(Graph *g)
{
m_graph=g;
pthread_t *audio_thread = new pthread_t;
pthread_create(audio_thread,NULL,(void*(*)(void*))audio_loop,this);
}
void alsa_device::play(size_t length, short* buf) {
int frames;
frames = snd_pcm_writei(playback_handle, buf, length);
if (frames < 0)
frames = snd_pcm_recover(playback_handle, frames, 0);
if (frames < 0) {
printf("snd_pcm_writei failed: %s\n", snd_strerror(frames));
}
if (frames > 0 && frames < (long)length)
printf("Short write (expected %li, wrote %li)\n", (long)length, frames);
}
......@@ -3,13 +3,18 @@
#include <alsa/asoundlib.h>
#include <limits.h>
class alsa_device {
#include <fluxa/Graph.h>
class alsa_device {
public:
alsa_device();
~alsa_device();
void play(short* buf, size_t length);
void start_crank(Graph *g);
void play(size_t length, short* buf);
Graph *m_graph;
private:
snd_pcm_t *playback_handle;
};
db.o: core/db.cpp core/db.h sqlite/sqlite3.h core/list.h core/types.h \
core/fixed.h core/list.h
db_container.o: core/db_container.cpp core/db_container.h core/db.h \
sqlite/sqlite3.h core/list.h core/types.h core/fixed.h core/list.h
fixed.o: src/core/fixed.cpp src/core/fixed.h
geometry.o: src/core/geometry.cpp src/core/types.h src/core/fixed.h \
src/core/list.h src/core/geometry.h src/core/vec3.h src/core/pdata.h
idmap.o: src/core/idmap.cpp src/core/idmap.h src/core/types.h \
src/core/fixed.h src/core/list.h
list.o: src/core/list.cpp src/core/list.h src/core/types.h \
src/core/fixed.h
noise.o: src/core/noise.cpp src/core/noise.h
engine.o: src/engine/engine.cpp src/engine/engine.h \
src/engine/scenegraph.h src/engine/scenenode.h src/engine/../core/list.h \
src/engine/../core/types.h src/engine/../core/fixed.h \
src/engine/../core/list.h src/engine/../core/mat44.h \
src/engine/../core/vec3.h src/engine/primitive.h src/engine/importgl.h \
src/engine/../core/fixed.h src/engine/../core/vec3.h \
src/engine/../core/pdata.h src/engine/texture.h \
src/engine/text_primitive.h src/core/fixed.h \
src/engine/jellyfish_primitive.h src/engine/primitive.h \
src/fluxa/Graph.h src/fluxa/GraphNode.h src/fluxa/Sample.h \
src/fluxa/Types.h src/fluxa/Allocator.h src/fluxa/ModuleNodes.h \
src/fluxa/Modules.h src/engine/obj_reader.h src/core/vec3.h \
src/core/types.h src/core/fixed.h
jellyfish_primitive.o: src/engine/jellyfish_primitive.cpp \
src/engine/jellyfish_primitive.h src/engine/primitive.h \
src/engine/importgl.h src/engine/../core/fixed.h \
src/engine/../core/list.h src/engine/../core/types.h \
src/engine/../core/fixed.h src/engine/../core/list.h \
src/engine/../core/vec3.h src/engine/../core/mat44.h \
src/engine/../core/vec3.h src/engine/../core/pdata.h \
src/engine/../core/geometry.h src/engine/../engine/scenenode.h \
src/engine/../engine/../core/list.h src/engine/../engine/../core/types.h \
src/engine/../engine/../core/fixed.h \
src/engine/../engine/../core/mat44.h src/engine/../engine/../core/vec3.h \
src/engine/../engine/primitive.h src/engine/../engine/importgl.h \
src/engine/../engine/../core/fixed.h src/engine/../engine/../core/vec3.h \
src/engine/../engine/../core/pdata.h src/engine/../engine/../core/list.h \
src/engine/../core/msg.h src/engine/jellyfish.h \
src/engine/../core/types.h src/engine/../fluxa/Graph.h \
src/engine/../fluxa/GraphNode.h src/engine/../fluxa/Sample.h \
src/engine/../fluxa/Types.h src/engine/../fluxa/Allocator.h \
src/engine/../fluxa/ModuleNodes.h src/engine/../fluxa/Modules.h
nomadic.o: src/engine/nomadic.cpp src/engine/importgl.h src/app.h \
src/engine/engine.h src/engine/scenegraph.h src/engine/scenenode.h \
src/engine/../core/list.h src/engine/../core/types.h \
src/engine/../core/fixed.h src/engine/../core/list.h \
src/engine/../core/mat44.h src/engine/../core/vec3.h \
src/engine/primitive.h src/engine/../core/fixed.h \
src/engine/../core/vec3.h src/engine/../core/pdata.h \
src/engine/texture.h src/scheme/scheme.h
obj_reader.o: src/engine/obj_reader.cpp src/engine/obj_reader.h \
src/core/vec3.h src/core/types.h src/core/fixed.h src/core/list.h
primitive.o: src/engine/primitive.cpp src/engine/primitive.h \
src/engine/importgl.h src/engine/../core/fixed.h \
src/engine/../core/list.h src/engine/../core/types.h \
src/engine/../core/fixed.h src/engine/../core/list.h \
src/engine/../core/vec3.h src/engine/../core/mat44.h \
src/engine/../core/vec3.h src/engine/../core/pdata.h \
src/engine/../core/geometry.h src/engine/../engine/scenenode.h \
src/engine/../engine/../core/list.h src/engine/../engine/../core/types.h \
src/engine/../engine/../core/fixed.h \
src/engine/../engine/../core/mat44.h src/engine/../engine/../core/vec3.h \
src/engine/../engine/primitive.h src/engine/../engine/importgl.h \
src/engine/../engine/../core/fixed.h src/engine/../engine/../core/vec3.h \
src/engine/../engine/../core/pdata.h src/engine/../engine/../core/list.h \
src/engine/cube.h
scenegraph.o: src/engine/scenegraph.cpp src/engine/scenegraph.h \
src/engine/scenenode.h src/engine/../core/list.h \
src/engine/../core/types.h src/engine/../core/fixed.h \
src/engine/../core/list.h src/engine/../core/mat44.h \
src/engine/../core/vec3.h src/engine/primitive.h src/engine/importgl.h \
src/engine/../core/fixed.h src/engine/../core/vec3.h \
src/engine/../core/pdata.h src/engine/texture.h
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