# A simple-to-use sound file writer

Steve Holden steve at holdenweb.com
Sat Jan 16 12:34:28 CET 2010

```Alf P. Steinbach wrote:
> * Grant Edwards:
>> On 2010-01-15, Steve Holden <steve at holdenweb.com> wrote:
>>
>>> I will, however, observe that your definition of a square wave is what I
>>> would have to call a "'square' wave" (and would prefer to call a "pulse
>>> train"), as I envisage a square wave as a waveform having a 50% duty
>>> cycle, as in
>>>
>>>  ___     ___
>>> |   |   |   |
>>> |   |   |   |
>>> |   |   |   |
>>> +---+---+---+---+ and so on ad infinitum, (though I might allow you
>>>     |   |   |   |                          to adjust the position
>>>     |   |   |   |                          of y=0 if you want)
>>>     |___|   |___|
>>
>> That is a square wave.
>>
>>> as opposed to your
>>>
>>>          _
>>>         | |
>>>         | |
>>>   ______| |______   ______
>>>                  | |
>>>                  | |
>>>                  |_|
>>
>> That isn't.
>>
>> Arguing to the contrary is just being Humpty Dumpty...
>
> Neither I nor Steve has called that latter wave a square wave.
>
> Steve, quoted above, has written that I defined a square wave that way.
> I have not. So Steve's statement is a misrepresentation (I described it
> as a sum of two square waves, which it is), whatever the reason for that
> misrepresentation.
>
>
>>> Or, best of all, you could show me how to synthesize any
>>> waveform by adding square waves with a 50% duty cycle.  Then I
>>> *will* be impressed.
>>
>> Isn't that what he claimed?  He said that his algorithm for
>> summing square waves demonstrated the converse of the ability
>> to construct a periodic function (like a square wave) from a
>> sine-cosine summation.
>
> Not by itself, no: it just synthesizes a sine.
>
> (single) article in this thread.
>
> For information about what the algorithm does, what you refer to as a
> "claim" (but note that a Python implementation has been posted to this
> thread, and that it works, and that besides the algorithm is trivial so
> that "claim" is a rather meaningless word here), read the article that
> you then responded to.
>
Though for what it's worth I wasn't impressed by the results of running
the posted program, since it yielded an AIFF file of mostly zeroes that
produced no audible sound.

\$ od -bc sinewave.aiff
0000000 106 117 122 115 000 002 261 076 101 111 106 106 103 117 115 115
F   O   R   M  \0 002 261   >   A   I   F   F   C   O   M   M
0000020 000 000 000 022 000 001 000 001 130 210 000 020 100 016 254 104
\0  \0  \0 022  \0 001  \0 001   X 210  \0 020   @ 016 254   D
0000040 000 000 000 000 000 000 123 123 116 104 000 002 261 030 000 000
\0  \0  \0  \0  \0  \0   S   S   N   D  \0 002 261 030  \0  \0
0000060 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000
\0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0
*
0530500 000 000 000 000 000 000
\0  \0  \0  \0  \0  \0
0530506

Any idea what I did wrong?

regards
Steve
--
Steve Holden           +1 571 484 6266   +1 800 494 3119
PyCon is coming! Atlanta, Feb 2010  http://us.pycon.org/
Holden Web LLC                 http://www.holdenweb.com/
UPCOMING EVENTS:        http://holdenweb.eventbrite.com/

```