Quantcast
Channel: beginners - openFrameworks
Viewing all articles
Browse latest Browse all 4929

ofImage from audio

$
0
0

@as1er wrote:

hello there,

trying to synthesize images from audio, can make it draw one frame, but then never updates again, i am guessing threads interweave and screw ofImage somewhere?

i am trying to use like this:

#pragma once
#include "ofMain.h"

class ofApp : public ofBaseApp{
    public:

        ofImage * image;
        ofSoundStream soundStream;
        ofMutex mutex;

            void setup(){
                image = new ofImage();
                image->allocate(512,1,OF_IMAGE_GRAYSCALE);

                soundStream.setup(this, 0, 2, 44100, 512, 4);
            }

            void update(){

            }

            void draw(){
                ofSetColor(255);
                mutex.lock();
                image->draw(0,0,250,100);
                mutex.unlock();
            }

            void audioIn(float * input, int bufferSize, int nChannels){
                mutex.lock();
                unsigned char * pix = image->getPixels();
                for (int i = 0; i < bufferSize; i++){
                    pix[i]        = (unsigned char) (ABS(input[i*2])*255.0);
                }
                image->update();

                mutex.unlock();
            }

};`

as you can see already tried to mutex the access and make the image live on the heap, even when calling ofImage.setColor results are the same, a bit lost as to why this simple code does not work.. thanks for any light

Posts: 3

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 4929

Trending Articles