I am mixing two wave files by using JUCE library, and writing to a file with AudioFormatWriter.
Now I want to redirect the mix to console, so how can I use AudioFormatWriter to write the mixed data onto console? how can I assign console path to the AudioFormatWriter?
Thanks for your time!
console as in terminal/output or as in mixing console in the studio ?
I want the mix to be display on the stdout.
As we can write it to file i want to write it on the stdout
you could try opening a file /dev/console on linux that shoud work
Thanks for your reply!!!
I have some other questions:
Can I redirect the result on /dev/console to a file for example:
$> xyz.exe > out.wav
Where xyz.exe is a application, which writes mixed output on the /dev/console, by using redirection I want to write the information into a file.
/dev/console is for Linux platform, what can I use if I want to write the mix file output on stdout on Windows platform?
i don’t know what will happen if you write to /dev/console and then do > file i guess it could work.
the question is for jules, can you pass STDIN/STDOUT constants available on those platforms to File() constructor, i really don’t know. If you can somehow then that will be it (0,1 are numeric values for in/out).
Thanks you very much Atom for your reply!!!
Can you please help me?
just a quick idea, write a small OutputStream class of your own, and instead of using File() to handle the streams, write/read using fopen() fwrite()/fread() those are supported on all 3 platforms that JUCE runs on, i guess this might be a little againt the whole idea of juce, but sometimes tricks like that are necessary.
i noticed that low-level printf() works with JUCE so you can use that too.
Yes - atom’s post is definitely the best way to do it, there are no built-in streams to push things to stdout.
Hi atom, jules,
Thanks for your reply!!!
Yes I am trying that, but I have one question,
How could i write the format specific header according to the mix output?
i.e. if I am mixing 2 wav files then i need to write the wave file header on to the stdout.
Currently i could able to write the the mix result but not the header.
So how could i get the header info?
well i don’t think it’s possible in juce, from what i see there is no access to those parts of the stream.
so either look info juce code and write a copy of WavAudioFormat with access to those parts, or look into: http://www.sonicspot.com/guide/wavefiles.html and write a header yourself it’s really simple just a few fields to describe the data stream inside. some time ago i chose to write it myslef it didn’t take very long, windows has built-in support for this http://msdn.microsoft.com/en-us/library/ms712636(VS.85).aspx and for linux/windows there is libsndfile.
Thank you for reply!
I tried as you suggested to write a small class. I have created one StandardOut class and it has handle to stdout, I used fwrite() to write to stdout, and copied the required portion from WavAudioFormat to write the header as well as the mixed data to stdout.
Still the outcome is not the perfect mix compare to writing the mix directly to file, the output is smaller and it sounds really very bad.
Please suggest me!
Thanks once again for your time!
there are many isuues when writing to stdout.
first of all it has to be open with +b flag (binary), other then that all samples should be written to stdout normally. i don’t see any way that quality could be compromised.
Actually, I don’t think it’s possible - to write a wav file, it first writes the data, leaving the header blank because it doesn’t know the total length until it’s finished. After you close it, it skips back and overwrites the header block with the final info. Obviously that ain’t gonna work on stdout.
Maybe just write it to a MemoryBlockOutputStream and use the data when it’s done.
well i assumed theat the structure and data is ready in memory, and the only problem is getting it out, like jules said you need to make sure that the header comes first and then the data chunk, and if any chunks are behind the data chunk (it’s possible with some smpl, cue chunks) make sure that you don’t miss them.
Hi Atom, Jules
Thanks for your help!!!
Yes I have implemented the logic of writing wav to stdout with your help.
Now I am trying the same with mp3, can you help me on that, too?
Thanks once again!
Surely it’s irrelevent whether it’s a wav/mp3 or any other format…?
juce does not support mp3 (and thats very good) enc/dec-oding. you’ll need to find some 3rd party library to do mp3s.