二进制模式的 Windows 管道 [英] Windows pipes in binary mode

查看:64
本文介绍了二进制模式的 Windows 管道的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Windows 中编写了一个程序,该程序将播放通过标准输入发送给它的二进制音频,我称之为 aplay(就像 linux 程序).然后我写了一个单独的程序如下

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);
}

出于某种原因,管道似乎没有在二进制模式下工作,因为音频出来的时候一团糟.如果我更改我的 aplay 以在文本模式下自行打开波形文件,它听起来与我通过管道打开波形文件时相同,如果我以二进制模式打开波形文件,它会完美播放.有谁知道我该如何解决这个问题?

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?

推荐答案

如果包含头文件

#include <fcntl.h>
#include <io.h>

你可以用

_setmode(_fileno(stdin), _O_BINARY);

这篇关于二进制模式的 Windows 管道的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆