# AudioFormatWriter bug?

**URL:** <https://forum.juce.com/t/audioformatwriter-bug/4186>\
**Category:** General JUCE discussion\
**Created:** [August 18, 2009, 4:32pm UTC](https://forum.juce.com/t/audioformatwriter-bug/4186 "2009-08-18T16:32:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![snortblt](https://avatars.discourse-cdn.com/v4/letter/s/c68b51/32.png) [@snortblt](https://forum.juce.com/u/snortblt)\
**Post date:** [August 18, 2009, 4:32pm UTC](https://forum.juce.com/t/audioformatwriter-bug/4186/1 "2009-08-18T16:32:14Z")

</div>

It appears that AudioFormatWriter::writeFromAudioReader has a bug. The documentation says:

> [@](#):
>
> If numSamplesToRead \< 0, it will write the entire length of the reader.

At least with a wave file reader and writer combo, this appears to fail, producing an empty (headers only) file. Passing any positive value for numSamplesToRead works as expected.

Looks like it just needs a:

`if (numSamplesToRead < 0)
    numSamplesToRead = reader.lengthInSamples;`

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [August 18, 2009, 7:30pm UTC](https://forum.juce.com/t/audioformatwriter-bug/4186/2 "2009-08-18T19:30:56Z")

</div>

But line 404 of juce\_AudioFormat.cpp does exactly what you’re suggesting… Are you looking at an old version of the codebase?

---

<div class="post-metadata">

**Author:** ![snortblt](https://avatars.discourse-cdn.com/v4/letter/s/c68b51/32.png) [@snortblt](https://forum.juce.com/u/snortblt)\
**Post date:** [August 19, 2009, 3:16pm UTC](https://forum.juce.com/t/audioformatwriter-bug/4186/3 "2009-08-19T15:16:39Z")

</div>

Yep. I was working from 1.46 or shortly thereafter. I see the fix in 1.5. Thanks.
