Commit 51d24e01 authored by dave griffiths's avatar dave griffiths
Browse files

fluxa work

parent e8f3e42e
target = 'jellyfish'
platform = ARGUMENTS.get('TARGET','LINUX')
env = Environment(CCFLAGS='-O3 -std=gnu++0x -ggdb -DUSE_MATH=1 -Wno-write-strings')
source = ['main.cpp',
'core/fixed.cpp',
'core/list.cpp',
'core/idmap.cpp',
'scheme/scheme.cpp',
'core/geometry.cpp',
'core/noise.cpp',
'fluxa/Sample.cpp',
'fluxa/Allocator.cpp',
'fluxa/Graph.cpp',
'fluxa/GraphNode.cpp',
'fluxa/Modules.cpp',
'fluxa/ModuleNodes.cpp',
'engine/obj_reader.cpp',
'engine/engine.cpp',
'engine/primitive.cpp',
'engine/text_primitive.cpp',
'engine/scenegraph.cpp',
'engine/scenenode.cpp',
'engine/texture.cpp',
'engine/nomadic.cpp',
'engine/jellyfish_primitive.cpp',
'engine/jellyfish.cpp'
source = ['src/main.cpp',
'src/audio/alsa.cpp',
'src/core/fixed.cpp',
'src/core/list.cpp',
'src/core/idmap.cpp',
'src/scheme/scheme.cpp',
'src/core/geometry.cpp',
'src/core/noise.cpp',
'src/fluxa/Sample.cpp',
'src/fluxa/Allocator.cpp',
'src/fluxa/Graph.cpp',
'src/fluxa/GraphNode.cpp',
'src/fluxa/Modules.cpp',
'src/fluxa/ModuleNodes.cpp',
'src/engine/obj_reader.cpp',
'src/engine/engine.cpp',
'src/engine/primitive.cpp',
'src/engine/text_primitive.cpp',
'src/engine/scenegraph.cpp',
'src/engine/scenenode.cpp',
'src/engine/texture.cpp',
'src/engine/nomadic.cpp',
'src/engine/jellyfish_primitive.cpp',
'src/engine/jellyfish.cpp'
]
if platform=='LINUX':
......@@ -36,11 +37,11 @@ if platform=='LINUX':
if platform=='RPI':
# raspberry pi
env.Append(LIBS = ['GLESv1_CM', 'EGL', 'bcm_host', 'X11', 'png', 'lo', 'jpeg'])
env.Append(LIBS = ['GLESv1_CM', 'EGL', 'bcm_host', 'X11', 'png', 'lo', 'asound'])
env.Append(CCFLAGS=' -DFLX_RPI -fpermissive')
env.Append(CPPPATH = '/opt/vc/include/interface/vcos/pthreads/:/opt/vc/include/interface/vmcs_host/linux:/opt/vc/include/:.')
env.Append(CPPPATH = '/opt/vc/include/interface/vcos/pthreads/:/opt/vc/include/interface/vmcs_host/linux:/opt/vc/include/:.:src/')
env.Append(LIBPATH = '/opt/vc/lib')
source.append(['rpi/input.cpp'])
source.append(['src/rpi/input.cpp'])
env.Program(target=target, source=source)
(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)
#include <stdio.h>
#include <stdlib.h>
#include <alsa/asoundlib.h>
#include <limits.h>
#include <../Fluxa/Graph.h>
main (int argc, char *argv[])
{
Graph g;
int i;
int err;
short buf[128];
snd_pcm_t *playback_handle;
snd_pcm_hw_params_t *hw_params;
if ((err = snd_pcm_open (&playback_handle, argv[1], SND_PCM_STREAM_PLAYBACK, 0)) < 0) {
fprintf (stderr, "cannot open audio device %s (%s)\n",
argv[1],
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);
}
fprintf (stderr, "here\n");
/*
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);
}
*/
fprintf (stderr, "there\n");
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);
}
for (i = 0; i<128; i++) {
buf[i]=rand()%SHRT_MAX;
}
for (i = 0; i < 100; ++i) {
if ((err = snd_pcm_writei (playback_handle, buf, 128)) != 128) {
fprintf (stderr, "write to audio interface failed (%s)\n",
snd_strerror (err));
exit (1);
}
}
snd_pcm_close (playback_handle);
exit (0);
}
#include "alsa.h"
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_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);
}
}
#include "alsa.h"
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_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) {
if ((err = snd_pcm_writei (playback_handle, buf, length)) != length) {
fprintf (stderr, "write to audio interface failed (%s)\n",
snd_strerror (err));
exit (1);
}
}
#include <stdio.h>
#include <stdlib.h>
#include <alsa/asoundlib.h>
#include <limits.h>
main (int argc, char *argv[])
{
int i;
int err;
short buf[128];
snd_pcm_t *playback_handle;
snd_pcm_hw_params_t *hw_params;
if ((err = snd_pcm_open (&playback_handle, argv[1], SND_PCM_STREAM_PLAYBACK, 0)) < 0) {
fprintf (stderr, "cannot open audio device %s (%s)\n",
argv[1],
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);
}
fprintf (stderr, "here\n");
/*
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);
}
*/
fprintf (stderr, "there\n");
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);
}
for (i = 0; i<128; i++) {
buf[i]=rand()%SHRT_MAX;
}
for (i = 0; i < 100; ++i) {
if ((err = snd_pcm_writei (playback_handle, buf, 128)) != 128) {
fprintf (stderr, "write to audio interface failed (%s)\n",
snd_strerror (err));
exit (1);
}
}
snd_pcm_close (playback_handle);
exit (0);
}
#include <stdio.h>
#include <stdlib.h>
#include <alsa/asoundlib.h>
#include <limits.h>
class alsa_device {
alsa_device();
~alsa_device();
void play(short* buf, size_t length);
private:
snd_pcm_t *playback_handle;
};
#include <stdio.h>
#include <stdlib.h>
#include <alsa/asoundlib.h>
#include <limits.h>
class alsa_device {
alsa_device();
~alsa_device();
void alsa_device::play(short* buf, size_t length);
private:
snd_pcm_t *playback_handle;
};
......@@ -17,7 +17,6 @@
#include "engine.h"
#include "text_primitive.h"
#include "jellyfish_primitive.h"
#include "fluxa/Graph.h"
#include "obj_reader.h"
#ifdef _EE
......@@ -53,7 +52,6 @@ engine::engine()
clear();
m_attached_prim = NULL;
m_attached_id = 0;
m_audio_graph = new Graph(70,16000);
}
engine::~engine()
......
......@@ -16,8 +16,6 @@
#include "scenegraph.h"
class Graph;
#ifndef FLX_ENGINE
#define FLX_ENGINE
......@@ -89,8 +87,6 @@ public:
float m_clear_r,m_clear_g,m_clear_b,m_clear_a;
Graph *get_audio_graph() { return m_audio_graph; }
private:
list m_state_stack;
......@@ -124,7 +120,6 @@ private:
static engine *m_engine;
scenegraph *m_sg;
Graph *m_audio_graph;
unsigned int m_screen_width;
unsigned int m_screen_height;
// camera attached to primitive...
......
......@@ -27,7 +27,6 @@ jellyfish::jellyfish(vec3 *heap_ptr, u32 heap_size) :
m_heap_size(heap_size)
{
m_instruction = new bool[m_heap_size];
m_audio_graph = engine::get()->get_audio_graph();
for (u32 n=0; n<m_heap_size; n++)
{
......@@ -273,7 +272,7 @@ void jellyfish::run()
push(vec3(n,n,n));
} break;
case SYNTH_CRT:
/* case SYNTH_CRT:
{
vec3 v=pop();
m_audio_graph->Create((int)v.x, (Graph::Type)((int)v.y), v.z);
......@@ -287,7 +286,7 @@ void jellyfish::run()
{
vec3 v=pop();
m_audio_graph->Play(v.x, (int)v.y, v.z);
} break;
} break;*/
case FLR:
{ vec3 t=pop(); push(vec3(floor((float)t.x),
floor((float)t.y),
......
jellyfish.o: src/engine/jellyfish.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/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 \
src/core/msg.h src/core/noise.h
......@@ -30,9 +30,10 @@ m_MaxPlaying(10),
m_NumNodes(NumNodes),
m_SampleRate(SampleRate)
{
Init();
m_Mutex = new pthread_mutex_t;
pthread_mutex_init(m_Mutex,NULL);
cerr<<"Creating a graph: "<<this<<endl;
Init();
m_Mutex = new pthread_mutex_t;
pthread_mutex_init(m_Mutex,NULL);
}
......@@ -50,7 +51,8 @@ void Graph::Init()
unsigned int count=m_NumNodes;
if (type==TERMINAL) count=2000;
if (type==TERMINAL) count=20;
count=10;
for(unsigned int n=0; n<count; n++)
{
......
......@@ -72,7 +72,7 @@ private:
};
unsigned int m_MaxPlaying;
std::list<pair<unsigned int, float> > m_RootNodes;
std::list<pair<unsigned int, float> > m_RootNodes;
map<unsigned int,GraphNode*> m_NodeMap;
map<Type,NodeDescVec*> m_NodeDescMap;
unsigned int m_NumNodes;
......
......@@ -17,6 +17,7 @@
#include "Modules.h"
#include <stdlib.h>
#include <math.h>
#include <iostream>
using namespace std;
......@@ -123,6 +124,7 @@ void WaveTable::Reset()
void WaveTable::WriteWaves()
{
cerr<<"writing waves"<<endl;
for (int n=0; n<NUM_TABLES; n++)
{
m_Table[n].Allocate(m_TableLength);
......@@ -198,6 +200,8 @@ void WaveTable::WriteWaves()
if (n<m_TableLength/1.5) m_Table[PULSE2].Set(n,1);
else m_Table[PULSE2].Set(n,-1);
}
cerr<<"written waves"<<endl;
}
void WaveTable::Trigger(float time, float pitch, float slidepitch, float vol)
......
......@@ -23,10 +23,12 @@
#include <png.h>
#include <pthread.h>
#ifdef USE_JPGLIB
extern "C"
{
#include <jpeglib.h>
}
#endif
#include <lo/lo.h>
......@@ -187,6 +189,8 @@ unsigned char* LoadPNG(const string filename,long &width, long &height)
return data;
}
#ifdef USE_JPGLIB
int WriteJPG(GLubyte *image, const char *filename, const char *description, int x, int y, int width, int height, int quality, int super)
{
struct jpeg_compress_struct cinfo;
......@@ -232,6 +236,7 @@ int WriteJPG(GLubyte *image, const char *filename, const char *description, int
return 0;
}