Hello,

I'm writing a c++ code that reads a wav file and stores read values to a 1D array of integers. After doing some manipulation, I am able to write the values of the array to a new output wav. I use libsndfile library to do the reading and writing (sf_read & sf_write).

I then play this output wav by using Audiere library. I know the manipulation works since the sound played is the one I expect.

My question is how can I play the contents of the array without having to write it to secondary storage just to have it read again?

Thanks for your help! ^_^

Recommended Answers

All 4 Replies

Like this in the manual perhaps?

virtual OutputStream* audiere::AudioDevice::openBuffer  	(   	void *   	 samples,
		int  	frame_count,
		int  	channel_count,
		int  	sample_rate,
		SampleFormat  	sample_format
	)  	[pure virtual]
  	

Open a single buffer with the specified PCM data. This is sometimes more efficient than streaming and works on a larger variety of audio devices. In some implementations, this may download the audio data to the sound card's memory itself.

Thank you very much for that. I can now play the array. Too bad it only works for 2 channels.

Do you have any idea as to why mono wav files don't play?

AudioDevicePtr device(OpenDevice());
	OutputStreamPtr sound;
        sound = device->openBuffer(outSound, largest, sfinfo.channels, sfinfo.samplerate * 2, SF_S16);
    
        sound->play();

Sorry, just ignore the question.
I simply forgot to multiply the frame count by two.

thanks again! ^_^

Hi guys,

I saw this post, I found it very interesting. I'm trying to use the library sndfile, can someone show me hot to save the samples vector to make some processing on it? I don't get really how to use the sf_read() method.

Greetz.

Giovanni.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.