I wrote a program in windows that will play binary audio sent to it over stdin, I called it aplay(like the linux program). I then wrote a seperate program as follows
FILE * f = popen("aplay.exe", "wb");
FILE * song = fopen("C:/Users/Ray/Dropbox/DJ Automica 2/Debug/raymonster 5.wav", "rb");
while(1)
{
byte buff[4096];
fread(buff, 4, 1024, song);
fwrite(buff, 4, 1024, f);
}
For some reason, the pipe doesn't seem to be working in binary mode, because the audio is coming out all messed up. If I change my aplay to open the wave file by itself in text mode it sounds the same as when I do it through the pipe, if I open the wave file in binary mode it plays perfectly. Does anyone know how I can fix this?
If you include the header files
#include <fcntl.h>
#include <io.h>
you can switch modes with
_setmode(_fileno(stdin), _O_BINARY);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With