我正在尝试使用scalaz iteratee包来处理恒定空间中的大型zip文件.我需要对zip文件中的每个文件执行一个长时间运行的进程.这些过程可以(并且应该)并行运行.
我创建了一个EnumeratorT将每个膨胀ZipEntry成一个File对象.签名如下:
def enumZipFile(f:File):EnumeratorT[IoExceptionOr[IO[File]], IO]
Run Code Online (Sandbox Code Playgroud)
我想附加一个IterateeT将在每个文件上执行长时间运行的进程.我基本上最终得到了类似的东西:
type IOE[A] = IoExceptionOr[A]
def action(f:File):IO[List[Promise[IOE[File]]]] = (
consume[Promise[IOE[File]], IO, List] %=
map[IOE[File], Promise[IOE[File]], IO](longRunningProcess) %=
map[IOE[IO[File]], IOE[File], IO](_.unsafePerformIO) &=
enumZipFile(f)
).run
def longRunningProcess:(iof:IOE[File]):Promise[IOE[File]] =
Promise { Thread.sleep(5000); iof }
Run Code Online (Sandbox Code Playgroud)
当我尝试运行它时:
action(new File("/really/big/file.zip")).unsafePerformIO.sequence.get
Run Code Online (Sandbox Code Playgroud)
我收到一条java.lang.OutOfMemoryError: Java heap space消息.这对我来说很有意义,因为它试图在所有这些IO和Promise对象的内存中建立一个庞大的列表.
几个问题:
longRunningProcess它的副作用.Enumerator方法是错误的方法吗?我几乎没有想法,所以任何事情都会有所帮助.
谢谢!
更新#1
这是堆栈跟踪:
[error] java.lang.OutOfMemoryError: Java heap space
[error] at scalaz.Free.flatMap(Free.scala:46)
[error] at scalaz.effect.IO$$anonfun$flatMap$1.apply(IO.scala:62) …Run Code Online (Sandbox Code Playgroud) 我试图在AS3中将8000hz,16位wav文件上采样到11025hz.在这一点上,我并不关心应用我知道最终需要的低通滤波器.
我一直在引用这个wiki页面.
这是我到目前为止所做的:
然而,当我去玩新的wav时,它是难以区分的噪音.这是我的代码:
const sourceRate:uint = 8000;
const targetRate:uint = 11025;
var lcm:uint = lcm(targetRate, sourceRate); // = 3528000
var l:uint = lcm / sourceRate; // = 441
var m:uint = lcm / targetRate; // = 320
// upsample by factor of l
var upsampleData:ByteArray = new ByteArray();
upsampleData.endian = Endian.LITTLE_ENDIAN;
// originalWavData is a ByteArray of the source wav data
// fill is a ByteArray that contains 440 zeroes, written using …Run Code Online (Sandbox Code Playgroud)